Fix two test failures from transformers v5 support#491
Merged
jlamypoirier merged 1 commit intomainfrom Apr 24, 2026
Merged
Conversation
- modeling_apriel2.py: Guard _init_weights under _TRANSFORMERS_V4. In v5, from_pretrained calls initialize_weights() after loading, which re-invokes _init_weights via smart_apply. The raw .data.normal_() calls bypass the guard_torch_init_functions patching that respects _is_hf_initialized, clobbering all loaded weights. In v5 the inherited PreTrainedModel default (which uses init.* functions) handles all cases correctly. - test_lm_head.py: Add num_documents_in_batch=1 to GRPO test kwargs, which LanguageModelGRPOLoss._forward_backward requires when computing the new_logprobs metric. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
modeling_apriel2.py: Guard_init_weightsunderif _TRANSFORMERS_V4. In transformers v5,from_pretrainedcallsinitialize_weights()after loading the checkpoint, which re-invokes_init_weightson every module viasmart_apply. The raw.data.normal_()calls bypassguard_torch_init_functionspatching (which gates on_is_hf_initialized), so all loaded weights were silently overwritten with fresh random values. In v5 the inheritedPreTrainedModel._init_weightsdefault already usesinit.*functions correctly and handlesnn.Linear,nn.Embedding, and*RMSNormmodules.test_lm_head.py: Addnum_documents_in_batch=1to GRPO test kwargs.LanguageModelGRPOLoss._forward_backwardreads this key when computing thenew_logprobsmetric, but the test never populated it.Test plan
pytest -v tests/layers/test_lm_head.py -k grpo— all 4 GRPO variants passpytest -v tests/models/test_hf_roundtrip.py -k apriel2— both apriel2 roundtrip cases passpytest -v -n 8 tests/— 2007 passed, 0 failed🤖 Generated with Claude Code