Skip to content

cross compile for windows #3220

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 57 commits into from
Nov 8, 2024
Merged

Conversation

lanluo-nvidia
Copy link
Collaborator

@lanluo-nvidia lanluo-nvidia commented Oct 7, 2024

Description

The cross compile for windows change has added the following new interface:

Usage 1:
cross compile and save the exported program to the disk in Linux:
torch_tensorrt.cross_compile_for_windows(toch.nn.Module, file_path, inputs, …..)
cross load the exported program from disk in Windows:
torch_tensorrt.load_cross_compiled_exported_program(file_path)

Usage 2:
export the model to exported program
ep = torch.export.export(…)
cross compile the exported program in Linux and return the trt_module:
trt_module = torch_tensorrt.dynamo.cross_compile_for_windows(ExportedProgram, inputs,…..)
save the cross compiled trt module to the disk in Linux:
torch_tensorrt.dynamo.save_cross_compiled_exported_program(trt_module, inputs,…..)
cross load the exported program from disk in Windows:
torch_tensorrt.dynamo.load_cross_compiled_exported_program(file_path)

Type of change

Please delete options that are not relevant and/or add your own.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

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

@lanluo-nvidia lanluo-nvidia added the WIP Work is in progress, pull request should not be merged yet label Oct 7, 2024
@lanluo-nvidia lanluo-nvidia self-assigned this Oct 7, 2024
@github-actions github-actions bot added component: conversion Issues re: Conversion stage component: core Issues re: The core compiler component: api [Python] Issues re: Python API component: runtime component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths labels Oct 7, 2024
@github-actions github-actions bot requested a review from narendasan October 7, 2024 14:06
@lanluo-nvidia lanluo-nvidia requested a review from peri044 October 7, 2024 17:59
@github-actions github-actions bot added the component: tests Issues re: Tests label Oct 7, 2024
@lanluo-nvidia lanluo-nvidia changed the title cross compile for windows (Still WIP) cross compile for windows Oct 14, 2024
@lanluo-nvidia lanluo-nvidia added the ciflow/binaries/all Build for all Python Versions label Oct 14, 2024
Copy link

pytorch-bot bot commented Oct 14, 2024

No ciflow labels are configured for this repo.
For information on how to enable CIFlow bot see this wiki

@lanluo-nvidia lanluo-nvidia removed the ciflow/binaries/all Build for all Python Versions label Oct 14, 2024
@lanluo-nvidia lanluo-nvidia changed the base branch from lluo/save_remove_inputs to main October 30, 2024 17: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.

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

--- /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/_compile.py	2024-10-30 18:19:43.261631+00:00
+++ /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/_compile.py	2024-10-30 18:20:03.016868+00:00
@@ -693,13 +693,13 @@
                        module, tuple(arg_inputs), kwargs=kwarg_inputs, strict=False
                    )
                    torch.export.save(exp_program, file_path)


-
def save_cross_compiled_exported_program(
    gm: torch.fx.GraphModule,
    file_path: str,
) -> None:
    from torch_tensorrt.dynamo._exporter import export
+
    exp_program = export(gm, cross_compile_flag=True)
    torch.export.save(exp_program, file_path)
--- /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/runtime/_utils.py	2024-10-30 18:19:43.281631+00:00
+++ /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/runtime/_utils.py	2024-10-30 18:20:06.042509+00:00
@@ -146,6 +146,6 @@
    serialized_target_platform: str,
) -> List[torch.Tensor]:

    raise RuntimeError(
        "The saved model is cross compiled for windows in Linux, should only be loadded in Windows via torch_tensorrt.load_cross_compiled_exported_program() api."
-    )
\ No newline at end of file
+    )

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:

--- /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/runtime/_utils.py	2024-10-31 16:35:01.922532+00:00
+++ /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/runtime/_utils.py	2024-10-31 16:35:26.529213+00:00
@@ -146,6 +146,6 @@
    serialized_target_platform: str,
) -> List[torch.Tensor]:

    raise RuntimeError(
        "The saved model is cross compiled for windows in Linux, should only be loadded in Windows via torch_tensorrt.load_cross_compiled_exported_program() api."
-    )
\ No newline at end of file
+    )

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:

--- /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/runtime/_utils.py	2024-10-31 23:51:37.956329+00:00
+++ /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/runtime/_utils.py	2024-10-31 23:52:02.447686+00:00
@@ -146,6 +146,6 @@
    serialized_target_platform: str,
) -> List[torch.Tensor]:

    raise RuntimeError(
        "The saved model is cross compiled for windows in Linux, should only be loadded in Windows via torch_tensorrt.load_cross_compiled_exported_program() api."
-    )
\ No newline at end of file
+    )

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:

--- /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/runtime/_utils.py	2024-11-01 17:19:50.118262+00:00
+++ /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/runtime/_utils.py	2024-11-01 17:20:13.032393+00:00
@@ -146,6 +146,6 @@
    serialized_target_platform: str,
) -> List[torch.Tensor]:

    raise RuntimeError(
        "The saved model is cross compiled for windows in Linux, should only be loadded in Windows via torch_tensorrt.load_cross_compiled_exported_program() api."
-    )
\ No newline at end of file
+    )

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:

--- /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/dynamo/_compiler.py	2024-11-01 18:10:52.286574+00:00
+++ /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/dynamo/_compiler.py	2024-11-01 18:11:12.489684+00:00
@@ -475,11 +475,14 @@
        if make_refittable:
            raise ValueError("Use flag make_refittable only. Flag refit is deprecated.")
        else:
            make_refittable = kwargs["refit"]

-    if "enable_cross_compile_for_windows" in kwargs.keys() and kwargs["enable_cross_compile_for_windows"]:
+    if (
+        "enable_cross_compile_for_windows" in kwargs.keys()
+        and kwargs["enable_cross_compile_for_windows"]
+    ):
        raise ValueError(
            "Please use cross_compile_for_windows() api if you want to cross compile the module in Linux for inferencing in Windows."
        )

    engine_capability = EngineCapability._from(engine_capability)

Copy link
Collaborator

@peri044 peri044 left a comment

Choose a reason for hiding this comment

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

LGTM

@lanluo-nvidia lanluo-nvidia merged commit bc95015 into main Nov 8, 2024
56 of 68 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
cla signed component: api [Python] Issues re: Python API component: conversion Issues re: Conversion stage component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths component: runtime component: tests Issues re: Tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants