| from modal import App, Image, Volume |
| import modal |
| import json |
| model_name = "Learnable" |
| app = App(f"Generalization Model {model_name} with ImageNet") |
| |
| image = ( |
| Image.from_registry("nvidia/cuda:12.8.1-cudnn-devel-ubuntu22.04",add_python="3.10") |
| .pip_install(["torch", "flax", "pandas", "tqdm","optax", "dataclasses", "argparse","matplotlib", |
| "scikit-learn","wandb","timm","torchvision","datasets","transformers","timm"]) |
| .run_commands("""pip install --upgrade "jax[cuda]" -f https://storage.googleapis.com/jax-releases/jax_cuda_releases.html""") |
| .add_local_file("pyproject.toml", "/root/pyproject.toml") |
| .add_local_dir("src", "/root/src") |
| ) |
| |
| volume1 = Volume.from_name("weights", create_if_missing=True) |
| volume2 = Volume.from_name("datasets", create_if_missing=True) |
| volume3 = Volume.from_name("plots", create_if_missing=True) |
| volume4 = Volume.from_name("results", create_if_missing=True) |
| volume5 = Volume.from_name("shot_noise", create_if_missing=True) |
| @app.function( |
| image=image, |
| gpu="H100", |
| timeout=3600 * 24, |
| volumes={ |
| "/root/weights":volume1,"/root/datasets/":volume2,"/root/plots/":volume3,"/root/results/":volume4, |
| "/root/shot_noise":volume5, |
| }, |
| ) |
| def run_command(): |
| import os |
| |
| os.system("ls /root/shot_noise") |
| |
| |
| |
| |
| |
| |
| |
| os.system(""" |
| CUDA_VISIBLE_DEVICES=0 python src/imagenet/generalization.py \ |
| --model-a /root/weights/lmc/imagenet/vit-finetune/finetune-learnable-indice0-heads12-shared1-routed0-topk0-mlpFalse-seed0/finetune-learnable-indice0-heads12-shared1-routed0-topk0-seed0/best_65052\ |
| --model-b /root/weights/lmc/imagenet/vit-finetune/finetune-learnable-indice0-heads12-shared1-routed0-topk0-mlpFalse-seed40/best_5004\ |
| --data-original /root/datasets/imagenet\ |
| --data-generalization /root/shot_noise/shot_noise/4 |
| """) |
| |
| |
| |
| |
| |
| |
| |
| if __name__ == "__main__": |
| with app.run(): |
| run_command.remote() |