Skip to content
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

check scale.ndim before applying t/transpose #1339

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

crcrpar
Copy link
Contributor

@crcrpar crcrpar commented Nov 25, 2024

This check is for torch.ops.aten.transpose.int.

This is because (a) scale could be 0D/1D and (b) the args and kwargs of torch.ops.aten.transpose.int would supply dim0 and dim1, which is not appropriate for <2D tensor and dim canonicalization would fail like torch._prims_common.canonicalize_dims

because (a) `scale` could be 0D/1D and `transpose` and (b) the args and
kwargs of `torch.ops.aten.transpose.int` would supply `dim0` and `dim1`,
leading to cause dim canonicalization to fail.
e.g. [`torch._prims_common.canonicalize_dims`](https://github.com/pytorch/pytorch/blob/07906f2/torch/_prims_common/__init__.py#L704)

Signed-off-by: Masaki Kozuki <[email protected]>
Copy link

pytorch-bot bot commented Nov 25, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/1339

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 New Failure

As of commit fdf4da5 with merge base b2e42ff (image):

NEW FAILURE - The following job has failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 25, 2024
@msaroufim msaroufim requested a review from vkuzo November 26, 2024 05:08
@vkuzo
Copy link
Contributor

vkuzo commented Nov 27, 2024

just curious, what's the functionality you are trying to enable?

@crcrpar
Copy link
Contributor Author

crcrpar commented Nov 27, 2024

I'm doing something funny in lightning-thunder to support torchao float8 in Lightning-AI/lightning-thunder#1415 where I create a python function from thunder IR and evaluate that function using torch.fx.
In thunder, tensor.t() is translated to transpose(tensor, 0, 1) so the python function to be evaluated by torch.fx has fp8_tensor.transpose(0, 1) instead of fp8_tensor.t(). Then I saw an error from dim canonicalization as I use tensor-wise scaling, i.e., 0dim scale factor.

@vkuzo
Copy link
Contributor

vkuzo commented Nov 27, 2024

sgtm. Can we add just add a corresponding test to test/float8/test_base.py?

@vkuzo vkuzo added the topic: improvement Use this tag if this PR is an improvement (doesn't fit into any of the other categories) label Nov 27, 2024
@@ -85,7 +85,10 @@ def float8_desugar_data_and_scale_op(aten_op, args, kwargs=None):
)
def float8_transpose(aten_op, args, kwargs=None):
new_data = aten_op(args[0]._data, *args[1:], **kwargs)
new_scale = aten_op(args[0]._scale, *args[1:], **kwargs)
if args[0]._scale.ndim == 2:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be >= 2 to handle tensors of rank 3+?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought for FP8 mostly scale would be 0D / 1D unless it's MX fp8. Anyway cases I'm interested in would be solved with if-else so I updated the condition

Signed-off-by: Masaki Kozuki <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. topic: improvement Use this tag if this PR is an improvement (doesn't fit into any of the other categories)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants