← Back to Pull requests

Keep Yuan's o_proj bias whole on every rank and describe it as replicated #8857

Closed
unknown closed this pull request without merging on Oct 21, 2026 01:13 UTC
View on GitHub
unknown unknown commented on Oct 18, 2026 23:57 UTC
Author

Partitioning Yuan's output projection crashes on a bias. The obvious fix for that would make it silently wrong, so this keeps the bias whole on every rank — and once it is, the bias is an ordinary replicated parameter, which removes the last parameter universal checkpoint conversion refused unconditionally.

The crash

shard_value_with_share_qk handles both Yuan projections. On the output-projection path it computes the divided bias into bias but returns sharded_bias, which that path never fills:

else:
    bias = bias / float(world_size)
return torch.nn.Parameter(sharded_weight), torch.nn.Parameter(sharded_bias)   # sharded_bias is still []

So any Yuan configuration with a bias on o_proj fails at TP ≥ 2 during partitioning, before training starts — AttributeError: 'list' object has no attribute 'detach' on torch 2.8.0. It has been there since 8ea995ee1f (June 2024); no test partitioned that projection with a bias.

Why the obvious fix is wrong

Assigning the divided bias to sharded_bias makes the crash go away and the numbers wrong. Yuan_LinearAllreduce inherits LinearAllreduce.forward, which all-reduces the partial products first and adds the bias once afterwards — and LinearAllreduce.gather_params already says so: the bias is replicated across ranks. A pre-divided bias would come out of the layer as bias / world_size.

Checked against the unsharded layer at 8 heads TP 2, 8 heads TP 4 and 16 heads TP 4, with the real head selection:

| bias treatment | matches the unsharded output |
|---|---|
| kept whole on every rank (this PR) | exact |
| divided by the world size | wrong |
| current code | raises |

What the description becomes

With the bias kept whole, Yuan_LinearAllreduce publishes it exactly as base LinearAllreduce does: replicated=True, one piece per rank held by every rank, scale 1. Only the weight follows the shared-QK head selection.

That corrects two things I said earlier, in #8706 and in the comment this PR replaces: that this path returned an empty bias — it raises — and that the bias needed a scaled piece. That reasoning came from the divide on the broken line. Once the bias is right, no scale is involved.

This was the last unconditional unsupported_reason in layers.py. The refusals that remain are all conditional on a configuration that cannot be described: no kv head count, a head count the shared-QK pairing cannot divide without two ranks sharing a head, and codegen configurations its own partition asserts against.

The tests discriminate

| corruption | result |
|---|---|
| original line restored | partition test fails on all 3 configurations |
| bias divided by the world size | partition test fails on all 3 configurations |
| bias published as unsupported again | description test and the Yuan collection test fail |
| original line restored, through the real layer | distributed test raises the original AttributeError at TP 2 and 4 |
| bias divided by the world size, through the real layer | distributed test fails 33 of 36 output elements |

TestYuanOutputProjectionBias is the integration test: it builds the injected Yuan_LinearAllreduce on a real process group, feeds each rank the activations for its own value heads, and checks the output and both gradients against the unsharded nn.Linear at TP 2 and 4 — so it exercises the wrapper's choice of the output-projection branch and the real all-reduce-then-bias order, not a reconstruction of it. test_yuan_output_projection_keeps_its_bias_whole is the cheaper unit check over more head counts, using the unsharded layer as its reference. test_yuan_output_projection_bias_is_described_as_replicated checks the published map, and that with head counts set the layer has nothing left in AUTOTP_UNSUPPORTED_PARAMETER_PATTERNS. test_collect_records_yuan_layout_as_unsupported used to require both Yuan biases to be refused; it now separates them — the value projection's bias follows its weight's head selection and is still refused without head counts, while the output projection's is not.

Validation

250 passed across the affine suite, the resume matrix, the coverage test, the AutoEP affine suite, the transfer-plan suite, tests/unit/runtime/tensor_parallel/ and TestYuanOutputProjectionBias, on CPU/gloo (DS_ACCELERATOR=cpu LOCAL_SIZE=4; Apple M4 Pro, macOS 26.5, Python 3.9.6, torch 2.8.0). The distributed test runs as real 2- and 4-process groups — confirmed by making it fail at each world size in turn. Not run on GPU. yapf 0.43.0 and flake8 are clean on the changed files.

Scope

The conv layer at layers.py that also divides its bias by the world size is untouched. Whether that is correct depends on where that layer adds the bias relative to its reduction — the case raised in #8252 — and I have not verified it.

Related: #8252, #8230, #8575, #8706.

cc @delock

Diff: 613 lines (+459 / -154) across 7 files Reviewer: delock Review duration: 2955m
All Vouch review confidence checks passed
Residual risk 0.22 = Change Risk (0.50) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 613 lines diff across 7 files
0.50
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
56%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.384
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #8857"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 56.8% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 50.2% (MEDIUM) · Higher = larger blast radius
50.2%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 56.8% · Lower = rushed or shallow review
56.8%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 21.7% · Safe to merge
21.7%