Repository navigation
Conversation
Method::set_input guards a DYNAMIC_BOUND input only against the total element count of its serialized bound shape: TensorImpl initializes numel_bound_ to the product of those sizes, and internal_resize_contiguous compares the incoming numel against it. A model bounded at (3, 4) therefore accepts (2, 6) -- the product fits, the per-dimension contract does not -- and the method proceeds with geometry it was not planned for. program.fbs already states that contract: for DYNAMIC_BOUND, "each dimension of the tensor at runtime should never exceed the corresponding dimension of the upper bound shape". Only the first half was enforced. Add the per-dimension check in set_input. input_tensor_meta() already exposes the serialized shape as a span straight over the flatbuffer, so the bound is available for free and outlives the Method; the existing lookup is moved up and reused rather than a second one added, and its Result is now error-checked instead of being dereferenced directly. Placed in set_input rather than resize_tensor, per review discussion: resize_tensor is used throughout the system, while this constraint is a property of method inputs. DYNAMIC_UNBOUND is deliberately skipped, since program.fbs says its sizes field carries no bound. Rank mismatches are left to resize_tensor. Lower bounds and divisibility are not serialized today and are left to a follow-up. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/24203
Note: Links to docs will display an error until the docs builds have been completed. ⏳ No Failures, 4 PendingAs of commit 4c110b8 with merge base d6abe23 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
On 64-bit the new per-dimension check in set_input now rejects these sizes before resize_tensor's numel bound check does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
In the portable runtime,
Method::set_inputchecks aDYNAMIC_BOUNDinput only against the total element count of its serialized bound shape:numel_bound_is the product of those sizes, and the resize compares the incoming numel against it. A model bounded at (3, 4) therefore accepts (2, 6).program.fbsalready states the per-dimension contract ("each dimension of the tensor at runtime should never exceed the corresponding dimension of the upper bound shape"). This PR enforces it inset_input, as @Gasoonjia suggested in #20546, rather than inresize_tensor, which is used throughout the runtime. The existinginput_tensor_meta()lookup moves above the resize and itsResultis now checked instead of being dereferenced directly.DYNAMIC_UNBOUNDis skipped, since its sizes carry no bound, and rank mismatches are left toresize_tensor. Minimum sizes and divisibility are not serialized, so they are not checked here: a dimension that was static at export is only bounded from above. The cross-input check inset_inputs()discussed in the issue is not part of this PR either. From reading the code, ATen mode changes more than the portable runtime: itsresize_tensor_impl(tensor_util_aten.cpp) checks only the rank, so this is the first shape boundset_inputapplies there.Part of #20546
I asked @JacobSzwejbka for a go-ahead on 4 Sep and have not heard back. I am opening this so the diff can be reviewed together with the questions below, and I will rework or close it if you would rather handle this differently. Three questions from that comment are still open:
InvalidArgument. In the portable runtime, a shape that also exceeds the numel bound used to getNotSupportedfromresize_tensorand now getsInvalidArgumentfrom the new check first (SetInputRejectsOverflowingSizesstill passes; the second commit updates its comment accordingly). Should that case keepNotSupported?Test plan
Five new tests in
runtime/executor/test/method_test.cpp:SetInputAcceptsShapesWithinPerDimBound,SetInputRejectsPerDimOverflowWithinNumelBound,SetInputRejectsPerDimOverflowBeyondNumelBound,SetInputRejectsRankMismatchOnBoundedInputandSetInputStaticShapeBehaviorUnchanged.Built with CMake on Ubuntu 24.04 (Release,
EXECUTORCH_BUILD_TESTS=ON,EXECUTORCH_ENABLE_LOGGING=ON) on top of main at a519331:All 22 tests pass, at both commits and again after merging main at d6abe23. With
method.cppreverted to main and the new tests kept,SetInputRejectsPerDimOverflowWithinNumelBoundandSetInputRejectsPerDimOverflowBeyondNumelBoundfail and the other 20 pass.lintrunner --skip MYPYreports no issues on the two files. I have not run the ATen-mode or Buck builds, and I have not measured the binary size on this base.I used Claude Code to write this PR.
cc @larryliu0820 @JacobSzwejbka @lucylq @nil-is-all