Pull Request已成功合入, 合并人@CANN-robot
(感谢 zhangqijia1 的贡献)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
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| math/log_add_exp | ✅ 唐燕峰, 冯彤 (2/2) | ✅ 唐燕峰 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)


compile


流水线任务触发成功
任务链接 [29f6369d007f418689abc658ac1e743f][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| pre_comment | ✅ SUCCESS | >>>>> | |
| Compile_harmony-infer | ✅ SUCCESS | >>>>> | |
| Compile_X86_monitor_910b | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910c | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_harmony-infer-chs-math | ✅ SUCCESS | >>>>> | |
| UT_Test | ✅ SUCCESS | ||
| UT_Test_experimental | ✅ SUCCESS | ||
| UT_Test_kernel | ✅ SUCCESS | ||
| PreSmoke_A900 | ✅ SUCCESS | >>>>> | |
| PreSmoke_ATK_Test_A2 | ✅ SUCCESS | >>>>> |
[2026-06-29 20:46:19] CI执行结束


流水线任务触发成功
任务链接 [d0ee3f5f3d3f41239bf5c8890dfeb445][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| codecheck | ✅ SUCCESS | >>>>> | |
| SCA | ✅ SUCCESS | >>>>> | |
| antipoison | ✅ SUCCESS | >>>>> | |
| codecheck_Pr | ✅ SUCCESS | ||
| StaticCheck_codespell_check | ✅ SUCCESS | ||
| StaticCheck_link_validity_check | ✅ SUCCESS | ||
| StaticCheck_resource_existence_check | ✅ SUCCESS | ||
| StaticCheck_tag_closed_check | ✅ SUCCESS | ||
| StaticCheck_markdownlint | ✅ SUCCESS | ||
| codecheck_codestyle | ✅ SUCCESS | >>>>> | |
| codecheck_precommit | ⚠️ WARNING | >>>>> | >>>>> |
[2026-06-29 20:41:03] CI执行结束


/lgtm
/approve


变更摘要
此 PR 主要解决 log_add_exp 算子在输入值域较小时因 1+exp(x) 舍入为 1 导致 log(1+exp(x)) 计算结果精度丢失的问题。在 API 层增加了对 RegBase 场景下的 format 严格校验,并将原有 format 警告逻辑重构为独立函数;在 Kernel 层引入了 StableLog1p 模板结构,通过数值稳定的 log1p 实现替代原先直接 Adds + Log 的组合,避免小值域下的精度误差。
主要改动
-
新增
StableLog1p模板结构:在log_add_exp_dag.h中引入StableLog1p<CT, In>,当1+x因舍入等于 1 时通过x * log(1+x) / ((1+x)-1)的公式修正,并正确处理无穷大边界情况;所有计算结构(LogAddExpSimplifiedCompute、LogAddExpSimplifiedWithCastCompute、LogAddExpFullCompute、LogAddExpFullWithCastCompute)的OpLog均替换为StableLog1p的输出。 -
新增
CMP_NE_MODE常量:在 Kernel 层添加CMP_NE_MODE = 5(对应AscendC::CMPMODE::NE),供StableLog1p中的不等于比较使用。 -
API 层
CheckFormat重构与新增:原有CheckFormat仅做 ND format 警告,现将其重命名为WarnFormat;同时新增一个严格版本CheckFormat,校验 self/other 与 out 的 format 一致性并拒绝私有 format,仅在IsRegBase()为 true 时调用并触发错误返回。 -
CheckParams中条件分支:在CheckParams末尾增加IsRegBase()判断,RegBase 场景下调用严格的CheckFormat校验;非 RegBase 场景则在aclnnLogAddExpGetWorkspaceSize中调用WarnFormat仅输出警告。


描述
使用数值稳定性公式来解决小值域下精度误差问题,对私有格式进行拦截
关联的Issue
#2084
测试
文档更新
类型标签