Skip to content

Add config tests for mamba and mamba2 architecture adapter#1532

Merged
jlarson4 merged 6 commits into
TransformerLensOrg:devfrom
MdSadiqMd:sadiq/mamba-adapter
Jul 23, 2026
Merged

Add config tests for mamba and mamba2 architecture adapter#1532
jlarson4 merged 6 commits into
TransformerLensOrg:devfrom
MdSadiqMd:sadiq/mamba-adapter

Conversation

@MdSadiqMd

Copy link
Copy Markdown
Contributor

Description

This PR adds unit tests for two SSM architecture adapters currently lacking focused testing:

  • MambaArchitectureAdapter (39 tests): Config flags (RMS norm, no positional embeddings, stateful), SSMBlockBridge structure with norm and SSMMixerBridge, mixer submodules (in_proj, conv1d, x_proj, dt_proj, out_proj), factory registration, and applicable_phases.

  • Mamba2ArchitectureAdapter (39 tests): Config flags plus computed fields (intermediate_size, conv_dim, expected_in_proj_out_features), SSM2MixerBridge structure (in_proj, conv1d, inner_norm, out_proj — no x_proj/dt_proj), factory registration, and architecture guards distinguishing Mamba2 from Mamba1.

Behavioural coverage (forward pass, hook firing) already lives in the integration tests:

  • tests/integration/model_bridge/test_mamba_adapter.py
  • tests/integration/model_bridge/test_mamba2_adapter.py

These unit tests complement the integration tier, following the pattern of existing adapter tests like test_opt_adapter.py and test_mixtral_adapter.py.

black, mypy, and pytest (unit tests) all pass locally.

Parts of #1302

Type of change

  • New feature (non-breaking change which adds functionality)

Screenshots

N/A

Checklist:

  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have not rewritten tests relating to key interfaces which would affect backward compatibility

@jlarson4
jlarson4 changed the base branch from main to dev July 22, 2026 22:11
@MdSadiqMd

Copy link
Copy Markdown
Contributor Author

hey @jlarson4, please review and merge this

@jlarson4 jlarson4 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.

Hi @MdSadiqMd, thank you for putting these tests together, sorry for the delay on the review. These tests are great, I just want to trim them down a little bit before merging. Notes below, nothing crazy. Let me know if you have any questions!

Comment thread tests/unit/model_bridge/supported_architectures/test_mamba_adapter.py Outdated
Comment thread tests/unit/model_bridge/supported_architectures/test_mamba2_adapter.py Outdated
Comment thread tests/unit/model_bridge/supported_architectures/test_mamba_adapter.py Outdated
Comment thread tests/unit/model_bridge/supported_architectures/test_mamba_adapter.py Outdated
Comment thread tests/unit/model_bridge/supported_architectures/test_mamba2_adapter.py Outdated
"""Mamba2 only applies to Phase 4 (generation + text quality)."""

def test_applicable_phases_is_phase_4_only(self, adapter: Mamba2ArchitectureAdapter) -> None:
assert adapter.applicable_phases == [4]

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.

Something I completely missed in my first review. Mamba and Mamba2 are now able to run through phase 1,2, and 3 as of PR #1481. Because you originally based your PR on main, this detail was lost as that has not been released to main yet. Since this runs the default phases now, it is probably safe to drop this test.

Thank you for your patience on this one, I am aiming to get the release out tomorrow which will get main up to date with these changes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

np, will do the fixes, and thank you very much for maintaining this repo

"""Mamba only applies to Phase 4 (generation + text quality)."""

def test_applicable_phases_is_phase_4_only(self, adapter: MambaArchitectureAdapter) -> None:
assert adapter.applicable_phases == [4]

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.

Same note from Mamba2

@MdSadiqMd

Copy link
Copy Markdown
Contributor Author

Hey @jlarson4 made the changes, please review it once again, let me know if anything else is needed from my side

@jlarson4

Copy link
Copy Markdown
Collaborator

Looks great @MdSadiqMd, merging now!

@jlarson4
jlarson4 merged commit 7e1ac1b into TransformerLensOrg:dev Jul 23, 2026
25 checks passed
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