Commit bc98113
subprocess_venv: two-stage install to fix torch/torchaudio CUDA-tag split
PR #516 routes the install through ``--index-url <cuda> --extra-index-url
https://pypi.org/simple`` so non-torch packages can still resolve from
PyPI. But uv treats ``--extra-index-url`` as having higher priority than
``--index-url`` (opposite of pip), so PyPI wins for every package — torch
and torchaudio included. On hosts where PyPI ships those with mismatched
``+cu`` local-version tags (currently ``torch==X+cu129`` vs
``torchaudio==X`` with no tag, internally cu128), the resulting venv
reproduces the same ABI mismatch this PR is meant to fix:
RuntimeError: Detected that PyTorch and TorchAudio were compiled with
different CUDA versions. PyTorch has CUDA version 12.9 whereas
TorchAudio has CUDA version 12.8.
Reproduced on MIT ORCD with the env override set
(``SENSELAB_TORCH_INDEX_URL=https://download.pytorch.org/whl/cu128``) —
override URL was honored in the marker but uv still resolved both wheels
from PyPI. So the override path was non-functional too.
Fix: split the install into two stages.
Stage 1 — ``uv pip install --index-url <chosen> torch torchaudio``
with NO ``--extra-index-url``. The chosen CUDA index is unambiguously
primary; both wheels and their ``nvidia-cuda-runtime-cu12``
transitives come from the same toolchain. Pins from the caller's
``requirements`` list flow through verbatim; multiple constraints
for the same package (``["torch>=2.8", "torch<2.9"]``) are all
forwarded so uv can combine them at resolve time.
Stage 2 — ``uv pip install <rest of requirements> safetensors numpy``
with no index flags. Backend-pinned torch / torchaudio specs are
filtered out so uv can't be tempted to re-resolve them from PyPI
against the matched ``+cu128`` wheels installed in Stage 1. uv
sees both already installed and satisfying constraints from their
transitives' point of view, and leaves them alone. The PyTorch
index now governs only the two packages it's designed for; stale
wheels on the CUDA index for utilities like setuptools / pyarrow
stay out of the picture.
Add ``requires_torch=True`` parameter to ``ensure_venv`` for opt-out:
subprocess venvs that genuinely don't touch torch (e.g. consuming a
pure-Python GitHub repo) can pass ``requires_torch=False`` to skip the
probe, skip Stage 1, and skip the IPC ``torchaudio`` append entirely —
single install pass against default PyPI. Marker omits ``torch_index``
in that case; a later ``requires_torch=True`` call against the same
name correctly invalidates and rebuilds via the existing URL-mismatch
clause.
Behavioral guarantees preserved from PR #516: marker schema (extended,
not changed), cache-hit fast path, env override
(``SENSELAB_TORCH_INDEX_URL``), ``SenselabCudaCompatibilityError``
wrapping on wheel-not-found errors (now scoped to Stage 1 where it
semantically belongs), pass-through of unrelated ``CalledProcessError``,
half-built-venv cleanup on failure, host-CUDA probe diagnostic,
cross-backend routing.
Tests: existing call-count assertions updated for the extra ``uv pip
install``; the two install-argv tests split into seven new ones
covering (1) Stage 1 names only ``--index-url`` with torch + torchaudio
pinned per requirements, (2) Stage 1 falls back to bare names when
requirements omit them (qwen backend), (3) Stage 2 carries no index
flags + IPC deps, (4) Stage 2 filters torch / torchaudio specs from
caller's requirements, (5) multiple constraints for the same package
all forward through Stage 1 verbatim, (6) ``requires_torch=False``
skips the probe + Stage 1 + IPC torchaudio entirely, and (7) switching
from ``requires_torch=False`` to ``True`` on the same name invalidates
the cache and rebuilds. The cross-backend regression test now asserts
both that Stage 1 routes through the chosen index AND that Stage 2
contains no torch / torchaudio specs at all — guarding against any
future re-introduction of ``--extra-index-url`` on the torch install
or a torch spec leaking into Stage 2.
Review feedback addressed:
- @satra: ``requires_torch`` opt-out for venvs that don't need torch
- gemini-code-assist #1: filter torch / torchaudio specs from Stage 2
- gemini-code-assist #2: list-based ``_torch_install_specs`` keeps
every matching constraint instead of clobbering through a dict
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent 92d8b3e commit bc98113
2 files changed
Lines changed: 410 additions & 78 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
195 | 195 | | |
196 | 196 | | |
197 | 197 | | |
| 198 | + | |
198 | 199 | | |
199 | 200 | | |
200 | 201 | | |
201 | 202 | | |
202 | 203 | | |
203 | 204 | | |
204 | 205 | | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
205 | 215 | | |
206 | 216 | | |
207 | 217 | | |
| |||
211 | 221 | | |
212 | 222 | | |
213 | 223 | | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
223 | 241 | | |
224 | 242 | | |
225 | 243 | | |
226 | | - | |
| 244 | + | |
227 | 245 | | |
228 | 246 | | |
229 | 247 | | |
230 | 248 | | |
231 | 249 | | |
| 250 | + | |
232 | 251 | | |
233 | 252 | | |
234 | 253 | | |
235 | 254 | | |
236 | | - | |
| 255 | + | |
237 | 256 | | |
238 | 257 | | |
239 | 258 | | |
| |||
254 | 273 | | |
255 | 274 | | |
256 | 275 | | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
262 | 360 | | |
263 | 361 | | |
264 | 362 | | |
265 | 363 | | |
266 | 364 | | |
267 | 365 | | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | 366 | | |
273 | 367 | | |
274 | | - | |
| 368 | + | |
275 | 369 | | |
276 | 370 | | |
277 | 371 | | |
278 | 372 | | |
279 | 373 | | |
280 | 374 | | |
281 | | - | |
282 | 375 | | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | 376 | | |
298 | 377 | | |
299 | 378 | | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
313 | 394 | | |
314 | 395 | | |
315 | 396 | | |
| |||
353 | 434 | | |
354 | 435 | | |
355 | 436 | | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
356 | 491 | | |
357 | 492 | | |
358 | 493 | | |
| |||
0 commit comments