Last active
October 31, 2025 11:53
-
-
Save WaterKnight1998/9a714e62665d151f7620948756c193cb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import subprocess | |
| from modal import App, Image, Volume, is_local, web_server, concurrent | |
| app = App("Scratch-to-Scale") | |
| CACHE_DIR = "/cache" | |
| VSCODE_VERSION = "1.104.1" | |
| image = ( | |
| Image.debian_slim(python_version="3.11") | |
| .uv_pip_install( | |
| "torch==2.8.0", | |
| "torchvision==0.23.0", | |
| "numpy", | |
| "transformers==4.56.1", | |
| "datasets==4.0.0", | |
| "huggingface_hub[hf_transfer]==0.34.4", | |
| "ipykernel==6.30.1", | |
| "nbdistributed==0.1.0", | |
| index_url="https://download.pytorch.org/whl/cu128", | |
| extra_index_url="https://pypi.org/simple", | |
| ) | |
| .env( | |
| { | |
| "HF_HUB_ENABLE_HF_TRANSFER": "1", | |
| "HF_HUB_CACHE": CACHE_DIR, | |
| } | |
| ) | |
| .apt_install("curl", "wget", "git") | |
| .apt_install( | |
| "libasound2", | |
| "libatk-bridge2.0-0", | |
| "libatk1.0-0", | |
| "libatspi2.0-0", | |
| "libcairo2", | |
| "libdbus-1-3", | |
| "libgbm1", | |
| "libglib2.0-0", | |
| "libgtk-3-0", | |
| "libnspr4", | |
| "libnss3", | |
| "libpango-1.0-0", | |
| "libxcomposite1", | |
| "libxdamage1", | |
| "libxext6", | |
| "libxfixes3", | |
| "libxkbcommon0", | |
| "libxkbfile1", | |
| "libxrandr2", | |
| "xdg-utils", | |
| ) | |
| .run_commands( | |
| [ | |
| f"wget -O vscode.deb https://update.code.visualstudio.com/{VSCODE_VERSION}/linux-deb-x64/stable && dpkg -i vscode.deb && rm vscode.deb" | |
| ] | |
| ) | |
| ) | |
| models_cache_volume = Volume.from_name( | |
| "scratch-to-scale-models", create_if_missing=True | |
| ) | |
| code_volume = Volume.from_name("scratch-to-scale-workspace", create_if_missing=True) | |
| vscode_config = Volume.from_name("scratch-to-scale-vscode-config", create_if_missing=True) | |
| vscode_server_config = Volume.from_name("scratch-to-scale-vscode-server-config", create_if_missing=True) | |
| if is_local() and False: | |
| with code_volume.batch_upload(force=True) as batch: | |
| batch.put_directory( | |
| os.path.dirname(os.path.abspath(__file__)) + "/repos/", "/", recursive=True | |
| ) | |
| @app.function( | |
| image=image, | |
| gpu="T4:2", | |
| volumes={"/workspace": code_volume, CACHE_DIR: models_cache_volume, "/root/.vscode": vscode_config, "/root/.vscode-server": vscode_server_config}, | |
| scaledown_window=30, | |
| max_containers=1, | |
| ) | |
| @web_server(8080, startup_timeout=70) | |
| @concurrent(max_inputs=100) | |
| def vscode(): | |
| subprocess.Popen( | |
| """code serve-web --host 0.0.0.0 --port 8080 --accept-server-license-terms --connection-token TokenExample""", shell=True | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment