已关闭
[Requirement|需求建议]: 对齐新生态算子开源精度标准,补全test实现 #312
Riki创建于  7月15日关闭于  7月16日
Riki
Riki成员
7月15日 创建

Backgroud(背景信息)

生态算子开源精度标准已发布新版,对浮点计算类算子的精度验证方法从原有的 MERE/MARE 统计方案,切换为逐元素混合容差 + 通过率 + 绝对误差硬上限方案:

  • 每元素通过条件:|actual - golden| ≤ atol + rtol × |golden|
  • 整体通过条件:matched_ratio ≥ required_matched_ratio 且 max_abs_error ≤ max_abs_error_limit
  • max_abs_error_limit = max(fixed_value, 32 × ULP)

当前 test/frame/verify.h 仍以 MERE_MARE 为主流策略,需要新增一套 MIXED_TOLERANCE 策略来落地新标准。

Origin(信息来源)

CANN生态开发者

Benefit / Necessity (价值/作用)

  • 对齐开源精度评审标准,避免在开源社区精度审查时被退回
  • 逐元素混合容差 + 99% 通过率 + max_abs_error 硬上限,比 MERE/MARE 的"平均值 + 最大相对误差 × 倍数"更具可解释性
  • applyMixedTolerance(cfg, dtype, golden, count) 一行完成阈值填充,调用方无需关心 mantissa bits / ULP 等细节
  • 旧策略保留向后兼容,存量用例不受影响

Design(设计方案)

**核心类 MixedToleranceStrategy:

void processElement(float outVal, float goldVal) override
{
    // 特殊值不匹配 → fail, 不进公式 (避免 UB)
    if (std::isnan(outVal) || std::isnan(goldVal) || std::isinf(outVal) || std::isinf(goldVal)) {
        maxAbsErrorFailed_ = true;
        failCount_++;
        return;
    }
    double diff = std::abs(static_cast<double>(outVal) - static_cast<double>(goldVal));
    if (diff > maxAbsError_) maxAbsError_ = diff;
    double limit = absTol_ + relTol_ * std::abs(static_cast<double>(goldVal));
    if (diff > limit) failCount_++;
}

bool reportResult(...)
{
    matchedRatio = (count - failCount) / count;
    pass = (matchedRatio >= requiredMatchedRatio) && !maxAbsErrorFailed && (maxAbsError <= maxAbsErrorLimit);
}

统一阈值填充入口 applyMixedTolerance(cfg, aclDataType, goldenPtr, count):

  • 内部调用 getMixedToleranceDefaults(dtype) 取 rtol/atol/fixed 三元组
  • 内部调用 computeMaxAbsErrorLimit(fixed, golden, count, getMantissaBits(dtype)) 按 golden 数组最大有限值算 32·ULP,再 max(fixed, 32·ULP) 作为 maxAbsErrorLimit
  • 自动设置 cfg.mode = PrecisionMode::MIXED_TOLERANCE 及 mixedRequiredMatchedRatio = 0.99

ULP 计算 getUlpsAt(magnitude, mantissaBits):

  • 一般公式:2^(floor(log2|x|) - mantissaBits)
  • x = 0 时退化为次正规数 ULP

兼容性策略:

  • 旧策略类(AbsStrategy / RelStrategy / CombinedStrategy / MereMareStrategy / ExactStrategy / IntegerStrategy)保持原样
  • 旧辅助函数 getMereThreshold / getMareMultiplier 保留
  • 旧调用方显式写 cfg.mode = PrecisionMode::MERE_MARE 的不受影响
  • 未显式设置 mode 的旧测试因默认值变化,将自动走新模式(需 review)
likedislike
RikiRiki成员
7月15日 添加了label:requirement
RikiRiki成员
7月15日 将 Twoliges 设为负责人
RikiRiki成员
7月15日 修改了issue 的描述
RikiRiki成员
7月15日 关联了pull request:feat(test):新增混合容差方案实现
RikiRiki成员
7月16日 关联了pull request:feat(frame): 加入混合容差精度测试
wangzitaowangzitao成员
7月16日 issue状态由 进行中 改变为 已完成
wangzitaowangzitao成员
7月16日 关闭了 issue