Skip to content

fix(test): unblock Kimi-Linear HF reference and gate MiniMax routed parity - #3644

Closed
yuhezhang-ai wants to merge 4 commits into
yuhez/fix/amint286-minimax-rope-referencefrom
yuhez/fix/amint288-kimi-outputrecorder-shim
Closed

fix(test): unblock Kimi-Linear HF reference and gate MiniMax routed parity#3644
yuhezhang-ai wants to merge 4 commits into
yuhez/fix/amint286-minimax-rope-referencefrom
yuhez/fix/amint288-kimi-outputrecorder-shim

Conversation

@yuhezhang-ai

Copy link
Copy Markdown
Contributor

What does this PR do?

Unblocks the Kimi-Linear vanilla-HF reference (AMINT-288) and closes the MiniMax M2.7 cross-framework residual with measured router evidence (AMINT-286). Stacked on #3643; includes a merge of #3635 (GLM parity diagnostics), whose router/shape machinery this PR extends.

With this stack, kimi_linear_48b_a3b_hellaswag passes all six phases on the standard profile for the first time (pipeline 64182587: source HF vs AM mean KL 0.0021 / cosine 0.9994; export reload 0.0023; resume exact-state), and minimax_m2.7_hellaswag_lora gates its shared 128-token prefix with full-2K metrics and router evidence kept diagnostic.

Changelog

Kimi-Linear reference compatibility (the checkpoint's remote code targets transformers 4.57.1 / fla-core 0.4.0; the CI image runs transformers 5.12.1 / fla-core 0.4.2; no in-tree implementation exists):

  • fix(transformers): alias the relocated OutputRecorder back into transformers.utils.generic in apply_cache_compatibility_patches (production compat patcher; same class object; no-op when present).
  • Re-resolve vanilla-HF reference configs from the checkpoint's auto_map when AutoModel's _CUSTOM_CONFIG_REGISTRATIONS hijacks AutoConfig to a nemo-owned class, and drop nemo component configs forwarded from config-based recipes.
  • Extend the remote masking patch to rename the legacy input_embeds kwarg.
  • Translate legacy fused_kda_gate(g, A, head_k_dim, g_bias=...) calls onto fla-core 0.4.2's renamed/reshaped API.

MiniMax M2.7 residual (router precision + measured tie sensitivity):

  • fix(moe): score sigmoid routing in fp32 by default, mirroring the softmax branch and the HF references' sigmoid(logits.float()); final weights keep the existing cast to input dtype. Production behavior change for sigmoid-router MoE models (MiniMax, GLM, DeepSeek families): bf16 sigmoid quantized scores at ~2e-3, flipping 7-13% of top-k selections per layer against the fp32 reference on M2.7's real bias lattices.
  • Pin AutoModel's strict-fp32 tensors across vanilla-HF layout differences (leaf-name registration): the AM-path name mlp.gate.e_score_correction_bias never matched in-tree mlp.e_score_correction_bias, silently casting the reference's router bias to bf16 (215-242/255 adjacent expert pairs collide exactly in bf16 at bias magnitude 8.6).
  • Extend the fix(glm): align and diagnose cross-framework router parity #3635 router diagnostics to MiniMax M2 (in-tree MiniMaxM2TopKRouter capture; model_family derived from config.model_type; groupless n_expert_groups=0 captures normalized) and enable router + [128, 512] shape diagnostics on the recipe.
  • Gate MiniMax cross-framework parity on a 128-token prefix with relaxed profiles (GLM-4.7-Flash disposition), justified by the captured evidence: 68% of tokens flip a routed expert within the first five layers, zero flips outside the measured score-noise band, bias-direction symmetric (0.489 vs 0.5), no token traverses 62 layers unflipped; vanilla HF disagrees with itself on the same 128-token prefix across total-length kernel regimes (mean KL 0.008, 127/128 argmax flips).

Validation

  • Pipeline 64182587: Kimi full pass (all six phases, standard profile); MiniMax router/shape evidence captured as designed.
  • Prefix-gate validation run for MiniMax pending from this head.
  • Unit coverage: fla/masking/OutputRecorder shims against fake old/new APIs; reference-config re-resolution round trip; HF+AM router capture and compare on tiny real MiniMax models; fp32 sigmoid gate vs fp32 reference math (bitwise); fp32 leaf-name contract. Touched suites pass in full (moe, minimax_m3_vl, deepseek_v3, ci_tests, _transformers). ruff clean; DCO-signed.

🤖 Generated with Claude Code

@copy-pr-bot

copy-pr-bot Bot commented Aug 24, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

yuhezhang-ai and others added 4 commits August 25, 2026 07:31
Transformers v5.x moved OutputRecorder from transformers.utils.generic to
transformers.utils.output_capturing without a back-compat alias. Pre-v5
remote-code checkpoints (Kimi-Linear-48B-A3B, MiniMax-M2.*) import it from
the old location for their auxiliary router-logit recorders, so the whole
modeling module fails at import (AMINT-288): with no in-tree kimi_linear in
Transformers, the checkpoint-robustness vanilla-HF source and export-reload
phases cannot construct a reference at all.

Alias the relocated class (re-exported by transformers.modeling_utils in
v5.x) back into transformers.utils.generic inside
apply_cache_compatibility_patches, which the checkpoint-robustness harness
already applies before every vanilla-HF reference load and which owns the
existing v5-removal shims (SlidingWindowCache, Cache.get_usable_length).
The alias binds the identical class object and is a no-op on Transformers
versions that still export it from utils.generic.

Verified against the cached Kimi-Linear remote code under transformers
5.12.1: module import now proceeds past OutputRecorder to the model's
fla-core dependency (present in the CI image). Kimi's remote code uses no
rope-init APIs, so it does not hit the separate v5 ROPE_INIT_FUNCTIONS
'default'-key removal that still breaks MiniMax-M2 remote code (whose
reference intentionally stays on the repaired in-tree path).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Yuhe Zhang <yuhez@nvidia.com>
…rations

nemo_automodel registers component config classes into Transformers'
CONFIG_MAPPING (_CUSTOM_CONFIG_REGISTRATIONS), and a locally registered
model_type beats checkpoint remote code even under trust_remote_code=True.
Inside the checkpoint-robustness process this hijacks the vanilla-HF
reference for remote-code-only models: AutoConfig resolves Kimi-Linear to
the AutoModel-owned config class while the model class comes from the
checkpoint's auto_map, and from_pretrained rejects the pair with a
config_class mismatch in both the source-load and export-reload phases
(AMINT-288, pipeline 64093591 after the OutputRecorder shim).

Re-resolve the checkpoint's own config class from its auto_map whenever the
reference config resolves to a nemo_automodel-owned class, pass the faithful
config explicitly so from_pretrained's internal resolution cannot re-select
the registered class, preserve a load-time FP8 dequantize request across the
replacement, and drop AutoModel component configs that config-based recipes
forward through the reference load kwargs. All paths are no-ops for models
whose configs already resolve to Transformers-owned classes.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Yuhe Zhang <yuhez@nvidia.com>
With the OutputRecorder shim and reference-config resolution in place, the
Kimi-Linear vanilla-HF reference now loads and fails one step later: its
pre-v5 remote code calls create_causal_mask(input_embeds=...), which
Transformers v5.x renamed to inputs_embeds (pipeline 64160712, job
408783019). Extend _patch_remote_masking_api_compatibility to rename the
legacy keyword when the installed function only accepts the new name, next
to the existing removed-cache_position handling. Functions that accept the
legacy API are still left unwrapped.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Yuhe Zhang <yuhez@nvidia.com>
With the masking rename fixed, Kimi-Linear's vanilla-HF reference reaches
its KDA layers and fails on the fifth compatibility break (pipeline
64176083, job 408883841): the checkpoint's remote code calls the pre-0.4.2
fla API fused_kda_gate(g, A_log, head_k_dim, g_bias=...) with a flat gate
projection, while fla-core 0.4.2 renamed the keyword to dt_bias, dropped
head_k_dim, and expects g pre-reshaped to [..., heads, head_k_dim].

Add _patch_remote_fla_api_compatibility next to the masking patch at both
vanilla-HF reference sites: translate legacy calls (reshape + keyword
rename), reject unsupported non-default beta/threshold overrides loudly,
pass new-style calls through untouched, and leave an installed fla that
still accepts g_bias unpatched.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Yuhe Zhang <yuhez@nvidia.com>
@yuhezhang-ai
yuhezhang-ai force-pushed the yuhez/fix/amint288-kimi-outputrecorder-shim branch from 6f904f5 to cde5b6e Compare August 25, 2026 14:50
@yuhezhang-ai

Copy link
Copy Markdown
Contributor Author

Restructured: the Kimi-Linear fixes are independent of the MiniMax work, so this stacked PR is replaced by a standalone PR based directly on #3567's branch (same head branch, now containing only the Kimi commits).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant