aitune.torch.backend.tensorrt.modelopt_calibration
aitune.torch.backend.tensorrt.modelopt_calibration
NVIDIA ModelOpt Calibration module for quantization and autocast.
Module Contents
Functions
Data
API
Build list of per-sample dicts (ONNX name -> array), skip empty, raise on batch size 0.
Merge list of per-sample dicts into one dict with arrays concatenated on axis=0.
Keep only samples whose non-batch shape matches the representative.
The representative is the sample with the largest total number of elements. Matching is on shape[1:] only, so different batch sizes are kept and concatenated along axis=0. Samples with different non-batch shapes are dropped with a warning.
Return a rank for this sample (larger = larger shape). Used to pick max-shape representative.
Convert one (args, kwargs) sample to a dict of ONNX input name -> numpy array.
Return True if sample has the same non-batch shapes as reference for all keys.
Compares shape[1:] only so different batch sizes (axis=0) are allowed and can be concatenated along axis=0.
Prepare calibration data in ModelOpt format from 1..N samples and graph_spec.
Builds a single dict of arrays (one per ONNX input) by mapping each sample to ONNX input names and concatenating all samples along axis=0. So you get one “large batch” per input, e.g. 3 samples of shapes (2,3,224,224), (1,3,224,224), (4,3,224,224) → one array of shape (7, 3, 224, 224). ModelOpt requires this format (dict of arrays, not a list of batches).
Tensors are moved to CPU and converted to numpy. Uses graph_spec.input_spec for ONNX input names and locators into normalized forward arguments.
Parameters:
List of 1..N Sample objects (args, kwargs); each can have any batch size.
Graph specification whose input_spec defines ONNX input names and locators into normalized forward arguments.
Returns: dict[str, np.ndarray]
Single dict mapping ONNX input names to numpy arrays. Each value has
Raises:
ValueError: If data is empty or graph_spec has no tensor inputs.