Skip to content

Commit

Permalink
Implemented basic pipeline for Refitting (#2886)
Browse files Browse the repository at this point in the history
  • Loading branch information
cehongwang committed Jul 9, 2024
1 parent 41b3928 commit 7592715
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
1 change: 0 additions & 1 deletion docsrc/py_api/dynamo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ Functions

.. autofunction:: refit_module_weights


Classes
--------

Expand Down
2 changes: 0 additions & 2 deletions py/torch_tensorrt/dynamo/_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,6 @@ def compile(
else:
make_refitable = kwargs["refit"]

if kwarg_inputs is None:
kwarg_inputs = {}
engine_capability = EngineCapability._from(engine_capability)

if torch_executed_modules is not None and torch_executed_modules:
Expand Down
15 changes: 9 additions & 6 deletions py/torch_tensorrt/dynamo/_refit.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
from typing import Any, Sequence, Tuple

import numpy as np
<<<<<<< HEAD
=======
import tensorrt as trt
>>>>>>> 9f46d3940 (Implemented basic pipeline for Refitting (#2886))
import torch
from torch.export import ExportedProgram
from torch_tensorrt._enums import dtype
Expand Down Expand Up @@ -42,8 +46,11 @@
)
from torch_tensorrt.logging import TRT_LOGGER

<<<<<<< HEAD
import tensorrt as trt

=======
>>>>>>> 9f46d3940 (Implemented basic pipeline for Refitting (#2886))
logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -96,16 +103,12 @@ def construct_refit_mapping(
layer_type: str = layer.type.name
if layer_type in MODULE_MAP:
# Cast the parent class to child class to access attributes
# For example: ILayer does not have ILayer.kernel/ILayer.bias
# For example: ILayer does not have ILayer.kernal/ILayer.bias
# So we cast it to IConvolutionLayer and access the attributes
layer.__class__ = MODULE_MAP[layer_type][0]
for weight_type, weight_name in MODULE_MAP[layer_type][1]:
weight = layer.__getattribute__(weight_type).copy()
weight_dtype_opt = dtype.try_from(weight.dtype)
assert (
weight_dtype_opt is not None
), f"Weights {weight_name} has unsupported dtype {weight.dtype}"
weight_dtype = weight_dtype_opt.to(trt.DataType)
weight_dtype = dtype.try_from(weight.dtype).to(trt.DataType)
weight_map[f"{layer.name} {weight_name}"] = (
weight,
weight_dtype,
Expand Down

0 comments on commit 7592715

Please sign in to comment.