快捷方式

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[source]

接收原始模块、输入和优化设置,运行优化工作流以将模块转换为优化后的模块,或称为 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 – 使用下一代 TRTModule,它同时支持 Python 和 TorchScript 基于的执行(包括在 C++ 中)。

返回

一个由 TensorRT 优化的 torch.nn.Module。

class torch_tensorrt.fx.TRTModule(engine=None, input_names=None, output_names=None, cuda_graph_batch_size=- 1)[source]
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)[source]

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

shape: 张量的形状。

dtype: 张量的数据类型。

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

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

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

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

has_batch_dim: 形状是否包含批处理维度。如果引擎希望使用动态形状运行,则必须提供批处理维度。

if the engine want to run with dynamic shape.

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

文档

访问全面的 PyTorch 开发者文档

查看文档

教程

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

查看教程

资源

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

查看资源