快捷方式

torch_tensorrt.fx

函数

torch_tensorrt.fx.compile(module: Module, input, min_acc_module_size: int = 10, max_batch_size: int = 2048, max_workspace_size=33554432, explicit_batch_dimension=False, lower_precision=LowerPrecision.FP16, verbose_log=False, timing_cache_prefix='', save_timing_cache=False, cuda_graph_batch_size=- 1, dynamic_batch=True, is_aten=False, use_experimental_fx_rt=False, correctness_atol=0.1, correctness_rtol=0.1) Module[源代码]

接收原始模块、输入和降级设置,运行降级工作流将模块转换为降级模块,即所谓的 TRTModule。

参数
  • module – 用于降级的原始模块。

  • input – 模块的输入。

  • max_batch_size – 最大批处理大小(必须 >= 1 才能设置,0 表示未设置)

  • min_acc_module_size – 加速子模块的最小节点数

  • max_workspace_size – 提供给 TensorRT 的最大工作空间大小。

  • explicit_batch_dimension – 如果设置为 True,则在 TensorRT 中使用显式批处理维度,否则使用隐式批处理维度。

  • lower_precision – 提供给 TRTModule 的 lower_precision 配置。

  • verbose_log – 如果设置为 True,则为 TensorRT 启用详细日志。

  • timing_cache_prefix – fx2trt 使用的计时缓存的计时缓存文件名。

  • save_timing_cache – 如果设置为 True,则使用当前计时缓存数据更新计时缓存。

  • cuda_graph_batch_size – Cuda 图批处理大小,默认为 -1。

  • dynamic_batch – 批处理维度 (dim=0) 是动态的。

  • use_experimental_fx_rt – 使用支持 Python 和 TorchScript 执行(包括在 C++ 中)的下一代 TRTModule。

返回

由 TensorRT 降级的 torch.nn.Module。

class torch_tensorrt.fx.TRTModule(engine=None, input_names=None, output_names=None, cuda_graph_batch_size=- 1)[源代码]
class torch_tensorrt.fx.InputTensorSpec(shape: Sequence[int], dtype: dtype, device: device = device(type='cpu'), shape_ranges: List[Tuple[Sequence[int], Sequence[int], Sequence[int]]] = [], has_batch_dim: bool = True)[源代码]

此类包含输入张量的信息。

shape: 张量的形状。

dtype: 张量的数据类型。

device: 张量的设备。这仅用于为给定模型生成输入

以便运行形状传播。对于 TensorRT 引擎,输入必须在 cuda 设备上。

shape_ranges: 如果需要动态形状(形状维度为-1),则必须提供此字段

(默认为空列表)。每个 shape_range 是一个包含三个元组的元组((最小输入形状),(优化输入形状),(最大输入形状))。每个 shape_range 用于填充一个 TensorRT 优化配置文件。例如,如果输入形状从 (1, 224) 变化到 (100, 224),并且我们希望针对 (25, 224) 进行优化,因为它是最常见的输入形状,那么我们将 shape_ranges 设置为 ((1, 224), (25, 225), (100, 224))。

has_batch_dim: 形状是否包含批处理维度。必须提供批处理维度

如果引擎希望以动态形状运行。

class torch_tensorrt.fx.TRTInterpreter(module: GraphModule, input_specs: List[InputTensorSpec], explicit_batch_dimension: bool = False, explicit_precision: bool = False, logger_level=None)[源代码]
class torch_tensorrt.fx.TRTInterpreterResult(engine, input_names, output_names, serialized_cache)[源代码]

文档

访问全面的 PyTorch 开发者文档

查看文档

教程

为初学者和高级开发者提供深入的教程

查看教程

资源

查找开发资源并让您的问题得到解答

查看资源