Replies: 1 comment 3 replies
-
Thanks for the RFC George. This looks good. Couple of points to add
|
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
aten
Converter Capabilities ScopingTL;DR
How can we differentiate and select converters on a more granular scale than simply supported/unsupported?
Goal(s)
Python-implemented
aten
converters are used across the array of frontends whichtorch_tensorrt
provides. Specifying the capabilities of each converter requires more precision than simply categorizing into "present" vs "absent". For instance, certain converters could be typed to only work for dynamic-shape tensors or only static-shape tensors. This RFC details how we might implement this sort of converter differentiation scheme.Usecases
When selecting the specific converter to translate a node, we can take into account global information about the runtime, including compilation settings and other selections. For example, consider the following node:
In the current implementation, we simply check if
torch.ops.aten.sub.Tensor
is in the converter registry dictionary. If so, we label the node supported; if not, we label it unsupported. In a future implementation, we could differentiate on more granular criteria, such as whether the input tensors have dynamic shapes. In this scenario, we might have a new converter decorator like:@tensorrt_converter(torch.ops.aten.sub.Tensor, dynamic=True, static=False)
An even more advanced implementation might have arguments such as:
@tensorrt_converter(torch.ops.aten.sub.Tensor, check_args=arg_check_fn)
The above would have a corresponding checker function,
arg_check_fn
, which validates the converter can correctly convert its input node. One example of a case where this might be useful is for_to_copy
, which is effectively an alias oftorch.to
. As discussed in #2058, this sort of operator can only be converted if its operands are of a certain type. For instance, we cannot converttensor.to(torch.long)
, but we can converttensor.to(torch.float)
.The vast majority of converters would have
check_args=lambda node: True
, but for a few, this construct would be very helpful in avoiding unnecessary errors and strongly-typing and enforcing conversion constraints. Furthermore, thischeck_args
function can be relaxed as the converter implementation is improved.Proposed APIs / UX
There would be no major changes needed to the existing user-contribution system for
aten
converters. The design of this feature is non-breaking, meaning that all of the existing converters will still work, as-is, with no changes to the decorator. A future feature/task can make all necessary changes to update the existing decorators.Example Workflow
First, a user would implement a converter as follows:
Then, during partitioning (here the
dynamo_compile
partitioner is shown), we call thecheck_args_fn
and validate the node:Internal Implementation
Design
Firstly, the
CONVERTERS
global registry will need some modifications. Instead of mapping node operations to their corresponding converter functions, it will instead map these node operations to adataclass
struct containing an argument-checking function, a dynamic shape boolean flag, and any other necessary differentiation flags. For instance, see below:Extensions Required to Core API implementations
The partitioning system in both
compile
andexport
paths would need to be tweaked to filter converters accordingly with the above. The newCONVERTERS
dictionary stores a target mapped to a sequence of potential converters. The partitioner's role is to determine which of those converter implementations is best-suited to handle the specific node. One sample of a converter priority list we might adhere to is strictest-first:1. If any inputs are dynamic, first try a converter with
dynamic=True
,static=False
, and vice-versa for static.2. Verify
check_args
passes. If not, repeat step 1 with the next-strictest converter. If no more unchecked converters remain, return that the op is unsupported.3. Select the passing converter's implementation as the one to use.
Data Structures
See above for a discussion of new data structures.
Implementation Phases
Prototype - Medium
dynamic
andstatic
flagsdynamo_compile
partitioner to handle this use case and properly filter the converters, using the newDYNAMO_CONVERTERS
registry built here: fix/feat: Add Dynamo-only converter registry #1944MVP - Small
export
dynamic
andstatic
(dependent on Dynamic shapes RFC Dynamic shape support in dynamo #2014)Extension Phase 1 - Small
Beta Was this translation helpful? Give feedback.
All reactions