fix: work around transformers lazy_load_kernel offline regression - #2276
Conversation
68b0710 to
d480a02
Compare
d480a02 to
bc73634
Compare
bc73634 to
25f4dd7
Compare
7297d9e to
4d75dd8
Compare
22d39c9 to
4ffd8e7
Compare
transformers >= 5.5 switched all Mamba-based models (NemotronH, Zamba2, Jamba, etc.) from direct `import mamba_ssm` / `import causal_conv1d` to `lazy_load_kernel()` which resolves kernel versions via HF Hub API. With `HF_HUB_OFFLINE=1` (set in our SLURM template), this raises `OfflineModeIsEnabled` — crashing model init even when the kernels are already cached locally. The compat patch wraps `lazy_load_kernel` to catch hub errors and load kernels from the local HF Hub cache (`$HF_HOME/hub/models--kernels-community--*/`). Regression chain in transformers: - PR #41577 (Oct 2025): lazy_load_kernel introduced - PR #43955 (Feb 2026): version=1 integer versioning bypasses snapshot_download cache - PR #44176 (Feb 2026): all Mamba models switched to lazy_load_kernel Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
4ffd8e7 to
a125615
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit a125615. Configure here.
| _mod.lazy_load_kernel = _patched_lazy_load_kernel | ||
|
|
||
| except ImportError: | ||
| pass |
There was a problem hiding this comment.
Narrow except ImportError won't catch AttributeError from missing attributes
Medium Severity
The outer except ImportError on line 110 only catches ImportError, but lines 46–47 access _hub_kernels.lazy_load_kernel and _hub_kernels._KERNEL_MODULE_MAPPING, which raise AttributeError if those names don't exist. Since transformers.integrations.hub_kernels existed before lazy_load_kernel was added, there are valid transformers versions where the module imports successfully but the attribute access crashes the app at startup. Catching (ImportError, AttributeError) would match the graceful-degradation intent.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit a125615. Configure here.
There was a problem hiding this comment.
that's the point, though
The original patch added ~70 lines of cache-walking fallback logic with 3 nested try/except blocks. This is unnecessary — when lazy_load_kernel returns None, NemotronH falls back to torch_forward, and prime-rl's own _patch_mamba2_use_triton_ssd() handles the rest via mamba_ssm directly. The fix is just catching ConnectionError (parent of OfflineModeIsEnabled) and returning None, same as upstream already does for FileNotFoundError. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>


Summary
HF_HUB_OFFLINE=1is set — as our multi-node SLURM template doeslazy_load_kernel()resolves kernel versions viaHfApi().list_repo_refs(), which raisesOfflineModeIsEnabledeven when kernels are cached locally$HF_HOME/hub/models--kernels-community--*/)The regression was introduced across three transformers PRs:
lazy_load_kernelintroducedversion=1integer versioning bypassessnapshot_downloadcache fallbacklazy_load_kernelNo upstream issue exists yet — will file one on huggingface/transformers.
🤖 Generated with Claude Code
Note
Medium Risk
Monkeypatches
transformersruntime behavior in a model-kernel loading path; if upstream behavior changes, this could mask real hub-kernel issues or alter which kernels get used in offline/online environments.Overview
Extends
prime_rl._compatfrom a single ring-flash-attn workaround into a small set of documented early-import compatibility shims.Adds a new patch for
transformers.integrations.hub_kernels.lazy_load_kernelontransformers>= 5.5 to gracefully handleHF_HUB_OFFLINE=1by catchingOfflineModeIsEnabledand returningNone(so Mamba-based models can skip hub kernels and proceed with the project’s direct kernel path).Reviewed by Cursor Bugbot for commit d3d91a6. Bugbot is set up for automated code reviews on this repo. Configure here.