-
Notifications
You must be signed in to change notification settings - Fork 364
feat: Add ExportedProgram as an IR #2191
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
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
import torch | ||
import torch.fx | ||
import torch_tensorrt.ts | ||
from torch._export import ExportedProgram | ||
from torch_tensorrt._enums import dtype | ||
from torch_tensorrt._Input import Input | ||
from torch_tensorrt.dynamo.compile import compile as dynamo_compile | ||
|
@@ -43,6 +44,7 @@ class _IRType(Enum): | |
fx = 1 | ||
dynamo = 2 | ||
torch_compile = 3 | ||
exported_program = 4 | ||
|
||
|
||
class _ModuleType(Enum): | ||
|
@@ -51,6 +53,7 @@ class _ModuleType(Enum): | |
nn = 0 | ||
ts = 1 | ||
fx = 2 | ||
ep = 3 | ||
peri044 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
def _parse_module_type(module: Any) -> _ModuleType: | ||
|
@@ -61,6 +64,8 @@ def _parse_module_type(module: Any) -> _ModuleType: | |
return _ModuleType.ts | ||
elif isinstance(module, torch.fx.GraphModule): | ||
return _ModuleType.fx | ||
elif isinstance(module, ExportedProgram): | ||
return _ModuleType.ep | ||
elif isinstance(module, torch.nn.Module): | ||
return _ModuleType.nn | ||
else: | ||
|
@@ -70,6 +75,7 @@ def _parse_module_type(module: Any) -> _ModuleType: | |
def _get_target_ir(module_type: _ModuleType, ir: str) -> _IRType: | ||
module_is_tsable = any(module_type == t for t in [_ModuleType.nn, _ModuleType.ts]) | ||
module_is_fxable = any(module_type == t for t in [_ModuleType.nn, _ModuleType.fx]) | ||
module_is_exportable = module_type == _ModuleType.ep | ||
|
||
ir_targets_torchscript = any(ir == opt for opt in ["torchscript", "ts"]) | ||
ir_targets_fx = ir == "fx" | ||
|
@@ -95,8 +101,16 @@ def _get_target_ir(module_type: _ModuleType, ir: str) -> _IRType: | |
"Input graph is a Torchscript module but the ir provided is default (dynamo). Please set ir=torchscript to suppress the warning. Compiling the module with ir=torchscript" | ||
) | ||
return _IRType.ts | ||
elif module_is_exportable: | ||
raise ValueError( | ||
"Input graph is an ExportedProgram which is not currently supported. Please provide torch.nn.Module or torch.fx.GraphModule as input." | ||
) | ||
peri044 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
else: | ||
raise ValueError("Module was provided in an unsupported format") | ||
elif ir == "exported_program": | ||
raise ValueError( | ||
"ir=exported_program is not currently supported. Supported ir options : ts|fx|dynamo" | ||
) | ||
Comment on lines
+110
to
+113
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above for input type. |
||
else: | ||
raise ValueError("Unknown ir was requested") | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated to this change, but the docstring on this
Enum
is not relevant to the content