Skip to content

fix(model): apply training.rope_scaling through the config on transformers 5 - #984

Closed
cemililik wants to merge 1 commit into
developmentfrom
fix/rope-scaling-transformers5
Closed

cemililik wants to merge 1 commit into
developmentfrom
fix/rope-scaling-transformers5

Conversation

@cemililik

@cemililik cemililik commented Oct 18, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

training.rope_scaling is documented, offered by the wizard for contexts above 4096 tokens, and present in config_template.yaml. On transformers 5 it crashed every model load, while the config validator and --dry-run accepted it, so a run exited 2 only after the model started to build.

Related issues

Fixes #103

Changes

  • forgelm/model.py: new _config_with_rope_scaling() loads the model's config and merges the requested keys over its own rope_parameters. _build_model_kwargs now passes that finished config to from_pretrained(config=...) instead of rope_scaling=....
  • The legacy key type is read as rope_type, so the form the docs show keeps working.
  • For a multimodal checkpoint the settings go to the text sub-config. A transformers without rope_parameters gets the legacy rope_scaling attribute.
  • With a config object, from_pretrained hands unknown keyword arguments to the model constructor, so training.sliding_window_attention is applied to the same config object (it used to travel as a keyword).

What went wrong before (reproduced on transformers 5.13.0)

training.rope_scaling Result
{type: linear, factor: 4} (as documented) KeyError: 'rope_type' while the model is built
{rope_type: linear, factor: 4} replaces the whole dict, rope_theta is lost, TypeError in the frequency computation

Type

  • Bug fix

Testing

  • TestConfigWithRopeScaling in tests/test_model.py builds a tiny local Llama on CPU (no network), runs a forward pass for linear, dynamic and yarn, and checks that rope_theta survives and can still be overridden, that the legacy type key works, and that the sliding-window override lands on the config.
  • The full CLAUDE.md gauntlet from a clean worktree of this branch: exit 0.

Not covered

The 5.3–5.9 range that the declared floor still admits was not exercised. #109 raises that floor.

Checklist

  • CHANGELOG entry under [Unreleased]
  • Tests added

🤖 Generated with Claude Code

Summary by Sourcery

Restore Transformers 5 compatibility for configured RoPE scaling during model loading.

Bug Fixes:

  • Fix training.rope_scaling model loading on Transformers 5 by applying requested RoPE settings through the model configuration while preserving existing parameters such as rope_theta.
  • Support legacy type RoPE configuration keys, multimodal text sub-configs, and older Transformers versions without rope_parameters.
  • Apply sliding-window attention overrides through the same configuration when RoPE scaling is enabled.

Tests:

  • Add unit and local CPU integration coverage for linear, dynamic, and YaRN RoPE scaling, configuration merging, legacy compatibility, multimodal models, and sliding-window overrides.

…rmers 5

`training.rope_scaling` (documented, offered by the wizard for contexts above 4096, and in config_template.yaml) was
passed to `from_pretrained(rope_scaling=...)`. On transformers 5 the RoPE settings live in `config.rope_parameters`:
the documented `{type: linear, factor: 4}` raises `KeyError: 'rope_type'` while the model is built, and
`{rope_type: ..., factor: ...}` replaces the whole dictionary so `rope_theta` is lost and the frequency computation
raises `TypeError`. `--dry-run` passes, then the run exits 2 at model construction.

The requested keys are now merged over the model's own `rope_parameters` (so `rope_theta` is kept and can still be
overridden), the legacy key `type` is read as `rope_type`, the settings go to the text sub-config of a multimodal
checkpoint, and the finished config object is what is loaded. With a config object, `from_pretrained` hands unknown
keyword arguments to the model constructor, so the sliding-window override is applied to the config as well.

Reproduced both failures and checked linear, dynamic and yarn on transformers 5.13.0 with a tiny local Llama config on
CPU, building the model and running a forward pass. The tests do the same, and use no network. The 5.3-5.9 range the
declared floor still admits is not exercised here.

Refs #103

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@sourcery-ai

sourcery-ai Bot commented Oct 18, 2026

Copy link
Copy Markdown

Sorry @cemililik, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 13 hours and 38 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@coderabbitai

coderabbitai Bot commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

Next included review available in 40 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 3 included reviews currently available. Your 48 included PR review attempts over the past 7 days set your current allowance at 3 reviews per hour.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: e6057727-a4a4-4b84-a450-614cd32a7a6e
📥 Commits

Reviewing files that changed from the base of the PR and between 56b4f0d and 3d94a14.

📒 Files selected for processing: 3
  • CHANGELOG.md
  • forgelm/model.py
  • tests/test_model.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai

sourcery-ai Bot commented Oct 18, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR fixes Transformers 5 model-loading failures by loading and mutating the model config before construction, merging rope scaling safely into existing parameters, routing related overrides through that config, and adding mocked plus end-to-end local-Llama regression tests.

Sequence diagram for Transformers 5 model loading with RoPE scaling

sequenceDiagram
    participant Builder as _build_model_kwargs
    participant AutoConfig
    participant ModelConfig
    participant Model as from_pretrained

    Builder->>_config_with_rope_scaling: _config_with_rope_scaling(name_or_path, rope_scaling, trust_remote_code, revision)
    _config_with_rope_scaling->>AutoConfig: AutoConfig.from_pretrained(name_or_path, trust_remote_code, revision)
    AutoConfig-->>_config_with_rope_scaling: model_config
    _config_with_rope_scaling->>ModelConfig: get_text_config()
    _config_with_rope_scaling->>ModelConfig: merge rope_parameters with requested keys
    _config_with_rope_scaling-->>Builder: finished model_config
    opt sliding_window_attention
    Builder->>ModelConfig: set sliding_window
    end
    Builder->>Model: from_pretrained(config=model_config)
    Model-->>Builder: constructed model
Loading

Flow diagram for Transformers 5 RoPE scaling compatibility

flowchart TD
    A[training.rope_scaling configured] --> B[Load model config]
    B --> C{Multimodal checkpoint?}
    C -->|Yes| D[Use text sub-config]
    C -->|No| E[Use model config]
    D --> F{Has rope_parameters?}
    E --> F
    F -->|Yes| G[Normalize type to rope_type and merge requested keys]
    F -->|No| H[Set legacy rope_scaling]
    G --> I[Apply sliding_window override to config]
    H --> I
    I --> J[from_pretrained with config]
Loading

File-Level Changes

Change Details Files
Move RoPE scaling application into the loaded model configuration for Transformers 5 compatibility.
  • Load the base configuration with AutoConfig before model construction.
  • Merge requested scaling keys over existing rope parameters so values such as rope_theta are preserved.
  • Normalize legacy type to rope_type and apply settings to multimodal text sub-configs.
  • Fall back to the legacy rope_scaling attribute when rope_parameters is unavailable.
  • Pass the completed config to from_pretrained instead of a rope_scaling keyword.
forgelm/model.py
Ensure sliding-window overrides are applied to the correct configuration path when RoPE scaling is enabled.
  • Store sliding_window_attention on the finished config alongside RoPE settings.
  • Retain the existing keyword-argument path when only sliding-window attention is configured.
forgelm/model.py
tests/test_model.py
Add regression coverage for configuration merging and real model construction.
  • Test keyword/config routing and revision propagation with mocked Transformers APIs.
  • Build and run a tiny local Llama for linear, dynamic, and YaRN scaling.
  • Verify legacy key normalization, rope_theta preservation and override behavior, multimodal targeting, and legacy Transformers fallback.
tests/test_model.py
Document the Transformers 5 compatibility fix and its tested version range.
  • Add an Unreleased changelog entry describing the merge semantics, multimodal handling, and sliding-window behavior.
  • Note that Transformers 5.3–5.9 remains untested.
CHANGELOG.md

Assessment against linked issues

Issue Objective Addressed Explanation
#103 Apply training.rope_scaling compatibly on Transformers 5 by merging requested RoPE settings into the loaded model config, preserving existing parameters such as rope_theta, canonicalizing the legacy type key, and supporting multimodal text configs and older Transformers. ✅
#103 Add regression coverage showing that documented RoPE scaling configurations load and run successfully, including preservation or override of rope_theta and relevant config behavior. ✅
#103 Resolve the issue's additional acceptance criteria for validation of non-finite/invalid factors, corrections to all listed English and Turkish documentation examples, and release-note coverage of the restored contract. ❌ The PR adds a changelog entry and model regression tests, but the diff does not update the validator's handling of NaN/inf or invalid longrope factors, nor correct the listed configuration and long-context documentation examples and their Turkish mirrors. The tests also do not cover those validation cases.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@cemililik

Copy link
Copy Markdown
Collaborator Author

Superseded by #999: the wave-0 fixes are combined by theme into five pull requests to cut the review load. This branch's commits are included there unchanged apart from the CHANGELOG.md merge; the branch stays on the remote.

@cemililik cemililik closed this Oct 18, 2026
cemililik added a commit that referenced this pull request Oct 18, 2026
…n.enforce, transformers CVE floor, FSDP strategies, purge output dir (#999)

## Summary

Six code fixes combined into one pull request, replacing #984, #985,
#987, #989, #990 and #992 (to be closed as superseded). Each fixes a
case where the code failed, or a documented option did nothing, without
saying so. Each was mutation-checked on its own; together they pass the
full gauntlet.

## Related issues

Refs #103, #95, #92, #98, #109, #104, #102. Not closed by this change:
the top-of-range problems named in #109 (`warmup_ratio` on transformers
5.15+, the string `fsdp` form removed in 5.20), the FSDP2 migration
(#104), and reading `training.output_dir` for the purge memorisation
check (#102).

## Changes

| # | Fix | Where |
|---|---|---|
| #984 | `training.rope_scaling` crashed every model load on
transformers 5 (`KeyError: 'rope_type'`, or `rope_theta` lost). The
requested keys are merged **over** the model's `rope_parameters` and the
finished config is loaded; `sliding_window_attention` travels in the
same config object. | `forgelm/model.py` |
| #985 | The CLI sets `HF_HUB_DISABLE_TELEMETRY=1` (via `setdefault`)
before `huggingface_hub` is imported, so TRL's trainer no longer sends
Hugging Face's anonymous usage ping the privacy page says does not
exist. Library use is not covered; the air-gap page says so. |
`cli/_config_load.py`, `cli/_dispatch.py` |
| #987 | `retention.enforce` was documented as a gate (`warn_on_excess`,
`block_on_excess` → `EXIT_EVAL_FAILURE`) but no command reads it. Docs,
field description, both wizards say it is reserved; the CLI warns when a
config sets either of the last two. | `config.py` (in place),
`cli/_config_load.py`, `wizard/_collectors.py` |
| #989 | `transformers>=5.3.0` was called the CVE floor but admitted
CVE-2026-5241 and CVE-2026-9856 (a crafted `chat_template` name writes
outside the save directory). Floor is now `>=5.10.1` (5.10.0 is yanked),
`huggingface_hub>=1.5.0`, the nightly floor job pins both, and tests
keep it from drifting. | `pyproject.toml`, `nightly.yml`, `tests/` |
| #990 | `fsdp_strategy: no_shard` / `hybrid_shard` passed `--dry-run`
and exited 2 after the model loaded (FSDP2 rejects them). They are now
rejected when the config loads (exit 1), and two knobs FSDP2 ignores
(`fsdp_auto_wrap: false`, `backward_post`) log a warning. | `config.py`
(in place), `cli/_config_load.py` |
| #992 | `forgelm purge --row-id` without `--output-dir` silently
pointed the memorisation check at the corpus directory. It now warns and
names the path. The purge module's line budget is raised by 8 with a
`budget_history` note (the project's documented option). |
`cli/subcommands/_purge.py`, `tools/check_module_size.py` |

`config.py` (0 lines of headroom on the module-size ratchet) and
`trainer.py` change only by in-place string edits; new warnings live in
`cli/_config_load.py`.

### Merge-conflict handling

The six branches touched `CHANGELOG.md`, `tests/test_cli.py` (two
appended test classes) and the import line in `cli/_dispatch.py`; all
three were resolved by keeping both sides (the import line now imports
`_disable_hub_telemetry` and `_warn_inert_fsdp_options`). The affected
test modules pass together (621 tests).

## Type

- [x] Bug fix
- [x] Dependency

## Testing

- The full `CLAUDE.md` gauntlet from a clean worktree of this branch:
exit 0.
- Per-fix tests as in the original pull requests, including: a real tiny
Llama on CPU for `rope_scaling` (linear, dynamic, yarn); the traversal
reproduction (**fails on transformers 5.3.0**, passes on 5.10.1); all 32
accepted FSDP variants building real `TrainingArguments`.
- transformers-facing test modules pass on a 5.10.1 / `huggingface_hub`
1.5.0 overlay (443 tests). The nightly minimum-versions job runs on its
schedule after merge; I did not dispatch it.

## Checklist

- [x] English and Turkish mirrors updated together
- [x] CHANGELOG entries under `[Unreleased]`
- [x] Tests added

🤖 Generated with [Claude Code](https://claude.com/claude-code)

## Summary by Sourcery

Harden CLI behavior and dependency compatibility across model loading,
privacy, retention, distributed training, and purge workflows.

Bug Fixes:
- Restore Transformers 5 compatibility for RoPE scaling and
sliding-window model configuration.
- Disable Hugging Face Hub telemetry by default for CLI runs while
preserving explicit operator opt-in.
- Warn when reserved retention enforcement modes are configured instead
of implying unsupported enforcement behavior.
- Reject unsupported FSDP1-only strategies during configuration and warn
about FSDP2 options that have no effect.
- Warn when purge uses the corpus directory as its implicit output
directory and clarify the memorisation-check scope.

Enhancements:
- Document the actual retention, FSDP, telemetry, and purge behavior in
English and Turkish user-facing documentation.

Build:
- Raise the minimum runtime dependencies to transformers>=5.10.1 and
huggingface_hub>=1.5.0 to address relevant security advisories.
- Update the nightly minimum-version job and packaging checks to enforce
the new dependency floors.

Tests:
- Add coverage for telemetry initialization, reserved retention
warnings, FSDP validation, purge output-directory warnings, Transformers
5 RoPE handling, and chat-template path traversal protection.

Chores:
- Increase the purge module size budget for the new output-directory
warning.

---------

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant