Skip to content

DO NOT MERGE: run all macOS CI on macos-m1-15 to reproduce the Sequoia failures - #198674

Closed
huydhn wants to merge 5 commits into
pytorch:mainfrom
huydhn:huydhn/mac-mps-add-macos-m1-15
Closed

huydhn wants to merge 5 commits into
pytorch:mainfrom
huydhn:huydhn/mac-mps-add-macos-m1-15

Conversation

@huydhn

@huydhn huydhn commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

DO NOT MERGE. A reproduction vehicle: points every macOS job at
macos-m1-15 so this PR's own CI exercises Sequoia on M1.

Run 36181945977
produced 19 consistent failures. 10 are covered by #198689; 9 are not.


NOT covered by #198689 — needs an owner

Both groups are CPU, so the MPS gates in #198689 do nothing for them. These
are what still block Wave 2 (us-east-1 → Sequoia).

8 x byte→half conversion, test_unary_ufuncs

default 3/3 on i-0bf334e585cb3d11b

TestUnaryUfuncsCPU::test_non_contig_byte_cpu_float16
TestUnaryUfuncsCPU::test_non_contig_byte_cpu_bfloat16
TestUnaryUfuncsCPU::test_non_contig__refs__conversions_byte_cpu_float16
TestUnaryUfuncsCPU::test_non_contig__refs__conversions_byte_cpu_bfloat16
TestUnaryUfuncsCPU::test_contig_vs_every_other_byte_cpu_float16
TestUnaryUfuncsCPU::test_contig_vs_every_other_byte_cpu_bfloat16
TestUnaryUfuncsCPU::test_contig_vs_every_other__refs__conversions_byte_cpu_float16
TestUnaryUfuncsCPU::test_contig_vs_every_other__refs__conversions_byte_cpu_bfloat16
test_unary_ufuncs.py:373  assertEqual(op(contig), op(non_contig))
AssertionError: Tensor-likes are not equal!
  Mismatched elements: 14 / 35 (40.0%)
  Greatest absolute difference: 255 at index (0, 1)

Wrong values, not precision drift — the non-contiguous path reads garbage.
Worth noting this would hit users on macOS 15, not just CI.

1 x linalg_pinv gradient, test_aotdispatch

default 2/3 on i-038ded07e7bdd9e9a

TestEagerFusionOpInfoCPU::test_aot_autograd_symbolic_exhaustive_linalg_pinv_hermitian_cpu_float32
AssertionError: Tensor-likes are not close!
  Mismatched elements: 2 / 50 (4.0%)
  Greatest absolute difference: 0.00048828125 (up to 1e-05 allowed)

Small numeric drift on the compiled-vs-eager gradient — plausibly Accelerate/LAPACK
on macOS 15. Different in character from the byte bug; likely a separate issue.


Covered by #198689 — 10 MPS

test_mps job (widest view) ·
also in 1/3 ·
2/3 ·
3/3

  • test_ops.py::TestCommonMPS::test_dtypes_scatter_reduce_amin/amax_mps
  • test_ops.py::TestCommonMPS::test_noncontiguous_samples_scatter_reduce_amin/amax_mps_int64
  • test_mps.py::TestConsistencyMPS::test_output_match_scatter_reduce_amin/amax_mps_int64
  • test_mps.py::TestMPS::test_large_bmm_float16 / bfloat16
  • test_nn.py::TestNNDeviceTypeMPS::test_grid_sample_large_index_2d/3d_mps_float32

Root cause: MACOS_VERSION used as a proxy for a hardware property (16 GB vs
32 GB; ulong atomics on Apple7 vs Apple8). #198689 adds or IS_APPLE_M1.


What the run established

  • Not a build/test OS mismatch. Build ran on Sequoia M1 and
    succeeded; tests still fail.
  • Not Sequoia generally. macos-m2-15
    and macos-m2-26 are green on the same artifact.
  • Not pre-existing on Sonoma. The all-Sonoma main run
    36180577497
    scheduled the identical 25758 test_unary_ufuncs items and passed.
  • So: macOS 15 on M1 specifically, for both the MPS and CPU groups.

Changes here

trunk.yml (build runner-type, default 1-3, openreg), mac-mps.yml (build
runner-type + the macos-m1-14 entry), inductor-perf-test-nightly-macos.yml
(build runner-type), actionlint.yaml (register macos-m1-15).

Close rather than merge: macos-m1-15 is ~10 runners against ~96 Sonoma pets,
and the tests fail there by construction.

cc @jgong5 @mingfeima @XiaobingSuper @sanchitintel @ashokei @jingxu10 @aditew01

@pytorch-bot

pytorch-bot Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 8 New Failures, 2 Unrelated Failures

As of commit a7aade8 with merge base f46ffe0 (image):

NEW FAILURES - The following jobs have failed:

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

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

@pytorch-bot pytorch-bot Bot added the topic: not user facing topic category label Sep 25, 2026
@huydhn huydhn added ciflow/trunk Trigger trunk jobs on your pull request ciflow/mps Run MPS tests (subset of trunk) labels Sep 25, 2026
@huydhn
huydhn force-pushed the huydhn/mac-mps-add-macos-m1-15 branch 3 times, most recently from 0cb9627 to 75195e9 Compare September 25, 2026 19:40
@huydhn huydhn changed the title Run Mac MPS tests on macos-m1-15 (Sequoia on M1) Reproduce the macOS 15 CI failures on macos-m1-15 Sep 25, 2026
@huydhn
huydhn force-pushed the huydhn/mac-mps-add-macos-m1-15 branch 2 times, most recently from 5eee103 to 5dc938e Compare September 25, 2026 19:48
@huydhn huydhn changed the title Reproduce the macOS 15 CI failures on macos-m1-15 DO NOT MERGE: run all macOS CI on macos-m1-15 to reproduce the Sequoia failures Sep 25, 2026
@huydhn huydhn added the keep-going Don't stop on first failure, keep running tests until the end label Sep 25, 2026
@malfet

malfet commented Sep 26, 2026

Copy link
Copy Markdown
Collaborator

@pytorchbot rebase -b main

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/main. Check the current status here

…a failures

pytorch-gha-infra#1535 moved the us-east-2 mac2 pool to Sequoia, and those pets
briefly also carried macos-m1-stable. Every default shard that landed on one
failed (22/22 on 2026-09-25); the same commits passed on Sonoma.

Failing tests, with 0 failures across 2,658 Sonoma shards in the prior 3 days:
- test_ops.py::TestCommonMPS::test_noncontiguous_samples_scatter_reduce_amin/amax_mps_int64
- test_mps.py::TestConsistencyMPS::test_output_match_scatter_reduce_amin_mps_int64
- test_mps.py::TestMPS::test_large_bmm_float16 / bfloat16
- test_nn.py::TestNNDeviceTypeMPS::test_grid_sample_large_index_2d_mps_float32

The infra fix put macos-m1-stable back to Sonoma-only, so the failures are no
longer reproducible anywhere. This points every macOS job at macos-m1-15 so this
PR's own CI run reproduces them in full.

- trunk.yml: build runner-type, default shards 1-3, openreg
- mac-mps.yml: build runner-type, and the test_mps entry that was macos-m1-14
- inductor-perf-test-nightly-macos.yml: build runner-type
- actionlint.yaml: register macos-m1-15

Not merging this. macos-m1-15 is 9 runners in us-east-2, against ~96 Sonoma
pets on macos-m1-stable, and the tests fail there by construction. Landing it
would red-line and starve all macOS CI. It exists to produce a full failure set
on demand; the real fix is in the MPS tests, after which us-east-1 migrates and
macos-m1-stable follows the hardware.

Left alone deliberately: the macos-m1-stable strings in
.github/scripts/test_filter_test_configs.py (job-name parser fixtures) and
test/test_reductions.py (a comment). Neither routes anything.
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Successfully rebased huydhn/mac-mps-add-macos-m1-15 onto refs/remotes/origin/main, please pull locally before adding more changes (for example, via git checkout huydhn/mac-mps-add-macos-m1-15 && git pull --rebase)

@pytorchmergebot
pytorchmergebot force-pushed the huydhn/mac-mps-add-macos-m1-15 branch from 5dc938e to 9cf38ca Compare September 26, 2026 22:11
malfet added a commit to huydhn/pytorch that referenced this pull request Sep 27, 2026
pytorch#198689 added `IS_APPLE_M1` as a `LazyVal` and gated `test_grid_sample_large_index_{2d,3d}` with `@skipMPSIf(MACOS_VERSION < 15.0 or IS_APPLE_M1, ...)`. `skipIf` only skips when its condition is a `str` or an actual `bool`. On macOS 14 the expression short-circuits to `True`, but on macOS 15 `or` returns the `LazyVal` object itself, which is truthy yet not a `bool`, so the skip is silently ignored and both tests still fail with `Invalid buffer size: 8.00 GiB` on the new `macos-m1-15` runners (e.g. https://github.com/pytorch/pytorch/actions/runs/36275460327/job/108500387624).

Evaluate `IS_APPLE_M1` eagerly instead. It adds no import cost: `TEST_MPS = torch.backends.mps.is_available()` on the line above already initializes the Metal device, and the `TEST_MPS and` guard short-circuits on Linux/Windows and on MPS-less macOS builds, where `torch._C._mps_get_name` is not defined. The alternative, teaching `skipIf` to treat any truthy object as a skip, would be a broader behavior change for every `skip*If` user.

Test Plan:
Checked that the new expression produces a real bool on both macOS version branches:
```
python -c "
import torch
from torch.testing._internal.common_utils import TEST_MPS
IS_APPLE_M1 = TEST_MPS and torch.backends.mps.get_name().startswith('Apple M1')
for mv in (14.6, 15.5):
    d = mv < 15.0 or IS_APPLE_M1
    print(mv, repr(d), isinstance(d, bool))"
```
CI on `macos-m1-15` (via pytorch#198674) should show `test_grid_sample_large_index_*` skipped.

This PR was authored with the help of an AI assistant (Claude Code).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
malfet and others added 3 commits September 26, 2026 17:16
pytorch#198689 added `IS_APPLE_M1` as a `LazyVal` and gated `test_grid_sample_large_index_{2d,3d}` with `@skipMPSIf(MACOS_VERSION < 15.0 or IS_APPLE_M1, ...)`. `skipIf` only skips when its condition is a `str` or an actual `bool`. On macOS 14 the expression short-circuits to `True`, but on macOS 15 `or` returns the `LazyVal` object itself, which is truthy yet not a `bool`, so the skip is silently ignored and both tests still fail with `Invalid buffer size: 8.00 GiB` on the new `macos-m1-15` runners (e.g. https://github.com/pytorch/pytorch/actions/runs/36275460327/job/108500387624).

Evaluate `IS_APPLE_M1` eagerly instead. It adds no import cost: `TEST_MPS = torch.backends.mps.is_available()` on the line above already initializes the Metal device, and the `TEST_MPS and` guard short-circuits on Linux/Windows and on MPS-less macOS builds, where `torch._C._mps_get_name` is not defined. The alternative, teaching `skipIf` to treat any truthy object as a skip, would be a broader behavior change for every `skip*If` user.

Test Plan:
Checked that the new expression produces a real bool on both macOS version branches:
```
python -c "
import torch
from torch.testing._internal.common_utils import TEST_MPS
IS_APPLE_M1 = TEST_MPS and torch.backends.mps.get_name().startswith('Apple M1')
for mv in (14.6, 15.5):
    d = mv < 15.0 or IS_APPLE_M1
    print(mv, repr(d), isinstance(d, bool))"
```
CI on `macos-m1-15` (via pytorch#198674) should show `test_grid_sample_large_index_*` skipped.

This PR was authored with the help of an AI assistant (Claude Code).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…onvert

On aarch64, contiguous `x.byte()` for float16/bfloat16 still does a direct `static_cast<uint8_t>`, which clang lowers to a saturating `fcvtzu` (-1 -> 0), while strided copies go through `c10::convert`, which narrows via int64 (-1 -> 255). This breaks `test_non_contig_byte_cpu_{float16,bfloat16}`, `test_contig_vs_every_other_byte_cpu_{float16,bfloat16}` and their `_refs` variants on Apple Silicon (e.g. https://github.com/pytorch/pytorch/actions/runs/36282025606/job/108516516926). pytorch#196646 fixed the same mismatch for float32, but by widening to int64, which on NEON means going through float64 and halves the lane count.

This adds float16/bfloat16 specializations and switches float32 to narrow via int32 instead, using the fact that a type with p significant bits has only multiples of 256 above 2^(p+7): every finite fp16 fits in int32; bf16 is clamped to +-2^16; float32 maps |x| >= 2^31 to 0. All three match `c10::convert` bit for bit wherever it is defined (|x| < 2^63), verified exhaustively for every float16, bfloat16 and float32 bit pattern.

Performance of `x.byte()`, 4M elements, single thread, M5 Pro (us):

| dtype    | main | this PR |
|----------|------|---------|
| float32  | 353  | 294     |
| float16  | 101  | 172     |
| bfloat16 | 170  | 281     |

For reference, a direct (UB) float32 -> uint8 cast takes ~180us, so the defined float32 path is now ~1.6x the plain cast instead of ~2x.

Question for reviewers: does defining this behavior make sense at all? `torch.Tensor.to` documents that when the truncated value cannot fit into the target type "the behavior is undefined and the result may vary across platforms", so the int64 wraparound is a convention that dates back to pytorch#36807 (CPU/CUDA consistency) rather than a documented contract. Keeping it costs ~1.7x for float16/bfloat16 relative to the plain cast. The alternative is to drop the int64 convention on the vectorized paths (including pytorch#196646's) and restrict the `byte` OpInfo's test inputs to the uint8 range (`domain=(0, None)`), accepting that contiguous and strided copies may disagree on out-of-range values.

The register-level `VecConvert<uint8_t, 1, float, N>` from pytorch#196646 (used by inductor) is left unchanged; it still narrows via int64 and gives identical results.

Test Plan:
```
python -m pytest test/test_unary_ufuncs.py test/test_ops.py -k "cpu and (byte or char or uint8 or _refs__conversions or float16 and to)"   # 5560 passed
python -m pytest test/test_torch.py test/test_type_promotion.py -k "cpu and (uint8 or byte or cast or copy or to_)"   # 219 passed
```
plus exhaustive bit-pattern checks of contiguous vs strided vs `x.double().to(torch.int64).to(torch.uint8)`.

This PR was authored with the help of an AI assistant (Claude Code).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@pytorch-bot pytorch-bot Bot added the module: cpu CPU specific problem (e.g., perf, algorithm) label Sep 27, 2026
The int32 routes matched c10::convert for every finite input below 2^63, but not for +inf and larger values, where the scalar int64 route saturates to 0xff. That made contiguous and strided copies disagree again for those inputs and broke test_float_to_int_conversion_nonfinite_cpu_uint8 on ARM64. Use the same int64 narrowing for all three dtypes so contiguous and strided results are identical for every input.

Test Plan:
```
python test/test_tensor_creation_ops.py -k float_to_int_conversion   # 12 passed
python -m pytest test/test_unary_ufuncs.py test/test_ops.py -k "cpu and (byte or char or uint8 or _refs__conversions or float16 and to)"   # 5560 passed
```
plus contiguous vs strided equality over every float16/bfloat16 bit pattern (incl. inf/nan) and 16M random float32 values.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/mps Run MPS tests (subset of trunk) ciflow/trunk Trigger trunk jobs on your pull request keep-going Don't stop on first failure, keep running tests until the end module: cpu CPU specific problem (e.g., perf, algorithm) topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants