Skip to content

Support int64 scalar tensor data for fold_in() - #206339

Closed
jbschlosser wants to merge 8 commits into
gh/jbschlosser/307/basefrom
gh/jbschlosser/307/head
Closed

jbschlosser wants to merge 8 commits into
gh/jbschlosser/307/basefrom
gh/jbschlosser/307/head

Conversation

@jbschlosser

@jbschlosser jbschlosser commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Expands fold_in() to support int64 scalar tensor data. This is useful because uint64 has limited support within PyTorch, and requiring it as the dtype for data makes doing math on such data annoying:

import torch
import torch.func._random as random

key = random.key(42, device="cuda")
step = torch.tensor(0, device="cuda")  # int64, e.g. a training-step counter

# New: int64 data is accepted directly.
k = random.fold_in(key, step)

# Old (uint64 only): reinterpret the bits first. view() is zero-copy and
# matches the int overload for negatives; .to(torch.uint64) would add a copy.
k_old = random.fold_in(key, step.view(torch.uint64))

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Nov 23, 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:

The PR lets `torch.func._random.fold_in()` and
`aten::_philox_key_fold_in.Tensor` accept int64 scalar tensor data as well as
uint64 on CPU, CUDA and meta, reading the int64 bits as uint64 so results match
the `int` overload. Recommendation: Approve. Nothing blocks; one non-blocking
docstring wording point remains.

Findings (1):

[minor] torch/func/_random.py:137
Non-blocking: the `data` docstring drops the "must" for `int` inputs. The old
text said an `int` "must be within the inclusive range" and applied the range
only to `int`. The new text, "The value to fold in, within `[-2**63, 2**64 -
1]`", describes the range for every input but no longer states it as a
requirement. In the code only the `int` path is checked, and it raises
`ValueError` when out of range (`_random.py:158-161`). Tensor values are already
bounded by their dtype. Suggested wording: "An `int` outside `[-2**63, 2**64 -
1]` raises `ValueError`."

Reviewed commit: b32c155

Review run

🐛 Report a bad review

🔗 Helpful Links

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

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

✅ You can merge normally! (1 Unrelated Failure)

As of commit b32c155 with merge base bcff2f4 (image):

🟡 GREEN LIGHT - OUTDATED (earlier commit) - PR requires human review:

  • User-facing surface
    • fold_in is listed in the autosummary entry of docs/source/func._random.md, so it counts as public API despite the private module
    • The diff changes its documented behavior: the data tensor may now be int64 as well as uint64
  • Triviality
    • This is a feature expansion, not a bugfix or no-op, so it fits no trivial change class
  • Correctness
    • No defect found: CPU and CUDA kernels and meta_philox_key_fold_in_tensor all reinterpret int64 bits as uint64, matching the int overload's remap
    • test_tensor_data_matches_int adds int64 and negative cases; the old int64-rejection check now uses int32

reason: needs_socialization
Reviewed commit: 283dd4b (NOT the current head b32c155)

Inference job

🐛 Report a wrong verdict

FLAKY - The following job failed but was likely due to flakiness present on trunk:

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

github-actions[bot]

This comment was marked as outdated.

[ghstack-poisoned]
[ghstack-poisoned]
github-actions[bot]

This comment was marked as outdated.

@albanD albanD left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds fair but should be clearer about the mapping.
in particular, if I pass 12 as data as uint64 or int64, I should get the same result right? Only if I pass a negative int64 do I get remapped to the top of the uint64 range?

Comment thread torch/func/_random.py Outdated
``uint64``, contain a single value, and reside on the same device
as ``key``.
``uint64`` or ``int64`` (whose negative values are remapped the same
way), contain a single value, and reside on the same device as

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does remapped the same way means?

@jbschlosser

Copy link
Copy Markdown
Contributor Author

in particular, if I pass 12 as data as uint64 or int64, I should get the same result right? Only if I pass a negative int64 do I get remapped to the top of the uint64 range?

this is correct; lemme get this reworded to make this clear

huydhn pushed a commit to pytorch/test-infra that referenced this pull request Nov 25, 2026
## Author Notes

We should never collapse things that would prevent merging.

## Agent Notes

Cancelled jobs land in `failedJobs`, so `isDrciGreen` treats them as
failures: they make the Dr. CI headline ❌, block the "ready for
review" promotion (`isCiGoodForReview`) and block merging. Their section
was nonetheless rendered collapsed, the only blocking section to be so
(NEW FAILURES, UNCLASSIFIED and AWAITING APPROVAL are open), sitting
next to the collapsed non-blocking FLAKY / BROKEN TRUNK / UNSTABLE
sections, so it read as non-blocking. For example,
pytorch/pytorch#206339 stays `in progress` only because of 4 collapsed
cancelled Lint jobs. This renders the CANCELLED JOBS section open and
adds a test for it. Tested with `npx jest --no-watchman
test/drci.test.ts` (67/67 pass).

This PR was written by Claude Code on behalf of albanD.
albanD added a commit to pytorch/test-infra that referenced this pull request Nov 26, 2026
…head (#9616)

## Author Notes

Making the (rare) case where a single workflow running on a single hash
work better. In particular, when you rerun the older run, it doesn't
become the "newer" because it's ID doesn't change. And so reruning
cannot clear a other workflow being cancelled or failed for flaky
reason. Making it so that success > fail > most recent.

## Agent Notes

`reorganizeWorkflows` keeps one run per workflow file
(`workflowUniqueId`) on the PR head and drops every job of the other
runs. It used to keep the run with the highest ID. A re-run keeps its
run ID (only `run_attempt` changes), so re-running the older run never
makes it win, and a newer cancelled or flakily failed run keeps
blocking. Example: pytorch/pytorch#206339 got two Lint runs in the same
second; concurrency cancelled the newer one (45427672193) while the
older one (45427672059) passed every job, yet Dr. CI dropped the passing
run and listed 4 cancelled jobs, keeping the PR from being promoted to
"ready for review".

The run is now picked by rank, then by highest ID within a rank: success
> anything else (failure, in progress, ...) > cancelled.

| Runs on the same head commit | Before | After |
|---|---|---|
| older success, newer cancelled | cancelled | success |
| older success, newer failed | failed | success |
| older failed, newer success | success | success |
| older failed, newer cancelled | cancelled | failed |
| all cancelled / no success or cancellation | highest ID | highest ID |

**Behavior change vs #5038:** the existing test "test new failed
workflow overrides old succeeding workflow" asserted that a newer failed
run beats an older successful run of the same workflow on the same
commit. This PR deliberately reverses that: the successful run wins, and
the test is flipped to "test old succeeding workflow overrides new
failed workflow" (expects 0 failed jobs). Trade-off: if two events run
the same workflow file with different job sets (e.g. label-gated jobs),
an older green run can now hide a newer red one.

No SQL change: workflow rows from `recent_pr_workflows_query` already
carry `conclusion`. Added table-driven `reorganizeWorkflows` tests (3 of
the 4 fail on the old logic). `npx jest --no-watchman` on `drci`,
`drciStatus`, `drciAuth` and `crcrComment` tests: 157/157 pass; prettier
clean; `tsc` error count unchanged from `main`.

This PR was written by Claude Code on behalf of albanD.
[ghstack-poisoned]
@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Dec 2, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: This PR needs a release notes: label
If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Details for Dev Infra team

Raised by workflow job

@jbschlosser jbschlosser added release notes: nn release notes category topic: improvements topic category labels Dec 2, 2026
@jbschlosser

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

@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 Dec 2, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 1 jobs have failed on stacked PR #206328, first few of them are: trunk / macos-py3-arm64 / test (default, 1, 3, macos-m1-stable)

Details for Dev Infra team

Raised by workflow job

@jbschlosser

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: HTTP Error 403: Forbidden

Details for Dev Infra team

Raised by workflow job

@jbschlosser

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: 1 jobs have failed on stacked PR #206328, first few of them are: trunk / macos-py3-arm64 / test (default, 1, 3, macos-m1-stable)

Details for Dev Infra team

Raised by workflow job

@jbschlosser

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge -i

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged while ignoring the following 3 checks: trunk / linux-jammy-cuda13.2-py3.11-gcc11 / test (pr_time_benchmarks, 1, 1, mt-l-bx86iavx512-94-344-t4-8) (#206328), trunk / macos-py3-arm64 / test (default, 1, 3, macos-m1-stable) (#206328), trunk / linux-jammy-cuda13.2-py3.11-gcc11 / test (pr_time_benchmarks, 1, 1, mt-l-bx86iavx512-94-344-t4-8) (#206339)

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

ciflow/trunk Trigger trunk jobs on your pull request GL/superseded GreenLight review is superseded by changes Merged ready for review Automated review passed, ready for a final review by a maintainer. release notes: nn release notes category topic: improvements topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants