-
Notifications
You must be signed in to change notification settings - Fork 358
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
Enabled python runtime saving #2999
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
|
||
import tensorrt as trt | ||
import torch | ||
import torch_tensorrt | ||
from torch.nn import Module | ||
from torch_tensorrt._Device import Device | ||
from torch_tensorrt._enums import dtype | ||
|
@@ -18,8 +19,6 @@ | |
from torch_tensorrt.dynamo.utils import DYNAMIC_DIM | ||
from torch_tensorrt.logging import TRT_LOGGER | ||
|
||
import torch_tensorrt | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
|
@@ -145,15 +144,23 @@ def __getstate__(self) -> Dict[str, Any]: | |
state = self.__dict__.copy() | ||
state["engine"] = bytearray(self.engine.serialize()) | ||
state.pop("context", None) | ||
state.pop("input_dtypes", None) | ||
state.pop("input_shapes", None) | ||
state.pop("output_dtypes", None) | ||
state.pop("output_shapes", None) | ||
state.pop("active_stream", None) | ||
state.pop("target_device_properties", None) | ||
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. Do we reuse this data on load to set up the engine properly? 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. Yes. Line 163 initialized all these data |
||
return state | ||
|
||
def __setstate__(self, state: Dict[str, Any]) -> None: | ||
logger = trt.Logger() | ||
runtime = trt.Runtime(logger) | ||
state["engine"] = runtime.deserialize_cuda_engine(state["engine"]) | ||
self.__dict__.update(state) | ||
self.target_device_properties = torch.cuda.get_device_properties( | ||
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. The deserialization should make sure that the gpu matches the gpu the engine was built on instead of just changing it |
||
self.target_device_id | ||
) | ||
if self.engine: | ||
self.context = self.engine.create_execution_context() | ||
self._initialize() | ||
|
||
def __deepcopy__(self, memo: Any) -> PythonTorchTensorRTModule: | ||
cls = self.__class__ | ||
|
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.
I dont think this data should be serialized. It should be reconstructed on reload
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.
These data are poped from the dict so they are not serialized