MCPcopy Create free account
hub / github.com/FlashSampling/FlashSampling / add_library_code

Function add_library_code

src/fused_mm_sampling/modal_lib/utils.py:136–175  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

134
135
136def add_library_code(image: modal.Image) -> modal.Image:
137 """Add the fused_mm_sampling source and benchmarking scripts to the image,
138 then pip-install the package so subprocess-based tools (e.g. ncu) can import it.
139
140 Layer order matters for caching: pyproject.toml (rarely changes) and dep
141 install go first so that source-only changes don't re-run pip.
142 """
143 return (
144 image
145 # 1. Install deps (cached as long as pyproject.toml is unchanged).
146 .add_local_file(
147 str(_repo_root / "pyproject.toml"),
148 remote_path="/opt/fmms/pyproject.toml",
149 copy=True,
150 )
151 .run_commands(
152 "mkdir -p /opt/fmms/src/fused_mm_sampling"
153 " && touch /opt/fmms/src/fused_mm_sampling/__init__.py"
154 " && cd /opt/fmms && pip install --break-system-packages -e ."
155 )
156 # 2. Copy source files (changes frequently, but deps layer is cached).
157 # The editable install points to /opt/fmms/src, so the real files
158 # are picked up at runtime.
159 .add_local_dir(
160 str(_repo_root / "src"),
161 remote_path="/opt/fmms/src",
162 copy=True,
163 ignore=["__pycache__", "*.pyc"],
164 )
165 .add_local_file(
166 str(_repo_root / "benchmarking" / "speed_test.py"),
167 remote_path="/opt/fmms/speed_test.py",
168 copy=True,
169 )
170 .add_local_file(
171 str(_repo_root / "benchmarking" / "nsys_wrapper.py"),
172 remote_path="/opt/fmms/nsys_wrapper.py",
173 copy=True,
174 )
175 )

Callers 2

modal_ncu.pyFile · 0.85
modal_nsys.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected