当前Pull Request已关闭, 关闭人@黄小猛
Thanks for your pull-request.
The full list of commands accepted by me can be found at here。
You can get sig-info at here
PR Approval Progress
⚠️ This PR does not yet meet the following requirements:lgtm (requires ≥ 2 person(s) per module)、approve (requires ≥ 1 person(s) per module)
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| test | ❌ (0/2)(You can also ask: zqwenn, wangmin0104, 王朝, zichun_ye, chengpeng25) | ❌ (0/1)(You can also ask: htchu, XDaoHong, crazyDannyBoy, shaoyf, adrian07110) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Guide
@hxm_ , thanks for your pull request.
The following commit(s) have not signed Contributor License Agreement (CLA).
| Commit | Reason |
|---|---|
| 275bf249 format code | the email is not signed for CLA! please check if it is correct and the same as your signed email. |
| 188f3d86 Revert "format code" This rever... | the email is not signed for CLA! please check if it is correct and the same as your signed email. |
If you need to sign CLA, you can click here to sign the CLA.
If you need to check if the email is set up correctly, you can click here to do it in the FAQs.
After signing the CLA or updating the email, you must comment /check-cla to check the CLA status again.


当前仓库存在以下 保护分支 :
| Protected Branch | Version | Release |
|---|---|---|
| master | ||
| v2.11.0 | ||
| v2.10.0 | ||
| v2.9.0 | ||
| v2.7.1 | ||
| v2.8.0 |
评论 /sync <branch1> <branch2> ... 可将当前 PR 修改同步到其它分支(创建同步 PR):
a) 如果当前 PR 是 Open 状态,同步操作将延迟到 PR 被合并时执行
b) 如果当前 PR 已经 Merged,将立即执行同步操作
注意:
- /sync 命令可以指定同步到多个分支,仅最后一个 /sync 命令生效
- 如果创建的同步 PR 不正确,可通过向同步 PR 的源分支提交轻量级 PR 完善,或使用 /close 命令关闭


✅ 跳过 docs ci 检查,没有需要检查的文档文件


| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | Build_X86 | ✅ | >>> |
| Build_ARM | ✅ | >>> | |
| Build_LibTorch_x86 | ✅ | >>> | |
| Build_LibTorch_ARM | ✅ | >>> | |
| Build_X86_torchair | 🛑 | >>> | |
| Build_ARM_torchair | 🛑 | >>> | |
| patch_test | 🛑 | >>> | |
| 恶意代码检查 | Antipoison | ✅ | >>> |
| 编码安全与规范检查 | CodeCheck | ✅ | >>> |
| check_error | ✅ | >>> | |
| CodeCheck_lintrunner | ✅ | >>> | |
| 开源片段检查 | SCA | ✅ | >>> |
| 开发者测试 | UT_X86_Part_01 | 🛑 | >>> |
| UT_X86_Part_02 | 🛑 | >>> | |
| UT_ARM_A3_Part_01 | 🛑 | >>> | |
| UT_ARM_A3_Part_02 | 🛑 | >>> | |
| UT_DIST_X86_Part_01 | 🛑 | >>> | |
| UT_DIST_X86_Part_02 | 🛑 | >>> | |
| UT_DIST_X86_Part_03 | 🛑 | >>> | |
| UT_DIST_X86_Part_04 | 🛑 | >>> | |
| UT_inductor_Part_01 | 🛑 | >>> | |
| UT_inductor_Part_02 | 🛑 | >>> | |
| UT_inductor_Part_03 | 🛑 | >>> | |
| UT_inductor_Part_04 | 🛑 | >>> | |
| UT_ARM_A2_Part_01 | ✅ | >>> | |
| UT_ARM_A2_Part_02 | ✅ | >>> | |
| UT_ARM_A2_Part_03 | ✅ | >>> | |
| 流水线 | PR-pipeline_pytorch | ✅ | >>> |


【合入来源】
【修改方案】
背景说明
通过
torch.jit.script()创建的模型是RecursiveScriptModule实例,与测试目的不符,所以本次测试模型均通过继承torch.jit.ScriptModule创建。torch.jit.ScriptModule继承自torch.nn.Module,在__init__执行完毕后通过init_then_script将模块编译为 TorchScript,内部持有_actual_script_module(RecursiveScriptModule实例)作为 C++ 侧代理。编译过程只迁移参数/子模块/缓冲区的存储,不替换类上的方法,也不影响 hook 相关属性(_backward_hooks、_backward_pre_hooks等),因此大部分 hook API 在 ScriptModule 子类上行为与普通 Module 一致。register_full_backward_hook例外的原因:该方法内部会设置self._is_full_backward_hook = True,该属性赋值被ScriptModule.__setattr__代理到 C++ 侧后,因类型不匹配(C++ 侧期望 NoneType)导致 RuntimeError。这是pytorch自身的bug。API 功能说明
register_full_backward_hook(hook, prepend=False) -> RemovableHandle
在模块上注册反向传播后置 hook。hook 签名为
hook(module, grad_input, grad_output) -> tuple[Tensor] or None,在模块梯度计算完成时被调用,可返回新的 grad_input 替代原有值。prepend=True 时 hook 在已有 hook 之前执行。返回 RemovableHandle 用于移除 hook。register_full_backward_pre_hook(hook, prepend=False) -> RemovableHandle
在模块上注册反向传播前置 hook。hook 签名为
hook(module, grad_output) -> tuple[Tensor] or None,在模块梯度计算之前被调用,可返回新的 grad_output 影响后续梯度计算。prepend=True 时 hook 在已有 hook 之前执行。返回 RemovableHandle 用于移除 hook。register_load_state_dict_pre_hook(hook) -> RemovableHandle
在 load_state_dict 调用前触发 hook。hook 签名为
hook(module, state_dict, prefix, local_metadata, strict, missing_keys, unexpected_keys, error_msgs) -> None,可用于在加载前对 state_dict 进行预处理。返回 RemovableHandle 用于移除 hook。register_load_state_dict_post_hook(hook) -> RemovableHandle
在 load_state_dict 调用后触发 hook。hook 签名为
hook(module, incompatible_keys) -> None,incompatible_keys 包含 missing_keys 和 unexpected_keys,可原地修改。返回 RemovableHandle 用于移除 hook。register_state_dict_pre_hook(hook) -> RemovableHandle
在 state_dict 调用前触发 hook。hook 签名为
hook(module, prefix, keep_vars) -> None,可用于在序列化前执行预处理。返回 RemovableHandle 用于移除 hook。register_state_dict_post_hook(hook) -> RemovableHandle
在 state_dict 调用后触发 hook。hook 签名为
hook(module, state_dict, prefix, local_metadata) -> None,可原地修改 state_dict。返回 RemovableHandle 用于移除 hook。测试用例说明
register_full_backward_hook
register_full_backward_pre_hook
register_load_state_dict_pre_hook & register_load_state_dict_post_hook
register_state_dict_pre_hook & register_state_dict_post_hook
【资料变更】
不涉及
【接口变更】
不涉及
【功能验证】
register_full_backward_hookregister_full_backward_pre_hookregister_load_state_dict_pre_hookregister_load_state_dict_post_hookregister_state_dict_pre_hookregister_state_dict_post_hook测试日志
【CheckList】