Merged
[Atanh] 修复原地 Golden 输入污染并兼容 TF 输入 #7021
[Atanh] 修复原地 Golden 输入污染并兼容 TF 输入 #7021
Merged
陈展熹Add on 12 days ago
Total: 1 files changed+30-4
@@ -19,9 +19,10 @@ Kernel/GEIR Enable 使用原生 output_dtypes;直接调用无元信息时按 x
19推导(Atanh 的 y.dtype == x.dtype),在 BF16 容器转换之前保存目标 dtype。19推导(Atanh 的 y.dtype == x.dtype),在 BF16 容器转换之前保存目标 dtype。
20Kernel/GEIR 输出类型仅支持 FP16、BF16、FP32。20Kernel/GEIR 输出类型仅支持 FP16、BF16、FP32。
21Promote 会改写原生 output_dtypes,不能用其冒充实际输出;完整回归沿用 Enable。21Promote 会改写原生 output_dtypes,不能用其冒充实际输出;完整回归沿用 Enable。
22-ACLNN 使用 out.dtype 或 inputRef.dtype,cast 后再写回并返回。22+普通 ACLNN 通路按 out.dtype cast 后写回;原地接口 Golden 按 inputRef.dtype 返回独立结果。
23BF16 在 Torch 中完成 cast,NumPy 仅按位承载同一 BF16 结果。23BF16 在 Torch 中完成 cast,NumPy 仅按位承载同一 BF16 结果。
24-provider third_party 保持原样;此修正不依赖该 provider 启用。24+Kernel/GEIR third_party 保持原样;ACLNN 原地通路在副本上执行 torch.atanh_ 参考。
25+TF E2E 使用 tf.math.atanh,输入先转换为 NumPy,输出保持输入 dtype 和 shape。
25"""26"""
26 27 
27import numpy as np28import numpy as np
@@ -31,6 +32,7 @@ __spec__ = {
31 "atanh": "AtanhTestSpec",32 "atanh": "AtanhTestSpec",
32 "aclnnAtanh": "AclnnAtanhTestSpec",33 "aclnnAtanh": "AclnnAtanhTestSpec",
33 "aclnnInplaceAtanh": "AclnnInplaceAtanhTestSpec",34 "aclnnInplaceAtanh": "AclnnInplaceAtanhTestSpec",
35+ "tf.math.atanh": "TensorFlowAtanhTestSpec",
34}36}
35 37 
36 38 
@@ -111,9 +113,33 @@ class AclnnAtanhTestSpec:
111 113 
112 114 
113class AclnnInplaceAtanhTestSpec:115class AclnnInplaceAtanhTestSpec:
114- """按原始 inputRef dtype 完整 cast,再执行原地写回。"""116+ """CPU 数值参考:按 inputRef dtype 返回独立结果,保留调用方输入。"""
115 117 
116 def golden(inputRef, **kwargs):118 def golden(inputRef, **kwargs):
119+ if not (inputRef.is_floating_point() or inputRef.is_complex()):
120+ raise TypeError(
121+ "aclnnInplaceAtanh requires a floating-point or complex inputRef"
122+ )
117 result = _atanh_reference(inputRef).to(dtype=inputRef.dtype)123 result = _atanh_reference(inputRef).to(dtype=inputRef.dtype)
118- inputRef.copy_(result)
119 return [result]124 return [result]
125+ 
126+ class ThirdPartyImpl:
127+ def __call__(self, inputRef, **kwargs):
128+ # 在副本上原地计算,避免重复参考调用污染调用方输入。
129+ return [inputRef.clone().atanh_()]
130+ 
131+ third_party = {"torch": ThirdPartyImpl}
132+ 
133+ 
134+class TensorFlowAtanhTestSpec:
135+ """TF EagerTensor/Variable 的独立数值参考,支持标量和空张量。"""
136+ 
137+ def golden(x, **kwargs):
138+ from ttk.utilities.dtypes import numpy_to_torch_tensor
139+ 
140+ array = np.asarray(x.numpy()) if hasattr(x, "numpy") else np.asarray(x)
141+ tensor = numpy_to_torch_tensor(np.array(array, copy=True, order="C"))
142+ result = _atanh_reference(tensor).to(dtype=tensor.dtype)
143+ return [_numpy_result(result)]
144+ 
145+ third_party = {"tf": "tf.math.atanh"}