Skip to content

Add an explicit RMSNorm kernel-family contract - #19

Closed
kiddyboots216 wants to merge 1 commit into
mainfrom
pr/k3-rmsnorm-family-contract
Closed

Add an explicit RMSNorm kernel-family contract#19
kiddyboots216 wants to merge 1 commit into
mainfrom
pr/k3-rmsnorm-family-contract

Conversation

@kiddyboots216

Copy link
Copy Markdown
Contributor

Which RMSNorm kernel runs was decided by whether a call site passed a residual argument: with one, the mean_dim reduction tree; without, the looped kernel. The two sum the hidden dimension in a different order, so rewriting a call site could move a layer between kernels without changing any declaration, leaving trainer and sampler on different reduction orders for the same layer.

A site now declares its family explicitly. Dispatch is bit-identical to the force_sglang_residual expressions the call sites used to carry, in every combination of rmsnorm and batch-invariant mode.

Sampler half: togethercomputer/xorl-sglang branch pr/k3-rmsnorm-family-contract.

Self-contained by design — carries its own batch_invariant_ops.py and conflicts with the sibling contract PRs.

@broly-code-security-scanner

Copy link
Copy Markdown

Broly Security Scan

Note

Clean scan
No vulnerabilities detected in this PR.

Note

Re-scan this PR anytime with /broly scan — useful after /broly undismiss, or to refresh findings without a new push.

Broly — SAST (zai-org/GLM-5.2) · Secrets · SCA · IaC · GH Actions · Base Images · Supply Chain Threats · Exploit Chains · Adversarial Verification

We're continuously improving Broly's accuracy and finding quality — your feedback is valuable. False positives, missed findings, bugs, and feature requests all welcome.

Ask in #security-engineering   Powered by Together AI

Two batch-invariant rmsnorm kernel families coexist (looped tl.sum +
1.0/tl.sqrt vs mean_dim + tl.rsqrt) and disagree at 1 ulp on rare bf16
boundary values, so an implicit family flip against serving is a silent
K3 seed (the 2026-07-04 norm-seed incident: 2.99e-5 from five such
seeds). Make the family an explicit declaration instead of a consequence
of how the call site is written.

- batch_invariant_ops: RMSNormFamily constants plus the bi_rms_norm /
  bi_fused_add_rms_norm funnels. The aten::rms_norm interpose, the fused
  autograd wrappers, and the family-1 trunk-contract wrapper route
  through them. Kernels untouched.
- The Qwen3.5 zero-centered twin registers as family-1 with a
  zero_centered fold in the funnel (same reduction tree, fp32 1+weight
  fold) rather than becoming a third family.
- RMSNorm: family declaration at construction or per call; violations
  raise; undeclared calls in a parity lane warn once and raise under
  XORL_RMSNORM_REQUIRE_FAMILY=1. Qwen3, Qwen3-MoE and the shared
  attention qk-norms declare their site families.
- tests: family contract guards plus cross-engine bitwise gates against
  SGLang's dispatched kernels per site-class, on adversarial shapes
  including the [4096, 128] 1-ulp seed shape.

batch_invariant_ops.py is new here and carries only the surface this
contract needs: the shared batch-invariant kernels and mode plumbing,
the rmsnorm kernels, and the family funnels. The shape-keyed GEMM config
table, the fused LM-head logprob, and the MoE router GEMM are separate
contracts and are not included.
@kiddyboots216
kiddyboots216 force-pushed the pr/k3-rmsnorm-family-contract branch from cc6e633 to 5f718cb Compare July 29, 2026 03:45
@qywu
qywu self-requested a review July 30, 2026 03:38
@kiddyboots216

Copy link
Copy Markdown
Contributor Author

Superseded by #22, which consolidates the explicit RMSNorm-family dispatch with the shared numerical contract on the repaired Foundation branch. This standalone copy should not be merged independently.

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.

2 participants