Add the fused_mm_sampling source and benchmarking scripts to the image, then pip-install the package so subprocess-based tools (e.g. ncu) can import it. Layer order matters for caching: pyproject.toml (rarely changes) and dep install go first so that source-only changes don't re-run pip
(image: modal.Image)
| 134 | |
| 135 | |
| 136 | def set_volume_caches(): |
| 137 | """Point cache env vars to the Modal volume and enable Triton autotune logging. |
| 138 | |
| 139 | XDG_CACHE_HOME: used by flashinfer, torch.compile, etc. |
| 140 | TRITON_CACHE_DIR: used by Triton for compiled kernels and autotune results. |
| 141 | Triton ignores XDG_CACHE_HOME and reads TRITON_CACHE_DIR (or TRITON_HOME) instead. |
| 142 | TRITON_PRINT_AUTOTUNING: surfaces autotune progress so silent waits |
| 143 | (cold cache, hangs) are debuggable from the run log. |
| 144 | """ |
| 145 | os.environ["XDG_CACHE_HOME"] = f"{volume_path}/cache" |
| 146 | os.environ["TRITON_CACHE_DIR"] = f"{volume_path}/cache/triton" |
| 147 | os.environ["TRITON_PRINT_AUTOTUNING"] = "1" |
| 148 | |
| 149 | |
| 150 | def add_library_code(image: modal.Image) -> modal.Image: |
| 151 | """Add the fused_mm_sampling source and benchmarking scripts to the image, |
| 152 | then pip-install the package so subprocess-based tools (e.g. ncu) can import it. |
| 153 | |
| 154 | Layer order matters for caching: pyproject.toml (rarely changes) and dep |
| 155 | install go first so that source-only changes don't re-run pip. |
| 156 | """ |
| 157 | return ( |
| 158 | image |
| 159 | # 1. Install deps (cached as long as pyproject.toml is unchanged). |
| 160 | .add_local_file( |
| 161 | str(_repo_root / "pyproject.toml"), |
| 162 | remote_path="/opt/fmms/pyproject.toml", |
| 163 | copy=True, |
| 164 | ) |
| 165 | .run_commands( |
| 166 | "mkdir -p /opt/fmms/src/fused_mm_sampling" |
| 167 | " && touch /opt/fmms/src/fused_mm_sampling/__init__.py" |
| 168 | " && cd /opt/fmms && pip install --break-system-packages -e ." |
| 169 | ) |
| 170 | # 2. Copy source files (changes frequently, but deps layer is cached). |
| 171 | # The editable install points to /opt/fmms/src, so the real files |
| 172 | # are picked up at runtime. |
| 173 | .add_local_dir( |
| 174 | str(_repo_root / "src"), |
| 175 | remote_path="/opt/fmms/src", |
| 176 | copy=True, |
| 177 | ignore=["__pycache__", "*.pyc"], |
| 178 | ) |
no outgoing calls
no test coverage detected