Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Delete one copy
  • Loading branch information
cehongwang committed Sep 19, 2025
commit 2540824bbb1a7216fbeab46e8907795c83fd676f
3 changes: 2 additions & 1 deletion py/torch_tensorrt/dynamo/_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,8 @@ def compile(

# Move the weights in the state_dict to CPU
if offload_module_to_cpu:
deallocate_module(exported_program.module(), delete_module=False)
deallocate_module(gm, delete_module=False)
# deallocate_module(exported_program.module(), delete_module=False)
logger.info(
"The PyTorch model was moved to the CPU to allocate all GPU memory to TensorRT. To retain the model on the GPU, set offload_module_to_cpu=False"
)
Expand Down
3 changes: 1 addition & 2 deletions py/torch_tensorrt/dynamo/conversion/_TRTInterpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,7 @@ def _save_weight_mapping(self) -> None:
_LOGGER.info("Building weight name mapping...")
# Stage 1: Name mapping
torch_device = to_torch_device(self.compilation_settings.device)
self.module.to(torch_device)
sd = self.module.state_dict()
sd = {k: v.to(torch_device) for k, v in self.module.state_dict().items()}
weight_name_map: dict[str, Any] = {}
weight_refit_map = self.ctx.weight_refit_map
constant_mapping = {k: v for k, v in weight_refit_map.items() if v.size == 1}
Expand Down
4 changes: 3 additions & 1 deletion py/torch_tensorrt/dynamo/lowering/passes/constant_folding.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def constant_fold(
# For TRT INetwork construction the constants are moved to CPU in get_attr call.
for node, constant in cf.node_replacements.items():
replace_node_with_constant(
gm, node, torch.nn.Parameter(constant, requires_grad=False)
gm,
node,
torch.nn.Parameter(constant.cpu().contiguous(), requires_grad=False),
)

erased_params = []
Expand Down