Skip to content

[Feature Refactoring][decomp] Make log_sigmoid_forward's buffer shape device-agnostic instead of backend-enumerated - #197530

Closed
youlituao wants to merge 5 commits into
pytorch:mainfrom
youlituao:feature/decouple-log-sigmoid-buffer
Closed

youlituao wants to merge 5 commits into
pytorch:mainfrom
youlituao:feature/decouple-log-sigmoid-buffer

Conversation

@youlituao

@youlituao youlituao commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

log_sigmoid_forward returns (output, buffer). The buffer is only consumed
by the CPU backward kernel (log_sigmoid_backward_cpu); the CUDA/XPU/MPS
forward 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_cuda and log_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 FakeTensor
shape inference under torch.compile/export and CrossRefFakeMode) decided
the buffer shape by enumerating backends:

if self.is_cuda or self.is_xpu:
    buffer = self.new_zeros((0,))
else:
    buffer = z

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/CrossRefFakeMode fail with a MetadataMismatchError
on that backend: XPU in #141332/#141333, MPS in #195417, and we reproduced the
identical failure on an out-of-tree PrivateUse1 device:

MetadataMismatchError: When comparing the output of
aten.log_sigmoid_forward.default on FakeTensor and concrete Tensors, found
mismatched tensor metadata for output[1]: Shapes torch.Size([0]) and
torch.Size([4]) are not equal!

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 broke
CrossRefFakeMode) — 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.py and torch/_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:

    if self.is_cpu or self.is_meta:
        buffer = z
    elif (
        self.is_cuda
        or self.is_xpu
        or self.is_mps
        or self.device.type == torch._C._get_privateuse1_backend_name()
    ):
        buffer = self.new_zeros((0,))
    else:
        buffer = z
    

    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_cpu alone would silently flip meta to the empty branch; (b)
    Tensor.is_privateuseone is not exposed as a Python property, so the
    PrivateUse1 backend is identified via its registered name
    (torch._C._get_privateuse1_backend_name(), called at runtime — no
    import-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 the
    production 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
    :0 index, so renamed trees are covered and fake creation skips the
    is_initialized lookup in FakeTensor._normalize_fake_device), full for
    meta. @onlyCPU per the file's convention for device-agnostic tests (the
    assertions pivot on fake/meta devices).

  • Added the hw_classification class attributes test/test_decomp.py was
    missing (TestDecomp / DecompOneOffTests → ACCELERATOR, HasDecompTest →
    GENERIC, per the [Test] Add proper hw_classification attribute to test classes #190991 convention) so the new test is picked up by
    device-parameterized CI runs.

  • Removed the two fake_backward_mps_xfails entries in test/test_ops.py
    for nn.functional.logsigmoid and
    nn.functional.binary_cross_entropy_with_logits (the latter decomposes
    through logsigmoid). They were added on main to mask exactly the
    fake-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.

device before after delta
CPU full buffer full buffer none
CUDA / XPU empty (0,) empty (0,) none
MPS full buffer (wrong, mismatched the real kernel) empty (0,) fixes the #195417 mismatch
meta (incl. device-less) full buffer full buffer none
PrivateUse1 (FakeTensor) full buffer (wrong, mismatched the real kernel) empty (0,) fixes the mismatch
XLA / HPU / MTIA / unknown full buffer (historical) full buffer (unchanged) none — preserved

Depends on

Not changed

  • The test_meta.py crossref expected failures for log_sigmoid_forward on
    cuda/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.
  • Pre-existing method-level @onlyCPU / @onlyCUDA gates in
    test/test_decomp.py are left untouched — most encode per-method device
    semantics (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_npu requires no changes: its native log_sigmoid_forward already
    returns an empty (0,) buffer (verified on device), so the fix aligns
    FakeTensor inference with the real kernel.

Test plan

  • NPU (PrivateUse1, torch_npu 2.13.0+git45fbeae, Ascend 910B3):
    CrossRefFakeMode + F.logsigmoid raised MetadataMismatchError
    before this PR (output[1] (0,) vs (4,)) and passes after;
    probe aten.log_sigmoid_forward buffer stays (0,);
    new UT green on the box (cpu variant; @onlyCPU skips the real npu
    variant by design — the in-test fake PrivateUse1 leg resolves to
    npu:0 on this tree and passes; real-kernel behavior is additionally
    covered by the probes).
  • CPU: new UT 1 passed; test/functorch/test_ops.py -k logsigmoid
    14 OK; test_meta.py -k logsigmoid 12 passed / 14 skipped (xfails
    unchanged).
  • CUDA (A100, torch 2.13.0a0): probe (0,) unchanged; functorch 28 OK;
    test_meta 52 tests OK (skipped=27); new UT 2 passed (cpu + cuda
    variants, pre-@onlyCPU form).
  • CI (lint / unittest shards).

@pytorch-bot

pytorch-bot Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

PR Status: Approved 🚀

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

✅ AUTOMATED REVIEW - OUTDATED (earlier commit) - 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.

Findings (3):

[minor] test/test_decomp.py:776
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.

[minor] torch/_decomp/decompositions.py:3564
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.

[info] torch/_decomp/decompositions_for_jvp.py:124
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.

Reviewed commit: 0e628f2 (NOT the current head 2c4dc38)

Review run

🔗 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 Failures

As of commit 2c4dc38 with merge base 41b4c95 (image):
💚 Looks good so far! There are no failures yet. 💚

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

@pytorch-bot

pytorch-bot Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

Workflows were awaiting approval. CI has now been triggered for the ciflow labels on this PR.

@youlituao youlituao changed the title [decomp] Make log_sigmoid_forward's buffer shape device-agnostic instead of backend-enumerated [Feature Refactoring][decomp] Make log_sigmoid_forward's buffer shape device-agnostic instead of backend-enumerated Sep 18, 2026
@youlituao youlituao changed the title [Feature Refactoring][decomp] Make log_sigmoid_forward's buffer shape device-agnostic instead of backend-enumerated [Feature Refactoring][decomp] Make log_sigmoid_forward's buffer shape device-agnostic instead of backend-enumerated Sep 18, 2026
@youlituao
youlituao force-pushed the feature/decouple-log-sigmoid-buffer branch from 6a77d6d to 63cb288 Compare September 22, 2026 11:36
@youlituao
youlituao marked this pull request as ready for review October 9, 2026 07:49
@youlituao

Copy link
Copy Markdown
Contributor Author

@pytorchbot label "release notes: inductor"

@youlituao

Copy link
Copy Markdown
Contributor Author

@jansel Could you help review this PR? It flips log_sigmoid_forward's
buffer-shape branch to the closed side ({cpu, meta}) so FakeTensor inference
matches the real kernels on CUDA/XPU/MPS and all PrivateUse1 backends (fixes
a MetadataMismatchError we hit on NPU), instead of extending the backend
enumeration one backend at a time — following your "smaller patches that
remove device hardcodings are welcome" guidance. Twin copies in
decompositions_for_jvp.py kept in lockstep; regression test +
hw_classification labels added per #190991. Related: #195417, #141333.

Also, as a first-time contributor the CI workflows are currently awaiting
approval — could you (or another maintainer) approve the workflow runs so CI
can start? Thanks!

cc @zou3519 @guangyey

@jansel jansel added the in progress PR is being worked on by the author, until the automated review accepts it label Oct 9, 2026
@jansel
jansel self-requested a review October 9, 2026 16:50

@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 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

if self.is_cpu or self.is_meta:

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.


def test_log_sigmoid_forward_buffer_shape(self, device):

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.

Comment thread test/test_decomp.py Outdated
# 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,))):

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.

🔴 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).

@youlituao
youlituao force-pushed the feature/decouple-log-sigmoid-buffer branch from 63cb288 to faeb775 Compare October 10, 2026 06:48

@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 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

if self.is_cpu or self.is_meta:

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.


if self.is_cpu or self.is_meta:

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.

Comment thread torch/_decomp/decompositions.py Resolved
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).
@youlituao
youlituao force-pushed the feature/decouple-log-sigmoid-buffer branch from faeb775 to 0e628f2 Compare October 10, 2026 07:02

@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 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

("mps", (0,)),

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.


# the same on a PrivateUse1 device. Meta tensors follow the CPU branch:

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.


or self.device.type == torch._C._get_privateuse1_backend_name()

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.

@github-actions
github-actions Bot dismissed stale reviews from themself October 10, 2026 07:09

Withdrawn: the automated review of 0e628f2 found nothing blocking.

@pytorch-bot pytorch-bot Bot added ready for review Automated review passed, ready for a final review by a maintainer. and removed in progress PR is being worked on by the author, until the automated review accepts it labels Oct 10, 2026
- 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
@youlituao

Copy link
Copy Markdown
Contributor Author

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

("mps", (0,)),

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.

# the same on a PrivateUse1 device. Meta tensors follow the CPU branch:

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.

or self.device.type == torch._C._get_privateuse1_backend_name()

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.

Thanks for the careful read — all three points taken:

  1. Agreed, the motivating PrivateUse1 case deserves a leg in the regression
    test itself. Added f"{torch._C._get_privateuse1_backend_name()}:0" —
    the name is resolved at runtime so renamed trees are covered too, and the
    explicit :0 index is actually required on vanilla trees: with no index,
    _pin_device_index does getattr(torch, "privateuseone"), which doesn't
    exist before a backend registers/renames. Verified on a vanilla tree:
    index-less fake creation fails with ModuleNotFoundError: No module named 'torch.privateuseone', hence the explicit :0. The leg passes on both
    the vanilla name and a renamed backend (verified on torch_npu, where it
    resolves to npu:0).

  2. You're right on all three counts. The (0,) allocations live in the
    forward kernels (log_sigmoid_forward_{cuda,mps}); the NOTE comments
    appear in some backward and out variants (log_sigmoid_backward_cuda,
    log_sigmoid_forward_out_mps, ...); and "matching aten on meta inputs"
    was circular — this decomposition is itself the registered Meta kernel
    (activate_meta() in torch/_meta_registrations.py). Rewrote the
    comment in both twins accordingly and scoped the PrivateUse1 claim to the
    backend we actually verified (torch_npu).

  3. Correct that the jvp copy never executes: maybe_register_decomposition
    swallows the duplicate registration, and the bottom
    _register_jit_decomposition_for_jvp picks the main-table function. We
    still keep the two files textually in lockstep (same convention as
    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) so the vendored copy can't silently drift from the live
    contract. Note the use_python=True on the registration line is live and
    load-bearing regardless: that helper compiles the main-table body, which
    is no longer TorchScript-scriptable with the runtime
    _get_privateuse1_backend_name() call.

Pushed as d61154c — happy to squash if preferred.

@youlituao

Copy link
Copy Markdown
Contributor Author

@jansel Thanks for approving the workflow runs. The PR is now ready for
review — could you take a look, or point me to the right reviewer on the
decompositions side?

Quick orientation:

  • The decomposition for log_sigmoid_forward now enumerates the
    evidence-backed empty-buffer devices (cuda/xpu/mps source-verified;
    PrivateUse1 verified on torch_npu) instead of the old
    is_cuda or is_xpu flip, while backends with unverified contracts
    (XLA/HPU/MTIA) keep the historical full-shape buffer — no behavioral
    delta beyond fixing the MPS (Fix FakeTensor/concrete metadata mismatch for log_sigmoid on MPS #195417) and out-of-tree PrivateUse1
    MetadataMismatchErrors.
  • The 3 review-thread findings are addressed in d61154c: the regression
    test gains a PrivateUse1 leg, and the buffer-contract comment is
    rewritten against the actual kernels.
  • CI is green except two known non-issues: docs_test fails in
    make doctest (matplotlib missing from the docs environment,
    unrelated to this change), and one arm64 job died on a runner-pod
    scheduling timeout. Happy to rerun either on request.

cc @albanD @ezyang @guangyey

@zou3519 zou3519 added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Oct 12, 2026
@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Oct 13, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your 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

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 1 jobs have failed, first few of them are: trunk / macos-py3-arm64 / test (mps, 1, 1, macos-m2-15)

Details for Dev Infra team Raised by workflow job

@guangyey

Copy link
Copy Markdown
Collaborator

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.
@youlituao
youlituao force-pushed the feature/decouple-log-sigmoid-buffer branch from c4226ce to 426da00 Compare October 13, 2026 09:10
@youlituao

Copy link
Copy Markdown
Contributor Author

Please fix the failure; they seem to be related.

@jansel @guangyey — following up on the CI failures @guangyey flagged
("Please fix the failure; they seem to be related"): they were related, and
the latest push resolves them.

  • The two TestFakeTensorMPS::test_fake_crossref_backward_* failures
    ("Unexpected success" for nn.functional.logsigmoid /
    nn.functional.binary_cross_entropy_with_logits) were related in a good
    way: this PR removes the fake-vs-real MPS buffer mismatch, so those two
    tests — which fake_backward_mps_xfails (test/test_ops.py) xfails for
    exactly that mismatch — started passing, and strict xfail reported the
    passes as failures. 426da00 drops the two stale entries; the rest of
    that list masks unrelated mismatches and stays.
  • The docs_test failure (matplotlib missing from the docs make doctest
    environment) and one arm64 job dying on a runner-pod scheduling timeout
    were infra, unrelated to this change.

With that in place, this is ready for review — @jansel could you take a
look, or point me to the right reviewer on the decompositions side?

Quick orientation:

  • The decomposition for log_sigmoid_forward now enumerates the
    evidence-backed empty-buffer devices (cuda/xpu/mps source-verified;
    PrivateUse1 verified on torch_npu) instead of the old is_cuda or is_xpu
    flip, while backends with unverified contracts (XLA/HPU/MTIA) keep the
    historical full-shape buffer — no behavioral delta beyond fixing the MPS
    (Fix FakeTensor/concrete metadata mismatch for log_sigmoid on MPS #195417) and out-of-tree PrivateUse1 MetadataMismatchErrors.
  • The regression test covers cpu/cuda/mps/PrivateUse1 (backend name resolved
    at runtime, explicit :0 index) and meta; the three review-thread
    findings are addressed in d61154c, and the stale-xfail cleanup in
    426da00.

@guangyey

Copy link
Copy Markdown
Collaborator

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.
@youlituao

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your 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

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 3 mandatory check(s) failed. The first few are:

Dig deeper by viewing the failures on hud

Details for Dev Infra team Raised by workflow job

Failing merge rule: Core Maintainers

@youlituao

youlituao commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor Author

There are still failures.

@guangyey Right — that was the third member of the same family, and it is
addressed in 2c4dc38: the latest CI run is fully green, which also
confirms it.

For context: the earlier "Unexpected success" failures were this PR's fix
working — the tests xfailed in fake_backward_mps_xfails mask exactly the
fake-vs-real MPS buffer mismatch that this PR removes, so once the mismatch
was fixed the strict xfails reported the now-passing tests as failures.
(CI shards stop at the first failure, which is why they surfaced one at a
time.) 426da00 dropped the first two entries.

multilabel_soft_margin_loss was the same story one level up: it is
CompositeImplicitAutograd and calls binary_cross_entropy_with_logits,
which decomposes through logsigmoid -> log_sigmoid_forward — so its entry
flipped for the same reason, and 2c4dc38 drops it.

We don't expect more. An unexpected success requires (a) an expectedFailure
mark and (b) the marked test now passing because of this PR. The mark
inventory is fully audited: the only entries routing through
log_sigmoid_forward were those three (special.log_ndtr, for example,
has no decomposition and does not route through this op, so its entry
stays), and the meta-key marks in test_meta.py are unaffected since meta
behavior is unchanged. The infra hiccups seen along the way (a docs_test
environment issue and an arm64 runner-pod scheduling timeout) were
unrelated to this change and have since cleared.

@guangyey

Copy link
Copy Markdown
Collaborator

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your 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

Advanced Debugging
Check the merge workflow status
here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot-triage-error ciflow/inductor ciflow/trunk Trigger trunk jobs on your pull request Merged open source ready for review Automated review passed, ready for a final review by a maintainer. release notes: inductor 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.

6 participants