Skip to content

fix/feat: Add support for 64bit Tensor inputs FX aten [9 / x] #2021

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

Closed
wants to merge 3 commits into from

Conversation

gs-olive
Copy link
Collaborator

Description

  • Add truncate_long_and_double argument in FX settings to allow 64bit inputs
  • Utilize existing Dynamo functionality to repair FX aten graphs with 64bit inputs
  • Refactor imports in Dynamo to avoid circular import issue from new dependency issues
  • Add test cases to validate new feature

Note: Breaks python setup.py install --fx-only by introducing Dynamo dependency in FX. Potential resolutions include moving Dynamo utilities out of the Dynamo directory, or changing C++ requiring imports in Dynamo, etc.

Fixes #2008

Type of change

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

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

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

Comment on lines +8 to +9
from torch_tensorrt._Device import Device
from torch_tensorrt._enums import EngineCapability
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These changes were required to avoid circular import errors in Python. Updates to #1983 could potentially fix this issue.

@gs-olive gs-olive force-pushed the dynamo_compile_64bit_support branch from 76a4cdc to 6635bdc Compare June 21, 2023 01:06
@gs-olive gs-olive force-pushed the fx_aten_64bit_support branch from d533463 to 4e843a3 Compare June 21, 2023 01:08
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

There are some changes that do not conform to Python style guidelines:

--- py/torch_tensorrt/dynamo/backend/utils.py	2023-06-21 01:08:42.236399 +0000
+++ py/torch_tensorrt/dynamo/backend/utils.py	2023-06-21 01:09:05.163004 +0000
@@ -73,10 +73,11 @@
            "Invalid device provided. Supported options: torch.device | torch_tensorrt.Device"
        )

    return device

+
def parse_dynamo_kwargs(kwargs: Dict) -> CompilationSettings:
    """Parses the kwargs field of a Dynamo backend

    Args:
        kwargs: Keyword arguments dictionary provided to the backend

@gs-olive gs-olive force-pushed the dynamo_compile_64bit_support branch from 6635bdc to 7548ad2 Compare June 21, 2023 01:11
@gs-olive gs-olive force-pushed the fx_aten_64bit_support branch from 4e843a3 to 993d8d2 Compare June 21, 2023 01:12
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

@gs-olive gs-olive force-pushed the dynamo_compile_64bit_support branch from 7548ad2 to 9cf1785 Compare June 21, 2023 03:13
@gs-olive gs-olive force-pushed the fx_aten_64bit_support branch from 993d8d2 to edf0bf7 Compare June 21, 2023 03:14
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

@gs-olive gs-olive force-pushed the dynamo_compile_64bit_support branch from 9cf1785 to 921dd2f Compare June 23, 2023 03:26
@gs-olive gs-olive force-pushed the fx_aten_64bit_support branch from edf0bf7 to 9a9820a Compare June 23, 2023 03:27
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

@gs-olive gs-olive force-pushed the dynamo_compile_64bit_support branch from 921dd2f to 46b585b Compare June 28, 2023 21:49
@gs-olive gs-olive force-pushed the fx_aten_64bit_support branch from 9a9820a to 183ba3a Compare June 28, 2023 21:50
@gs-olive gs-olive removed the request for review from yinghai June 28, 2023 21:50
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

@gs-olive gs-olive force-pushed the dynamo_compile_64bit_support branch from 46b585b to eca6d00 Compare June 29, 2023 00:49
@gs-olive gs-olive force-pushed the fx_aten_64bit_support branch from 183ba3a to 938dfad Compare June 29, 2023 00:50
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

@gs-olive gs-olive force-pushed the dynamo_compile_64bit_support branch from eca6d00 to fb6f8eb Compare July 7, 2023 22:23
@gs-olive gs-olive force-pushed the fx_aten_64bit_support branch from 938dfad to dd3bad9 Compare July 7, 2023 22:25
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

There are some changes that do not conform to Python style guidelines:

--- py/torch_tensorrt/dynamo/fx_ts_compat/lower.py	2023-07-07 22:25:55.960522 +0000
+++ py/torch_tensorrt/dynamo/fx_ts_compat/lower.py	2023-07-07 22:26:11.127951 +0000
@@ -8,11 +8,15 @@
import torch.fx as fx
import torch.nn as nn
import torch_tensorrt.fx.tracer.dispatch_tracer.aten_tracer as aten_tracer
from torch.fx.passes.splitter_base import SplitResult

-from torch_tensorrt.dynamo.common import TRTInterpreter, TRTInterpreterResult, use_python_runtime_parser
+from torch_tensorrt.dynamo.common import (
+    TRTInterpreter,
+    TRTInterpreterResult,
+    use_python_runtime_parser,
+)
from .lower_setting import LowerSetting
from .passes.lower_pass_manager_builder import LowerPassManagerBuilder
from .passes.pass_utils import PassFunc, validate_inference
from torch_tensorrt.fx.tools.timing_cache_utils import TimingCacheManager
from torch_tensorrt.fx.tools.trt_splitter import TRTSplitter, TRTSplitterSetting

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

gs-olive added 2 commits July 7, 2023 15:26
- Add `common` directory which stores code common to both the compile
and export path, to reduce code duplication and better organize the
repository
- Update necessary imports, promote the `_defaults` module to
`torch_tensorrt.dynamo._defaults`
- Add default, setting, and function arguments for
`truncate_long_and_double` in Dynamo
- Add utilities for repairing long/double inputs to TRT engines,
including support for autocasting back to long/double after the
computation completes
- Add multiple helper functions to enable easy testing and diagnosis of
long/double IO to TRT engines
- Add necessary compiler code to enable usage of the `truncate_long_and_double`
argument as a switch for the feature
- Add Dynamo compile support for `truncate_long_and_double` compilation
argument by intercepting long/double type inputs and casting them to
their 32-bit counterparts prior to usage in TRT-accelerated subgraphs,
then casting back if necessary
- Add robust logic to handle 64-bit inputs and outputs
- Add test cases for long and double scenarios
- Centralize truncation utility for later use in Dynamo export path
@gs-olive gs-olive force-pushed the dynamo_compile_64bit_support branch from fb6f8eb to 21847e3 Compare July 7, 2023 22:27
- Add `truncate_long_and_double` argument in FX settings to allow 64bit
inputs
- Utilize existing Dynamo functionality to repair FX aten graphs with
64bit inputs
- Refactor imports in Dynamo to avoid circular import issue from new
dependency issues
- Add test cases to validate new feature
@gs-olive gs-olive force-pushed the fx_aten_64bit_support branch from dd3bad9 to c4a0e9d Compare July 7, 2023 22:28
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

@gs-olive gs-olive linked an issue Jul 13, 2023 that may be closed by this pull request
@gs-olive gs-olive force-pushed the dynamo_compile_64bit_support branch 2 times, most recently from dfa04ed to 9548c7f Compare July 14, 2023 22:27
@peri044
Copy link
Collaborator

peri044 commented Jul 18, 2023

Closing this in favor of #1983

@peri044 peri044 closed this Jul 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

✨[Feature] Automatic casting of Long/Double Tensor constants in FX
3 participants