评价此页

torch.utils#

创建日期: 2023年7月21日 | 最后更新日期: 2025年12月5日

rename_privateuse1_backend

重命名 privateuse1 后端设备,使其在 PyTorch API 中作为设备名称更方便使用。

generate_methods_for_privateuse1_backend

在重命名 privateuse1 后端后,自动为自定义后端生成属性和方法。

get_cpp_backtrace

返回一个包含当前线程 C++ 调用堆栈的字符串。

set_module

为给定对象设置 python 对象的 module 属性,以便更方便地打印。

swap_tensors

此函数交换两个 Tensor 对象的内容。

torch.utils.collect_env#

torch.utils.flop_counter#

baddbmm_flop

计算 baddbmm 操作的浮点运算次数。

bmm_flop

计算 bmm 操作的浮点运算次数。

conv_backward_flop

conv_flop

计算卷积的浮点运算次数。

conv_flop_count

计算卷积的浮点运算次数。

register_flop_formula

sdpa_backward_flop

计算自注意力后向传播的浮点运算次数。

sdpa_backward_flop_count

sdpa_flop

计算自注意力的浮点运算次数。

sdpa_flop_count

计算自注意力的浮点运算次数。

shape_wrapper

torch.utils.hipify.hipify_python#

Python Hipify 脚本。 ## # Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved. # 2017-2018 Advanced Micro Devices, Inc. and # Facebook Inc. All rights reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the “Software”), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE。

compute_stats

extract_arguments

返回即将到来的函数参数闭包中的参数列表。

file_add_header

file_specific_replacement

find_bracket_group

查找第一个平衡的括号。

find_closure_group

查找平衡闭包组的通用方法

find_parentheses_group

查找第一个平衡的方括号。

fix_static_global_kernels

HIP 中的静态全局内核会导致编译错误。

hip_header_magic

如果文件进行了内核内置函数调用但未包含 cuda_runtime.h 头文件,则会自动添加一个 #include 以匹配 NVCC 提供的“magic” include。

hipify

is_caffe2_gpu_file

is_cusparse_file

is_out_of_place

is_pytorch_file

is_special_file

openf

preprocess_file_and_save_result

preprocessor

对指定文件执行 CUDA -> HIP 转换。

processKernelLaunches

将 CUDA 风格的内核启动替换为 HIP 风格的内核启动。

replace_extern_shared

匹配 'extern __shared__ type foo[];' 语法,并使用 HIP_DYNAMIC_SHARED() MACRO 代替。

replace_math_functions

FIXME: 暂时替换 std:: 对数学函数的调用为非 std:: 版本,以防止链接器错误。注意:这可能会导致运行测试时出现正确性问题,因为可能不会调用正确的数学函数版本(exp/expf)。

str2bool

ArgumentParser 不支持 type=bool。