AutoEP: read and write the transformers output-capture registry as a dict (#9029)
## AutoEP: read and write the transformers output-capture registry as a
dict
### Problem
`cpu-torch-latest` installs transformers from git `main`, and since
2026-11-06 it fails on every PR with:
```
FAILED unit/v1/moe/test_autoep_unit.py::TestModelDetectionAndReplacement::test_hf_mixtral_causal_lm_matches_autoep_with_router_logits
FAILED unit/v1/moe/test_autoep_unit.py::TestModelDetectionAndReplacement::test_hf_minimax_m3_causal_lm_matches_autoep_with_router_logits
E TypeError: _CanRecordRegistry.get() takes 2 positional arguments but 3 were given
deepspeed/module_inject/auto_ep_presets/base.py:326
```
### Cause
huggingface/transformers#49594 (commit `c5bd76ec51`, 2026-11-06) changed
`transformers.utils.output_capturing._CAN_RECORD_REGISTRY` from a plain
dict to `class _CanRecordRegistry(dict)`, whose `get(model)` and
`__setitem__(model, value)` take a model and use `str(model.__class__)`
as the key. The released transformers 5.22.1 and 5.22.2 still have the
plain dict.
AutoEP's `router_logits` retargeting
(`deepspeed/module_inject/auto_ep_presets/base.py`) uses the registry as
a plain dict keyed by `str(module.__class__)`:
| Line | Call | With the new class |
|---|---|---|
| 326 | `registry.get(key, default)` | `TypeError` (the failure above) |
| 364 | `registry.get(key)` | looks up `"<class 'str'>"` and returns
`{}` |
| 305 | `registry[key] = entry` (restore) | stores under `"<class
'str'>"` |
`registry.pop` and `registry.update` are not overridden and keep
working.
### Change
| Where | What |
|---|---|
| `deepspeed/module_inject/auto_ep_presets/base.py` | Two helpers,
`_registry_get` and `_registry_set`, call `dict.get` and
`dict.__setitem__` directly; lines 305, 326 and 364 use them. The keys
stay `str(module.__class__)`, which is also what the subclass stores
under, so this works for both registry shapes. |
| `tests/unit/v1/moe/test_autoep_unit.py` |
`TestTransformersOutputRecorderRegistry`: runs
`_install_instance_transformers_output_recorders` with a plain dict and
with a dict subclass that mirrors the new `get(model)` /
`__setitem__(model, value)`; checks that the retargeted entries are
visible under the class key while the hooks are installed, and that the
registry is restored exactly afterwards (the original entry back, the
added one removed). CI runs one transformers version, so this covers
both shapes in every run. |
### Duplicate check
Searched open PRs and issues on 2026-11-06 for "_CanRecordRegistry",
"_CAN_RECORD_REGISTRY", "output capture registry" and the error message:
none found.
### Tests
Hardware: CPU only (`DS_ACCELERATOR=cpu`), Intel Xeon Platinum 8375C,
Ubuntu 22.04.5, CPython 3.12.14, torch 2.10.0, pytest 8.3.5,
pytest-xdist 3.8.0. Command, from `tests/`: `pytest --forked -n 4
unit/v1/moe/test_autoep_unit.py` (as in `cpu-torch-latest`).
| `unit/v1/moe/test_autoep_unit.py` | transformers 5.22.1 (plain dict) |
transformers `main` at `073a202c6` (`_CanRecordRegistry`) |
|---|---|---|
| master (`8af59b2e7`) | 197 passed, 6 skipped | 2 failed (the two tests
above), 195 passed, 6 skipped |
| this PR | 199 passed, 6 skipped | 199 passed, 6 skipped |
| the new test on master's code | `plain_dict` passes, `model_keyed`
fails | `plain_dict` passes, `model_keyed` fails |
`pre-commit run --files` on both changed files: all hooks pass.
Not run: GPU (the change touches only registry reads and writes on the
host).
### Compatibility
AutoEP with Hugging Face models that record `router_logits`: the
Mixtral, MiniMax-M3 and Qwen3-MoE presets (through
`TransformersTopLevelRouterLogitsAdapter`) and the Qwen3.5-MoE preset
use this path. Works with transformers 5.22.x and with transformers
`main`. No ZeRO, offload, precision or parallelism behavior changes.
### AI assistance
This change, its test and this description were prepared with AI
assistance (Claude), which also ran the tests above.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Signed-off-by: pengdurice <pengduhit@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>