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

fix: Address .numpy() issue on fake tensors #1949

Merged
merged 1 commit into from
May 25, 2023

Conversation

gs-olive
Copy link
Collaborator

Description

  • Add fake_tensor_unsupported decorator to helper backend
  • Refactor conversion implementation to use compilation settings object as well, to reduce code duplication and encourage reuse
  • Improve debugger messages by pre-formatting support string

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

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

@gs-olive gs-olive added the component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths label May 24, 2023
@gs-olive gs-olive requested a review from narendasan May 24, 2023 20:49
@gs-olive gs-olive self-assigned this May 24, 2023
@github-actions github-actions bot added the component: api [Python] Issues re: Python API label May 24, 2023
@gs-olive gs-olive changed the title fix: Fix .numpy() issue on fake tensors fix: Address .numpy() issue on fake tensors May 24, 2023
@@ -52,6 +52,7 @@ def aot_torch_tensorrt_aten_backend(
)


@fake_tensor_unsupported
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is the ultimate backend everything goes through right? so does that mean we cant work on fake tensors? is this different than symbolic shapes?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also could we just turn a "fake_tensor" into an "ITensor" immediately. sounds like they are similar

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes this is the backend everything goes through, and my understanding is that FakeTensors are for use at compile time, and are distinct from SymInts which are the symbolic shape representations.

The challenge with fake tensors right now is that any tensors instantiated during the call are fake, which means that the constant tensors which we need to provide to TensorRT, as in the code snippet below, are "fake" and thus contain no value to be parsed. I think a long-term solution could be to support Fake Tensors fully, but this solution temporarily resolves TRT/Torch compatibility issues.

if isinstance(value, int):
value = torch.IntTensor([value])
if isinstance(value, float):
value = torch.Tensor([value])
if dtype:
value = value.to(dtype)
constant = network.add_constant(value.shape, to_numpy(value))

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Instantiated #1951 with a feature proposal and additional discussion

@gs-olive gs-olive requested a review from narendasan May 25, 2023 00:45
- Add `fake_tensor_unsupported` decorator to helper backend
- Refactor `conversion` implementation to use compilation settings
object as well, to reduce code duplication and encourage reuse
- Improve debugger messages by pre-formatting support string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla signed component: api [Python] Issues re: Python API component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants