Skip to content

test(nemotron_h): use a real NemotronHConfig in stateful-cache tests - #1845

Merged
jlarson4 merged 1 commit into
TransformerLensOrg:devfrom
YHC66:fix-nemotron-h-cache-test-mock
Oct 1, 2026
Merged

jlarson4 merged 1 commit into
TransformerLensOrg:devfrom
YHC66:fix-nemotron-h-cache-test-mock

Conversation

@YHC66

@YHC66 YHC66 commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Description

TestNemotronHStatefulCache passes a bare MagicMock() as the HF model, so hf_model.config is a MagicMock too. On transformers 5.17, DynamicCache(config=...) goes through get_layer_types_and_kwargs, which does num_kv_shared_layers > 0, and both tests fail with:

TypeError: '>' not supported between instances of 'MagicMock' and 'int'

CI pins transformers 5.13.0, so this doesn't show there, but pyproject.toml allows transformers>=5.9.0 and the tests break as soon as the lock moves up.

The adapter itself is fine: with a real NemotronHConfig, DynamicCache(config=...) builds on both 5.13 and 5.17. This PR only changes the tests to hand create_stateful_cache a mock model carrying a tiny real NemotronHConfig (built with the typed layers_block_type argument, so mypy reports nothing new for the file).

Results:

transformers 5.17 transformers 5.13 (locked)
test_nemotron_h_adapter.py before 2 failed, 43 passed 45 passed
test_nemotron_h_adapter.py after 45 passed 45 passed

On dev 02a7f5a0 with transformers 5.17, these two were the only failures in tests/unit -m "not slow" (6792 passed). With the locked environment, tests/unit -m "not slow" passes in full after the change (6898 passed).

Type of change

  • Bug fix (non-breaking change which fixes an issue)

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

DynamicCache(config=...) on newer transformers (5.17) compares
config.num_kv_shared_layers against an int, which fails on a bare
MagicMock config. Use a tiny real NemotronHConfig instead.
@jlarson4

jlarson4 commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

Looks good, thanks @YHC66!

@jlarson4
jlarson4 merged commit cfac4be into TransformerLensOrg:dev Oct 1, 2026
27 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