-
Notifications
You must be signed in to change notification settings - Fork 363
cross compile for windows #3220
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
Merged
Changes from all commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
458a4d1
skip run_shape_analysis
lanluo-nvidia 2f408f9
test
lanluo-nvidia 1c5e86c
test
lanluo-nvidia ba487dc
test
lanluo-nvidia 99d2274
Merge branch 'main' into lluo/save_remove_inputs
lanluo-nvidia 2b43480
test
lanluo-nvidia 92105ce
cross compile for windows initial check in
lanluo-nvidia dd24bdf
test
lanluo-nvidia e6c9fa4
add testcase
lanluo-nvidia 9909eca
add test case
lanluo-nvidia 312a79e
add test case
lanluo-nvidia b4e02e1
Merge branch 'main' into lluo/save_remove_inputs
lanluo-nvidia 3d94f8b
test
lanluo-nvidia f43669a
Merge branch 'lluo/save_remove_inputs' into lluo/cross_compilation_fo…
lanluo-nvidia f4d0d27
test
lanluo-nvidia 2a43ca1
add more logs
lanluo-nvidia 76ddd66
test
lanluo-nvidia 28ba6cc
Merge branch 'main' into lluo/save_remove_inputs
lanluo-nvidia b89cbe0
resolve comments
lanluo-nvidia 079c4be
test
lanluo-nvidia 90f1a60
clean up
lanluo-nvidia c38dc5b
test
lanluo-nvidia 2843d37
Merge branch 'main' into lluo/save_remove_inputs
lanluo-nvidia b06a41b
Merge branch 'lluo/save_remove_inputs' into lluo/cross_compilation_fo…
lanluo-nvidia 3eb48d7
test
lanluo-nvidia fedc5c2
Merge branch 'lluo/save_remove_inputs' into lluo/cross_compilation_fo…
lanluo-nvidia 50eb0d8
replace dummy inference
lanluo-nvidia 95ed602
test
lanluo-nvidia 120f30d
test
lanluo-nvidia 424cbf7
add run_test_with_dynamic_shape change
lanluo-nvidia 2fc9cef
Merge branch 'main' into lluo/save_remove_inputs
lanluo-nvidia ef54cfc
split the PR, add dummy inference for converter test
lanluo-nvidia 14f5d61
test
lanluo-nvidia 7563959
test
lanluo-nvidia 77355f0
test
lanluo-nvidia 13361fd
add linear lowering meta val
lanluo-nvidia f0a9fef
add linear_lowering change
lanluo-nvidia cff64a4
test
lanluo-nvidia 933abac
test
lanluo-nvidia 8417684
resolve comments
lanluo-nvidia 8676f88
test
lanluo-nvidia 785d0b1
change solution: use no_op_placeholder during save and replace it wit…
lanluo-nvidia b85cb74
Merge branch 'lluo/save_remove_inputs' into lluo/cross_compilation_fo…
lanluo-nvidia 5d594b1
test
lanluo-nvidia 076f47a
resolve comments
lanluo-nvidia 8250179
Merge branch 'main' into lluo/save_remove_inputs
lanluo-nvidia 96e93e4
resolve comments
lanluo-nvidia 7d055bf
Merge branch 'lluo/save_remove_inputs' into lluo/cross_compilation_fo…
lanluo-nvidia 6e214d6
Merge branch 'main' into lluo/cross_compilation_for_windows
lanluo-nvidia cf0e0ae
resolve comments
lanluo-nvidia fb7fd1d
resolve comments
lanluo-nvidia 8fc89dc
resolve comments
lanluo-nvidia 63b3376
Merge branch 'main' into lluo/cross_compilation_for_windows
lanluo-nvidia 1a1ba41
merge latest main
lanluo-nvidia 96bc256
fix linting
lanluo-nvidia eebe1bc
test
lanluo-nvidia a35a932
resolve comments
lanluo-nvidia 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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
""" | ||
.. _resnet_cross_runtime_compilation_for_windows_example: | ||
|
||
cross runtime compilation limitations: | ||
The cross compile and saved model can only be loaded in Windows, it can no longer be loaded in Linux | ||
The cross compile and saved model can only be loaded in the same Compute Capability as the Linux which it was cross compiled | ||
(for example, if the model was cross compiled in Linux with GeForceRTX 4080 which has Compute Capability of 8.9, | ||
It cannot be loaded in Windows with GeForceRTX 3080 which has Compute Capability of 8.6) | ||
|
||
Cross runtime compilation for windows example | ||
====================================================== | ||
|
||
Compile and save the Resnet Model using Torch-TensorRT in Linux: | ||
|
||
python examples/dynamo/cross_runtime_compilation_for_windows.py --path trt_resnet.ep | ||
|
||
Load the Resnet Model saved in Windows: | ||
|
||
python examples/dynamo/cross_runtime_compilation_for_windows.py --path trt_resnet.ep --load True | ||
|
||
""" | ||
|
||
# %% | ||
# Imports and Model Definition | ||
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
import argparse | ||
import platform | ||
|
||
import torch | ||
import torch_tensorrt as torchtrt | ||
import torchvision.models as models | ||
|
||
PARSER = argparse.ArgumentParser( | ||
description="Cross runtime comilation for windows example: Resnet Model" | ||
) | ||
PARSER.add_argument( | ||
"--load", default=False, type=bool, required=False, help="Load the model in Windows" | ||
) | ||
PARSER.add_argument( | ||
"--path", | ||
type=str, | ||
required=True, | ||
help="Path to the saved model file", | ||
) | ||
|
||
args = PARSER.parse_args() | ||
torch.manual_seed(0) | ||
model = models.resnet18().eval().cuda() | ||
input = torch.rand((1, 3, 224, 224)).to("cuda") | ||
inputs = [input] | ||
|
||
# %% | ||
# According to the argument, it is either cross compile and save resnet model for windows in Linux | ||
# or load the saved resnet model in Windows | ||
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
if args.load: | ||
# load the saved model in Windows | ||
if platform.system() != "Windows" or platform.machine() != "AMD64": | ||
raise ValueError( | ||
"cross runtime compiled model for windows can only be loaded in Windows system" | ||
) | ||
loaded_model = torchtrt.load_cross_compiled_exported_program(args.path).module() | ||
print(f"model has been successfully loaded from ${args.path}") | ||
# inference | ||
trt_output = loaded_model(input) | ||
print(f"inference result: {trt_output}") | ||
else: | ||
if platform.system() != "Linux" or platform.architecture()[0] != "64bit": | ||
raise ValueError( | ||
"cross runtime compiled model for windows can only be compiled in Linux system" | ||
) | ||
compile_spec = { | ||
"debug": True, | ||
"min_block_size": 1, | ||
} | ||
torchtrt.cross_compile_for_windows( | ||
model, file_path=args.path, inputs=inputs, **compile_spec | ||
) | ||
print( | ||
f"model has been successfully cross compiled and saved in Linux to {args.path}" | ||
) |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.