Repository navigation
Conversation
PR Status: Approved 🚀Please fix all CI failures and trigger merge by commenting "@pytorchbot merge". ✅ AUTOMATED REVIEW - OUTDATED (earlier commit) - Ready for human review:
Findings (3): Reviewed commit: 🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/197530
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 2c4dc38 with merge base 41b4c95 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
|
6a77d6d to
63cb288
Compare
|
@pytorchbot label "release notes: inductor" |
|
@jansel Could you help review this PR? It flips Also, as a first-time contributor the CI workflows are currently awaiting |
There was a problem hiding this comment.
Automated review of 63cb288: changes requested before human review.
The PR changes the log_sigmoid_forward decomposition so only CPU and meta inputs get a full-shape buffer. That fixes the FakeTensor buffer-shape mismatch on MPS and PrivateUse1. However, the new regression test only checks cpu, cuda and meta, and the old code already returned the expected shape for all three, so the test cannot fail without the fix. The inverted default also changes the buffer shape for every other backend (e.g. XLA), which needs justification.
🔴 1 blocking finding is attached to the code below.
⚪ 2 non-blocking findings
pytorch/torch/_decomp/decompositions.py
Line 3566 in 63cb288
Inverting to a cpu/meta allowlist sends every other device (XLA, which Dynamo fakeifies, plus any out-of-tree backend whose kernel keeps a full buffer) to the (0,) branch, where it used to get a full-shape buffer. Please confirm torch_xla's buffer shape, or list the empty-buffer devices explicitly (cuda/xpu/mps). The comment's claim that all PrivateUse1 kernels return (0,) has no in-tree support.
Line 761 in 63cb288
The test ignores device but sits in the device-instantiated TestDecomp class, so it runs once per device and is classified ACCELERATOR. Use @ onlyCPU, as other device-agnostic tests in this file do, or move it to a non-device class.
Please address the findings and push; a new commit normally gets a fresh automated review.
This review is AI-generated and advisory. Each new automated review replaces the previous one.
| # assertions pivot on fake/meta devices and are independent of the | ||
| # injected `device`. | ||
| with FakeTensorMode(): | ||
| for fake_device, expected_shape in (("cpu", (3,)), ("cuda", (0,))): |
There was a problem hiding this comment.
🔴 The regression test cannot fail on the pre-PR code. The old branch (is_cuda or is_xpu -> (0,), else full) already gives cpu (3,), cuda (0,) and meta (3,). Add a device whose result changes, e.g. a fake 'mps' case expecting (0,). Fake MPS tensors work without the hardware (see test_fake_tensor.py).
63cb288 to
faeb775
Compare
There was a problem hiding this comment.
Automated review of faeb775: changes requested before human review.
The PR changes the log_sigmoid_forward decomposition so its buffer output matches the real kernels. The MPS part is correct and covered by the new test. The new branch for all PrivateUse1 backends is wrong for backends that use the CPU boxed fallback, including the in-tree openreg reference backend, so fake shapes now disagree with real ones, and no test covers that branch.
🔴 1 blocking finding is attached to the code below.
⚪ 2 non-blocking findings
pytorch/torch/_decomp/decompositions.py
Line 3568 in faeb775
The if self.is_cpu or self.is_meta: buffer = z branch does exactly what the final else: buffer = z does, so it is dead and makes the backend list look closed when it is not. Remove it, or turn the logic into a real closed set. The same applies to decompositions_for_jvp.py:118.
This copy of log_sigmoid_forward is never registered. maybe_register_decomposition swallows the duplicate-registration error, and _register_jit_decomposition_for_jvp picks up the decompositions.py version, so this edit has no effect. Copying the full Note here also creates a second copy to keep in sync. Delete this copy, or replace the Note with See Note \[log_sigmoid_forward buffer contract\].
Please address the findings and push; a new commit normally gets a fresh automated review.
This review is AI-generated and advisory. Each new automated review replaces the previous one.
The log_sigmoid_forward decomposition decided the shape of its second
output (buffer) by enumerating CUDA and XPU. The buffer is materialized
only by log_sigmoid_backward_cpu; the CUDA/XPU/MPS kernels allocate an
empty (0,) buffer and ignore it (see the NOTE comments in
log_sigmoid_backward_{cuda,mps}), and we verified the same on a
PrivateUse1 device. Enumerate the evidence-backed empty-buffer devices
(cuda/xpu/mps + the PrivateUse1 backend via its registered name) while
keeping cpu and meta on the full-shape branch — meta has no device and
the op has no Meta kernel, so the decomposition defines its meta
behavior. Backends not listed keep their historical full-shape buffer:
no behavioral delta beyond the two fixes (MPS per pytorch#195417, PrivateUse1
per our device verification).
Fixes the MetadataMismatchError class seen on XPU (pytorch#141333), MPS
(pytorch#195417) and out-of-tree PrivateUse1 devices.
Also adds the missing `hw_classification` class attributes to
test/test_decomp.py (per the pytorch#190991 convention) so the new regression
test is picked up by device-parameterized CI runs.
Part of the device-decoupling sweep (pytorch#194355).
faeb775 to
0e628f2
Compare
There was a problem hiding this comment.
Automated review of 0e628f2: nothing blocking; ready for human review.
The PR fixes the log_sigmoid_forward decomposition so its buffer shape matches the real kernels on MPS and PrivateUse1. CUDA and MPS were checked against the in-tree kernels. The use_python=True switch for the JVP registration is required, because TorchScript cannot compile _get_privateuse1_backend_name, and it changes no runtime behavior because a forward formula exists. The new test fails on the old code for MPS. There are no maintainer comments, and the remaining points are minor.
⚪ 3 non-blocking findings
Line 776 in 0e628f2
The regression test covers cpu, cuda and mps but not PrivateUse1, which is the motivating NPU case and a new branch in the decomposition. Consider adding a fake 'privateuseone:0' case; the explicit index avoids the is_initialized lookup in _normalize_fake_device.
pytorch/torch/_decomp/decompositions.py
Line 3564 in 0e628f2
The Note is partly inaccurate. The CUDA/MPS kernels that allocate the (0,) buffer are the forward functions; the NOTEs exist only in some backward and forward-out variants. 'We verified the same on a PrivateUse1 device' can't be checked from this repo, and it is a blanket assumption that applies to every out-of-tree PrivateUse1 backend. On meta, the decomposition is the registered Meta impl (via activate_meta), so 'matching aten on meta inputs' is circular. The same comment is copied in decompositions_for_jvp.py.
This local copy is dead code. maybe_register_decomposition swallows the duplicate-registration error, so _register_jit_decomposition_for_jvp uses the decompositions.py version. Keeping the two copies 'in lockstep' has no effect.
This review is AI-generated and advisory. Each new automated review replaces the previous one.
Withdrawn: the automated review of 0e628f2 found nothing blocking.
- test: add the PrivateUse1 leg to the FakeTensor regression test (name resolved at runtime, explicit :0 index required by _pin_device_index)
- decompositions{,_for_jvp}: rewrite the buffer-contract comment against the actual kernels ((0,) allocation is in the forward kernels; NOTEs live in backward/out variants; the decomposition is the registered Meta kernel via activate_meta) and scope the PrivateUse1 claim to torch_npu
Thanks for the careful read — all three points taken:
Pushed as d61154c — happy to squash if preferred. |
|
@jansel Thanks for approving the workflow runs. The PR is now ready for Quick orientation:
|
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Merge failedReason: 1 jobs have failed, first few of them are: trunk / macos-py3-arm64 / test (mps, 1, 1, macos-m2-15) Details for Dev Infra teamRaised by workflow job |
|
Please fix the failure; they seem to be related. |
The fake_backward_mps_xfails entries for logsigmoid and binary_cross_entropy_with_logits (the latter decomposes through logsigmoid) mask exactly the fake-vs-real MPS buffer mismatch this PR fixes; with the fix in place the strict xfails report unexpected successes. Drop the two entries; the remaining ones mask unrelated mismatches and stay.
c4226ce to
426da00
Compare
@jansel @guangyey — following up on the CI failures @guangyey flagged
With that in place, this is ready for review — @jansel could you take a Quick orientation:
|
|
There are still failures. |
Same family as the previous two: multilabel_soft_margin_loss is CompositeImplicitAutograd and calls binary_cross_entropy_with_logits, which decomposes through logsigmoid -> log_sigmoid_forward — so the buffer-mismatch fix makes its fake_backward_mps_xfails entry report an unexpected success as well. special.log_ndtr stays: it has no decomposition and does not route through this op.
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Merge failedReason: 3 mandatory check(s) failed. The first few are: Dig deeper by viewing the failures on hud |
@guangyey Right — that was the third member of the same family, and it is For context: the earlier "Unexpected success" failures were this PR's fix
We don't expect more. An unexpected success requires (a) an expectedFailure |
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Summary
log_sigmoid_forwardreturns(output, buffer). The buffer is only consumedby the CPU backward kernel (
log_sigmoid_backward_cpu); the CUDA/XPU/MPSforward kernels (
log_sigmoid_forward_{cuda,mps}) allocate an empty(0,)buffer and ignore its contents (the "buffer is only used by CPU dispatch, we
just ignore it here" NOTE also appears in some backward and out variants, e.g.
log_sigmoid_backward_cudaandlog_sigmoid_forward_out_mps). PrivateUse1(out-of-tree) backends follow the accelerator semantics: we verified on
torch_npu (Ascend) that the real kernel returns an empty
(0,)buffer.The decomposition in
torch/_decomp/decompositions.py(used for FakeTensorshape inference under
torch.compile/export andCrossRefFakeMode) decidedthe buffer shape by enumerating backends:
Every time a new backend was added, someone had to extend this enumeration and
until then FakeTensor inference disagreed with the real kernel, making
torch.compile/export/CrossRefFakeModefail with aMetadataMismatchErroron that backend: XPU in #141332/#141333, MPS in #195417, and we reproduced the
identical failure on an out-of-tree PrivateUse1 device:
This PR makes the empty-buffer set explicit and evidence-backed — cuda/xpu/mps
(source-verified) plus PrivateUse1 (verified on device, where the real kernel
returns
(0,)and the old enumeration produced a full-shape buffer that brokeCrossRefFakeMode) — while every backend not in that list (XLA, HPU, MTIA,and any backend whose contract is unverified) keeps the historical full-shape
buffer: no behavioral delta beyond the two fixes.
Changes
torch/_decomp/decompositions.pyandtorch/_decomp/decompositions_for_jvp.py(the twin copies must stay in lockstep — upstream precedent Fix mismatched tensor metadata between FakeTensor and Intel XPU concrete tensor when running
F.logsigmoid#141333/Fix FakeTensor/concrete metadata mismatch for log_sigmoid on MPS #195417):the branch now enumerates the evidence-backed empty-buffer devices and keeps
the historical full-shape default for everything else:
Design notes: (a) meta tensors stay on the full branch — this op has no Meta
kernel, so the decomposition defines its meta behavior, and
not self.is_cpualone would silently flip meta to the empty branch; (b)Tensor.is_privateuseoneis not exposed as a Python property, so thePrivateUse1 backend is identified via its registered name
(
torch._C._get_privateuse1_backend_name(), called at runtime — noimport-time freeze); (c) backends whose contract is unverified keep the
historical default — no behavioral delta beyond the two fixes.
Added a regression test
TestDecomp::test_log_sigmoid_forward_buffer_shape(in
test/test_decomp.py, owner:module: decompositions) calling theproduction symbols through
FakeTensorMode: buffer full-shape for cpu,empty for cuda, empty for mps (the discriminating leg — the pre-PR
enumeration gives a full-shape buffer for mps, so the test fails without
this fix), empty for PrivateUse1 (the backend name is resolved at runtime
via
torch._C._get_privateuse1_backend_name()and pinned with an explicit:0index, so renamed trees are covered and fake creation skips theis_initializedlookup inFakeTensor._normalize_fake_device), full formeta.
@onlyCPUper the file's convention for device-agnostic tests (theassertions pivot on fake/meta devices).
Added the
hw_classificationclass attributestest/test_decomp.pywasmissing (TestDecomp / DecompOneOffTests → ACCELERATOR, HasDecompTest →
GENERIC, per the [Test] Add proper
hw_classificationattribute to test classes #190991 convention) so the new test is picked up bydevice-parameterized CI runs.
Removed the two
fake_backward_mps_xfailsentries intest/test_ops.pyfor
nn.functional.logsigmoidandnn.functional.binary_cross_entropy_with_logits(the latter decomposesthrough
logsigmoid). They were added on main to mask exactly thefake-vs-real MPS buffer mismatch this PR fixes; with the fix in place
they report unexpected successes. The remaining entries mask unrelated
mismatches and stay.
(0,)(0,)(0,)(0,)Depends on
hw_classificationattribute to test classes #190991 (HardwareClassificationenum) — used by the added labels.Already merged; present in trunk.
condition, enumeration fix — the evidence-backed form here subsumes it) and
[Test] Enable XPU for test_decomp cross-reference tests #193116 (XPU enablement of the same suite, orthogonal).
Not changed
test_meta.pycrossref expected failures forlog_sigmoid_forwardoncuda/xpu ([xpu][fix]Add XPU expected failure for log_sigmoid_forward in test_meta #196554-style) are intentionally untouched: those are about
device-less meta tensors vs real kernels, and meta behavior is unchanged.
@onlyCPU/@onlyCUDAgates intest/test_decomp.pyare left untouched — most encode per-method devicesemantics (RNG determinism, precision, CUDA-specific NaN behavior,
CPU-only reference behavior), a few are legacy CPU scoping that
device-enablement efforts like [Test] Enable XPU for test_decomp cross-reference tests #193116 are better positioned to remove.
torch_npurequires no changes: its nativelog_sigmoid_forwardalreadyreturns an empty
(0,)buffer (verified on device), so the fix alignsFakeTensor inference with the real kernel.
Test plan
CrossRefFakeMode+F.logsigmoidraisedMetadataMismatchErrorbefore this PR (output[1]
(0,)vs(4,)) and passes after;probe
aten.log_sigmoid_forwardbuffer stays(0,);new UT green on the box (cpu variant;
@onlyCPUskips the real npuvariant by design — the in-test fake PrivateUse1 leg resolves to
npu:0on this tree and passes; real-kernel behavior is additionallycovered by the probes).
test/functorch/test_ops.py -k logsigmoid14 OK;
test_meta.py -k logsigmoid12 passed / 14 skipped (xfailsunchanged).
(0,)unchanged; functorch 28 OK;test_meta 52 tests OK (skipped=27); new UT 2 passed (cpu + cuda
variants, pre-
@onlyCPUform).