Skip to content

Add tuple-returning pop overload - #180786

Closed
cyyever wants to merge 6 commits into
pytorch:mainfrom
cyyever:pop-tuple-overload
Closed

cyyever wants to merge 6 commits into
pytorch:mainfrom
cyyever:pop-tuple-overload

Conversation

@cyyever

@cyyever cyyever commented Apr 20, 2026

Copy link
Copy Markdown
Collaborator

This PR adds tuple-returning pop overload and fix callers to avoid un-initialisation errors.

@pytorch-bot pytorch-bot Bot added the release notes: mobile release notes category label Apr 20, 2026
@pytorch-bot

pytorch-bot Bot commented Apr 20, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

❌ 31 Pending, 1 Unrelated Failure, 2 Unclassified Failures

As of commit f3ac55b with merge base 8832cb4 (image):

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

UNSTABLE - The following jobs are marked as unstable, possibly due to flakiness on trunk:

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

@cyyever
cyyever requested a review from Skylion007 April 20, 2026 01:19
@cyyever
cyyever force-pushed the pop-tuple-overload branch 2 times, most recently from b1dafb6 to 9516d81 Compare April 20, 2026 03:19
@zou3519 zou3519 added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Apr 20, 2026
@cyyever
cyyever force-pushed the pop-tuple-overload branch from 9516d81 to 9b88598 Compare May 9, 2026 09:25
@cyyever
cyyever requested review from jeffdaily and zou3519 May 15, 2026 03:11
@cyyever
cyyever force-pushed the pop-tuple-overload branch 2 times, most recently from d33513c to 3607826 Compare May 15, 2026 03:32
@cyyever
cyyever requested a review from ezyang May 15, 2026 03:35
@cyyever
cyyever requested review from albanD and soulitzer as code owners May 15, 2026 04:22
@ezyang

ezyang commented May 15, 2026

Copy link
Copy Markdown
Contributor

@claude code review please!

@claude

claude Bot commented May 15, 2026 •

Copy link
Copy Markdown

Claude finished @ezyang's task in 1m 55s —— View job


Code Review: Add tuple-returning pop overload

  • Read and analyze the PR diff
  • Review the new pop overload in stack.h
  • Review caller conversions
  • Post review feedback

Overall this is a nice quality-of-life improvement. The tuple-returning pop eliminates uninitialized variable warnings and makes the code more concise. The structured binding pattern is easier to read and less error-prone.

Looks good. A few observations:

1. minList / maxList semantic equivalence (correct but worth noting)

The variable assignment order flipped (a was previously the second schema arg, now it's the first), and the comparison predicates were updated accordingly. I verified these are semantically equivalent:

  • Old: a = pop() (top = 2nd arg), b = pop() (1st arg) → push(b.size() < a.size() ? b : a)
  • New: a = peek(0) (1st arg), b = peek(1) (2nd arg) → push(a.size() < b.size() ? a : b)

Both return the smaller list. Correct.

2. record_function_ops.cpp — pop order fix

The old code had:

auto fut = jit::pop(stack).toFuture();   // top = 2nd arg (Future)
auto tensor = jit::pop(stack).toTensor(); // 1st arg (Tensor)

The new code correctly uses schema order:

auto [tensor, fut] = jit::pop<at::Tensor, c10::intrusive_ptr<c10::ivalue::Future>>(stack);

This matches the schema (Tensor x, Future(t) y). Correct.

3. createTensorFromList — nice use of if constexpr

The refactoring to pop requires_grad separately (since it's conditionally present) and then use the tuple pop for the remaining 3 args is clean. The upgrade from if to if constexpr is a good bonus since if_set_requires_grad is a template parameter.

4. Minor: requires clause vs SFINAE

The requires(sizeof...(Types) > 0) constraint is needed to disambiguate from the single-IValue-returning pop(Stack&). Using C++20 requires-clauses is fine here — PyTorch already uses C++20 features elsewhere. Though I'd note that the existing codebase seems to not use requires-clauses much; if there are compiler compatibility concerns for some platforms this might be worth verifying in CI (which seems green so far, so probably fine).

5. No deprecation of old overload

The comment // variadic pop (prefer the tuple-returning overload below for new code): is appropriate guidance. No need to formally deprecate the old one since it's used pervasively and both patterns are valid.


Summary: Clean PR, correct semantics, no issues found. The DEFINE_TO(at::DimVector, toDimVector) addition is a prerequisite for the aten::split conversion and makes sense. CI is green. Ship it.

@ezyang

ezyang commented May 15, 2026

Copy link
Copy Markdown
Contributor

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label May 15, 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

@cyyever

cyyever commented May 15, 2026

Copy link
Copy Markdown
Collaborator Author

@pytorchbot merge -i

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

The merge job was canceled or timed out. This most often happen if two merge requests were issued for the same PR, or if merge job was waiting for more than 6 hours for tests to finish. In later case, please do not hesitate to reissue the merge command
For more information see pytorch-bot wiki.

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged while ignoring the following 0 checks:

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: vllm-test / vllm-x-pytorch-build / build

Details for Dev Infra team Raised by workflow job

@cyyever

cyyever commented May 16, 2026

Copy link
Copy Markdown
Collaborator Author

@pytorchmergebot merge -f "Unrelated vllm failure"

@pytorchmergebot pytorchmergebot added the ci-no-td Do not run TD on this PR label May 16, 2026
@cyyever
cyyever restored the pop-tuple-overload branch May 16, 2026 06:47
@cyyever cyyever reopened this May 16, 2026
@cyyever

cyyever commented May 16, 2026

Copy link
Copy Markdown
Collaborator Author

@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

cyyever added 5 commits May 16, 2026 06:50
Add DEFINE_TO(at::DimVector, toDimVector) so the templated IValue::to<T>
path supports DimVector, then convert the aten::split operator in
register_special_ops.cpp from manual peek + drop to the structured
pop<at::Tensor, at::DimVector, int64_t>(stack) form.
The pop(stack).to<List<T>>() sequence popped top-down, so the local
named "a" was schema's "b" and vice versa. The size tiebreaker compiled
to identical observable behavior only because of a matching inversion
in the comparison. Use the typed tuple pop so the locals follow schema
order, and write the tiebreaker the same way.
Convert the boxed implementation of the legacy Tensor-handle variant
from two sequential pop(stack).toX() calls to the tuple-returning pop.
Local names now follow schema order ((Tensor x, Future y)) directly.

The _RecordFunction overload below is left alone: its second arg goes
through IValue::toCustomClass<T>(), which is not routed through the
DEFINE_TO templated to<T> path.
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Successfully rebased pop-tuple-overload onto refs/remotes/origin/main, please pull locally before adding more changes (for example, via git checkout pop-tuple-overload && git pull --rebase)

@cyyever
cyyever force-pushed the pop-tuple-overload branch from a269aa7 to f3ac55b Compare May 16, 2026 11:24
@cyyever

cyyever commented May 16, 2026

Copy link
Copy Markdown
Collaborator Author

@pytorchmergebot merge -f "Use C++17, other failures unrelated"

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use -f as last resort and instead consider -i/--ignore-current to continue the merge ignoring current failures. This will allow currently pending tests to finish and report signal before the merge.

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

@cyyever
cyyever deleted the pop-tuple-overload branch July 3, 2026 09:36
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
This PR adds tuple-returning pop overload and fix callers to avoid un-initialisation errors.
Pull Request resolved: pytorch#180786
Approved by: https://github.com/ezyang
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
This reverts commit 1dbe101.

Reverted pytorch#180786 on behalf of https://github.com/pytorch-auto-revert due to Reverted automatically by pytorch's autorevert, to avoid this behaviour add the tag autorevert: disable ([comment](pytorch#180786 (comment)))
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
This PR adds tuple-returning pop overload and fix callers to avoid un-initialisation errors.
Pull Request resolved: pytorch#180786
Approved by: https://github.com/ezyang
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
This PR adds tuple-returning pop overload and fix callers to avoid un-initialisation errors.
Pull Request resolved: pytorch#180786
Approved by: https://github.com/ezyang
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
This reverts commit 1dbe101.

Reverted pytorch#180786 on behalf of https://github.com/pytorch-auto-revert due to Reverted automatically by pytorch's autorevert, to avoid this behaviour add the tag autorevert: disable ([comment](pytorch#180786 (comment)))
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
This PR adds tuple-returning pop overload and fix callers to avoid un-initialisation errors.
Pull Request resolved: pytorch#180786
Approved by: https://github.com/ezyang
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-no-td Do not run TD on this PR ciflow/trunk Trigger trunk jobs on your pull request ciflow/vllm Merged open source release notes: mobile release notes category Reverted 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