Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/194112
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New Failure, 18 Pending, 2 Unrelated Failures, 2 Unclassified FailuresAs of commit 7acd36a with merge base fdc97e8 ( NEW FAILURE - The following job has failed:
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:
BROKEN TRUNK - The following job failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
UNSTABLE - The following job is marked as unstable, possibly due to flakiness on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@claude fable do your thing and review this one |
|
Claude finished @drisspg's task in 19m 35s —— View job Reviewed the three overflow fixes: the PR Review: #194112 (click to expand)
SummaryFixes three silent int64/int overflows in Code Quality
Testing
RecommendationRequest Changes Blocking: item 1 — the PR's stated goal is making this shape math overflow-safe, and an int64 signed-overflow (UB) remains reachable in the very function being fixed, through the very op being fixed, using the tooling the PR already adds. Items 2–3 are should-fix but wouldn't block on their own.
|
| @@ -3874,6 +3870,24 @@ def error_inputs_max_pool1d(op_info, device, **kwargs): | |||
| kwargs={'kernel_size': 5, 'stride': 1, 'padding': 0, 'dilation': 1}), | |||
| error_regex=error_msg) | |||
|
|
|||
| # error inputs for invalid output size, with a kernel past INT32_MAX: | |||
There was a problem hiding this comment.
This won't run out of space or require largeTensor decorators?
There was a problem hiding this comment.
No, because it should never allocate, just error out right away
ceafc74 to
e393227
Compare
| // Not (x + y - 1) / y: that overflows for large x or y and silently rounds | ||
| // down. Truncation already rounds a negative quotient up, so only a positive | ||
| // remainder needs the correction. | ||
| return x / y + (x % y > 0); |
There was a problem hiding this comment.
I hate that this is not called ceil_div
Skylion007
left a comment
There was a problem hiding this comment.
I have my nit about the possible static assert otherwise looks good.
e393227 to
1a3537c
Compare
`torch.max_pool1d` segfaults for several out-of-domain integer arguments. Two overflows in the shape math remain after the `at::divup` fix this is stacked on: 1. `div_rtn()` computed the floor quotient in `int` regardless of `T`, although every call site passes `div_rtn<int64_t>`. The truncated remainder gets the wrong sign, so the floor correction is skipped and the quotient wraps: for #73190 the true output size `-2147483694` became `+2147483602`, sailing past `TORCH_CHECK(OW > 0)`. Also fixes the shape checks in im2col/col2im, ConvolutionMM2d/3d and the CUDA and MPS pooling paths, which use the same helper. 2. `dilation * (kernel_size - 1) + 1` in `pooling_output_shape()` overflows int64 for large kernels, wrapping the pad bound positive and producing a bogus output size (#142454). Compute it with `c10::mul_overflows` and reject the overflow instead. This is also what produced the nonsensical "pad should be at most half of effective kernel size, but got pad=0" message. The third overflow, in `at::divup`, is the parent PR: `PoolingParams1D` bounds the output range with it, so the CPU kernel read a window starting past the end of the input. That one is only reachable once (1) is fixed, and only on the non-autograd CPU path -- `max_pool1d_with_indices` rejects such strides in `safe_downcast<int>`. Fixes #73190, #136719, #142454 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01EFzKNdrvb8pUYeCUSxhtEA
1a3537c to
7acd36a
Compare
Attention! native_functions.yaml was changedIf you are adding a new function or defaulted argument to native_functions.yaml, you cannot use it from pre-existing Python frontend code until our FC window passes (two weeks). Split your PR into two PRs, one which adds the new C++ functionality, and one that makes use of it from Python, and land them two weeks apart. See https://github.com/pytorch/pytorch/wiki/PyTorch's-Python-Frontend-Backward-and-Forward-Compatibility-Policy#forwards-compatibility-fc for more info. Attention! PyTorch one of the C-stable API file was changedYou MUST NOT change existing function declarations in this, as this header defines a stable C ABI. If you need to change the signature for a function, introduce a new v2 version of the function and modify code generation to target the new version of the function. |
This PR needs a
|
5 similar comments
This PR needs a
|
This PR needs a
|
This PR needs a
|
This PR needs a
|
This PR needs a
|
|
@pytorchbot merge -f "Pull and trunk are green, rest of the failures seems unrelated" |
Merge startedYour change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
torch.max_pool1dsegfaults for several out-of-domain integer arguments.There are three separate silent integer overflows in the shape math, and all three have to go for the op to be safe — fixing (1) alone makes (3) newly reachable.
1.
div_rtn()floor-divides inintEvery call site passes
div_rtn<int64_t>, so the truncated remainder gets the wrong sign, the floor correction is skipped, and the quotient wraps. For #73190 (kernel_size = stride = dilation = 2147483697) the true output size-2147483694becomes+2147483602and sails pastTORCH_CHECK(OW > 0); for #136719 (kernel_size = stride = INT64_MAX) a true0becomes1. In both cases the kernel then indexes out of bounds.The helper is shared, so this also affects the shape checks in
im2col_shape_check.h,ConvolutionMM2d/3d.cpp,DilatedConvolutionUtils.h, the CUDAIm2Col/Col2Im/ConvolutionMM2dkernels and MPSPooling.mm. Two side effects, both improvements:slow_conv_dilated2dwithdilation = 2147483697used to silently return a[1, 1, 0, 0]tensor and now raisescalculated output size -1 -1 is too small, andF.unfoldwith an INT32-boundary stride now fails in theim2colshape check instead of downstream innumel.Checked the two bodies against an
__int128floor-division reference: identical on all 1,000,100 realistic in-range cases (|x| <= 5000,|y| <= 50); over 3,000,000 randomint64pairs the old one is wrong 1,499,994 times and the new one 0.2.
dilation * (kernel_size - 1) + 1overflows inpooling_output_shape()This is #142454, a different root —
div_rtnis doing exact arithmetic on already-garbage input. Withkernel_size = 8608480567731124087anddilation = 1250999896764, the effective kernel size wraps to+3689346979942061737, so the pad check passes; the numerator wraps to+4919136089788855880, soOWcomes out1. Computed withc10::mul_overflows/add_overflowsand rejected instead.This is also where the nonsensical
pad should be at most half of effective kernel size, but got pad=0messages came from: the wrapped bound went negative, sopad = 0failed a check about padding for reasons that had nothing to do with padding. Those inputs now report the actual problem.3.
at::divup()overflows — handled in #195035PoolingParams1D::valid_output_endbounds the output range withdivup, so with a large stride the CPU kernel got a range whose window starts past the end of the input:Reachable only once (1) is fixed, and only on the non-autograd CPU path —
max_pool1d_with_indicesrejects such strides insafe_downcast<int>, which is why it stayed hidden.OW = 1is correct here; the fixed result matches whatmax_pool1d_with_indicescomputes for the same arguments.Testing
Error cases added to the
nn.functional.max_pool1dOpInfo (the INT32-boundary kernels, theINT64_MAXkernel, and the effective-kernel-size overflow). (3) produces a correct result rather than an error, so it goes in the existingtest_max_pool1d_corner_casesas one morecheck(...)— adding it as an OpInfo sample input instead fails 10 generic tests, since thewith_indicesvariant legitimately rejects INT64_MAX strides.🤖 Generated with Claude Code