-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
64 lines (50 loc) · 1.56 KB
/
run.py
File metadata and controls
64 lines (50 loc) · 1.56 KB
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
import sys
from pathlib import Path
REMOTE_PROJECT_DIR = "/root/project"
sys.path.append(str(Path(__file__).resolve().parent / "src"))
sys.path.append(REMOTE_PROJECT_DIR + "/src")
from dotenv import load_dotenv
load_dotenv(".env")
import math
import os
import pathlib
import hydra
import modal
from omegaconf import OmegaConf
from trainer import train
from utils.sandbox import extract_dependencies
vol = modal.Volume.from_name(os.environ["MODAL_VOLUME_NAME"], create_if_missing=True)
chkpt_dir = pathlib.Path("/vol")
OmegaConf.register_new_resolver("eval", lambda expr: eval(expr, {"math": math}))
app = modal.App()
dependencies = extract_dependencies("pyproject.toml")
env_vars = dict(os.environ)
image = (
modal.Image.debian_slim(python_version="3.13")
.add_local_dir(
".",
REMOTE_PROJECT_DIR,
copy=True,
ignore=["*.venv", "*__pycache__", "*.idea", "*.ruff_cache"],
)
.apt_install("git")
.pip_install("uv")
.run_commands(f"uv pip install --system --compile-bytecode {dependencies}")
.env(env_vars)
)
@app.function(
gpu="A100",
image=image,
timeout=10800,
volumes={str(chkpt_dir): vol},
)
def run():
"""Entry point for launching llm fine-tuning job in a Modal cloud environment.
Environment Variables:
TRAIN_CONFIG: The name of the Hydra config to use (e.g., "lora", "fourier").
"""
config_name = os.environ["TRAIN_CONFIG"]
hydra.initialize(config_path="./project/configs", version_base=None)
config = hydra.compose(config_name=config_name)
train(config)
vol.commit()