评价此页

torch.compiler API 参考#

创建于: 2023 年 6 月 02 日 | 最后更新于: 2025 年 6 月 22 日

有关 torch.compiler 的快速概述,请参阅 torch.compiler

compile

有关此函数的参数的详细信息,请参阅 torch.compile()

reset

此函数清除所有编译缓存,并将系统恢复到初始状态。

allow_in_graph

指示编译器前端(Dynamo)跳过对函数的符号自省,而是在遇到函数时直接将其写入图。

substitute_in_graph

为某个函数(通常是 C 扩展中的 C 函数)注册一个 polyfill 处理程序,在将原始函数内联到图中时用于替换原始函数。

assume_constant_result

此函数用于标记一个函数 fn 具有常量结果。

list_backends

返回可传递给 torch.compile(..., backend="name") 的有效字符串。

disable

此函数提供了一个装饰器,用于禁用函数上的编译。

set_stance

设置编译器的当前姿态(stance)。

set_enable_guard_collectives

在 guard 评估 *期间* 启用 collectives 的使用,以跨进程同步行为。

cudagraph_mark_step_begin

指示推理或训练的新迭代即将开始。

is_compiling

指示图是否作为 torch.compile() 或 torch.export() 的一部分执行/跟踪。

is_dynamo_compiling

指示图是否通过 TorchDynamo 进行了追踪。

is_exporting

指示当前是否处于导出状态。

skip_guard_on_inbuilt_nn_modules_unsafe

一个通用函数,用于跳过对内置 nn 模块(如 torch.nn.Linear)的 guard。

skip_guard_on_all_nn_modules_unsafe

一个通用函数,用于跳过对所有 nn 模块的 guard,包括用户定义的和内置的 nn 模块(如 torch.nn.Linear)。

keep_tensor_guards_unsafe

一个通用函数,用于保留对所有张量的 tensor guard。

skip_guard_on_globals_unsafe

一个通用函数,用于跳过对所有全局变量的 guard。

nested_compile_region

指示 ``torch.compile`` 标记的操作集合构成一个嵌套编译区域(通常在完整模型中重复出现),其代码可以编译一次并安全重用。