Skip to content

Add Kimi K3 numerical validation - #4731

Merged
shuhuayu merged 1 commit into
pytorch:mainfrom
shuhuayu:k3-parity
Oct 2, 2026
Merged

shuhuayu merged 1 commit into
pytorch:mainfrom
shuhuayu:k3-parity

Conversation

@shuhuayu

@shuhuayu shuhuayu commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Make the manual Moonshot BF16 forward-parity diagnostic reproducible with a pinned Hugging Face revision, seed 42, deterministic algorithms, and the eager reference attention backend. Reference dependency versions are documented, not enforced at runtime.
  • Adapt the diagnostic to the current Kimi K3 config structure and retain the released vocabulary IDs while reducing the architecture to the current debugmodel dimensions.
  • Reuse the existing kimi_k3_debugmodel_mm_muon B200 integration test as a 10-step loss/gradient-norm regression; this PR adds no new training recipe.
  • Document the existing Kimi K3 TP/SP, EP, PP, and VPP support and B200 coverage.
  • Leave the existing KDA unit-test coverage unchanged from main.

Why

Kimi K3 had training smoke coverage but no checked-in, architecture-specific loss/gradient-norm trace. This change makes the existing 2-GPU FSDP2/EP2 DistMuon run detect numerical drift through scripts/loss_compare.py without adding another nearly identical test configuration.

The one-GPU model-only seed checkpoint uses the existing AdamW kimi_k3_debugmodel_mm recipe because DistMuon requires DTensor parameters. The measured 10-step run still uses kimi_k3_debugmodel_mm_muon; the seed recipe only initializes the shared model state.

The Moonshot comparison remains a manual diagnostic rather than CI. CI drift detection comes from the B200 golden.

Moonshot BF16 parity

The pinned diagnostic was run twice on one GB300 GPU with identical results:

  • Hugging Face revision: 9f62e4e9fffbd0a83ddd60e1c209d828994b3569
  • Pixel preprocessing max difference: 1.192e-07
  • Projected vision features: cosine 0.999987, max difference 3.125e-02
  • MoE routes: 5230/5248 match (99.7%)
  • Final logits: KL 1.0212e-05, cosine 0.999968, max difference 1.5625e-02
  • Top-1 and top-5: 100% match

B200 golden

  • Config: kimi_k3_debugmodel_mm_muon
  • Parallelism: FSDP2 + EP2 on 2 B200 GPUs
  • Metrics: full-precision TensorBoard loss and grad_norm, 10 steps
  • Determinism: seed 42 with deterministic algorithms enabled by loss_compare.py
  • Export: B200 run 36969900518
  • Golden SHA-256: 358b64b64f4f649b14d943b78e860af79fea028181b108d8eba4bd65745d39d8
  • Independent import/assert: B200 run 36971319111

Validation

  • Two local GB300 Moonshot runs completed with identical metrics.
  • The B200 export produced the checked-in trace; an independent B200 run extracted all 10 steps and passed exact equality for both loss and gradient norm.
  • tests/unit_tests/cpu/test_integration_test_definitions.py: 17 passed.
  • PR-scoped formatting, lint, and documentation hooks pass; targeted Pyrefly reports zero errors.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 16, 2026
@shuhuayu shuhuayu changed the title Add Kimi K3 HybridEP and numerical validation Add Kimi K3 numerical validation Sep 16, 2026
@shuhuayu shuhuayu mentioned this pull request Sep 21, 2026
14 of 18 tasks
@shuhuayu
shuhuayu force-pushed the k3-parity branch 2 times, most recently from a222ab0 to 4ade385 Compare October 2, 2026 05:39
@shuhuayu shuhuayu added the ciflow/b200 Trigger B200 CI label Oct 2, 2026
@shuhuayu
shuhuayu force-pushed the k3-parity branch 2 times, most recently from 0b4d8df to 68d9e9e Compare October 2, 2026 05:58
@shuhuayu
shuhuayu marked this pull request as ready for review October 2, 2026 07:42
@pytorch-bot pytorch-bot Bot added the ciflow/fake-pg Run 1-GPU Fake PG integration tests label Oct 2, 2026

End-to-end KL divergence against the Hugging Face implementation (multimodal
inputs): **6.7634e-7**, with **100% top-1 and top-5 match**.
inputs): **1.0212e-5**, with **100% top-1 and top-5 match**.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this caused by recent KDA changes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think the main reason is the previous number is ran using fp32 and i updated it with bf16.

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

Labels

ciflow/b200 Trigger B200 CI ciflow/fake-pg Run 1-GPU Fake PG integration tests CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants