已合并
fix: align multinomial sampling with normalized probabilities #4500
fix: align multinomial sampling with normalized probabilities #4500
已合并
fenglin28创建于 8月7日
fenglin28成员
8月7日

描述

修复 StatelessSampleMultinomial 边界场景下的采样行为:

  • 在二分查找前检查 CDF 最后一项是否大于 0
  • 新增可选输入 norm_probs,用于准确判断零概率类别
  • norm_probs 存在时,使用 x 执行二分查找,使用 norm_probs 处理零概率类别回退;缺省时保留基于相邻 CDF 值的兼容路径
  • 增加 x 的维度校验,以及 x 与 norm_probs 的形状一致性校验
  • 同步更新算子定义、L0 接口、tiling、kernel 配置、UT 和 README

关联的Issue

https://gitcode.com/cann/ops-math/issues/2558

测试

完整通过 UT、泛化 ST 及流水线验证

文档更新

更新 README 中 x 和 norm_probs 的输入及约束说明

类型标签

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 fenglin28 的贡献)
Ffenglin28成员
8月7日 创建了 pull request,commit 1a781a1c
atomgit-bot
atomgit-bot
8月7日 评论:

变更摘要

此PR在 stateless_sample_multinomial_impl.h 的 SimtUniform 内核函数中新增了对多项分布累积概率的校验逻辑,通过引入 asc_assert.h 并添加 assert 断言,确保在二分查找之前累积分布数组的最后一个元素(即总累积概率)大于零,防止无效分布数据导致未定义行为。

主要改动

  • 新增 asc_assert.h 头文件引入:在 stateless_sample_multinomial_impl.h 中添加了 #include "utils/debug/asc_assert.h",为后续断言提供 assert 宏支持。
  • 新增累积分布有效性断言:在 SimtUniform 函数的二分查找循环之前,添加了 assert(x[numCat - 1] > static_cast<XT>(0)),用于在运行时校验多项分布的累积分布数组末尾元素大于零,确保分布数据合法。
likedislike
不准确?
atomgit-bot
atomgit-bot
8月7日 评论:

代码审查

✅ 未发现问题

likedislike
不准确?
CANN-robotCANN-robot成员
8月7日 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
8月7日 评论:

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.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.


PR Approval Progress

✅ Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
*/*/README.md ✅ 蔡雯雯, 顾宝成, 王瑞 (3/2) ✅ 蔡雯雯 (1/1)
*/*/docs/acl*.md ✅ 蔡雯雯, 王瑞, 顾宝成 (3/2) ✅ 蔡雯雯 (1/1)
*/*/op_api/*.h ✅ 汤磊, 顾宝成, 王瑞 (3/2) ✅ 汤磊 (1/1)
*/*/op_host/*_def.cpp ✅ 汤磊, 王瑞, 顾宝成 (3/2) ✅ 汤磊 (1/1)
repo-cann/ops-math ✅ 王瑞, 顾宝成 (2/2) ✅ 王瑞 (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

fenglin28, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
此处折叠了266条消息 查看更多
tang-lei01成员
8月26日 评论:

/approve

likedislike
CANN-robot
CANN-robot成员
8月26日 评论:

The following users do not have permission to comment /lgtm or /approve on any module in this PR:
zhouwenfang

likedislike
CANN-robotCANN-robot成员
8月26日 添加了label:approved
CANN-robotCANN-robot成员
8月26日 关闭了关联的issue
CANN-robotCANN-robot成员
8月26日 合入了pull request