Thanks for sending an issue! Please fill in the following template to help quickly solve your problem.
BNLL 在计算 log(1 + exp(-abs(x))) 时,原实现直接使用 Adds(1, e) + Ln。当 e 较小时,1 + e 的 float32 舍入会损失 有效位,并放大最终输出误差。
log(1 + exp(-abs(x)))
Adds(1, e) + Ln
e
1 + e
Adds(1, exp(-abs(x))) + Ln
log1p(exp(-abs(x)))
x=-10
BNLL 在小指数值区域采用数值稳定的 log1p 计算方式,降低舍入误差, 并保持 float16、float32 全量用例通过。 原始 Adds(1, e) + Ln 实现在 x=-10 附近存在约 5170 ULP 的误差。 根因是 1 + small_e 在 float32 中发生有效位损失。
1 + small_e
Thanks for sending an issue! Please fill in the following template to help quickly solve your problem.
Describe the current behavior / 问题描述 (Mandatory / 必填)
BNLL 在计算
log(1 + exp(-abs(x)))时,原实现直接使用Adds(1, e) + Ln。当e较小时,1 + e的 float32 舍入会损失有效位,并放大最终输出误差。
Environment / 环境信息 (Mandatory / 必填)
Steps to reproduce the issue / 重现步骤 (Mandatory / 必填)
Adds(1, exp(-abs(x))) + Ln与高精度log1p(exp(-abs(x)))的输出。x=-10等小指数值区域的输出误差。Describe the expected behavior / 预期结果 (Mandatory / 必填)
BNLL 在小指数值区域采用数值稳定的 log1p 计算方式,降低舍入误差,
并保持 float16、float32 全量用例通过。
原始
Adds(1, e) + Ln实现在x=-10附近存在约 5170 ULP 的误差。根因是
1 + small_e在 float32 中发生有效位损失。Related log / screenshot / 日志 / 截图 (Mandatory / 必填)
Special notes for this issue/备注 (Optional / 选填)