'DeprecationWarning: Use build_serialized_network...' ambiguous return type


When I call builder.build_engine, I get ‘DeprecationWarning: Use build_serialized_network instead’,
but according to the Builder’s docs, the two have different return types.

I’m a bit confused about why the warning is seemingly misleading; what might be the reason behind this?


TensorRT Version: 8.6.1
GPU Type: NVIDIA GeForce RTX 4090
Nvidia Driver Version: 535.129.03
CUDA Version: 12.2
CUDNN Version: -
Operating System + Version: Ubuntu 22.04.4 LTS
Python Version (if applicable): Python 3.10
TensorFlow Version (if applicable): -
PyTorch Version (if applicable): 2.0.1
Baremetal or Container (if container which image + tag): Baremetal

Relevant Files

Attached trt_reproduce_deprecation.txt since .py is not allowed.

Steps To Reproduce

Just try and use builder.build_engine(network, builder_config) and the DeprecationWarning will pop up. When it does and I replace builder.build_engine with builder.build_serialized_network I get an error as the two methods return different types.

import tensorrt as trt

# Create a TensorRT builder
builder = trt.Builder(trt.Logger(trt.Logger.WARNING))

# Set network creation flags (e.g., enable explicit batch mode)
network_flags = 1 << int(trt.NetworkDefinitionCreationFlag.EXPLICIT_BATCH)

# Create a network definition
network = builder.create_network(flags=network_flags)

# Set up builder parameters
builder_config = builder.create_builder_config()
builder_config.max_workspace_size = 1 << 30
builder_config.set_memory_pool_limit(pool = trt.MemoryPoolType.WORKSPACE, pool_size = 1 << 30)

# Build the TensorRT engine from the optimized network
engine = builder.build_engine(network, builder_config)
# DeprecationWarning: Use build_serialized_network instead.**
# engine = builder.build_engine(network, builder_config)**

# Create a TensorRT execution context
context = engine.create_execution_context()

If I replce the method, the last line throws:

AttributeError: 'tensorrt_bindings.tensorrt.IHostMemory' object has no attribute 'create_execution_context'

This is because the ‘engine’ is now a tensorrt_bindings.tensorrt.IHostMemory,
Instead of the previous case, when it was a tensorrt_bindings.tensorrt.ICudaEngine.

1 Like