[model] support Nanbeige4.2 Looped Transformer for LoRA/full SFT - #10668
[model] support Nanbeige4.2 Looped Transformer for LoRA/full SFT#106684teven wants to merge 3 commits into
Conversation
Add Nanbeige4.2 model registration, chat templates, transformers>=5 rope_scaling compatibility patch, and training examples.
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
Add Base pretrain/SFT examples with ChatML special-token setup, and clarify that Base and Instruct share the architecture but use different tokenizer paths.
Nanbeige4.2's trust_remote_code files predate the transformers>=5.x
refactors and crash in two places:
1. Checkpoint save crashes with `AttributeError: 'list' object has no
attribute 'keys'` because the remote `modeling_nanbeige.py` declares
`_tied_weights_keys` as List[str], but transformers>=5.x refactored
tied-weights handling to expect Dict[str, str] (target -> source) and
calls `.keys()` on it in `remove_tied_weights_from_state_dict`.
2. Standalone `from_pretrained` (e.g. test_embed.py) crashes with
`KeyError: 'type'` because the remote `_init_rope` reads
`rope_scaling['type']`, but transformers>=5.x injects
`{'rope_type': 'default', ...}` (renamed key).
Fixes:
- `patcher.py`: add two compatibility shims in `patch_config` and
`patch_model` that normalize rope_scaling (rope_type -> type / None)
and convert `_tied_weights_keys` from list to dict at model load time.
Both shims are guarded by `model_type == 'nanbeige'` and become no-ops
once upstream Nanbeige ships transformers>=5.x-compatible remote code.
- `scripts/patch_nanbeige_remote_code.py`: one-shot idempotent patcher
for the cached remote code on GPU clusters, fixing standalone scripts
that bypass LlamaFactory (e.g. test_embed.py). Patches
modeling_nanbeige.py (tied_weights + _init_rope) and
configuration_nanbeige.py (_rope_scaling_validation), clears
__pycache__.
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
Follow-up fix: Nanbeige4.2 remote code vs transformers>=5.xWhile running training on the production GPU cluster, two crashes showed up that are not bugs in LlamaFactory itself, but incompatibilities between Nanbeige4.2's Problem 1: checkpoint save crashesThe remote Problem 2: standalone
|
Summary
model_type=nanbeige,trust_remote_code) for LoRA and full SFT.nanbeige/nanbeige_nothinkchat templates and WebUI model entries for Base/Instruct.rope_scalinginjection so remotemodeling_nanbeige.pycan initialize RoPE correctly.Notes
num_loops=2(roughly 2x forward compute vs a plain 22-layer model).Test plan
trust_remote_code=true,use_fast_tokenizer=falsenanbeige/nanbeige_nothinkexamples/train_full/nanbeige42_full_sft.yaml— validated on the production GPU cluster after fixing the transformers>=5.x remote-code incompatibilities (see commitdb026093and the follow-up comment:_tied_weights_keyslist->dict crash during checkpoint save, andrope_scaling["type"]KeyError in standalonefrom_pretrained).