-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tensor Operation fixes when input is sliced (non-contiguous) #106985
Conversation
Note regarding the
|
Note regarding the
|
cdb474e
to
4cd0a0b
Compare
internal static bool IsContiguousAndDense<T>(scoped in ReadOnlyTensorSpan<T> tensor) | ||
{ | ||
// Right most dimension must be 1 for a dense tensor. | ||
if (tensor._shape.Strides[^1] != 1) | ||
return false; | ||
|
||
// For other dimensions, the stride must be equal to the product of the dimensions to the right. | ||
for (int i = tensor._shape._rank - 2; i >= 0; i--) | ||
{ | ||
if (tensor._shape.Strides[i] != TensorPrimitives.Product(tensor.Lengths.Slice(i + 1, tensor.Lengths.Length - i - 1))) | ||
return false; | ||
} | ||
return true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For .NET 10 we should think about if we can use a bit or two to track that the span is contiguous/dense.
We should also ensure a tracking issue exists to ensure we can operate "row by row" and avoid allocating in the case that its not dense.
/backport to release/9.0-staging |
Started backporting to release/9.0-staging: https://github.com/dotnet/runtime/actions/runs/10601443057 |
@michaelgsharp an error occurred while backporting to release/9.0-staging, please check the run log for details! Error: The specified backport target branch release/9.0-staging wasn't found in the repo. |
/backport to release/9.0 |
Started backporting to release/9.0: https://github.com/dotnet/runtime/actions/runs/10601530979 |
…106985) * slicing fixes * rebased on main
This pr Fixes #106280.
Basically when the input was being sliced, the Tensor operations weren't always respecting that. This caused extra data to be processed and in some cases changed the final output. Will be backported to 9.0.