Skip to content

CP Ulysses gloo tests: report the gradient mismatch, not just the parameter name - #17972

Merged
danielhanchen merged 1 commit into
mainfrom
cp-media-towers-test-report-mismatch
Nov 16, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
cp-media-towers-test-report-mismatch

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

tests/test_cp_ulysses_media_towers_gloo.py::test_gemma4_with_towers_matches_one_process (from #17930) has failed in four of the last gloo shard runs on unrelated PRs (staging runs of #17957, #17960, #17831 and #17966), always as:

E   AssertionError: model.language_model.layers.0.self_attn.q_proj.weight

and it passes locally every time (5 of 5 standalone, and 53 of 53 with all five test_cp_*gloo*.py files in one process, so it is not state left by an earlier test in the worker). The assertion passes msg = name, which replaces torch's whole mismatch report with the parameter name, so the CI logs do not say how many elements are off or by how much. Without that there is no way to tell a float32 reduction-order difference on the CI runners' CPUs (a tolerance question) from a real context parallel gradient bug.

Change

Test only. The gradient assert_close calls in test_cp_ulysses_media_towers_gloo.py and test_cp_ulysses_generic_gloo.py pass msg as a callable that prefixes the parameter name to torch's report instead of replacing it:

model.language_model.layers.0.self_attn.q_proj.weight: Tensor-likes are not close!

Mismatched elements: ...
Greatest absolute difference: ... (up to ... allowed)
Greatest relative difference: ... (up to ... allowed)

Tolerances are unchanged. The next CI failure will carry the numbers needed to decide whether the tolerance or the code is wrong.

Testing

  • Both files (2-rank gloo, CPU): 24 passed.
  • The message form checked directly against torch.testing.assert_close (output above).

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T12:07:59.938706Z 95e9d64 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. Delightful!

Reviewed commit: 95e9d641c7

ℹ️ 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 3318be0 into main Nov 16, 2026
@danielhanchen
danielhanchen deleted the cp-media-towers-test-report-mismatch branch November 16, 2026 12:10
danielhanchen added a commit that referenced this pull request Nov 16, 2026
… flake it (#17980)

## Summary


`tests/test_cp_ulysses_media_towers_gloo.py::test_gemma4_with_towers_matches_one_process`
(added in #17930) fails intermittently in the `Repo tests (CPU, gloo)`
job, always on a layer 0 attention projection. With the mismatch report
from #17972 the latest failure reads:

```
model.language_model.layers.0.self_attn.k_proj.weight: Tensor-likes are not close!
Mismatched elements: 2 / 512 (0.4%)
Greatest absolute difference: 1.88e-05 at index (11, 31) (up to 1.42e-05 allowed)
```

That is float32 rounding, not a context parallel bug. Layer 0 gradients
go through every layer of backprop and are summed in a different order
on either side of the shard seam. Running the same versions as CI (torch
2.10.0+cpu, transformers 5.17.0), the worst parameter on this host is
k_proj at 0.62x the tolerance on every run, and the runners whose CPU
kernels round differently hit 1.33x.

## Change

The test now builds the tiny Gemma 4 model in float64 instead of
float32. It checks attention routing with the towers present, so
precision is not what it measures. The tolerance is unchanged. In
float64 the worst parameter (the same k_proj) is at 0.012x the
tolerance, so there is about 80x headroom where float32 had very little.

## Verification

- `tests/test_cp_ulysses_media_towers_gloo.py`: 2 passed.
- Sabotage: skipping `manager.attach_attention_hooks(model)` in the
worker fails at the same tolerance on `embed_tokens.weight` with 3047 /
3072 elements mismatched and a greatest absolute difference of 2.37.
That means the tight tolerance still catches real routing errors.
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