Skip to content

PP gloo parity test: give gemma3 its own per-element grad tolerance - #15273

Merged
danielhanchen merged 1 commit into
mainfrom
ci-pp-gemma3-grad-tolerance
Oct 25, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
ci-pp-gemma3-grad-tolerance

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

tests/test_pp_fsdp2_gloo.py::test_pp2_x_tp2_matches_one_process[gemma3] fails now and then in Repo tests (CPU, rest), for example on #15222, which does not touch parallelism. The failure is only AssertionError: base_model.model.model.layers.0.self_attn.v_proj.lora_A.default.weight from the step-0 grads check.

Cause

The tolerance, not the product. The step-0 grads check allows 2e-5 of each tensor's largest entry per element for every architecture. Measured on main on this host, gemma3's (pp 2, tp 2) grads differ from the one-process reference by:

value
relative L2, every LoRA weight in layers 0 to 4 3e-6 to 2e-5
largest per-element diff / tensor max 2.1e-5
worst entry vs the current bound 0.999

The error is uniform across layers and tensors, the shape of fp32 reordering rather than a wrong slice or a missing reduction. Gemma3 already has its own looser step-0 norm bound in this file (STEP0_NORM_REL["gemma3"] = 3e-4, against 1e-5 for llama and qwen3) for the same reason. The grads check had no per-architecture bound.

Fix

  • GRAD_ATOL_REL gives gemma3 1e-4 and keeps llama and qwen3 at 2e-5. The two per-architecture tests pass it to _check.
  • The 5e-5 relative L2 bound over all grads is unchanged, so a systematic error still fails.
  • The per-tensor assert keeps assert_close's mismatch detail. It used to print only the name.

Verification

  • tests/test_pp_fsdp2_gloo.py: 12 passed.
  • Faults injected into the gemma3 step-0 grads of layers.0.self_attn.v_proj.lora_A, on both (pp 2, tp 2) and (pp 2, dp 2). Each fails the new gemma3 bound, and the clean results pass:
    • one entry off by 5e-4 of the tensor max;
    • the whole tensor with 1e-3 relative noise;
    • the tensor halved (a missing reduction).

Gemma3's step-0 LoRA grads differ from the one-process reference by about
1e-5 of each tensor (relative L2) on every layer, up to 2.1e-5 of the max per
element, which is its fp32 reordering floor (the file already gives it a 30x
looser step-0 norm bound). The shared 2e-5 per-element bound sat on that
floor: 0.999 of it on this host, and over it on CI for
test_pp2_x_tp2_matches_one_process[gemma3]. gemma3 now gets 1e-4; llama and
qwen3 keep 2e-5, the 5e-5 relative L2 bound is unchanged, and the assert keeps
assert_close's mismatch detail.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-25T14:44:51.200263Z 6514929 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 6514929d81

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit 8b050a7 into main Oct 25, 2026
0 of 14 checks passed
@danielhanchen
danielhanchen deleted the ci-pp-gemma3-grad-tolerance branch October 25, 2026 14:52
danielhanchen added a commit that referenced this pull request Oct 25, 2026
…ernels (#15286)

Follow-up to #15273.
`tests/test_pp_fsdp2_gloo.py::test_pp2_x_tp2_matches_one_process[gemma3]`
still fails on some CI runners, for example #15275, whose base includes
#15273:

```
AssertionError: base_model.model.model.layers.0.self_attn.v_proj.lora_B.default.weight: Tensor-likes are not close!
Mismatched elements: 1 / 64 (1.6%)
Greatest absolute difference: 1.7233192920684814e-05 at index (14, 1) (up to 8.591873198747636e-06 allowed)
```

## Cause

The bound I set in #15273 came from this host's AVX-512 kernels.
Gemma3's tensor-parallel fp32 noise depends on which kernels MKL and
oneDNN dispatch to.

Worst step-0 grad difference against the one-process reference, as a
fraction of the tensor max / relative L2, same seed:

| arch, layout | AVX-512 (this host) | MKL + oneDNN held to AVX2 |
| --- | --- | --- |
| gemma3, pp 2 x tp 2 | 2.8e-5 / 2.4e-5 | 1.6e-4 / 1.4e-4 |
| gemma3, pp 2 x dp 2 | 3.8e-7 | 4.1e-7 |
| llama, pp 2 x tp 2 | | 2.5e-6 / 2.6e-6 |
| qwen3, pp 2 x tp 2 | | 5.8e-6 / 4.5e-6 |

The AVX2 run fails main's bounds the same way CI does: 18 of 168 tensors
over gemma3's per-element bound, and the relative L2 over the shared
5e-5. A CI runner saw 2e-4 per element.

So gemma3 under tensor parallel sits about 30x above llama and qwen3 on
the same code. The size moves with the instruction set, the signature of
rounding amplified by the model's conditioning rather than a systematic
error. The thread count makes no difference (1, 2 and 4 threads give
identical numbers).

## Fix

| | per element | relative L2 |
| --- | --- | --- |
| gemma3 (`GRAD_ATOL_REL` / new `GRAD_L2_REL`) | 1e-3 | 5e-4 |
| llama, qwen3 (unchanged) | 2e-5 | 5e-5 |

llama and qwen3 keep the strict bounds on the same tensor parallel code,
which is architecture-generic. A gemma3-specific fault, such as a wrong
shard or a missed reduction, is an O(1) difference.

## Verification

- `test_pp2_x_tp2_matches_one_process`, AVX2 emulation
(`DNNL_MAX_CPU_ISA=AVX2 MKL_ENABLE_INSTRUCTIONS=AVX2
ATEN_CPU_CAPABILITY=avx2`): main 1 failed, 2 passed (the gemma3 case, as
on CI); this PR 3 passed. On this host's default kernels both pass.
- Whole file: 12 passed under both kernel sets.
- Faults injected into gemma3's (pp 2, tp 2) step-0 `v_proj.lora_B` grad
under AVX2. Each fails, and the clean results pass:
  - one entry off by 1e-2 of the tensor max;
  - the whole tensor with 5e-3 relative noise;
  - the tensor halved (a missing reduction);
  - the two tp shards swapped.
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