{ "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 }