Skip to content
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

Updated TensorRT Python API in torch2trt #630

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions torch2trt/converters/mul.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@


@tensorrt_converter('torch.mul')
@tensorrt_converter('torch.Tensor.mul_')
@tensorrt_converter('torch.Tensor.__imul__')
@tensorrt_converter('torch.Tensor.__mul__')
@tensorrt_converter('torch.Tensor.__rmul__')
Expand Down
15 changes: 10 additions & 5 deletions torch2trt/torch2trt.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,18 +555,23 @@ def torch2trt(module,
outputs = (outputs,)
ctx.mark_outputs(outputs, output_names)

builder.max_workspace_size = max_workspace_size
builder.fp16_mode = fp16_mode
builder.max_batch_size = max_batch_size
builder.strict_type_constraints = strict_type_constraints
config = builder.create_builder_config()
config.max_workspace_size = max_workspace_size

if strict_type_constraints:
config.set_flag(trt.BuilderFlag.STRICT_TYPES)

if fp16_mode:
config.set_flag(trt.BuilderFlag.FP16)

if int8_mode:

# default to use input tensors for calibration
if int8_calib_dataset is None:
int8_calib_dataset = TensorBatchDataset(inputs_in)

builder.int8_mode = True
config.set_flag(trt.BuilderFlag.INT8)

#Making sure not to run calibration with QAT mode on
if not 'qat_mode' in kwargs:
Expand All @@ -575,7 +580,7 @@ def torch2trt(module,
inputs, int8_calib_dataset, batch_size=int8_calib_batch_size, algorithm=int8_calib_algorithm
)

engine = builder.build_cuda_engine(network)
engine = builder.build_engine(network, config)

module_trt = TRTModule(engine, input_names, output_names)

Expand Down