Validate from_slice/from_vec shapes and add stepped slice_assign#3615
Open
NahButch wants to merge 1 commit into
Open
Validate from_slice/from_vec shapes and add stepped slice_assign#3615NahButch wants to merge 1 commit into
NahButch wants to merge 1 commit into
Conversation
from_slice and from_vec accepted shapes whose element count does not match the data length, building tensors whose shape lies about their storage; reads past the data then fail or silently misbehave later (huggingface#3534). Both now return Error::ShapeMismatch, while one-hole shape inference keeps working. This also turns silent mask-construction bugs of the huggingface#3582 family into immediate errors. Adds slice_assign_with_step, the stepped counterpart of slice_assign matching Python's dst[start:end:step] = src semantics (huggingface#3095), built on the same mask/pad approach with zero-dilation along stepped dims. Fixes huggingface#3534 Fixes huggingface#3095 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
from_sliceandfrom_vecaccepted shapes whose element count does not match the data length, building tensors whose shape lies about their storage; reads past the data then fail or silently misbehave later (#3534). Both now returnError::ShapeMismatch, while one-hole shape inference keeps working. This also turns silent mask-construction bugs of the #3582 family into immediate errors.Adds
slice_assign_with_step, the stepped counterpart ofslice_assignmatching Python'sdst[start:end:step] = srcsemantics (#3095), built on the same mask/pad approach with zero-dilation along stepped dims; tests cover 1-D/2-D mixed steps, step-1 equivalence withslice_assign, and error cases.Note: this implements the validation approach @pjdurden outlined on #3534 last month; happy to defer if that work is still in flight.
Fixes #3534
Fixes #3095
🤖 Generated with Claude Code