File size: 5,726 Bytes
38bc440 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "3b26d339-8e2d-4f7e-8dbf-24c649932de4",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"source": [
"%pip install -q huggingface-hub plotly numpy"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b7aebf99-b8fb-4892-90e2-2261202ac576",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import plotly.graph_objects as go\n",
"import numpy as np\n",
"\n",
"# Setting the time scale\n",
"time = np.arange(0, 24, 0.1) # 24 hours, in increments of 0.1 hour\n",
"\n",
"# Generating usage patterns\n",
"np.random.seed(42)\n",
"low_usage = (np.random.poisson(70, len(time)) * (np.random.rand(len(time)) < 0.15).astype(int))//2 \n",
"bursty_usage = np.random.poisson(70, len(time)) * (np.random.rand(len(time)) < 0.15).astype(int)\n",
"bursty_usage = np.random.poisson(100, len(time)) * (np.random.rand(len(time)) < 0.2).astype(int)//1.4\n",
"\n",
"high_volume = np.random.normal(loc=15, scale=2, size=len(time))*1.75\n",
"\n",
"# Applying smoothing\n",
"smooth_low_usage = np.convolve(low_usage, np.ones(50)/50, mode='same')\n",
"smooth_bursty_usage = np.convolve(bursty_usage, np.ones(50)/50, mode='same')\n",
"smooth_high_volume = np.convolve(high_volume, np.ones(50)/50, mode='same')\n",
"total_usage = smooth_low_usage + smooth_bursty_usage + smooth_high_volume\n",
"\n",
"# Plotting using Plotly\n",
"fig = go.Figure()\n",
"fig.add_trace(go.Scatter(x=time, y=smooth_low_usage, mode='lines', name='Low Usage', line=dict(color='#B0C4DE'))) # Light Steel Blue\n",
"fig.add_trace(go.Scatter(x=time, y=smooth_bursty_usage, mode='lines', name='Bursty Usage', line=dict(color='#FFB6C1'))) # Light Pink\n",
"fig.add_trace(go.Scatter(x=time, y=smooth_high_volume, mode='lines', name='High Volume', line=dict(color='#98FB98'))) # Pale Green\n",
"fig.add_trace(go.Scatter(x=time, y=total_usage, mode='lines', name='Total Usage', line=dict(color='#2F4F4F', width=3))) # Dark Slate Gray\n",
"\n",
"fig.update_layout(\n",
" title={\n",
" 'text': 'Comparison of Usage Models and Total Impact',\n",
" 'y': 0.9,\n",
" 'x': 0.5,\n",
" 'xanchor': 'center',\n",
" 'yanchor': 'top',\n",
" 'font': {\n",
" 'size': 24 # Adjust the font size as needed\n",
" }\n",
" },\n",
" xaxis_title='Time (hours)',\n",
" yaxis_title='Requests',\n",
" legend_title='Usage Pattern',\n",
" xaxis=dict(\n",
" title_font_size=28, # Larger axis title font size\n",
" tickfont_size=16 # Larger tick label font size\n",
" ),\n",
" yaxis=dict(\n",
" title_font_size=28, # Larger axis title font size\n",
" tickfont_size=16 # Larger tick label font size\n",
" ),\n",
" legend=dict(\n",
" x=0.5, # Horizontal position, 0 is left\n",
" y=-0.1, # Vertical position, negative values to move it down\n",
" orientation=\"h\", # Horizontal layout\n",
" xanchor='center', # Anchor the legend at the center\n",
" yanchor='top' # Anchor the legend at the top\n",
" ),\n",
" template='plotly_white'\n",
")\n",
"\n",
"\n",
"fig.show()\n"
]
},
{
"cell_type": "markdown",
"id": "fc54b448-2eb3-44cc-8304-983e27138296",
"metadata": {},
"source": [
"# Push Image"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4ef615e2-ab36-43f1-b310-cac8b17d29b7",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"image_out = \"multi-lora-serving-pattern.png\"\n",
"fig.write_image(image_out, width=1920, height=1080, scale=2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "13d8ee16-65ec-4a32-84e9-e6b99aab92af",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"from huggingface_hub import HfApi\n",
"\n",
"api = HfApi()\n",
"api.upload_file(\n",
" path_or_fileobj=image_out,\n",
" path_in_repo=f\"blog/multi-lora-serving/{image_out}\",\n",
" repo_id=\"huggingface/documentation-images\",\n",
" repo_type=\"dataset\",\n",
" commit_message=\"Updating title\",\n",
")"
]
},
{
"cell_type": "markdown",
"id": "81e6b86b-c439-4acd-a072-2ef3ab782f90",
"metadata": {},
"source": [
"# Push Notebook"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "adca7ec0-25c3-42e3-84b7-f7f9342e4e4f",
"metadata": {},
"outputs": [],
"source": [
"from huggingface_hub import HfApi\n",
"\n",
"api = HfApi()\n",
"api.upload_file(\n",
" path_or_fileobj=\"multi-lora-serving-pattern.ipynb\",\n",
" path_in_repo=\"blog/multi-lora-serving/multi-lora-serving-pattern.ipynb\",\n",
" repo_id=\"huggingface/documentation-images\",\n",
" repo_type=\"dataset\",\n",
")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.14"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|