TensorRT Optimization Profiles
Introduction
TensorRT optimization profiles optimize the performance of a TensorRT engine. They are used to profile the performance of a model at different input shapes and batch sizes.
By default, a single profile is generated from the graph spec that supports the minimum and maximum shapes of the input tensors.
Using samples for profile generation
Set the number of samples to use for profile generation
You can set the number of samples to use for profile generation by setting the max_num_samples_stored in the aitune.torch.config module. By default, it is set to 1 as samples are stored for each backend, model module, and each batch size.
Use the ProfileMode.SAMPLES_USED mode
You can use the ProfileMode.SAMPLES_USED mode to auto-generate multiple profiles from shapes of samples used for tuning.
Use the correct samples and the right batch sizes during tuning
If you use a different batch size than the one used for profile generation, the model will not be able to run.
NOTE: As samples for a single parameter have different shapes, we are wrapping them in a DynamicShapeDataset to handle different shapes.
See tests/functional/pytorch/027_aitune_torch_toy_model_tensorrt_backend.py for a full example.
Using your own profiles
You can use your own profiles by setting the profiles argument in the TensorRTBackendConfig class.
These profiles assume the module defines forward(input), so input is the path of its top-level tensor parameter:
Getting the input paths
Profile keys are Python-like tensor paths rooted at their real forward parameter names. For forward(input),
the key is "input". A nested dictionary path uses a key such as inputs["tokens"]. You can get
the exact keys from the Path column in tuning logs for the default single-profile mode.