Repository navigation
Keep every nested RoPE base, and never put a per-label mapping in rope_theta - #11192
Conversation
…e_theta #11037 taught the rope_scaling alias setter to carry the RoPE base frequency across an assignment. On a config whose rope_parameters is a NESTED per-label dict it does two wrong things, both on main now. First, _rope_theta_snapshot returns a {label: base} MAPPING for nested parameters, and _carry_per_layer_rope_theta answers None for three different reasons, one of which is the no-op "every entry already names its own base". _carry_rope_theta_across_assignment read that None as "nothing nested to restore, fall through" and the fall-through treated the mapping as a scalar, so it landed in config.rope_theta. A T5Gemma2DecoderConfig assigned its own parameters back now serializes a rope_theta OBJECT where a number belongs, on a config that previously had no such key at all. The merge base of #11037 adds no attribute and serializes identically, so this is a regression, and it contradicts the no-op #11037 claims for already-complete parameters. Second, _rope_parameters_are_per_layer decided nested-vs-flat from layer_types alone with a subset test. transformers resolves the nesting axis as getattr(self, "_rope_type_labels", getattr(self, "layer_types", None)) and asks isdisjoint, not issubset. Both halves of that difference matter: DeepSeek V4 keys its rope by rope-type label (main / compress) while its layer_types names attention blocks, and laguna, mellum and zaya each declare a base for a label their default layer_types does not list. All four were read as flat, so no nested snapshot was taken and every per-label base went to None, which is the TypeError: unsupported operand type(s) for ** or pow(): 'NoneType' and 'Tensor' this patch exists to prevent. On DeepSeek V4 a top-level rope_theta was also written INTO the nested dict. The fix is three changes. _rope_nesting_labels mirrors transformers' own resolution, _rope_type_labels first with a sentinel so an explicitly None value is respected; _rope_parameters_are_per_layer uses it and spells the predicate the way transformers spells it. The nested branch returns instead of falling through when carried is a mapping and nothing was restored. An isinstance check before the writes makes "a base frequency is a number" structural. Precedence is untouched, so a per-layer replacement with a scalar carried base still sets config.rope_theta, and the zoo's deliberate Gemma local base still wins. Tests, next to #11037's own: the two defects at helper level, both on the real config classes, and a sweep of CONFIG_MAPPING so a new model with a nested rope dict is covered the day it lands. Five of the six fail on main. The sixth pins unsloth_zoo/empty_model.py's Gemma local rotary base, which passes on both. Verified one venv per transformers minor: 4.57.6 stays a no-op, and 5.0.0 through 5.17.0 all pass.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review |
|
@codex security review |
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
* Repair the three checks that went red on main today All three reproduce on a clean origin/main (1d5210d) and none needs a product behaviour change, but they do not share a cause, so each is attributed here. install.ps1, studio/setup.ps1: unslothai#10533 added a comment naming an antivirus vendor to Get-SecuritySoftwareNote. The ban on vendor names in shipped scripts landed two days earlier in unslothai#10978, and it is not a style rule: PowerShell hands the entire top-level script block to the scanner at compile time, so comments are classifier input, and VirusTotal's analysis of install.ps1 quoted one of our own comments back as grounds for suspicion. The knowledge is moved rather than deleted, into AV_SHAPES_RECORD, which is where the guard's failure message says it belongs and which now records what each suite calls its protected-folders feature. The function never hard-coded a product name; it reads what SecurityCenter2 registered, and that is now said where the list used to be. tests/test_apply_qkv_fallback.py, tests/test_lora_dropout_patch_summary.py: unslothai#11038 added two skip guards reading torch.cuda.is_available(), which tests/_zoo_aggressive_cuda_spoof.py patches True process-wide and never puts back. A skipif is evaluated at import, so either file sharing a session with tests/version_compat or tests/vllm_compat un-skips on a CPU-only box and dies inside torch. They go through tests/_shared/real_accelerator.py instead, which records the answer before any spoof can run. test_apply_qkv_fallback_end_to_end allocates on "cuda" by name, so it takes has_real_cuda rather than the broad probe, which is also true on an XPU-only or Ascend NPU-only host. tests/python/test_docker_hub_readme.py: here the test was wrong, not the README. It took the first "#### Docker" heading and read to the next "####". The README grew a second Docker heading above the one carrying the run command, so the pins read a one-line pointer that was never meant to hold a docker run. It now picks the section by content and requires exactly one section to carry a run command, in both directions: zero is the regression it was written for, and more than one means two places tell the user how to start the image while only one is pinned. The stale-token check widened from that one section to every Docker section. * Let the save-signature probe resolve the import unslothai#11067 deferred Fourth check red on main today, in the (CPU, rest) shard: five failures in tests/test_st_save_merged_signature.py, all KeyError: "'__name__' not in globals". unslothai#11067 put `from ..save import _is_adapter_save_method` inside _save_pretrained_merged, deferred on purpose because a module-scope bind out of unsloth.save closes an import cycle. This file reads the two closures out of the source and execs them so the assertions run without importing unsloth, and a bare globals dict has no __name__ or __package__ for a relative import to resolve against, so every test that calls the body died on the import rather than on what it was checking. Satisfying it by importing unsloth would give up what the file is for, so the harness now stands up a package of its own holding the REAL helper, pulled from unsloth/save.py by source the way _normalize_save_method already is. The import executes and binds the shipped function, so its spelling rules still reach these tests; neutering that function fails three of them, which is how I checked the resolution is not cosmetic. That unmasked a second mismatch the import error was hiding. test_the_forwarding_path_still_accepts_lora asserted that "lora" is accepted when modules.json is present. unslothai#11067 deliberately retired that premise: save_pretrained_merged writes a loadable SentenceTransformer and an adapter-only save has no base weights for one, where previously "lora" matched no branch in merge_and_overwrite_lora and fell through to a 16bit merge that happened to write something loadable for a request that asked for adapters. Taking the product as correct, the test now pins the new refusal. The invariant it was really protecting survives and is what is checked: the no_modules refusal must not leak into the branch that has modules.json. Both paths raise now, so a bare pytest.raises would no longer notice one borrowing the other's reason; the messages are pinned apart, and a second test holds the pair distinct, which neither can see on its own. * Drop the torch import the skip-guard fix left unused Source lint caught it: tests/test_lora_dropout_patch_summary.py imported torch only for the torch.cuda.is_available() in the guard this PR replaced, so the import was left bound and unused. The sibling file still uses torch eleven times and keeps its import. * Let the rope carry drift tests run on a transformers that has no rope_parameters Fifth check red on main, in Core (HF=4.57.6 + TRL<1). Both tests from unslothai#11192 assume transformers 5's config.rope_parameters and fail on the 4.x job: test_rope_carry_keeps_every_nested_base_on_every_real_config AssertionError: no config with a nested rope dict was found to check test_rope_carry_leaves_the_zoo_gemma_local_base_alone_on_a_real_config AttributeError: 'Gemma2Config' object has no attribute 'rope_parameters' Both reproduce locally on transformers 4.57.6, the same pin that job resolves. The second is a one word fix. It already treats rope_parameters as optional, via an isinstance check, but read it with attribute access, and 4.x raises rather than returning None, so the tolerance was unreachable. getattr with a default. The first swept for nested rope dicts and asserted it found at least one. On 4.x there is no rope_parameters at all, so the sweep is empty and the assert fires. The two cases are now told apart: no rope_parameters anywhere is 4.x, where this carry does not exist and there is nothing to damage, and skips with that reason; the attribute present but no nested config is still drift and still fails. Collapsing them would either red the 4.x job forever or silently stop testing 5.x. Checked in both directions rather than assumed. On 4.57.6 the skip fires and the Gemma test passes. On 5.17.0 the skip does not fire and the sweep finds 16 nested configs, including the four the docstring names: deepseek_v4, laguna, mellum and zaya. Also stopped the sweep being ended by an unrelated optional dependency. CONFIG_MAPPING is lazy, so .items() imports every config module to hand back the classes, and one model whose module needs something missing takes the whole sweep down before the loop body runs. Seen with transformers.models.gemma3n, which imports timm.data.ImageNetInfo and raises on a timm that does not export it. Iterating keys and resolving inside the existing try skips that model, which is right: a config that cannot be built here cannot be the one that regressed. * Stop one test's account fence deciding another test's assertions tests/multi_account/test_routing_invariance.py::test_owner_routing_facts_and_shared_queue failed in Repo tests (CPU, rest) on assert active_generations._FENCED == set() carrying an account id it never created. It passed when run alone, passed on some pull requests and failed on others, which is the shape that eventually gets a real test deleted for being flaky. state.active_generations keeps _ACTIVE and _FENCED on the module, so they are process-global and outlive the test that wrote them. Retiring or deactivating an account fences it, and staying fenced is the CORRECT end state for those tests, so none of them is at fault. What was missing is isolation, the same way a tmp dir is isolated rather than every test being asked to clean up after itself. Measured rather than guessed: a report-only probe over the backend suite names 15 leakers, in test_job_accounts.py, test_account_storage.py, test_account_integration_wiring.py and test_account_retired_workspace_recreated.py. Whichever of them landed in an xdist worker ahead of the routing test decided its assertion. So the reset goes in conftest as an autouse fixture, before and after each test, using the reset_for_tests() the module already ships for exactly this. Before AND after: clearing only on the way in leaves the last test of a worker holding a fence, and clearing only on the way out trusts every other plugin to have left it alone. The files that already reset around themselves keep doing so; resetting twice costs nothing and the local call documents the intent at its own site. Reproduced before fixing, and confirmed by differential. Running the four leaker files together with the routing test: pristine main 3 failed, incl. test_owner_routing_facts_and_shared_queue with this fix 2 failed, that one gone The remaining two are an unrelated rag_db pair that fails identically on main in this environment. test_generation_state_isolation.py guards the repair. The structural check reads conftest rather than exercising ordering, because observing a leak functionally would require assuming test ORDER and this suite runs under pytest-randomly, where a test may not assume it. Dropping autouse from the fixture fails that check, which is how I confirmed it is not decorative.
…e_theta (unslothai#11192) * Keep every nested RoPE base, and never put a per-label mapping in rope_theta unslothai#11037 taught the rope_scaling alias setter to carry the RoPE base frequency across an assignment. On a config whose rope_parameters is a NESTED per-label dict it does two wrong things, both on main now. First, _rope_theta_snapshot returns a {label: base} MAPPING for nested parameters, and _carry_per_layer_rope_theta answers None for three different reasons, one of which is the no-op "every entry already names its own base". _carry_rope_theta_across_assignment read that None as "nothing nested to restore, fall through" and the fall-through treated the mapping as a scalar, so it landed in config.rope_theta. A T5Gemma2DecoderConfig assigned its own parameters back now serializes a rope_theta OBJECT where a number belongs, on a config that previously had no such key at all. The merge base of unslothai#11037 adds no attribute and serializes identically, so this is a regression, and it contradicts the no-op unslothai#11037 claims for already-complete parameters. Second, _rope_parameters_are_per_layer decided nested-vs-flat from layer_types alone with a subset test. transformers resolves the nesting axis as getattr(self, "_rope_type_labels", getattr(self, "layer_types", None)) and asks isdisjoint, not issubset. Both halves of that difference matter: DeepSeek V4 keys its rope by rope-type label (main / compress) while its layer_types names attention blocks, and laguna, mellum and zaya each declare a base for a label their default layer_types does not list. All four were read as flat, so no nested snapshot was taken and every per-label base went to None, which is the TypeError: unsupported operand type(s) for ** or pow(): 'NoneType' and 'Tensor' this patch exists to prevent. On DeepSeek V4 a top-level rope_theta was also written INTO the nested dict. The fix is three changes. _rope_nesting_labels mirrors transformers' own resolution, _rope_type_labels first with a sentinel so an explicitly None value is respected; _rope_parameters_are_per_layer uses it and spells the predicate the way transformers spells it. The nested branch returns instead of falling through when carried is a mapping and nothing was restored. An isinstance check before the writes makes "a base frequency is a number" structural. Precedence is untouched, so a per-layer replacement with a scalar carried base still sets config.rope_theta, and the zoo's deliberate Gemma local base still wins. Tests, next to unslothai#11037's own: the two defects at helper level, both on the real config classes, and a sweep of CONFIG_MAPPING so a new model with a nested rope dict is covered the day it lands. Five of the six fail on main. The sixth pins unsloth_zoo/empty_model.py's Gemma local rotary base, which passes on both. Verified one venv per transformers minor: 4.57.6 stays a no-op, and 5.0.0 through 5.17.0 all pass. * Trim the RoPE carry comments to the facts the code cannot state --------- Co-authored-by: danielhanchen <[email protected]> Co-authored-by: danielhanchen <[email protected]>
* Repair the three checks that went red on main today All three reproduce on a clean origin/main (1d5210d) and none needs a product behaviour change, but they do not share a cause, so each is attributed here. install.ps1, studio/setup.ps1: unslothai#10533 added a comment naming an antivirus vendor to Get-SecuritySoftwareNote. The ban on vendor names in shipped scripts landed two days earlier in unslothai#10978, and it is not a style rule: PowerShell hands the entire top-level script block to the scanner at compile time, so comments are classifier input, and VirusTotal's analysis of install.ps1 quoted one of our own comments back as grounds for suspicion. The knowledge is moved rather than deleted, into AV_SHAPES_RECORD, which is where the guard's failure message says it belongs and which now records what each suite calls its protected-folders feature. The function never hard-coded a product name; it reads what SecurityCenter2 registered, and that is now said where the list used to be. tests/test_apply_qkv_fallback.py, tests/test_lora_dropout_patch_summary.py: unslothai#11038 added two skip guards reading torch.cuda.is_available(), which tests/_zoo_aggressive_cuda_spoof.py patches True process-wide and never puts back. A skipif is evaluated at import, so either file sharing a session with tests/version_compat or tests/vllm_compat un-skips on a CPU-only box and dies inside torch. They go through tests/_shared/real_accelerator.py instead, which records the answer before any spoof can run. test_apply_qkv_fallback_end_to_end allocates on "cuda" by name, so it takes has_real_cuda rather than the broad probe, which is also true on an XPU-only or Ascend NPU-only host. tests/python/test_docker_hub_readme.py: here the test was wrong, not the README. It took the first "#### Docker" heading and read to the next "####". The README grew a second Docker heading above the one carrying the run command, so the pins read a one-line pointer that was never meant to hold a docker run. It now picks the section by content and requires exactly one section to carry a run command, in both directions: zero is the regression it was written for, and more than one means two places tell the user how to start the image while only one is pinned. The stale-token check widened from that one section to every Docker section. * Let the save-signature probe resolve the import unslothai#11067 deferred Fourth check red on main today, in the (CPU, rest) shard: five failures in tests/test_st_save_merged_signature.py, all KeyError: "'__name__' not in globals". unslothai#11067 put `from ..save import _is_adapter_save_method` inside _save_pretrained_merged, deferred on purpose because a module-scope bind out of unsloth.save closes an import cycle. This file reads the two closures out of the source and execs them so the assertions run without importing unsloth, and a bare globals dict has no __name__ or __package__ for a relative import to resolve against, so every test that calls the body died on the import rather than on what it was checking. Satisfying it by importing unsloth would give up what the file is for, so the harness now stands up a package of its own holding the REAL helper, pulled from unsloth/save.py by source the way _normalize_save_method already is. The import executes and binds the shipped function, so its spelling rules still reach these tests; neutering that function fails three of them, which is how I checked the resolution is not cosmetic. That unmasked a second mismatch the import error was hiding. test_the_forwarding_path_still_accepts_lora asserted that "lora" is accepted when modules.json is present. unslothai#11067 deliberately retired that premise: save_pretrained_merged writes a loadable SentenceTransformer and an adapter-only save has no base weights for one, where previously "lora" matched no branch in merge_and_overwrite_lora and fell through to a 16bit merge that happened to write something loadable for a request that asked for adapters. Taking the product as correct, the test now pins the new refusal. The invariant it was really protecting survives and is what is checked: the no_modules refusal must not leak into the branch that has modules.json. Both paths raise now, so a bare pytest.raises would no longer notice one borrowing the other's reason; the messages are pinned apart, and a second test holds the pair distinct, which neither can see on its own. * Drop the torch import the skip-guard fix left unused Source lint caught it: tests/test_lora_dropout_patch_summary.py imported torch only for the torch.cuda.is_available() in the guard this PR replaced, so the import was left bound and unused. The sibling file still uses torch eleven times and keeps its import. * Let the rope carry drift tests run on a transformers that has no rope_parameters Fifth check red on main, in Core (HF=4.57.6 + TRL<1). Both tests from unslothai#11192 assume transformers 5's config.rope_parameters and fail on the 4.x job: test_rope_carry_keeps_every_nested_base_on_every_real_config AssertionError: no config with a nested rope dict was found to check test_rope_carry_leaves_the_zoo_gemma_local_base_alone_on_a_real_config AttributeError: 'Gemma2Config' object has no attribute 'rope_parameters' Both reproduce locally on transformers 4.57.6, the same pin that job resolves. The second is a one word fix. It already treats rope_parameters as optional, via an isinstance check, but read it with attribute access, and 4.x raises rather than returning None, so the tolerance was unreachable. getattr with a default. The first swept for nested rope dicts and asserted it found at least one. On 4.x there is no rope_parameters at all, so the sweep is empty and the assert fires. The two cases are now told apart: no rope_parameters anywhere is 4.x, where this carry does not exist and there is nothing to damage, and skips with that reason; the attribute present but no nested config is still drift and still fails. Collapsing them would either red the 4.x job forever or silently stop testing 5.x. Checked in both directions rather than assumed. On 4.57.6 the skip fires and the Gemma test passes. On 5.17.0 the skip does not fire and the sweep finds 16 nested configs, including the four the docstring names: deepseek_v4, laguna, mellum and zaya. Also stopped the sweep being ended by an unrelated optional dependency. CONFIG_MAPPING is lazy, so .items() imports every config module to hand back the classes, and one model whose module needs something missing takes the whole sweep down before the loop body runs. Seen with transformers.models.gemma3n, which imports timm.data.ImageNetInfo and raises on a timm that does not export it. Iterating keys and resolving inside the existing try skips that model, which is right: a config that cannot be built here cannot be the one that regressed. * Stop one test's account fence deciding another test's assertions tests/multi_account/test_routing_invariance.py::test_owner_routing_facts_and_shared_queue failed in Repo tests (CPU, rest) on assert active_generations._FENCED == set() carrying an account id it never created. It passed when run alone, passed on some pull requests and failed on others, which is the shape that eventually gets a real test deleted for being flaky. state.active_generations keeps _ACTIVE and _FENCED on the module, so they are process-global and outlive the test that wrote them. Retiring or deactivating an account fences it, and staying fenced is the CORRECT end state for those tests, so none of them is at fault. What was missing is isolation, the same way a tmp dir is isolated rather than every test being asked to clean up after itself. Measured rather than guessed: a report-only probe over the backend suite names 15 leakers, in test_job_accounts.py, test_account_storage.py, test_account_integration_wiring.py and test_account_retired_workspace_recreated.py. Whichever of them landed in an xdist worker ahead of the routing test decided its assertion. So the reset goes in conftest as an autouse fixture, before and after each test, using the reset_for_tests() the module already ships for exactly this. Before AND after: clearing only on the way in leaves the last test of a worker holding a fence, and clearing only on the way out trusts every other plugin to have left it alone. The files that already reset around themselves keep doing so; resetting twice costs nothing and the local call documents the intent at its own site. Reproduced before fixing, and confirmed by differential. Running the four leaker files together with the routing test: pristine main 3 failed, incl. test_owner_routing_facts_and_shared_queue with this fix 2 failed, that one gone The remaining two are an unrelated rag_db pair that fails identically on main in this environment. test_generation_state_isolation.py guards the repair. The structural check reads conftest rather than exercising ordering, because observing a leak functionally would require assuming test ORDER and this suite runs under pytest-randomly, where a test may not assume it. Dropping autouse from the fixture fails that check, which is how I confirmed it is not decorative.
#11037 taught the
rope_scalingalias setter to carry the RoPE base frequency across an assignment. On a config whoserope_parametersis a NESTED per-label dict, that carry does two wrong things. Both are on main now.Defect 1: a per-label mapping lands in the scalar
rope_thetaslot_rope_theta_snapshotreturns a{label: base}MAPPING when the parameters are nested, because that is the shape the bases live in._carry_per_layer_rope_thetaputs that mapping back one level down and returnsNonewhen it wrote nothing, and "every entry already names its own base" is one of the three reasons it answersNone._carry_rope_theta_across_assignmentreads thatNoneas "no nested snapshot to restore, fall through", and the fall-through treatscarriedas a scalar base (import_fixes.py:1027-1032, then1065-1067). So the mapping is assigned toconfig.rope_theta.The result on transformers 5.17.0, assigning a
T5Gemma2DecoderConfigits own parameters back:c.rope_theta{'sliding_attention': 10000.0, 'full_attention': 1000000.0}"rope_theta"OBJECTto_json_string()on main now contains:where a number belongs, on a config that had no
rope_thetakey at all. This is a regression #11037 introduced: the merge base adds no attribute and serializes identically, and it contradicts the no-op that #11037 claims for parameters that are already complete.Defect 2: the nested discriminator misreads four real model families as flat
This is the more serious of the two.
_rope_parameters_are_per_layerdecided nested-vs-flat fromconfig.layer_typeswith a subset test (import_fixes.py:945,949). transformers resolves the nesting axis differently:_rope_type_labelscomes first, and the test isisdisjoint, notissubset.DeepseekV4Configkeys its rope by rope-type label while itslayer_typesnames attention blocks (configuration_deepseek_v4.py:193-198):So unsloth read a DeepSeek V4 config as flat: it took no nested snapshot, and it wrote a top-level
rope_thetaINTO the nested dict, which is exactly the "makes transformers read the whole thing as flat" failure the helper's own docstring warns about.issubsetversusisdisjointis not a corner case either. A config may declare bases for more labels than its defaultlayer_typesactually uses, and three families ship exactly that on 5.17.0:layer_typesissubsetnot isdisjointfull_attention,sliding_attention['full_attention']full_attention,sliding_attention['full_attention']hybrid,hybrid_sliding['hybrid']I swept every config class in
CONFIG_MAPPINGon 5.17.0. Of the 16 that ship a nested rope dict, four lose every base under the subset-only discriminator and none do after this change:Those
Nonebases are not cosmetic. They are the failure #11037 exists to prevent, still live on main. Laguna, end to end on 5.17.0:On transformers 5.17.0, replacing the per-label scaling on DeepSeek V4:
rope_parameterstop level"rope_theta": 10000.0The base loss itself also happens on plain transformers with no unsloth patch at all, so that half is not a regression #11037 introduced. The point is that the carry exists to repair exactly this and did not, and that on DeepSeek V4 it additionally corrupted the dict. Both are fixed here.
The fix
unsloth/import_fixes.py, three changes, no behaviour change for any shape that already worked.New
_rope_nesting_labels(config)mirrors transformers' own resolution,_rope_type_labelsfirst with a sentinel so an explicitlyNonevalue is respected, falling back tolayer_types._rope_parameters_are_per_layernow uses it and switchesissubsettonot isdisjoint, so the predicate is spelled the same way transformers spells it.In the nested branch of
_carry_rope_theta_across_assignment, when nothing was restored andcarriedis a mapping, return instead of falling through. A{label: base}mapping is meaningful only one level down; there is no scalar to fall through with, whether the reason was "nothing needed restoring" or "the write was refused".A
isinstance(base, dict)guard immediately before the writes. A base frequency is a number, so no path can put a mapping in the scalar slot again.The existing precedence is untouched: the new parameters' base, then the config's own, then what was carried. A per-layer replacement with a SCALAR carried base still sets
config.rope_theta, which is wherestandardize_rope_paramsreads the base it hands to each label.Tests
Five added to
tests/test_import_fixes_drift.py, next to #11037's own helper test.test_rope_theta_carry_never_puts_a_per_label_mapping_in_the_scalar_slot(defect 1, helper level, plus a config that refuses the nested write)test_rope_theta_carry_follows_rope_type_labels_not_only_layer_types(defect 2, the_rope_type_labelshalf, including a genuinely flat replacement over the same config)test_rope_carry_handles_rope_labels_not_all_present_in_layer_types(defect 2, theissubsetvsisdisjointhalf, which is the laguna / mellum / zaya shape)test_rope_carry_on_the_real_nested_configs(both defects on the realT5Gemma2DecoderConfigandDeepseekV4Config, assertingto_json_string()is byte-identical across the no-op assignment)test_rope_carry_keeps_every_nested_base_on_every_real_configsweepsCONFIG_MAPPINGrather than naming models, so a new model with a nested rope dict is covered the day it landsPlus one pin,
test_rope_carry_leaves_the_zoo_gemma_local_base_alone_on_a_real_config:unsloth_zoo/empty_model.py:915-919sets Gemma's LOCAL rotary base and then replaces the scaling, and that stated base must survive the carry. It passes on main and on this branch; it is here so the carry cannot be loosened later without noticing.All five fail on main and pass here. On main, transformers 5.17.0:
Test results
tests/test_import_fixes_drift.py,tests/utils/test_rope_scaling_drift.py,tests/test_triton_optional_import.py,tests/test_longrope_short_long_boundary.py,tests/test_callback_signature_drift.py,tests/utils/test_attn_mask_upstream_drift.py,tests/notebooks/test_colab_oracle_drift.py,tests/test_offload_device_property.py, on transformers 5.17.0:No pre-existing failure in the touched area; the only failures anywhere are the five new tests against main. The sixth new test is the zoo Gemma pin, which passes on both.
Compatibility
One venv per transformers minor, python 3.13 / torch 2.11.0, running the four files #11037 touched or added:
rope_scalingproperty to own, probe reports the base is not dropped, setter not patched, a replacedrope_scalingstill leavesrope_theta == 500000.0Alongside the suites, the two reproductions were run on each version.
T5Gemma2DecoderConfigexists from 5.0.0, so defect 1 is reachable across the whole 5.x range and is repaired on all of it.DeepseekV4Configfirst appears in 5.8.1, and defect 2 is repaired on every version from there. The helper-level tests for both run everywhere, including where the model classes do not exist.On 4.57.6 the no-op was verified rather than assumed: there is no
rope_scalingproperty to own, the probe reports the base is not dropped, the setter is left unpatched, and a replacedrope_scalingstill leavesrope_theta == 500000.0.Note on #11037's
Fixes #2405Unrelated to the code here, worth recording: #2405 was closed as COMPLETED by #6197 on 2026-06-11, three months before #11037 was opened, and GitHub records #6197 as its closer. #11037's merge did not and could not close it. #2405 was also filed 2025-04-24, when the newest transformers was 4.51.3, and the
rope_scalingalias property together with the move ofrope_thetaintorope_parametersfirst shipped in 5.0.0 on 2026-01-26 and is absent from every 4.x through the final 4.57.6. The accurate description of #11037 is that it hardens the transformers-5 behaviour of the code path #6197 added, not that it fixes #2405.Refs #11037.