Commit d6fec64
Make RoPE config nullable to fix silent NoPE-model corruption (#177)
`_extract_rope_config()` never returned `None`, so NoPE models
(NemotronH, GraniteMoeHybrid, GPT-2/BERT/OPT families) silently received
`rope_type='default'` and had spurious rotary ops injected into their
ONNX graphs. The existing NemotronH fix (#110) is a model-class
workaround; this PR fixes the root cause in the config system.
### Changes
- **`_extract_rope_config()`** returns `None` unless the HF config has a
real RoPE signal: `rope_parameters`, `rope_scaling`, or legacy
`rotary_dim` / `rotary_pct` / `rotary_emb_base`. `rope_theta` alone is
dead data (NemotronH carries it without using RoPE) and is deliberately
not treated as a signal.
- **`ArchitectureConfig.from_transformers()`** propagates `None` to both
the `rope` sub-config and every flat RoPE field when the model is NoPE.
`dataclasses.replace(rope_config, ...)` call sites now guard against
`None`.
- **`ArchitectureConfig.rope_type`** default is `None` (the structural
NoPE signal). `rope_theta` / `partial_rotary_factor` keep inert numeric
defaults so `ArchitectureConfig(rope_type="default", ...)` still works
for direct construction in tests.
- **`initialize_rope()`** returns `None` when `rope_type is None` and
`mrope_section is None`.
- **`TextModel.forward()`** guards `self.rotary_emb(...)` and passes
`position_embeddings=None` down when RoPE is absent.
- **`Attention.__init__`** tolerates `partial_rotary_factor=None`
(treated as the inert 1.0) so NoPE-routed attention doesn't crash on
`math.isclose(None, 1.0)`.
### Tests
- New: `test_from_transformers_nope_model_has_none_rope`,
`test_from_transformers_legacy_rotary_dim_enables_rope`,
`test_rope_theta_alone_is_not_a_rope_signal`, `test_nope_returns_none`
(initialize_rope).
- Existing fakes in `_config_resolver_test.py` / `_configs_test.py` now
include `rope_parameters={"rope_type": "default"}` to match how real HF
`PretrainedConfig.__post_init__` populates the field.
- `make_config()` test helper opts into `rope_type="default"` so
component tests keep the RoPE code path. Direct `BambaConfig` /
`JambaConfig` / `Gemma2Config` test constructors and
`deepseek_ocr2.py`'s internal `ArchitectureConfig` opt in explicitly.
### Intentionally out of scope
- Simplifying the NemotronH / GraniteMoeHybrid text-model workarounds —
they use bespoke layer types (`NemotronHMambaLayer`, etc.) and can't
drop straight onto `TextModel`. They remain correct and now coexist with
a structural defense in the config layer.
- Phase 2 (calling `validate()` in the build path, nullable MoE
sub-config, deprecating flat RoPE fields) and Phase 3 (feature-group
sub-configs, per-model config classes) from the issue.
### Example
```python
# NemotronH config → no RoPE signal → structurally NoPE
class FakeNemotronH:
model_type = "nemotron_h"
rope_theta = 10_000.0 # dead data, ignored
# no rope_parameters, no rope_scaling, no rotary_*
...
cfg = ArchitectureConfig.from_transformers(FakeNemotronH())
assert cfg.rope is None
assert cfg.rope_type is None
assert initialize_rope(cfg) is None # TextModel now skips RoPE automatically
```
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
Co-authored-by: Justin Chu <justinchuby@users.noreply.github.com>1 parent 87c0524 commit d6fec64
11 files changed
Lines changed: 287 additions & 45 deletions
File tree
- src/mobius
- _testing
- components
- models
- rewrite_rules
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
23 | 29 | | |
24 | 30 | | |
25 | 31 | | |
| |||
35 | 41 | | |
36 | 42 | | |
37 | 43 | | |
| 44 | + | |
38 | 45 | | |
39 | 46 | | |
40 | 47 | | |
| |||
141 | 148 | | |
142 | 149 | | |
143 | 150 | | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
144 | 154 | | |
145 | 155 | | |
146 | 156 | | |
| |||
280 | 290 | | |
281 | 291 | | |
282 | 292 | | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
283 | 297 | | |
284 | 298 | | |
285 | 299 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
282 | 282 | | |
283 | 283 | | |
284 | 284 | | |
285 | | - | |
| 285 | + | |
286 | 286 | | |
287 | 287 | | |
288 | 288 | | |
289 | 289 | | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
290 | 306 | | |
291 | | - | |
292 | | - | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
293 | 321 | | |
294 | 322 | | |
295 | 323 | | |
| |||
734 | 762 | | |
735 | 763 | | |
736 | 764 | | |
737 | | - | |
738 | | - | |
739 | | - | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
740 | 784 | | |
741 | | - | |
| 785 | + | |
742 | 786 | | |
743 | 787 | | |
744 | 788 | | |
| |||
883 | 927 | | |
884 | 928 | | |
885 | 929 | | |
886 | | - | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
887 | 934 | | |
888 | 935 | | |
889 | 936 | | |
890 | 937 | | |
891 | 938 | | |
892 | 939 | | |
893 | | - | |
| 940 | + | |
| 941 | + | |
894 | 942 | | |
895 | 943 | | |
896 | 944 | | |
| |||
1052 | 1100 | | |
1053 | 1101 | | |
1054 | 1102 | | |
1055 | | - | |
1056 | | - | |
1057 | | - | |
1058 | | - | |
1059 | | - | |
1060 | | - | |
1061 | | - | |
1062 | | - | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
1063 | 1123 | | |
1064 | 1124 | | |
1065 | 1125 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
37 | 43 | | |
38 | 44 | | |
39 | 45 | | |
| |||
125 | 131 | | |
126 | 132 | | |
127 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
128 | 137 | | |
129 | 138 | | |
130 | 139 | | |
| |||
232 | 241 | | |
233 | 242 | | |
234 | 243 | | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
235 | 310 | | |
236 | 311 | | |
237 | 312 | | |
238 | 313 | | |
239 | 314 | | |
240 | | - | |
| 315 | + | |
241 | 316 | | |
242 | 317 | | |
243 | 318 | | |
244 | 319 | | |
245 | 320 | | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
246 | 356 | | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | 357 | | |
253 | 358 | | |
254 | 359 | | |
255 | 360 | | |
256 | | - | |
| 361 | + | |
| 362 | + | |
257 | 363 | | |
258 | 364 | | |
| 365 | + | |
259 | 366 | | |
260 | 367 | | |
261 | 368 | | |
| |||
268 | 375 | | |
269 | 376 | | |
270 | 377 | | |
271 | | - | |
| 378 | + | |
272 | 379 | | |
273 | 380 | | |
| 381 | + | |
274 | 382 | | |
275 | 383 | | |
276 | 384 | | |
277 | 385 | | |
278 | 386 | | |
279 | 387 | | |
280 | 388 | | |
281 | | - | |
| 389 | + | |
282 | 390 | | |
283 | 391 | | |
| 392 | + | |
284 | 393 | | |
285 | 394 | | |
286 | 395 | | |
287 | 396 | | |
288 | 397 | | |
289 | 398 | | |
290 | 399 | | |
291 | | - | |
| 400 | + | |
292 | 401 | | |
293 | 402 | | |
| 403 | + | |
294 | 404 | | |
295 | 405 | | |
296 | 406 | | |
| |||
319 | 429 | | |
320 | 430 | | |
321 | 431 | | |
322 | | - | |
| 432 | + | |
323 | 433 | | |
324 | 434 | | |
| 435 | + | |
325 | 436 | | |
326 | 437 | | |
327 | 438 | | |
| |||
0 commit comments