-
Notifications
You must be signed in to change notification settings - Fork 72
[torchlib] Update linear implementation to support 1d weights #2340
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
Conversation
It is possible when users call `F.linear()` directly in PyTorch.
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.
Pull Request Overview
This PR updates the aten_linear
implementation to handle cases where the weight tensor is 1-dimensional by unsqueezing it instead of transposing, while retaining existing behavior for 2D weights.
- Add a branch for 1D
weight
tensors and useUnsqueeze
- Keep assertion and transpose logic for 2D
weight
tensors
Comments suppressed due to low confidence (2)
onnxscript/function_libs/torch_lib/ops/nn.py:836
- The transpose assignment is not indented under the
else:
block, so it always executes and overrides the 1DUnsqueeze
path. It should be moved inside theelse:
scope.
weight_transposed = op.Transpose(weight, perm=[1, 0])
onnxscript/function_libs/torch_lib/ops/nn.py:831
- [nitpick] The new branch for 1D weight handling isn’t covered by existing tests. Consider adding unit tests to verify behavior when
weight
is 1D.
if len(weight.shape) == 1:
❌ 3 Tests Failed:
View the top 3 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
It is possible when users call
F.linear()
directly in PyTorch.