已关闭
[Requirement|需求建议]: 对齐新生态算子开源精度标准,补全test实现 #312
Riki创建于 7月15日关闭于 7月16日
7月15日 添加了label:requirement
7月15日 将 Twoliges 设为负责人
7月15日 修改了issue 的描述
7月15日 关联了pull request:feat(test):新增混合容差方案实现
7月16日 关联了pull request:feat(frame): 加入混合容差精度测试
7月16日 issue状态由 进行中 改变为 已完成
7月16日 关闭了 issue
Backgroud(背景信息)
生态算子开源精度标准已发布新版,对浮点计算类算子的精度验证方法从原有的 MERE/MARE 统计方案,切换为逐元素混合容差 + 通过率 + 绝对误差硬上限方案:
|actual - golden| ≤ atol + rtol × |golden|matched_ratio ≥ required_matched_ratio且max_abs_error ≤ max_abs_error_limitmax_abs_error_limit = max(fixed_value, 32 × ULP)当前
test/frame/verify.h仍以MERE_MARE为主流策略,需要新增一套MIXED_TOLERANCE策略来落地新标准。Origin(信息来源)
CANN生态开发者
Benefit / Necessity (价值/作用)
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)作为maxAbsErrorLimitcfg.mode = PrecisionMode::MIXED_TOLERANCE及mixedRequiredMatchedRatio = 0.99ULP 计算
getUlpsAt(magnitude, mantissaBits):2^(floor(log2|x|) - mantissaBits)兼容性策略:
AbsStrategy/RelStrategy/CombinedStrategy/MereMareStrategy/ExactStrategy/IntegerStrategy)保持原样getMereThreshold/getMareMultiplier保留cfg.mode = PrecisionMode::MERE_MARE的不受影响