Skip to content

Build the reduced float Reduce test reference from the rounded inputs - #206820

Closed
pablo-garay wants to merge 1 commit into
pytorch:mainfrom
pablo-garay:rocm-vec-reduce-ref-from-reduced-inputs
Closed

pablo-garay wants to merge 1 commit into
pytorch:mainfrom
pablo-garay:rocm-vec-reduce-ref-from-reduced-inputs

Conversation

@pablo-garay

@pablo-garay pablo-garay commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor
  • Passes lint (spin fixlint)
  • Added/updated tests
  • Updated documentation (if applicable)
  • Included benchmark results (for PRs impacting perf)

Linked issue or supporting maintainer

Supported by @jeffdaily
Tracking issue: https://github.com/jithunnair-amd/sandbox/issues/11666

BC-breaking?

No

Summary (human written only)

vec_test_all_types_AVX512 FunctionalTestsReducedFloat/0.Reduce (BFloat16) failed on the ROCm MI350 default job with seed 1795644424012988038 (map3_reduce_all, Length: 49; fp32: -0.0549982; bf16: -0.0659196, failing job) and passed when rerun with a new seed. The test compares the reduced float reductions against a float reference computed from the unrounded inputs, while the vectorized path gets the inputs rounded to BFloat16/Half. Since reduce_all and map*_reduce_all in functional_bfloat16.h convert to float and do all the math in float, the only real difference is the input rounding, and summed over up to 66 terms it can exceed the 0.01 + 1% tolerance whenever the result cancels to near zero. This builds the float reference inputs from the rounded values, so the test checks the vectorized reduction instead of input quantization. The tolerances are unchanged.

Agent details

An AI coding agent did the CI log analysis and wrote the change and this description. No local PyTorch build was available, so the C++ test was not compiled or run, and nothing was run on a GPU (the test itself is CPU-only). A numpy model of the test (same ValueGen distribution and AVX512 BFloat16 sizes, all four reductions) fails about 0.7% of seeds with the current reference and none of 20000 seeds with the reference built from the rounded inputs.

FunctionalTestsReducedFloat.Reduce generates float inputs, rounds them to
BFloat16/Half for the vectorized path, and compares against a float reference
computed from the unrounded inputs. The reduced float reduce helpers
(reduce_all, map*_reduce_all in functional_bfloat16.h) convert to float and
do all of the math in float, so the only real difference between the two
results is the input rounding. Summed over up to N terms (66 for AVX512
BFloat16) that rounding error is on the order of 0.01, while the tolerance is
0.01 + 1% of the result, which fails whenever the sum cancels to near zero.
This happened on CI with seed 1795644424012988038:
map3_reduce_all, Length: 49; fp32: -0.0549982; bf16: -0.0659196.

Build the float reference inputs from the rounded values instead, so the
comparison measures the vectorized reduction rather than the input
quantization. The tolerances are unchanged.

Test Plan:
A numpy model of the test (same ValueGen distribution, AVX512 BFloat16 sizes,
all four reductions) fails about 0.7% of seeds with the old construction and
none of 20000 seeds with the new one. No local build was available to run the
C++ test itself.

```
python3 sim_reduce.py
```

Signed-off-by: Pablo Garay <[email protected]>
@pytorch-bot pytorch-bot Bot added the topic: not user facing topic category label Nov 26, 2026
@pytorch-bot

pytorch-bot Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

PR Status: Approved 🚀

Please fix all CI failures and trigger merge by commenting "@pytorchbot merge".

✅ AUTOMATED REVIEW - Ready for human review:

This PR changes the `FunctionalTestsReducedFloat.Reduce` test so its float
reference is built from the BFloat16/Half-rounded inputs, not the unrounded
ones. The fix looks right and old seeds still reproduce, but this comes from
reading the code only. Recommendation: Approve, with one non-blocking point.

Findings (1):

[minor] aten/src/ATen/test/vec_test_all_types.cpp:1935
Non-blocking: the test could be stricter now. This is a follow-up idea; the PR
loosens nothing. The old `atol = rtol = 0.01` was sized to absorb input-rounding
noise in the reference, and this PR removes that noise. `cmp` takes `VT val`, so
the float results of `reduce_all` and `map*_reduce_all` are rounded to
BFloat16/Half before the comparison. Together, that rounding and the old
tolerance leave much more slack than the float result needs. A regression such
as accumulating in BFloat16 inside `functional_bfloat16.h` might still pass for
many seeds (plausible from the arithmetic, not demonstrated). Suggestion:
compare `y2` as a float against `y1` with a tighter tolerance to sharpen those
four checks. This wouldn't help `reduce2_all`, which rounds to `scalar_t`
internally before returning (`functional_bfloat16.h:181`, `:185`, `:225`).

Reviewed commit: 6f56673

Review run

🐛 Report a bad review

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/206820

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 New Failure, 1 Unclassified Failure

As of commit 6f56673 with merge base deaabcc (image):

NEW FAILURE - The following job has failed:

  • trunk / macos-py3-arm64 / test (default, 2, 3, macos-m1-stable) (gh)
    test/test_scaled_matmul_cuda.py::TestFP8MatmulDeviceMPS::test_mxfp8_scaled_grouped_mm_2d_3d_G_4_M_16640_N_8192_K_4096_format_nvfp4_use_out_False_mps

    AI verdict: AI verdict: probably not related

    The suspect only changes the C++ CPU gtest vec_test_all_types.cpp. The failing test is a Python MPS test that died with an asynchronous 'MPS command buffer execution failed: Internal Error' during a simple .to(device) copy. That is a GPU runtime fault, and nothing in the commit can reach it. The same shard was green at the merge base and on later trunk commit 53540cb.

    Full reasoning on HUD →

UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:

  • Auto Request Review (gh) (this job did not run on the merge base, so DrCI cannot tell whether the failure is pre-existing)

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@jithunnair-amd jithunnair-amd added ciflow/trunk Trigger trunk jobs on your pull request ciflow/rocm-mi350 Trigger "default" config CI on ROCm MI350 runners labels Nov 26, 2026
@pytorch-bot

pytorch-bot Bot commented Nov 26, 2026

Copy link
Copy Markdown

Warning: Unknown label ciflow/rocm-mi350.
Currently recognized labels are

  • ciflow/b200
  • ciflow/b200-cuspy
  • ciflow/b200-distributed
  • ciflow/b200-symm-mem
  • ciflow/binaries
  • ciflow/binaries_libtorch
  • ciflow/binaries_wheel
  • ciflow/cpp-faketensor
  • ciflow/docker
  • ciflow/dtensor
  • ciflow/gb300
  • ciflow/h100
  • ciflow/h100-cutlass-backend
  • ciflow/h100-distributed
  • ciflow/h100-symm-mem
  • ciflow/inductor
  • ciflow/inductor-cu126
  • ciflow/inductor-micro-benchmark
  • ciflow/inductor-micro-benchmark-cpu-x86
  • ciflow/inductor-pallas
  • ciflow/inductor-perf-compare
  • ciflow/inductor-perf-test-nightly-rocm-mi300
  • ciflow/inductor-perf-test-nightly-rocm-mi350
  • ciflow/inductor-perf-test-nightly-x86-zen
  • ciflow/inductor-perf-test-nightly-xpu
  • ciflow/inductor-periodic
  • ciflow/inductor-rocm-mi200
  • ciflow/inductor-rocm-mi300
  • ciflow/mps
  • ciflow/native-aot
  • ciflow/nightly
  • ciflow/op-benchmark
  • ciflow/periodic
  • ciflow/periodic-rocm-mi200
  • ciflow/periodic-rocm-mi300
  • ciflow/periodic-rocm-mi350
  • ciflow/periodic-strict
  • ciflow/pull
  • ciflow/riscv64
  • ciflow/rocm-mi200
  • ciflow/rocm-mi300
  • ciflow/rocm-nightly
  • ciflow/rocm-preview
  • ciflow/rocm-rx7900
  • ciflow/s390
  • ciflow/slow
  • ciflow/slow-rocm-mi200
  • ciflow/torchtitan
  • ciflow/triton_binaries
  • ciflow/trunk
  • ciflow/tsan
  • ciflow/unstable
  • ciflow/win-arm64
  • ciflow/xpu

Please add the new label to .github/pytorch-probot.yml

@pablo-garay
pablo-garay marked this pull request as ready for review December 1, 2026 16:31
@github-actions
github-actions Bot requested a review from jeffdaily December 1, 2026 16:33
@github-actions github-actions Bot added bot-triaged This is a label only to be used by the auto triage bot triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels Dec 1, 2026
@pytorch-bot pytorch-bot Bot added the in progress PR is being worked on by the author, until the automated review accepts it label Dec 1, 2026

@github-actions github-actions Bot left a comment

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.

Automated review of 6f56673: nothing blocking; ready for human review.

This PR changes the FunctionalTestsReducedFloat.Reduce test so its float reference is built from the BFloat16/Half-rounded inputs, not the unrounded ones. The fix looks right and old seeds still reproduce, but this comes from reading the code only. Recommendation: Approve, with one non-blocking point.

⚪ 1 non-blocking finding is attached to the code below, collapsed.

This review is AI-generated and advisory. Each new automated review replaces the previous one. Report a bad review

x_f2[i] = RT(x_b2[i]);
x_f3[i] = RT(x_b3[i]);
}
float atol = 0.01f;

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.

⚪ Non-blocking: the test could be stricter now.

This is a follow-up idea; the PR loosens nothing. The old atol = rtol = 0.01 was sized to absorb input-rounding noise in the reference, and this PR removes that noise. cmp takes VT val, so the float results of reduce_all and map*_reduce_all are rounded to BFloat16/Half before the comparison. Together, that rounding and the old tolerance leave much more slack than the float result needs. A regression such as accumulating in BFloat16 inside functional_bfloat16.h might still pass for many seeds (plausible from the arithmetic, not demonstrated). Suggestion: compare y2 as a float against y1 with a tighter tolerance to sharpen those four checks. This wouldn't help reduce2_all, which rounds to scalar_t internally before returning (functional_bfloat16.h:181, :185, :225).

Report this finding

@jeffdaily

Copy link
Copy Markdown
Collaborator

@pytorchbot merge -i

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged while ignoring the following 2 checks: Auto Request Review, trunk / macos-py3-arm64 / test (default, 2, 3, macos-m1-stable)

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

This branch was previously deployed

1 inactive deployment
bedrock — 6f566735 Deployed Dec 1, 2026 by pablo-garay via analyze #46170
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot-triaged This is a label only to be used by the auto triage bot ciflow/trunk Trigger trunk jobs on your pull request in progress PR is being worked on by the author, until the automated review accepts it Merged open source topic: not user facing topic category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants