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

feat: support aten._local_scalar_dense converter #2752

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

Conversation

chohk88
Copy link
Collaborator

@chohk88 chohk88 commented Apr 16, 2024

Description

A converter for the torch.ops.aten._local_scalar_dense operation, a low-level operation in PyTorch used internally to extract a scalar value from a tensor containing a single element.

To reviewer, I did not incorporate type-specific considerations in the implementation of the converter and test code. However, all test cases have successfully passed. I would greatly appreciate any feedback or suggestions regarding this aspect—especially if there are potential implications or improvements I might have overlooked.

image

Fixes # (issue)

Type of change

Please delete options that are not relevant and/or add your own.

  • New feature (non-breaking change which adds functionality)

Checklist:

  • My code follows the style guidelines of this project (You can use the linters)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas and hacks
  • I have made corresponding changes to the documentation
  • I have added tests to verify my fix or my feature
  • New and existing unit tests pass locally with my changes
  • I have added the relevant labels to my PR in so that relevant reviewers are notified

@chohk88 chohk88 self-assigned this Apr 16, 2024
@github-actions github-actions bot added component: tests Issues re: Tests component: conversion Issues re: Conversion stage component: converters Issues re: Specific op converters component: api [Python] Issues re: Python API component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths labels Apr 16, 2024
@github-actions github-actions bot requested a review from peri044 April 16, 2024 08:56
@chohk88 chohk88 linked an issue Apr 16, 2024 that may be closed by this pull request
github-actions[bot]

This comment was marked as resolved.

github-actions[bot]

This comment was marked as resolved.

@chohk88
Copy link
Collaborator Author

chohk88 commented Apr 16, 2024

I would appreciate your feedback on the type-related issues mentioned in the description.

github-actions[bot]

This comment was marked as resolved.

github-actions[bot]

This comment was marked as resolved.

@zewenli98
Copy link
Collaborator

@chohk88 @narendasan I checked the aten schema where there are only two funcs return Scalar type, i.e.,

- func: item(Tensor self) -> Scalar
- func: _local_scalar_dense(Tensor self) -> Scalar

I found some people have similar issues like: pytorch/xla#909
Their cases are moving data from XLA to CPU, so I'm thinking if this op is only called when moving data to CPUs.

For the functionality, my understanding to this function is to extract the first element in the input, whatever it is a single tensor or list of tensors, and then move it to CPUs. If true, I don't think it's meaningful to implement this converter. Instead, we can have a lowering pass to remove this op to avoid potential graph breaks.

Do you know why this converter is needed? or is this op used in any models?

@narendasan narendasan added the Blocked Issue cannot be resolved until a change in a dependency label May 3, 2024
@narendasan
Copy link
Collaborator

Needs #2810 to be implemented to fully work

@chohk88 chohk88 force-pushed the aten_local_scalar_dense_converter branch from 8a80daf to aa18d8f Compare June 12, 2024 23:15
@chohk88 chohk88 force-pushed the aten_local_scalar_dense_converter branch from aa18d8f to 8831462 Compare June 12, 2024 23:27
Copy link
Collaborator

@peri044 peri044 left a comment

Choose a reason for hiding this comment

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

This looks good to me. Seems like all this op does is to gather the first element.

To reviewer, I did not incorporate type-specific considerations in the implementation of the converter and test code.

The type should always be the input data type correct ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Blocked Issue cannot be resolved until a change in a dependency cla signed component: api [Python] Issues re: Python API component: conversion Issues re: Conversion stage component: converters Issues re: Specific op converters component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths component: tests Issues re: Tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aten._local_scalar_dense
5 participants