Skip to content

fix(zamba2): tolerate missing optional mamba kernel symbols - #3768

Merged
Qubitium merged 1 commit into
mainfrom
fix/zamba2-missing-mamba-symbols
Nov 11, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/zamba2-missing-mamba-symbols

Conversation

@ZX-ModelCloud

Copy link
Copy Markdown
Collaborator

TL;DR

Zamba2 no longer assumes the optional mamba kernel symbols exist. getattr probing disables the fast path explicitly, and the upstream forward is left in place when the legacy mixer methods are gone.

Problem

Zamba2QModel.monkey_patch read selective_state_update, mamba_chunk_scan_combined, mamba_split_conv1d_scan_combined, causal_conv1d_fn, causal_conv1d_update, and is_torchdynamo_compiling unconditionally from transformers.models.zamba2.modeling_zamba2.

Current transformers releases only export causal_conv1d_fn / causal_conv1d_update; the other symbols are gone. Loading a Zamba2 model therefore raises AttributeError before quantization starts, and two tests in tests/test_zamba2_support.py fail.

Fix

  • Probe optional symbols with getattr(..., None) and record missing capabilities.
  • Log a warning with the missing symbol names when the fast path is disabled; the mixer uses the Torch/upstream fallback instead of silently taking a wrong path.
  • Guard is_torchdynamo_compiling the same way.
  • Only install the monkeypatch when the mixer class still exposes cuda_kernels_forward and torch_forward. Newer transformers mixers select kernels inside their own forward, so patching them would replace a valid implementation with calls to methods that no longer exist.

Tests

  • test_zamba2_missing_fast_path_kernels_are_detected
  • test_zamba2_dense_mixer_falls_back_when_kernels_are_missing
  • test_zamba2_mixer_without_legacy_paths_keeps_upstream_forward
  • test_zamba2_real_model_monkey_patch_tolerates_missing_kernels
  • Existing fast/slow path tests updated to tolerate absent attributes.

Validation

  • pytest tests/test_zamba2_support.py -q → 10 passed on both supported accelerator backends.
  • pytest tests/test_zamba_support.py -q → 6 passed.
  • Tiny real-model forward smoke test passed on both accelerator backends.
  • ruff check and ruff format --check pass.

Reviewer notes

This is a localized bug fix (optional-symbol gating inside one monkeypatch), so no Mermaid logic-flow page is added; the logic-flow skill excludes localized bug fixes. No quantization math, packed layout, or kernel-selection semantics are changed.

The legacy Zamba2 monkeypatch read selective_state_update, mamba_chunk_scan_combined, mamba_split_conv1d_scan_combined and is_torchdynamo_compiling unconditionally. Current transformers releases no longer expose them, so loading a Zamba2 model raised AttributeError before any quantization work started.

Probe the optional symbols with getattr, log the missing capabilities explicitly, and fall back to the Torch/upstream path. Newer transformers mixers no longer expose cuda_kernels_forward/torch_forward; leave their forward untouched because they already select kernels internally.

Add symbol-guard, fallback, and real-model regression tests.
@Qubitium
Qubitium marked this pull request as ready for review November 11, 2026 09:32

@Qubitium Qubitium left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed the fallback and legacy mixer paths. 16 focused tests and 411 model-plan tests pass; a tiny Zamba2 forward returns finite logits.

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.

2 participants