模板类 Int8Calibrator¶
定义在 文件 ptq.h
继承关系¶
基类型¶
private Algorithm
类文档¶
-
template<typename Algorithm, typename DataLoaderUniquePtr>
class Int8Calibrator : private Algorithm¶ 基于指定的 TensorRT 校准算法和 LibTorch DataLoader 的通用 Int8Calibrator 实现。
- 模板参数
Algorithm – class nvinfer1::IInt8Calibrator(默认值:nvinfer1::IInt8EntropyCalibrator2)- 要使用的算法
DataLoaderUniquePtr – std::unique_ptr<torch::data::DataLoader> - DataLoader 类型
公共函数
-
inline Int8Calibrator(DataLoaderUniquePtr dataloader, const std::string &cache_file_path, bool use_cache)¶
构造一个新的 Int8Calibrator 对象。
使用提供的 DataLoader,构造一个可用于 Torch-TensorRT PTQ 的校准器
- 参数
dataloader – std::unqiue_ptr<torch::data::DataLoader> - 指向 DataLoader 的唯一指针,应为从 make_data_loader 工厂返回的内容
cache_file_path – const std::string& - 用于存储/查找校准缓存的路径
use_cache – : bool - 是否使用缓存(如果存在)
-
inline int getBatchSize() const noexcept override¶
获取下一批次的批次大小(由于 TRT 和显式批次的问题,始终为 1)
- 返回值
int
-
inline bool getBatch(void *bindings[], const char *names[], int nbBindings) noexcept override¶
获取下一批次。
- 参数
bindings – void*[] - 绑定指针数组(从 TensorRT 校准器馈入),这些缓冲区应填充每个输入的批次数据
names – const char*[] - 绑定的名称
nbBindings – int - 绑定的数量
- 返回值
true - 校准器有新的批次要消耗
- 返回值
false - 校准器没有新的批次要消耗
-
inline const void *readCalibrationCache(size_t &length) noexcept override¶
读取校准缓存。
如何从校准缓存中读取,仅在使用 use_cache 设置时启用
- 参数
length –
- 返回值
const void* - 指向缓存数据的指针
-
inline void writeCalibrationCache(const void *cache, size_t length) noexcept override¶
写入校准缓存。
将 TensorRT 提供的校准缓存写入指定文件
- 参数
cache – const void* - 缓存数据
length – size_t - 缓存长度
-
inline operator nvinfer1::IInt8Calibrator*()¶
转换为 nvinfer1::IInt8Calibrator* 的运算符
方便转换为 IInt8Calibrator* 的函数,以便轻松分配给 CompileSpec 中的 ptq_calibrator 字段
- 返回值
nvinfer1::IInt8Calibrator*