Skip to content

Pin torchcodec to match downgraded torch in qwen3_5 / nemotron_nano templates - #259

Merged
danielhanchen merged 1 commit into
mainfrom
fix/torchcodec-torch-abi-uv-templates
Apr 29, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
fix/torchcodec-torch-abi-uv-templates

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

  • Qwen3_5_(4B)_Vision.ipynb (and the rest of the qwen3_5 / nemotron_nano / granite4 families) crashes on Colab during from unsloth import FastVisionModel with a torchcodec ABI mismatch.
  • Root cause: Colab preinstalls torchcodec 0.10 against torch 2.10. Both installation_qwen3_5_content (force-installs torch==2.8.0) and installation_nemotron_nano_content (force-installs torch==2.7.1) downgrade torch without touching torchcodec, so the leftover 0.10 binding tries to load and hits an undefined torch CUDA symbol the moment transformers transitively imports torchcodec.
  • Fix: pin torchcodec inside the torch-downgrade branch of each template to the matching version from pytorch/torchcodec's compatibility table (torch 2.7 -> torchcodec 0.6, torch 2.8 -> torchcodec 0.7).

Repro

Open Qwen3_5_(4B)_Vision.ipynb on a fresh Colab runtime, run the install cell, then run the next cell. Import fails with:

RuntimeError: Could not load libtorchcodec.
...
FFmpeg version 4:
  OSError: /usr/local/lib/python3.12/dist-packages/torchcodec/libtorchcodec_core4.so:
  undefined symbol: _ZN3c104cuda29c10_cuda_check_implementationEiPKcS2_jb

That symbol is a torch 2.10 CUDA C++ API entry that no longer exists in torch 2.8. The libtorchcodec binding for FFmpeg 4 (the FFmpeg version Colab ships, libavcodec.so.58 / libavutil.so.56) is the one that almost loads, but it was compiled against torch 2.10's c10_cuda and so resolves an ABI symbol that was removed.

Fix

Add inside the torch-downgrade branch of each template:

# torch 2.8 needs torchcodec 0.7; Colab preinstalls 0.10 against torch 2.10
# which ABI-mismatches once we downgrade torch and breaks transformers import.
!uv pip install -qqq --no-deps "torchcodec==0.7.0"

(==0.6.0 for the nemotron_nano template at torch 2.7.1.)

--no-deps is defensive: torchcodec base has no unconditional runtime dependencies (only [dev] extras), so this won't pull or push torch around.

Templates updated in update_all_notebooks.py

  • installation_qwen3_5_content: !uv pip install -qqq --no-deps \"torchcodec==0.7.0\" inside the torch 2.8 branch.
  • installation_nemotron_nano_content: !uv pip install -qqq --no-deps \"torchcodec==0.6.0\" inside the torch 2.7.1 branch.

Notebooks regenerated via the updater

qwen3_5 family (uses installation_qwen3_5_content):

  • Qwen3_5_(0_8B)_Vision, Qwen3_5_(2B)_Vision, Qwen3_5_(4B)_Vision, Qwen3_5_(4B)_Vision_GRPO, Qwen3_5_MoE, Qwen_3_5_27B_A100(80GB)

nemotron_nano family (uses installation_nemotron_nano_content, also reused by Granite4 per the dispatcher):

  • Nemotron-3-Nano-30B-A3B_A100, Nemotron-Nano-3-30B-A3B_A100, Granite4.0, Granite4.0_350M, plus their Kaggle- mirrors

29 files total: template + 14 nb/ + 14 python_scripts/ mirrors.

Why other torch-pinning templates are not changed

  • installation_gpt_oss_content uses \"torch>=2.8.0\" rather than an == pin, so on Colab uv leaves the preinstalled torch 2.10 in place and Colab's torchcodec 0.10 still matches.
  • installation_content and installation_kaggle_content do not touch torch at all.

Test plan

  • On a fresh Colab runtime, Qwen3_5_(4B)_Vision.ipynb runs the install cell, then from unsloth import FastVisionModel succeeds.
  • Spot check one nemotron and one granite4 notebook on Colab end-to-end.
  • Confirm import torchcodec; torchcodec.__version__ reports 0.7.0 (qwen3_5) or 0.6.0 (nemotron_nano / granite4) after the install cell.

…emplates

Colab preinstalls torchcodec 0.10 against torch 2.10. Both
installation_qwen3_5_content (forces torch==2.8.0) and
installation_nemotron_nano_content (forces torch==2.7.1) downgrade torch
without touching torchcodec, so the leftover 0.10 binding hits a torch
CUDA ABI mismatch (undefined symbol _ZN3c104cuda29c10_cuda_check_implementationEiPKcS2_jb)
the moment transformers transitively imports torchcodec on
"from unsloth import FastVisionModel".

Per pytorch/torchcodec compatibility table:
  torch 2.7 -> torchcodec 0.6
  torch 2.8 -> torchcodec 0.7

Pin torchcodec inside the torch-downgrade branch of each affected template
and propagate to the qwen3_5 family (6 notebooks), nemotron_nano family
(4 notebooks) and granite4 family (4 notebooks). torchcodec base has zero
unconditional runtime deps (same shape as torchao), so --no-deps is purely
defensive and does not affect torch.

Generated artifacts updated via update_all_notebooks.py.
@danielhanchen
danielhanchen merged commit b0dc07e into main Apr 29, 2026
2 checks passed

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates several Jupyter notebooks and Python scripts to explicitly install compatible versions of torchcodec (0.6.0 for torch 2.7.1 and 0.7.0 for torch 2.8.0). This change prevents ABI mismatches in Google Colab environments where a pre-installed newer version of torchcodec would otherwise break transformers imports after a torch downgrade. The update_all_notebooks.py script was also updated to reflect these changes. I have no feedback to provide.

@danielhanchen
danielhanchen deleted the fix/torchcodec-torch-abi-uv-templates branch April 29, 2026 20:58
danielhanchen added a commit that referenced this pull request Apr 29, 2026
…o install cells (#260)

The two-line ABI-mismatch explanation that #259 added inside the install
templates ends up rendered into every regenerated install cell. The pin
itself is self-documenting, so drop the comment and let update_all_notebooks.py
regenerate cleaner cells across the qwen3_5, nemotron_nano and granite4
families plus their python_scripts mirrors.
danielhanchen added a commit that referenced this pull request Apr 29, 2026
#261)

Two leftover bugs after #259 / #260:

1. installation_nemotron_nano_content pins torch==2.7.1 but #259 set
   torchcodec==0.6.0. Per pytorch/torchcodec's compatibility table 0.6
   targets torch 2.8, not 2.7; the right pin for torch 2.7 is
   torchcodec==0.5 (also covered by 0.4 / 0.3). The 0.6 wheel still
   ABI-mismatches against torch 2.7.1 the same way 0.10 did, so the
   nemotron and granite4 notebooks would still hit the libtorchcodec
   undefined-symbol error on Colab. Switch to torchcodec==0.5 (cp312
   manylinux wheel exists).

2. installation_qwen3_5_content, installation_nemotron_nano_content and
   installation_gpt_oss_content all install bare "tokenizers" (no
   constraint), but the transformers versions they pair with declare a
   hard tokenizers<=0.23.0,>=0.22.0:
       transformers 4.56.2: tokenizers<=0.23.0,>=0.22.0
       transformers 5.2.0:  tokenizers<=0.23.0,>=0.22.0
   PyPI's current latest tokenizers is 0.23.1, which is outside that
   range. Bare "tokenizers" pulls 0.23.1 into a transformers install
   that was never tested against it. The live notebooks already carry
   the constraint string "tokenizers>=0.22.0,<=0.23.0"; the templates
   were the drifted side. Sync templates to match.

Generated artifacts updated via update_all_notebooks.py.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant