Datasets:

Modalities:
Image
Size:
< 1K
Libraries:
Datasets
License:
derek-thomas commited on
Commit
38bc440
·
verified ·
1 Parent(s): 9dea51c

Upload blog/multi-lora-serving/multi-lora-serving-pattern.ipynb with huggingface_hub

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