Skip to content

Commit c6ee6e4

Browse files
committed
simplify experiments input for modal deploy script
1 parent b3d3af9 commit c6ee6e4

2 files changed

Lines changed: 31 additions & 18 deletions

File tree

bundles/modal/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Deploy align-app as a serverless GPU application on Modal with scale-to-zero.
55
## Prerequisites
66

77
1. Install Modal CLI:
8+
89
```bash
910
pip install modal
1011
modal setup # authenticate with Modal
@@ -42,6 +43,12 @@ Edit `app.py` to adjust:
4243
- `timeout=30 * MINUTES` - Max request duration
4344
- `startup_timeout=5 * MINUTES` - Max time for container to start
4445

46+
Experiment data is baked into the image and passed to `align-app` at startup:
47+
48+
- `EXPERIMENTS` - Local path copied into the image at `/app/experiments`.
49+
If it is a directory, it is copied directly.
50+
If it is a `.zip`, it is unpacked into `/app` during the build.
51+
4552
## Costs
4653

4754
- **L4 GPU**: ~$0.76/hour (billed per second)

bundles/modal/app.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
PORT = 8080
88

99
REPO_ROOT = Path(__file__).parent.parent.parent
10-
EXPERIMENTS_ZIP = os.environ.get("ALIGN_EXPERIMENTS_ZIP")
10+
EXPERIMENTS = os.environ.get("EXPERIMENTS")
11+
EXPERIMENTS_PATH = Path(EXPERIMENTS) if EXPERIMENTS else None
1112

1213
app = modal.App("align-app")
1314

@@ -36,25 +37,30 @@ def download_models():
3637
.workdir("/app")
3738
)
3839

39-
if EXPERIMENTS_ZIP:
40-
image = (
41-
base_image.add_local_file(EXPERIMENTS_ZIP, "/app/experiments.zip", copy=True)
42-
.run_commands(
43-
"poetry config virtualenvs.create false && poetry install --only main",
44-
"unzip experiments.zip -d /app && rm experiments.zip",
40+
image = base_image
41+
42+
if EXPERIMENTS_PATH and EXPERIMENTS_PATH.exists():
43+
if EXPERIMENTS_PATH.is_dir():
44+
image = image.add_local_dir(
45+
str(EXPERIMENTS_PATH), "/app/experiments", copy=True
4546
)
46-
.run_function(
47-
download_models,
48-
secrets=[modal.Secret.from_name("huggingface")],
47+
elif EXPERIMENTS_PATH.suffix.lower() == ".zip":
48+
image = image.add_local_file(
49+
str(EXPERIMENTS_PATH), "/app/experiments.zip", copy=True
4950
)
50-
)
51-
else:
52-
image = base_image.run_commands(
53-
"poetry config virtualenvs.create false && poetry install --only main"
54-
).run_function(
55-
download_models,
56-
secrets=[modal.Secret.from_name("huggingface")],
57-
)
51+
52+
install_commands = [
53+
"poetry config virtualenvs.create false && poetry install --only main",
54+
]
55+
56+
if EXPERIMENTS_PATH and EXPERIMENTS_PATH.exists():
57+
if EXPERIMENTS_PATH.is_file() and EXPERIMENTS_PATH.suffix.lower() == ".zip":
58+
install_commands.append("unzip experiments.zip -d /app && rm experiments.zip")
59+
60+
image = image.run_commands(*install_commands).run_function(
61+
download_models,
62+
secrets=[modal.Secret.from_name("huggingface")],
63+
)
5864

5965

6066
@app.function(

0 commit comments

Comments
 (0)