已合并
Added foreach op erf erfc exp expm1 floor frac log log1p log10 mullist mulscalarlist compatibility processing &&Modified ut #1800
tramp-ll创建于 2024年8月21日
Added foreach op erf erfc exp expm1 floor frac log log1p log10 mullist mulscalarlist compatibility processing &&Modified ut #1800
已合并
tramp-ll创建于 2024年8月21日
refs/pull/1800/head合入到master
39 个文件变更+729-216
@@ -14,6 +14,7 @@
14#include <ATen/native/ForeachUtils.h>14#include <ATen/native/ForeachUtils.h>
15#include "op_plugin/OpApiInterface.h"15#include "op_plugin/OpApiInterface.h"
16#include "op_plugin/utils/op_api_common.h"16#include "op_plugin/utils/op_api_common.h"
17+#include "torch_npu/csrc/framework/utils/UtilForOpAdapter.h"
17 18 
18namespace op_api {19namespace op_api {
19using npu_preparation = at_npu::native::OpPreparation;20using npu_preparation = at_npu::native::OpPreparation;
@@ -43,6 +44,14 @@ void _split_and_exec_npu_cmd_erf(at::TensorList tensors1, at::TensorList result_
43 44 
44void _foreach_erf_(const at::TensorList self)45void _foreach_erf_(const at::TensorList self)
45{46{
47+ DO_COMPATIBILITY(aclnnForeachErf, at::native::foreach_tensor_erf_slow_(self));
48+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
49+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
50+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
51+ if (!is_support_nd_out) {
52+ return at::native::foreach_tensor_erf_slow_(self);
53+ }
54+ 
46 at::native::check_foreach_api_restrictions(self);55 at::native::check_foreach_api_restrictions(self);
47 if (!at::native::can_use_fast_route(self) || at::native::has_integral_tensor(self, true)) {56 if (!at::native::can_use_fast_route(self) || at::native::has_integral_tensor(self, true)) {
48 return at::native::foreach_tensor_erf_slow_(self);57 return at::native::foreach_tensor_erf_slow_(self);
@@ -53,6 +62,14 @@ void _foreach_erf_(const at::TensorList self)
53 62 
54std::vector<at::Tensor> _foreach_erf(const at::TensorList self)63std::vector<at::Tensor> _foreach_erf(const at::TensorList self)
55{64{
65+ DO_COMPATIBILITY(aclnnForeachErf, at::native::foreach_tensor_erf_slow(self));
66+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
67+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
68+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
69+ if (!is_support_nd_out) {
70+ return at::native::foreach_tensor_erf_slow(self);
71+ }
72+
56 at::native::check_foreach_api_restrictions(self);73 at::native::check_foreach_api_restrictions(self);
57 if (!at::native::can_use_fast_route(self) || at::native::has_integral_tensor(self, true)) {74 if (!at::native::can_use_fast_route(self) || at::native::has_integral_tensor(self, true)) {
58 return at::native::foreach_tensor_erf_slow(self);75 return at::native::foreach_tensor_erf_slow(self);
@@ -14,6 +14,7 @@
14#include <ATen/native/ForeachUtils.h>14#include <ATen/native/ForeachUtils.h>
15#include "op_plugin/OpApiInterface.h"15#include "op_plugin/OpApiInterface.h"
16#include "op_plugin/utils/op_api_common.h"16#include "op_plugin/utils/op_api_common.h"
17+#include "torch_npu/csrc/framework/utils/UtilForOpAdapter.h"
17 18 
18namespace op_api {19namespace op_api {
19using npu_preparation = at_npu::native::OpPreparation;20using npu_preparation = at_npu::native::OpPreparation;
@@ -44,6 +45,14 @@ void _split_and_exec_npu_cmd_erfc(at::TensorList tensors1, at::TensorList result
44 45 
45void _foreach_erfc_(const at::TensorList self)46void _foreach_erfc_(const at::TensorList self)
46{47{
48+ DO_COMPATIBILITY(aclnnForeachErfc, at::native::foreach_tensor_erfc_slow_(self));
49+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
50+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
51+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
52+ if (!is_support_nd_out) {
53+ return at::native::foreach_tensor_erfc_slow_(self);
54+ }
55+ 
47 at::native::check_foreach_api_restrictions(self);56 at::native::check_foreach_api_restrictions(self);
48 if (!at::native::can_use_fast_route(self) || at::native::has_integral_tensor(self, true)) {57 if (!at::native::can_use_fast_route(self) || at::native::has_integral_tensor(self, true)) {
49 return at::native::foreach_tensor_erfc_slow_(self);58 return at::native::foreach_tensor_erfc_slow_(self);
@@ -54,6 +63,14 @@ void _foreach_erfc_(const at::TensorList self)
54 63 
55std::vector<at::Tensor> _foreach_erfc(const at::TensorList self)64std::vector<at::Tensor> _foreach_erfc(const at::TensorList self)
56{65{
66+ DO_COMPATIBILITY(aclnnForeachErfc, at::native::foreach_tensor_erfc_slow(self));
67+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
68+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
69+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
70+ if (!is_support_nd_out) {
71+ return at::native::foreach_tensor_erfc_slow(self);
72+ }
73+
57 at::native::check_foreach_api_restrictions(self);74 at::native::check_foreach_api_restrictions(self);
58 if (!at::native::can_use_fast_route(self) || at::native::has_integral_tensor(self, true)) {75 if (!at::native::can_use_fast_route(self) || at::native::has_integral_tensor(self, true)) {
59 return at::native::foreach_tensor_erfc_slow(self);76 return at::native::foreach_tensor_erfc_slow(self);
@@ -15,6 +15,7 @@
15#include "op_plugin/OpApiInterface.h"15#include "op_plugin/OpApiInterface.h"
16#include "op_plugin/utils/op_api_common.h"16#include "op_plugin/utils/op_api_common.h"
17#include <ATen/native/ForeachUtils.h>17#include <ATen/native/ForeachUtils.h>
18+#include "torch_npu/csrc/framework/utils/UtilForOpAdapter.h"
18 19 
19namespace op_api {20namespace op_api {
20using npu_preparation = at_npu::native::OpPreparation;21using npu_preparation = at_npu::native::OpPreparation;
@@ -45,6 +46,14 @@ void _split_and_exec_npu_cmd_exp(const at::TensorList tensors1, at::TensorList r
45 46 
46void _foreach_exp_(const at::TensorList self)47void _foreach_exp_(const at::TensorList self)
47{48{
49+ DO_COMPATIBILITY(aclnnForeachExp, at::native::foreach_tensor_exp_slow_(self));
50+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
51+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
52+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
53+ if (!is_support_nd_out) {
54+ return at::native::foreach_tensor_exp_slow_(self);
55+ }
56+ 
48 at::native::check_foreach_api_restrictions(self);57 at::native::check_foreach_api_restrictions(self);
49 if (!at::native::can_use_fast_route(self) || at::native::has_integral_tensor(self, true)) {58 if (!at::native::can_use_fast_route(self) || at::native::has_integral_tensor(self, true)) {
50 return at::native::foreach_tensor_exp_slow_(self);59 return at::native::foreach_tensor_exp_slow_(self);
@@ -61,6 +70,14 @@ void _foreach_exp_(const at::TensorList self)
61 70 
62std::vector<at::Tensor> _foreach_exp(const at::TensorList self)71std::vector<at::Tensor> _foreach_exp(const at::TensorList self)
63{72{
73+ DO_COMPATIBILITY(aclnnForeachExp, at::native::foreach_tensor_exp_slow(self));
74+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
75+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
76+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
77+ if (!is_support_nd_out) {
78+ return at::native::foreach_tensor_exp_slow(self);
79+ }
80+
64 at::native::check_foreach_api_restrictions(self);81 at::native::check_foreach_api_restrictions(self);
65 if (!at::native::can_use_fast_route(self) || at::native::has_integral_tensor(self, true)) {82 if (!at::native::can_use_fast_route(self) || at::native::has_integral_tensor(self, true)) {
66 return at::native::foreach_tensor_exp_slow(self);83 return at::native::foreach_tensor_exp_slow(self);
@@ -15,6 +15,7 @@
15#include "op_plugin/OpApiInterface.h"15#include "op_plugin/OpApiInterface.h"
16#include "op_plugin/utils/op_api_common.h"16#include "op_plugin/utils/op_api_common.h"
17#include <ATen/native/ForeachUtils.h>17#include <ATen/native/ForeachUtils.h>
18+#include "torch_npu/csrc/framework/utils/UtilForOpAdapter.h"
18 19 
19namespace op_api {20namespace op_api {
20using npu_preparation = at_npu::native::OpPreparation;21using npu_preparation = at_npu::native::OpPreparation;
@@ -45,6 +46,14 @@ void _split_and_exec_npu_cmd_expm1(const at::TensorList tensors1, at::TensorList
45 46 
46void _foreach_expm1_(const at::TensorList self)47void _foreach_expm1_(const at::TensorList self)
47{48{
49+ DO_COMPATIBILITY(aclnnForeachExpm1, at::native::foreach_tensor_expm1_slow_(self));
50+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
51+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
52+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
53+ if (!is_support_nd_out) {
54+ return at::native::foreach_tensor_expm1_slow_(self);
55+ }
56+ 
48 at::native::check_foreach_api_restrictions(self);57 at::native::check_foreach_api_restrictions(self);
49 if (!at::native::can_use_fast_route(self) || at::native::has_integral_tensor(self, true)) {58 if (!at::native::can_use_fast_route(self) || at::native::has_integral_tensor(self, true)) {
50 return at::native::foreach_tensor_expm1_slow_(self);59 return at::native::foreach_tensor_expm1_slow_(self);
@@ -63,6 +72,14 @@ void _foreach_expm1_(const at::TensorList self)
63 72 
64std::vector<at::Tensor> _foreach_expm1(const at::TensorList self)73std::vector<at::Tensor> _foreach_expm1(const at::TensorList self)
65{74{
75+ DO_COMPATIBILITY(aclnnForeachExpm1, at::native::foreach_tensor_expm1_slow(self));
76+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
77+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
78+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
79+ if (!is_support_nd_out) {
80+ return at::native::foreach_tensor_expm1_slow(self);
81+ }
82+
66 at::native::check_foreach_api_restrictions(self);83 at::native::check_foreach_api_restrictions(self);
67 if (!at::native::can_use_fast_route(self) || at::native::has_integral_tensor(self, true)) {84 if (!at::native::can_use_fast_route(self) || at::native::has_integral_tensor(self, true)) {
68 return at::native::foreach_tensor_expm1_slow(self);85 return at::native::foreach_tensor_expm1_slow(self);
@@ -15,6 +15,7 @@
15#include <ATen/native/ForeachUtils.h>15#include <ATen/native/ForeachUtils.h>
16#include "op_plugin/OpApiInterface.h"16#include "op_plugin/OpApiInterface.h"
17#include "op_plugin/utils/op_api_common.h"17#include "op_plugin/utils/op_api_common.h"
18+#include "torch_npu/csrc/framework/utils/UtilForOpAdapter.h"
18 19 
19namespace op_api {20namespace op_api {
20 21 
@@ -70,6 +71,14 @@ std::vector<at::Tensor> exec_npu_cmd(at::TensorList tensors1, at::TensorList ten
70 71 
71void _foreach_lerp_(const at::TensorList tensors1, const at::TensorList tensors2, const at::TensorList weight)72void _foreach_lerp_(const at::TensorList tensors1, const at::TensorList tensors2, const at::TensorList weight)
72{73{
74+ DO_COMPATIBILITY(aclnnForeachLerpList, at::native::foreach_tensor_ternary_lerp_slow_(tensors1, tensors2, weight));
75+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
76+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
77+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
78+ if (!is_support_nd_out) {
79+ return at::native::foreach_tensor_ternary_lerp_slow_(tensors1, tensors2, weight);
80+ }
81+ 
73 at::native::check_foreach_api_restrictions(tensors1, tensors2, weight);82 at::native::check_foreach_api_restrictions(tensors1, tensors2, weight);
74 if (!at::native::can_use_fast_route({tensors1, tensors2, weight})) {83 if (!at::native::can_use_fast_route({tensors1, tensors2, weight})) {
75 return at::native::foreach_tensor_ternary_lerp_slow_(tensors1, tensors2, weight);84 return at::native::foreach_tensor_ternary_lerp_slow_(tensors1, tensors2, weight);
@@ -79,6 +88,14 @@ void _foreach_lerp_(const at::TensorList tensors1, const at::TensorList tensors2
79 88 
80std::vector<at::Tensor> _foreach_lerp(const at::TensorList tensors1, const at::TensorList tensors2, const at::TensorList weight)89std::vector<at::Tensor> _foreach_lerp(const at::TensorList tensors1, const at::TensorList tensors2, const at::TensorList weight)
81{90{
91+ DO_COMPATIBILITY(aclnnForeachLerpList, at::native::foreach_tensor_ternary_lerp_slow(tensors1, tensors2, weight));
92+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
93+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
94+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
95+ if (!is_support_nd_out) {
96+ return at::native::foreach_tensor_ternary_lerp_slow(tensors1, tensors2, weight);
97+ }
98+
82 at::native::check_foreach_api_restrictions(tensors1, tensors2, weight);99 at::native::check_foreach_api_restrictions(tensors1, tensors2, weight);
83 if (!at::native::can_use_fast_route({tensors1, tensors2, weight})) {100 if (!at::native::can_use_fast_route({tensors1, tensors2, weight})) {
84 return at::native::foreach_tensor_ternary_lerp_slow(tensors1, tensors2, weight);101 return at::native::foreach_tensor_ternary_lerp_slow(tensors1, tensors2, weight);
@@ -16,6 +16,7 @@
16#include "op_plugin/OpApiInterface.h"16#include "op_plugin/OpApiInterface.h"
17#include "op_plugin/utils/op_api_common.h"17#include "op_plugin/utils/op_api_common.h"
18#include "op_plugin/utils/custom_functions/opapi/scalar_op_api.h"18#include "op_plugin/utils/custom_functions/opapi/scalar_op_api.h"
19+#include "torch_npu/csrc/framework/utils/UtilForOpAdapter.h"
19 20 
20namespace op_api {21namespace op_api {
21 22 
@@ -75,6 +76,14 @@ std::vector<at::Tensor> exec_npu_cmd(at::TensorList tensors1, at::TensorList ten
75 76 
76void _foreach_lerp_(const at::TensorList tensors1, const at::TensorList tensors2, const at::Scalar& weight)77void _foreach_lerp_(const at::TensorList tensors1, const at::TensorList tensors2, const at::Scalar& weight)
77{78{
79+ DO_COMPATIBILITY(aclnnForeachLerpScalar, at::native::foreach_tensor_lerp_list_kernel_slow_(tensors1, tensors2, weight));
80+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
81+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
82+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
83+ if (!is_support_nd_out) {
84+ return at::native::foreach_tensor_lerp_list_kernel_slow_(tensors1, tensors2, weight);
85+ }
86+ 
78 at::native::check_foreach_api_restrictions(tensors1, tensors2);87 at::native::check_foreach_api_restrictions(tensors1, tensors2);
79 if (!at::native::can_use_fast_route({tensors1, tensors2}, weight)) {88 if (!at::native::can_use_fast_route({tensors1, tensors2}, weight)) {
80 return at::native::foreach_tensor_lerp_list_kernel_slow_(tensors1, tensors2, weight);89 return at::native::foreach_tensor_lerp_list_kernel_slow_(tensors1, tensors2, weight);
@@ -84,6 +93,14 @@ void _foreach_lerp_(const at::TensorList tensors1, const at::TensorList tensors2
84 93 
85std::vector<at::Tensor> _foreach_lerp(const at::TensorList tensors1, const at::TensorList tensors2, const at::Scalar& weight)94std::vector<at::Tensor> _foreach_lerp(const at::TensorList tensors1, const at::TensorList tensors2, const at::Scalar& weight)
86{95{
96+ DO_COMPATIBILITY(aclnnForeachLerpScalar, at::native::foreach_tensor_lerp_list_kernel_slow(tensors1, tensors2, weight));
97+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
98+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
99+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
100+ if (!is_support_nd_out) {
101+ return at::native::foreach_tensor_lerp_list_kernel_slow(tensors1, tensors2, weight);
102+ }
103+
87 at::native::check_foreach_api_restrictions(tensors1, tensors2);104 at::native::check_foreach_api_restrictions(tensors1, tensors2);
88 if (!at::native::can_use_fast_route({tensors1, tensors2}, weight)) {105 if (!at::native::can_use_fast_route({tensors1, tensors2}, weight)) {
89 return at::native::foreach_tensor_lerp_list_kernel_slow(tensors1, tensors2, weight);106 return at::native::foreach_tensor_lerp_list_kernel_slow(tensors1, tensors2, weight);
@@ -15,6 +15,7 @@
15#include "op_plugin/OpApiInterface.h"15#include "op_plugin/OpApiInterface.h"
16#include "op_plugin/utils/op_api_common.h"16#include "op_plugin/utils/op_api_common.h"
17#include <ATen/native/ForeachUtils.h>17#include <ATen/native/ForeachUtils.h>
18+#include "torch_npu/csrc/framework/utils/UtilForOpAdapter.h"
18 19 
19namespace op_api {20namespace op_api {
20using npu_preparation = at_npu::native::OpPreparation;21using npu_preparation = at_npu::native::OpPreparation;
@@ -46,6 +47,14 @@ void _split_and_exec_npu_cmd_log10(at::TensorList tensors1, at::TensorList resul
46 47 
47void _foreach_log10_(const at::TensorList self)48void _foreach_log10_(const at::TensorList self)
48{49{
50+ DO_COMPATIBILITY(aclnnForeachLog10, at::native::foreach_tensor_log10_slow_(self));
51+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
52+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
53+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
54+ if (!is_support_nd_out) {
55+ return at::native::foreach_tensor_log10_slow_(self);
56+ }
57+ 
49 at::native::check_foreach_api_restrictions(self);58 at::native::check_foreach_api_restrictions(self);
50 if (!at::native::can_use_fast_route(self) || at::native::has_integral_tensor(self, true)) {59 if (!at::native::can_use_fast_route(self) || at::native::has_integral_tensor(self, true)) {
51 return at::native::foreach_tensor_log10_slow_(self);60 return at::native::foreach_tensor_log10_slow_(self);
@@ -63,6 +72,14 @@ void _foreach_log10_(const at::TensorList self)
63 72 
64std::vector<at::Tensor> _foreach_log10(const at::TensorList self)73std::vector<at::Tensor> _foreach_log10(const at::TensorList self)
65{74{
75+ DO_COMPATIBILITY(aclnnForeachLog10, at::native::foreach_tensor_log10_slow(self));
76+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
77+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
78+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
79+ if (!is_support_nd_out) {
80+ return at::native::foreach_tensor_log10_slow(self);
81+ }
82+ 
66 at::native::check_foreach_api_restrictions(self);83 at::native::check_foreach_api_restrictions(self);
67 if (!at::native::can_use_fast_route(self) || at::native::has_integral_tensor(self, true)) {84 if (!at::native::can_use_fast_route(self) || at::native::has_integral_tensor(self, true)) {
68 return at::native::foreach_tensor_log10_slow(self);85 return at::native::foreach_tensor_log10_slow(self);
@@ -15,6 +15,7 @@
15#include "op_plugin/OpApiInterface.h"15#include "op_plugin/OpApiInterface.h"
16#include "op_plugin/utils/op_api_common.h"16#include "op_plugin/utils/op_api_common.h"
17#include <ATen/native/ForeachUtils.h>17#include <ATen/native/ForeachUtils.h>
18+#include "torch_npu/csrc/framework/utils/UtilForOpAdapter.h"
18 19 
19namespace op_api {20namespace op_api {
20using npu_preparation = at_npu::native::OpPreparation;21using npu_preparation = at_npu::native::OpPreparation;
@@ -47,6 +48,14 @@ void _split_and_exec_npu_cmd_log1p(const at::TensorList tensors1, at::TensorList
47 48 
48void _foreach_log1p_(const at::TensorList self)49void _foreach_log1p_(const at::TensorList self)
49{50{
51+ DO_COMPATIBILITY(aclnnForeachLog1p, at::native::foreach_tensor_log1p_slow_(self));
52+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
53+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
54+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
55+ if (!is_support_nd_out) {
56+ return at::native::foreach_tensor_log1p_slow_(self);
57+ }
58+ 
50 at::native::check_foreach_api_restrictions(self);59 at::native::check_foreach_api_restrictions(self);
51 if (!at::native::can_use_fast_route(self) || at::native::has_integral_tensor(self, true)) {60 if (!at::native::can_use_fast_route(self) || at::native::has_integral_tensor(self, true)) {
52 return at::native::foreach_tensor_log1p_slow_(self);61 return at::native::foreach_tensor_log1p_slow_(self);
@@ -66,6 +75,14 @@ void _foreach_log1p_(const at::TensorList self)
66 75 
67std::vector<at::Tensor> _foreach_log1p(const at::TensorList self)76std::vector<at::Tensor> _foreach_log1p(const at::TensorList self)
68{77{
78+ DO_COMPATIBILITY(aclnnForeachLog1p, at::native::foreach_tensor_log1p_slow(self));
79+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
80+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
81+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
82+ if (!is_support_nd_out) {
83+ return at::native::foreach_tensor_log1p_slow(self);
84+ }
85+
69 at::native::check_foreach_api_restrictions(self);86 at::native::check_foreach_api_restrictions(self);
70 if (!at::native::can_use_fast_route(self) || at::native::has_integral_tensor(self, true)) {87 if (!at::native::can_use_fast_route(self) || at::native::has_integral_tensor(self, true)) {
71 return at::native::foreach_tensor_log1p_slow(self);88 return at::native::foreach_tensor_log1p_slow(self);
@@ -15,6 +15,7 @@
15#include "op_plugin/OpApiInterface.h"15#include "op_plugin/OpApiInterface.h"
16#include "op_plugin/utils/op_api_common.h"16#include "op_plugin/utils/op_api_common.h"
17#include <ATen/native/ForeachUtils.h>17#include <ATen/native/ForeachUtils.h>
18+#include "torch_npu/csrc/framework/utils/UtilForOpAdapter.h"
18 19 
19namespace op_api {20namespace op_api {
20using npu_preparation = at_npu::native::OpPreparation;21using npu_preparation = at_npu::native::OpPreparation;
@@ -46,6 +47,14 @@ void _split_and_exec_npu_cmd_log2(at::TensorList tensors1, at::TensorList result
46 47 
47void _foreach_log2_(const at::TensorList self)48void _foreach_log2_(const at::TensorList self)
48{49{
50+ DO_COMPATIBILITY(aclnnForeachLog2, at::native::foreach_tensor_log2_slow_(self));
51+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
52+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
53+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
54+ if (!is_support_nd_out) {
55+ return at::native::foreach_tensor_log2_slow_(self);
56+ }
57+ 
49 at::native::check_foreach_api_restrictions(self);58 at::native::check_foreach_api_restrictions(self);
50 if (!at::native::can_use_fast_route(self) || at::native::has_integral_tensor(self, true)) {59 if (!at::native::can_use_fast_route(self) || at::native::has_integral_tensor(self, true)) {
51 return at::native::foreach_tensor_log2_slow_(self);60 return at::native::foreach_tensor_log2_slow_(self);
@@ -64,6 +73,14 @@ void _foreach_log2_(const at::TensorList self)
64 73 
65std::vector<at::Tensor> _foreach_log2(const at::TensorList self)74std::vector<at::Tensor> _foreach_log2(const at::TensorList self)
66{75{
76+ DO_COMPATIBILITY(aclnnForeachLog2, at::native::foreach_tensor_log2_slow(self));
77+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
78+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
79+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
80+ if (!is_support_nd_out) {
81+ return at::native::foreach_tensor_log2_slow(self);
82+ }
83+
67 at::native::check_foreach_api_restrictions(self);84 at::native::check_foreach_api_restrictions(self);
68 if (!at::native::can_use_fast_route(self) || at::native::has_integral_tensor(self, true)) {85 if (!at::native::can_use_fast_route(self) || at::native::has_integral_tensor(self, true)) {
69 return at::native::foreach_tensor_log2_slow(self);86 return at::native::foreach_tensor_log2_slow(self);
@@ -15,6 +15,7 @@
15#include "op_plugin/OpApiInterface.h"15#include "op_plugin/OpApiInterface.h"
16#include "op_plugin/utils/op_api_common.h"16#include "op_plugin/utils/op_api_common.h"
17#include <ATen/native/ForeachUtils.h>17#include <ATen/native/ForeachUtils.h>
18+#include "torch_npu/csrc/framework/utils/UtilForOpAdapter.h"
18 19 
19namespace op_api {20namespace op_api {
20using npu_preparation = at_npu::native::OpPreparation;21using npu_preparation = at_npu::native::OpPreparation;
@@ -46,6 +47,14 @@ void _split_and_exec_npu_cmd_log(at::TensorList tensors1, at::TensorList result_
46 47 
47void _foreach_log_(const at::TensorList self)48void _foreach_log_(const at::TensorList self)
48{49{
50+ DO_COMPATIBILITY(aclnnForeachLog, at::native::foreach_tensor_log_slow_(self));
51+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
52+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
53+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
54+ if (!is_support_nd_out) {
55+ return at::native::foreach_tensor_log_slow_(self);
56+ }
57+ 
49 at::native::check_foreach_api_restrictions(self);58 at::native::check_foreach_api_restrictions(self);
50 if (!at::native::can_use_fast_route(self) || at::native::has_integral_tensor(self, true)) {59 if (!at::native::can_use_fast_route(self) || at::native::has_integral_tensor(self, true)) {
51 return at::native::foreach_tensor_log_slow_(self);60 return at::native::foreach_tensor_log_slow_(self);
@@ -64,6 +73,14 @@ void _foreach_log_(const at::TensorList self)
64 73 
65std::vector<at::Tensor> _foreach_log(const at::TensorList self)74std::vector<at::Tensor> _foreach_log(const at::TensorList self)
66{75{
76+ DO_COMPATIBILITY(aclnnForeachLog, at::native::foreach_tensor_log_slow(self));
77+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
78+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
79+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
80+ if (!is_support_nd_out) {
81+ return at::native::foreach_tensor_log_slow(self);
82+ }
83+
67 at::native::check_foreach_api_restrictions(self);84 at::native::check_foreach_api_restrictions(self);
68 if (!at::native::can_use_fast_route(self) || at::native::has_integral_tensor(self, true)) {85 if (!at::native::can_use_fast_route(self) || at::native::has_integral_tensor(self, true)) {
69 return at::native::foreach_tensor_log_slow(self);86 return at::native::foreach_tensor_log_slow(self);
@@ -25,6 +25,14 @@ using npu_preparation = at_npu::native::OpPreparation;
25#if VERSION_BETWEEN(V1R11, V1R11)25#if VERSION_BETWEEN(V1R11, V1R11)
26std::vector<at::Tensor> _foreach_maximum(at::TensorList tensors1, at::TensorList tensors2)26std::vector<at::Tensor> _foreach_maximum(at::TensorList tensors1, at::TensorList tensors2)
27{27{
28+ DO_COMPATIBILITY(aclnnForeachMaximumList, at::native::foreach_tensor_maximum_slow(tensors1, tensors2));
29+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
30+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
31+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
32+ if (!is_support_nd_out) {
33+ return at::native::foreach_tensor_maximum_slow(tensors1, tensors2);
34+ }
35+ 
28 at::native::check_foreach_api_restrictions(tensors1, tensors2);36 at::native::check_foreach_api_restrictions(tensors1, tensors2);
29 if (!at::native::can_use_fast_route(tensors1, tensors2, false)) {37 if (!at::native::can_use_fast_route(tensors1, tensors2, false)) {
30 return at::native::foreach_tensor_maximum_slow(tensors1, tensors2);38 return at::native::foreach_tensor_maximum_slow(tensors1, tensors2);
@@ -47,6 +55,14 @@ std::vector<at::Tensor> _foreach_maximum(at::TensorList tensors1, at::TensorList
47#if VERSION_BETWEEN(V2R0, V2R0)55#if VERSION_BETWEEN(V2R0, V2R0)
48std::vector<at::Tensor> _foreach_maximum(at::TensorList tensors1, at::TensorList tensors2)56std::vector<at::Tensor> _foreach_maximum(at::TensorList tensors1, at::TensorList tensors2)
49{57{
58+ DO_COMPATIBILITY(aclnnForeachMaximumList, at::native::foreach_tensor_clamp_max_list_kernel_slow(tensors1, tensors2));
59+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
60+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
61+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
62+ if (!is_support_nd_out) {
63+ return at::native::foreach_tensor_clamp_max_list_kernel_slow(tensors1, tensors2);
64+ }
65+ 
50 at::native::check_foreach_api_restrictions(tensors1, tensors2);66 at::native::check_foreach_api_restrictions(tensors1, tensors2);
51 if (!at::native::can_use_fast_route(tensors1, tensors2, false)) {67 if (!at::native::can_use_fast_route(tensors1, tensors2, false)) {
52 return at::native::foreach_tensor_clamp_max_list_kernel_slow(tensors1, tensors2);68 return at::native::foreach_tensor_clamp_max_list_kernel_slow(tensors1, tensors2);
@@ -95,6 +111,14 @@ void _split_and_exec_npu_cmd_max(at::TensorList& tensors1, at::TensorList& tenso
95 111 
96std::vector<at::Tensor> _foreach_maximum(at::TensorList tensors1, at::TensorList tensors2)112std::vector<at::Tensor> _foreach_maximum(at::TensorList tensors1, at::TensorList tensors2)
97{113{
114+ DO_COMPATIBILITY(aclnnForeachMaximumList, at::native::foreach_tensor_clamp_min_list_kernel_slow(tensors1, tensors2));
115+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
116+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
117+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
118+ if (!is_support_nd_out) {
119+ return at::native::foreach_tensor_clamp_min_list_kernel_slow(tensors1, tensors2);
120+ }
121+ 
98 at::native::check_foreach_api_restrictions(tensors1, tensors2);122 at::native::check_foreach_api_restrictions(tensors1, tensors2);
99 if (!at::native::can_use_fast_route(tensors1, tensors2, false)) {123 if (!at::native::can_use_fast_route(tensors1, tensors2, false)) {
100 return at::native::foreach_tensor_clamp_min_list_kernel_slow(tensors1, tensors2);124 return at::native::foreach_tensor_clamp_min_list_kernel_slow(tensors1, tensors2);
@@ -115,6 +139,14 @@ std::vector<at::Tensor> _foreach_maximum(at::TensorList tensors1, at::TensorList
115 139 
116void _foreach_maximum_(at::TensorList tensors1, at::TensorList tensors2)140void _foreach_maximum_(at::TensorList tensors1, at::TensorList tensors2)
117{141{
142+ DO_COMPATIBILITY(aclnnForeachMaximumList, at::native::foreach_tensor_clamp_min_list_kernel_slow_(tensors1, tensors2));
143+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
144+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
145+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
146+ if (!is_support_nd_out) {
147+ return at::native::foreach_tensor_clamp_min_list_kernel_slow_(tensors1, tensors2);
148+ }
149+ 
118 at::native::check_foreach_api_restrictions(tensors1, tensors2);150 at::native::check_foreach_api_restrictions(tensors1, tensors2);
119 if (!at::native::can_use_fast_route(tensors1, tensors2, false)) {151 if (!at::native::can_use_fast_route(tensors1, tensors2, false)) {
120 return at::native::foreach_tensor_clamp_min_list_kernel_slow_(tensors1, tensors2);152 return at::native::foreach_tensor_clamp_min_list_kernel_slow_(tensors1, tensors2);
@@ -181,11 +213,14 @@ void _split_and_exec_npu_cmd_max_scalar_list(at::TensorList& tensors1, at::Array
181std::vector<at::Tensor> _foreach_maximum(at::TensorList tensors, const at::Scalar& scalar)213std::vector<at::Tensor> _foreach_maximum(at::TensorList tensors, const at::Scalar& scalar)
182{214{
183 at::native::check_foreach_api_restrictions(tensors);215 at::native::check_foreach_api_restrictions(tensors);
184- static const bool is_support_nd_out = c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&216+ DO_COMPATIBILITY(aclnnForeachMaximumScalar, at::native::foreach_tensor_clamp_min_scalar_kernel_slow(tensors, scalar));
185- c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1;217+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
218+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
219+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
186 if (!is_support_nd_out) {220 if (!is_support_nd_out) {
187 return at::native::foreach_tensor_clamp_min_scalar_kernel_slow(tensors, scalar);221 return at::native::foreach_tensor_clamp_min_scalar_kernel_slow(tensors, scalar);
188 }222 }
223+ 
189 if (!at::native::can_use_fast_route(tensors, scalar, false)) {224 if (!at::native::can_use_fast_route(tensors, scalar, false)) {
190 return at::native::foreach_tensor_clamp_min_scalar_kernel_slow(tensors, scalar);225 return at::native::foreach_tensor_clamp_min_scalar_kernel_slow(tensors, scalar);
191 }226 }
@@ -206,8 +241,10 @@ std::vector<at::Tensor> _foreach_maximum(at::TensorList tensors, const at::Scala
206void _foreach_maximum_(at::TensorList tensors, const at::Scalar& scalar)241void _foreach_maximum_(at::TensorList tensors, const at::Scalar& scalar)
207{242{
208 at::native::check_foreach_api_restrictions(tensors);243 at::native::check_foreach_api_restrictions(tensors);
209- static const bool is_support_nd_out = c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&244+ DO_COMPATIBILITY(aclnnForeachMaximumScalar, at::native::foreach_tensor_clamp_min_scalar_kernel_slow_(tensors, scalar));
210- c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1;245+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
246+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
247+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
211 if (!is_support_nd_out) {248 if (!is_support_nd_out) {
212 return at::native::foreach_tensor_clamp_min_scalar_kernel_slow_(tensors, scalar);249 return at::native::foreach_tensor_clamp_min_scalar_kernel_slow_(tensors, scalar);
213 }250 }
@@ -222,6 +259,14 @@ void _foreach_maximum_(at::TensorList tensors, const at::Scalar& scalar)
222 259 
223std::vector<at::Tensor> _foreach_maximum(at::TensorList tensors, at::ArrayRef<at::Scalar> scalars)260std::vector<at::Tensor> _foreach_maximum(at::TensorList tensors, at::ArrayRef<at::Scalar> scalars)
224{261{
262+ DO_COMPATIBILITY(aclnnForeachMaximumScalarList, at::native::foreach_tensor_clamp_min_scalarlist_kernel_slow(tensors, scalars));
263+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
264+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
265+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
266+ if (!is_support_nd_out) {
267+ return at::native::foreach_tensor_clamp_min_scalarlist_kernel_slow(tensors, scalars);
268+ }
269+ 
225 at::native::check_foreach_api_restrictions(tensors, scalars);270 at::native::check_foreach_api_restrictions(tensors, scalars);
226 if (!at::native::can_use_fast_route(tensors, scalars, false)) {271 if (!at::native::can_use_fast_route(tensors, scalars, false)) {
227 return at::native::foreach_tensor_clamp_min_scalarlist_kernel_slow(tensors, scalars);272 return at::native::foreach_tensor_clamp_min_scalarlist_kernel_slow(tensors, scalars);
@@ -242,6 +287,14 @@ std::vector<at::Tensor> _foreach_maximum(at::TensorList tensors, at::ArrayRef<at
242 287 
243void _foreach_maximum_(at::TensorList tensors, at::ArrayRef<at::Scalar> scalars)288void _foreach_maximum_(at::TensorList tensors, at::ArrayRef<at::Scalar> scalars)
244{289{
290+ DO_COMPATIBILITY(aclnnForeachMaximumScalarList, at::native::foreach_tensor_clamp_min_scalarlist_kernel_slow_(tensors, scalars));
291+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
292+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
293+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
294+ if (!is_support_nd_out) {
295+ return at::native::foreach_tensor_clamp_min_scalarlist_kernel_slow_(tensors, scalars);
296+ }
297+
245 at::native::check_foreach_api_restrictions(tensors, scalars);298 at::native::check_foreach_api_restrictions(tensors, scalars);
246 if (!at::native::can_use_fast_route(tensors, scalars, false)) {299 if (!at::native::can_use_fast_route(tensors, scalars, false)) {
247 return at::native::foreach_tensor_clamp_min_scalarlist_kernel_slow_(tensors, scalars);300 return at::native::foreach_tensor_clamp_min_scalarlist_kernel_slow_(tensors, scalars);
@@ -25,6 +25,14 @@ using npu_preparation = at_npu::native::OpPreparation;
25#if VERSION_BETWEEN(V1R11, V1R11)25#if VERSION_BETWEEN(V1R11, V1R11)
26std::vector<at::Tensor> _foreach_minimum(at::TensorList tensors1, at::TensorList tensors2)26std::vector<at::Tensor> _foreach_minimum(at::TensorList tensors1, at::TensorList tensors2)
27{27{
28+ DO_COMPATIBILITY(aclnnForeachMinimumList, at::native::foreach_tensor_minimum_slow(tensors1, tensors2));
29+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
30+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
31+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
32+ if (!is_support_nd_out) {
33+ return at::native::foreach_tensor_minimum_slow(tensors1, tensors2);
34+ }
35+ 
28 at::native::check_foreach_api_restrictions(tensors1, tensors2);36 at::native::check_foreach_api_restrictions(tensors1, tensors2);
29 if (!at::native::can_use_fast_route(tensors1, tensors2, false)) {37 if (!at::native::can_use_fast_route(tensors1, tensors2, false)) {
30 return at::native::foreach_tensor_minimum_slow(tensors1, tensors2);38 return at::native::foreach_tensor_minimum_slow(tensors1, tensors2);
@@ -47,6 +55,14 @@ std::vector<at::Tensor> _foreach_minimum(at::TensorList tensors1, at::TensorList
47#if VERSION_BETWEEN(V2R0, V2R0)55#if VERSION_BETWEEN(V2R0, V2R0)
48std::vector<at::Tensor> _foreach_minimum(at::TensorList tensors1, at::TensorList tensors2)56std::vector<at::Tensor> _foreach_minimum(at::TensorList tensors1, at::TensorList tensors2)
49{57{
58+ DO_COMPATIBILITY(aclnnForeachMinimumList, at::native::foreach_tensor_clamp_min_list_kernel_slow(tensors1, tensors2));
59+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
60+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
61+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
62+ if (!is_support_nd_out) {
63+ return at::native::foreach_tensor_clamp_min_list_kernel_slow(tensors1, tensors2);
64+ }
65+ 
50 at::native::check_foreach_api_restrictions(tensors1, tensors2);66 at::native::check_foreach_api_restrictions(tensors1, tensors2);
51 if (!at::native::can_use_fast_route(tensors1, tensors2, false)) {67 if (!at::native::can_use_fast_route(tensors1, tensors2, false)) {
52 return at::native::foreach_tensor_clamp_min_list_kernel_slow(tensors1, tensors2);68 return at::native::foreach_tensor_clamp_min_list_kernel_slow(tensors1, tensors2);
@@ -94,6 +110,14 @@ void _split_and_exec_npu_cmd_min(at::TensorList& tensors1, at::TensorList& tenso
94 110 
95std::vector<at::Tensor> _foreach_minimum(at::TensorList tensors1, at::TensorList tensors2)111std::vector<at::Tensor> _foreach_minimum(at::TensorList tensors1, at::TensorList tensors2)
96{112{
113+ DO_COMPATIBILITY(aclnnForeachMinimumList, at::native::foreach_tensor_clamp_max_list_kernel_slow(tensors1, tensors2));
114+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
115+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
116+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
117+ if (!is_support_nd_out) {
118+ return at::native::foreach_tensor_clamp_max_list_kernel_slow(tensors1, tensors2);
119+ }
120+ 
97 at::native::check_foreach_api_restrictions(tensors1, tensors2);121 at::native::check_foreach_api_restrictions(tensors1, tensors2);
98 if (!at::native::can_use_fast_route(tensors1, tensors2, false)) {122 if (!at::native::can_use_fast_route(tensors1, tensors2, false)) {
99 return at::native::foreach_tensor_clamp_max_list_kernel_slow(tensors1, tensors2);123 return at::native::foreach_tensor_clamp_max_list_kernel_slow(tensors1, tensors2);
@@ -114,6 +138,14 @@ std::vector<at::Tensor> _foreach_minimum(at::TensorList tensors1, at::TensorList
114 138 
115void _foreach_minimum_(at::TensorList tensors1, at::TensorList tensors2)139void _foreach_minimum_(at::TensorList tensors1, at::TensorList tensors2)
116{140{
141+ DO_COMPATIBILITY(aclnnForeachMinimumList, at::native::foreach_tensor_clamp_max_list_kernel_slow_(tensors1, tensors2));
142+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
143+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
144+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
145+ if (!is_support_nd_out) {
146+ return at::native::foreach_tensor_clamp_max_list_kernel_slow_(tensors1, tensors2);
147+ }
148+ 
117 at::native::check_foreach_api_restrictions(tensors1, tensors2);149 at::native::check_foreach_api_restrictions(tensors1, tensors2);
118 if (!at::native::can_use_fast_route(tensors1, tensors2, false)) {150 if (!at::native::can_use_fast_route(tensors1, tensors2, false)) {
119 return at::native::foreach_tensor_clamp_max_list_kernel_slow_(tensors1, tensors2);151 return at::native::foreach_tensor_clamp_max_list_kernel_slow_(tensors1, tensors2);
@@ -220,6 +252,14 @@ void _foreach_minimum_(at::TensorList tensors, const at::Scalar& scalar)
220 252 
221std::vector<at::Tensor> _foreach_minimum(at::TensorList tensors, at::ArrayRef<at::Scalar> scalars)253std::vector<at::Tensor> _foreach_minimum(at::TensorList tensors, at::ArrayRef<at::Scalar> scalars)
222{254{
255+ DO_COMPATIBILITY(aclnnForeachMinimumScalarList, at::native::foreach_tensor_clamp_max_scalarlist_kernel_slow(tensors, scalars));
256+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
257+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
258+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
259+ if (!is_support_nd_out) {
260+ return at::native::foreach_tensor_clamp_max_scalarlist_kernel_slow(tensors, scalars);
261+ }
262+ 
223 at::native::check_foreach_api_restrictions(tensors, scalars);263 at::native::check_foreach_api_restrictions(tensors, scalars);
224 if (!at::native::can_use_fast_route(tensors, scalars, false)) {264 if (!at::native::can_use_fast_route(tensors, scalars, false)) {
225 return at::native::foreach_tensor_clamp_max_scalarlist_kernel_slow(tensors, scalars);265 return at::native::foreach_tensor_clamp_max_scalarlist_kernel_slow(tensors, scalars);
@@ -239,6 +279,14 @@ std::vector<at::Tensor> _foreach_minimum(at::TensorList tensors, at::ArrayRef<at
239 279 
240void _foreach_minimum_(at::TensorList tensors, at::ArrayRef<at::Scalar> scalars)280void _foreach_minimum_(at::TensorList tensors, at::ArrayRef<at::Scalar> scalars)
241{281{
282+ DO_COMPATIBILITY(aclnnForeachMinimumScalarList, at::native::foreach_tensor_clamp_max_scalarlist_kernel_slow_(tensors, scalars));
283+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
284+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
285+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
286+ if (!is_support_nd_out) {
287+ return at::native::foreach_tensor_clamp_max_scalarlist_kernel_slow_(tensors, scalars);
288+ }
289+
242 at::native::check_foreach_api_restrictions(tensors, scalars);290 at::native::check_foreach_api_restrictions(tensors, scalars);
243 if (!at::native::can_use_fast_route(tensors, scalars, false)) {291 if (!at::native::can_use_fast_route(tensors, scalars, false)) {
244 return at::native::foreach_tensor_clamp_max_scalarlist_kernel_slow_(tensors, scalars);292 return at::native::foreach_tensor_clamp_max_scalarlist_kernel_slow_(tensors, scalars);
@@ -14,6 +14,7 @@
14#include <ATen/native/ForeachUtils.h>14#include <ATen/native/ForeachUtils.h>
15#include "op_plugin/OpApiInterface.h"15#include "op_plugin/OpApiInterface.h"
16#include "op_plugin/utils/op_api_common.h"16#include "op_plugin/utils/op_api_common.h"
17+#include "torch_npu/csrc/framework/utils/UtilForOpAdapter.h"
17 18 
18namespace op_api {19namespace op_api {
19using npu_preparation = at_npu::native::OpPreparation;20using npu_preparation = at_npu::native::OpPreparation;
@@ -46,6 +47,14 @@ void _split_and_exec_npu_cmd_mul(at::TensorList &tensors1, at::TensorList &tenso
46 47 
47std::vector<at::Tensor> _foreach_mul(at::TensorList tensors1, at::TensorList tensors2)48std::vector<at::Tensor> _foreach_mul(at::TensorList tensors1, at::TensorList tensors2)
48{49{
50+ DO_COMPATIBILITY(aclnnForeachMulList, at::native::foreach_tensor_mul_list_kernel_slow(tensors1, tensors2));
51+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
52+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
53+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
54+ if (!is_support_nd_out) {
55+ return at::native::foreach_tensor_mul_list_kernel_slow(tensors1, tensors2);
56+ }
57+ 
49 at::native::check_foreach_api_restrictions(tensors1, tensors2);58 at::native::check_foreach_api_restrictions(tensors1, tensors2);
50 if (!at::native::can_use_fast_route(tensors1, tensors2, false)) {59 if (!at::native::can_use_fast_route(tensors1, tensors2, false)) {
51 return at::native::foreach_tensor_mul_list_kernel_slow(tensors1, tensors2);60 return at::native::foreach_tensor_mul_list_kernel_slow(tensors1, tensors2);
@@ -65,6 +74,14 @@ std::vector<at::Tensor> _foreach_mul(at::TensorList tensors1, at::TensorList ten
65 74 
66void _foreach_mul_(at::TensorList tensors1, at::TensorList tensors2)75void _foreach_mul_(at::TensorList tensors1, at::TensorList tensors2)
67{76{
77+ DO_COMPATIBILITY(aclnnForeachMulList, at::native::foreach_tensor_mul_list_kernel_slow_(tensors1, tensors2));
78+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
79+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
80+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
81+ if (!is_support_nd_out) {
82+ return at::native::foreach_tensor_mul_list_kernel_slow_(tensors1, tensors2);
83+ }
84+ 
68 at::native::check_foreach_api_restrictions(tensors1, tensors2);85 at::native::check_foreach_api_restrictions(tensors1, tensors2);
69 if (!at::native::can_use_fast_route(tensors1, tensors2, false)) {86 if (!at::native::can_use_fast_route(tensors1, tensors2, false)) {
70 return at::native::foreach_tensor_mul_list_kernel_slow_(tensors1, tensors2);87 return at::native::foreach_tensor_mul_list_kernel_slow_(tensors1, tensors2);
@@ -102,6 +119,14 @@ void _split_and_exec_npu_cmd_mul_scalarlist(at::TensorList &tensors1, at::ArrayR
102 119 
103std::vector<at::Tensor> _foreach_mul(at::TensorList tensors, at::ArrayRef<at::Scalar> scalars)120std::vector<at::Tensor> _foreach_mul(at::TensorList tensors, at::ArrayRef<at::Scalar> scalars)
104{121{
122+ DO_COMPATIBILITY(aclnnForeachMulScalarList, at::native::foreach_tensor_mul_scalarlist_kernel_slow(tensors, scalars));
123+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
124+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
125+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
126+ if (!is_support_nd_out) {
127+ return at::native::foreach_tensor_mul_scalarlist_kernel_slow(tensors, scalars);
128+ }
129+ 
105 // default slow path for now, wait for ascendc aclnn framwork support scalarlist type130 // default slow path for now, wait for ascendc aclnn framwork support scalarlist type
106 at::native::check_foreach_api_restrictions(tensors, scalars);131 at::native::check_foreach_api_restrictions(tensors, scalars);
107 if (!at::native::can_use_fast_route(tensors, scalars, true)) {132 if (!at::native::can_use_fast_route(tensors, scalars, true)) {
@@ -122,6 +147,14 @@ std::vector<at::Tensor> _foreach_mul(at::TensorList tensors, at::ArrayRef<at::Sc
122 147 
123void _foreach_mul_(at::TensorList tensors, at::ArrayRef<at::Scalar> scalars)148void _foreach_mul_(at::TensorList tensors, at::ArrayRef<at::Scalar> scalars)
124{149{
150+ DO_COMPATIBILITY(aclnnForeachMulScalarList, at::native::foreach_tensor_mul_scalarlist_kernel_slow_(tensors, scalars));
151+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
152+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
153+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
154+ if (!is_support_nd_out) {
155+ return at::native::foreach_tensor_mul_scalarlist_kernel_slow_(tensors, scalars);
156+ }
157+ 
125 // default slow path for now, wait for ascendc aclnn framwork support scalarlist type158 // default slow path for now, wait for ascendc aclnn framwork support scalarlist type
126 at::native::check_foreach_api_restrictions(tensors, scalars);159 at::native::check_foreach_api_restrictions(tensors, scalars);
127 if (!at::native::can_use_fast_route(tensors, scalars, true)) {160 if (!at::native::can_use_fast_route(tensors, scalars, true)) {
@@ -15,6 +15,7 @@
15#include "op_plugin/OpApiInterface.h"15#include "op_plugin/OpApiInterface.h"
16#include "op_plugin/utils/op_api_common.h"16#include "op_plugin/utils/op_api_common.h"
17#include "op_plugin/utils/custom_functions/opapi/scalar_op_api.h"17#include "op_plugin/utils/custom_functions/opapi/scalar_op_api.h"
18+#include "torch_npu/csrc/framework/utils/UtilForOpAdapter.h"
18 19 
19namespace op_api {20namespace op_api {
20using npu_preparation = at_npu::native::OpPreparation;21using npu_preparation = at_npu::native::OpPreparation;
@@ -47,6 +48,13 @@ void _split_and_exec_npu_cmd_mul(const at::TensorList tensors1, const at::Scalar
47 48 
48std::vector<at::Tensor> _foreach_mul(const at::TensorList self, const at::Scalar& scalar)49std::vector<at::Tensor> _foreach_mul(const at::TensorList self, const at::Scalar& scalar)
49{50{
51+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
52+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
53+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
54+ if (!is_support_nd_out) {
55+ return at::native::foreach_tensor_mul_scalar_kernel_slow(self, scalar);
56+ }
57+
50 at::native::check_foreach_api_restrictions(self);58 at::native::check_foreach_api_restrictions(self);
51 if (!at::native::can_use_fast_route(self, scalar, false)) {59 if (!at::native::can_use_fast_route(self, scalar, false)) {
52 return at::native::foreach_tensor_mul_scalar_kernel_slow(self, scalar);60 return at::native::foreach_tensor_mul_scalar_kernel_slow(self, scalar);
@@ -68,6 +76,13 @@ std::vector<at::Tensor> _foreach_mul(const at::TensorList self, const at::Scalar
68 76 
69void _foreach_mul_(const at::TensorList self, const at::Scalar& scalar)77void _foreach_mul_(const at::TensorList self, const at::Scalar& scalar)
70{78{
79+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
80+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
81+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
82+ if (!is_support_nd_out) {
83+ return at::native::foreach_tensor_mul_scalar_kernel_slow_(self, scalar);
84+ }
85+
71 at::native::check_foreach_api_restrictions(self);86 at::native::check_foreach_api_restrictions(self);
72 if (!at::native::can_use_fast_route(self, scalar, false)) {87 if (!at::native::can_use_fast_route(self, scalar, false)) {
73 return at::native::foreach_tensor_mul_scalar_kernel_slow_(self, scalar);88 return at::native::foreach_tensor_mul_scalar_kernel_slow_(self, scalar);
@@ -16,6 +16,7 @@
16#include "op_plugin/utils/op_api_common.h"16#include "op_plugin/utils/op_api_common.h"
17#include <ATen/native/ForeachUtils.h>17#include <ATen/native/ForeachUtils.h>
18#include "op_plugin/utils/custom_functions/opapi/ForeachConstants.h"18#include "op_plugin/utils/custom_functions/opapi/ForeachConstants.h"
19+#include "torch_npu/csrc/framework/utils/UtilForOpAdapter.h"
19 20 
20namespace op_api {21namespace op_api {
21using npu_preparation = at_npu::native::OpPreparation;22using npu_preparation = at_npu::native::OpPreparation;
@@ -53,6 +54,14 @@ bool check_neg_is_supported_data_type(at::ScalarType scalar_type)
53 54 
54void _foreach_neg_(const at::TensorList self)55void _foreach_neg_(const at::TensorList self)
55{56{
57+ DO_COMPATIBILITY(aclnnForeachNeg, at::native::foreach_tensor_neg_slow_(self));
58+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
59+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
60+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
61+ if (!is_support_nd_out) {
62+ return at::native::foreach_tensor_neg_slow_(self);
63+ }
64+ 
56 at::native::check_foreach_api_restrictions(self);65 at::native::check_foreach_api_restrictions(self);
57 if (!at::native::can_use_fast_route(self) || at::native::has_integral_tensor(self, true)) {66 if (!at::native::can_use_fast_route(self) || at::native::has_integral_tensor(self, true)) {
58 return at::native::foreach_tensor_neg_slow_(self);67 return at::native::foreach_tensor_neg_slow_(self);
@@ -71,6 +80,14 @@ void _foreach_neg_(const at::TensorList self)
71 80 
72std::vector<at::Tensor> _foreach_neg(const at::TensorList self)81std::vector<at::Tensor> _foreach_neg(const at::TensorList self)
73{82{
83+ DO_COMPATIBILITY(aclnnForeachNeg, at::native::foreach_tensor_neg_slow(self));
84+ static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 &&
85+ c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) ||
86+ (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4);
87+ if (!is_support_nd_out) {
88+ return at::native::foreach_tensor_neg_slow(self);
89+ }
90+ 
74 at::native::check_foreach_api_restrictions(self);91 at::native::check_foreach_api_restrictions(self);
75 if (!at::native::can_use_fast_route(self) || at::native::has_integral_tensor(self, true)) {92 if (!at::native::can_use_fast_route(self) || at::native::has_integral_tensor(self, true)) {
76 return at::native::foreach_tensor_neg_slow(self);93 return at::native::foreach_tensor_neg_slow(self);
@@ -2,6 +2,8 @@ import unittest
2import random2import random
3import torch3import torch
4import torch_npu4import torch_npu
5+from scipy import special
6+ 
5import hypothesis7import hypothesis
6from torch_npu.testing.testcase import TestCase, run_tests8from torch_npu.testing.testcase import TestCase, run_tests
7from torch_npu.testing.common_utils import SupportedDevices9from torch_npu.testing.common_utils import SupportedDevices
@@ -14,6 +16,17 @@ class TestForeachErf(TestCase):
14 "float32" : torch.float32,16 "float32" : torch.float32,
15 "bfloat16" : torch.bfloat16,17 "bfloat16" : torch.bfloat16,
16 }18 }
19+
20+ def assert_equal_bfloat16(self, cpu_outs, npu_outs):
21+ for cpu_out, npu_out in zip(cpu_outs, npu_outs):
22+ if (cpu_out.shape != npu_out.shape):
23+ self.fail("shape error")
24+ if (cpu_out.dtype != npu_out.dtype):
25+ self.fail("dtype error!")
26+ result = torch.allclose(cpu_out, npu_out.cpu(), rtol=0.001, atol=0.001)
27+ if not result:
28+ self.fail("result error!")
29+ return True
17 30 
18 def create_tensors(self, tensor_nums, dtype):31 def create_tensors(self, tensor_nums, dtype):
19 cpu_tensors = []32 cpu_tensors = []
@@ -29,7 +42,7 @@ class TestForeachErf(TestCase):
29 npu_tensors.append(t.npu())42 npu_tensors.append(t.npu())
30 return tuple(cpu_tensors), tuple(npu_tensors)43 return tuple(cpu_tensors), tuple(npu_tensors)
31 44 
32- @SupportedDevices(['Ascend910B'])45+
33 def test_foreach_erf_out_float32_shpae_tensor_num(self):46 def test_foreach_erf_out_float32_shpae_tensor_num(self):
34 tensor_num_list = [20, 50]47 tensor_num_list = [20, 50]
35 for tensor_num in tensor_num_list :48 for tensor_num in tensor_num_list :
@@ -39,12 +52,13 @@ class TestForeachErf(TestCase):
39 52 
40 self.assertRtolEqual(cpu_output, npu_output)53 self.assertRtolEqual(cpu_output, npu_output)
41 54
42- @SupportedDevices(['Ascend910B'])55+
43 def test_foreach_erf_out_float16_shpae_tensor_num(self):56 def test_foreach_erf_out_float16_shpae_tensor_num(self):
44 tensor_num_list = [20, 50]57 tensor_num_list = [20, 50]
45 for tensor_num in tensor_num_list :58 for tensor_num in tensor_num_list :
46 cpu_tensors, npu_tensors = self.create_tensors(tensor_num, "float16")59 cpu_tensors, npu_tensors = self.create_tensors(tensor_num, "float16")
47- cpu_output = torch._foreach_erf(cpu_tensors)60+ cpu_tensors = [cpu_tensor.numpy() for cpu_tensor in cpu_tensors]
61+ cpu_output = [torch.from_numpy(special.erf(cpu_tensors[i])).half() for i in range(len(cpu_tensors))]
48 npu_output = torch._foreach_erf(npu_tensors)62 npu_output = torch._foreach_erf(npu_tensors)
49 63 
50 self.assertRtolEqual(cpu_output, npu_output)64 self.assertRtolEqual(cpu_output, npu_output)
@@ -57,9 +71,9 @@ class TestForeachErf(TestCase):
57 cpu_output = torch._foreach_erf(cpu_tensors)71 cpu_output = torch._foreach_erf(cpu_tensors)
58 npu_output = torch._foreach_erf(npu_tensors)72 npu_output = torch._foreach_erf(npu_tensors)
59 73 
60- self.assertRtolEqual(cpu_output, npu_output)74+ self.assert_equal_bfloat16(cpu_output, npu_output)
61 75 
62- @SupportedDevices(['Ascend910B'])76+
63 def test_foreach_erf_inplace_float32_shpae_tensor_num(self):77 def test_foreach_erf_inplace_float32_shpae_tensor_num(self):
64 tensor_num_list = [20, 50]78 tensor_num_list = [20, 50]
65 for tensor_num in tensor_num_list :79 for tensor_num in tensor_num_list :
@@ -69,15 +83,16 @@ class TestForeachErf(TestCase):
69 83 
70 self.assertRtolEqual(cpu_tensors, npu_tensors)84 self.assertRtolEqual(cpu_tensors, npu_tensors)
71 85
72- @SupportedDevices(['Ascend910B'])86+
73 def test_foreach_erf_inplace_float16_shpae_tensor_num(self):87 def test_foreach_erf_inplace_float16_shpae_tensor_num(self):
74 tensor_num_list = [20, 50]88 tensor_num_list = [20, 50]
75 for tensor_num in tensor_num_list :89 for tensor_num in tensor_num_list :
76 cpu_tensors, npu_tensors = self.create_tensors(tensor_num, "float16")90 cpu_tensors, npu_tensors = self.create_tensors(tensor_num, "float16")
77- torch._foreach_erf_(cpu_tensors)91+ cpu_tensors = [cpu_tensor.numpy() for cpu_tensor in cpu_tensors]
92+ cpu_output = [torch.from_numpy(special.erf(cpu_tensors[i])).half() for i in range(len(cpu_tensors))]
78 torch._foreach_erf_(npu_tensors)93 torch._foreach_erf_(npu_tensors)
79 94 
80- self.assertRtolEqual(cpu_tensors, npu_tensors)95+ self.assertRtolEqual(cpu_output, npu_tensors)
81 96 
82 @SupportedDevices(['Ascend910B'])97 @SupportedDevices(['Ascend910B'])
83 def test_foreach_erf_inplace_bfloat16_shpae_tensor_num(self):98 def test_foreach_erf_inplace_bfloat16_shpae_tensor_num(self):
@@ -87,7 +102,7 @@ class TestForeachErf(TestCase):
87 torch._foreach_erf_(cpu_tensors)102 torch._foreach_erf_(cpu_tensors)
88 torch._foreach_erf_(npu_tensors)103 torch._foreach_erf_(npu_tensors)
89 104 
90- self.assertRtolEqual(cpu_tensors, npu_tensors)105+ self.assert_equal_bfloat16(cpu_tensors, npu_tensors)
91 106 
92 107 
93if __name__ == "__main__":108if __name__ == "__main__":
@@ -2,6 +2,7 @@ import unittest
2import random2import random
3import torch3import torch
4import torch_npu4import torch_npu
5+from scipy import special
5import hypothesis6import hypothesis
6from torch_npu.testing.testcase import TestCase, run_tests7from torch_npu.testing.testcase import TestCase, run_tests
7from torch_npu.testing.common_utils import SupportedDevices8from torch_npu.testing.common_utils import SupportedDevices
@@ -14,6 +15,17 @@ class TestForeachErfc(TestCase):
14 "float32" : torch.float32,15 "float32" : torch.float32,
15 "bfloat16" : torch.bfloat16,16 "bfloat16" : torch.bfloat16,
16 }17 }
18+
19+ def assert_equal_bfloat16(self, cpu_outs, npu_outs):
20+ for cpu_out, npu_out in zip(cpu_outs, npu_outs):
21+ if (cpu_out.shape != npu_out.shape):
22+ self.fail("shape error")
23+ if (cpu_out.dtype != npu_out.dtype):
24+ self.fail("dtype error!")
25+ result = torch.allclose(cpu_out, npu_out.cpu(), rtol=0.001, atol=0.001)
26+ if not result:
27+ self.fail("result error!")
28+ return True
17 29 
18 def create_tensors(self, tensor_nums, dtype):30 def create_tensors(self, tensor_nums, dtype):
19 cpu_tensors = []31 cpu_tensors = []
@@ -29,7 +41,7 @@ class TestForeachErfc(TestCase):
29 npu_tensors.append(t.npu())41 npu_tensors.append(t.npu())
30 return tuple(cpu_tensors), tuple(npu_tensors)42 return tuple(cpu_tensors), tuple(npu_tensors)
31 43 
32- @SupportedDevices(['Ascend910B'])44+
33 def test_foreach_erfc_out_float32_shpae_tensor_num(self):45 def test_foreach_erfc_out_float32_shpae_tensor_num(self):
34 tensor_num_list = [20, 50]46 tensor_num_list = [20, 50]
35 for tensor_num in tensor_num_list :47 for tensor_num in tensor_num_list :
@@ -39,12 +51,13 @@ class TestForeachErfc(TestCase):
39 51 
40 self.assertRtolEqual(cpu_output, npu_output)52 self.assertRtolEqual(cpu_output, npu_output)
41 53
42- @SupportedDevices(['Ascend910B'])54+
43 def test_foreach_erfc_out_float16_shpae_tensor_num(self):55 def test_foreach_erfc_out_float16_shpae_tensor_num(self):
44 tensor_num_list = [20, 50]56 tensor_num_list = [20, 50]
45 for tensor_num in tensor_num_list :57 for tensor_num in tensor_num_list :
46 cpu_tensors, npu_tensors = self.create_tensors(tensor_num, "float16")58 cpu_tensors, npu_tensors = self.create_tensors(tensor_num, "float16")
47- cpu_output = torch._foreach_erfc(cpu_tensors)59+ cpu_tensors = [cpu_tensor.numpy() for cpu_tensor in cpu_tensors]
60+ cpu_output = [torch.from_numpy(special.erfc(cpu_tensors[i])).half() for i in range(len(cpu_tensors))]
48 npu_output = torch._foreach_erfc(npu_tensors)61 npu_output = torch._foreach_erfc(npu_tensors)
49 62 
50 self.assertRtolEqual(cpu_output, npu_output)63 self.assertRtolEqual(cpu_output, npu_output)
@@ -57,9 +70,9 @@ class TestForeachErfc(TestCase):
57 cpu_output = torch._foreach_erfc(cpu_tensors)70 cpu_output = torch._foreach_erfc(cpu_tensors)
58 npu_output = torch._foreach_erfc(npu_tensors)71 npu_output = torch._foreach_erfc(npu_tensors)
59 72 
60- self.assertRtolEqual(cpu_output, npu_output)73+ self.assert_equal_bfloat16(cpu_output, npu_output)
61 74 
62- @SupportedDevices(['Ascend910B'])75+
63 def test_foreach_erfc_inplace_float32_shpae_tensor_num(self):76 def test_foreach_erfc_inplace_float32_shpae_tensor_num(self):
64 tensor_num_list = [20, 50]77 tensor_num_list = [20, 50]
65 for tensor_num in tensor_num_list :78 for tensor_num in tensor_num_list :
@@ -69,15 +82,16 @@ class TestForeachErfc(TestCase):
69 82 
70 self.assertRtolEqual(cpu_tensors, npu_tensors)83 self.assertRtolEqual(cpu_tensors, npu_tensors)
71 84
72- @SupportedDevices(['Ascend910B'])85+
73 def test_foreach_erfc_inplace_float16_shpae_tensor_num(self):86 def test_foreach_erfc_inplace_float16_shpae_tensor_num(self):
74 tensor_num_list = [20, 50]87 tensor_num_list = [20, 50]
75 for tensor_num in tensor_num_list :88 for tensor_num in tensor_num_list :
76 cpu_tensors, npu_tensors = self.create_tensors(tensor_num, "float16")89 cpu_tensors, npu_tensors = self.create_tensors(tensor_num, "float16")
77- torch._foreach_erfc_(cpu_tensors)90+ cpu_tensors = [cpu_tensor.numpy() for cpu_tensor in cpu_tensors]
91+ cpu_output = [torch.from_numpy(special.erfc(cpu_tensors[i])).half() for i in range(len(cpu_tensors))]
78 torch._foreach_erfc_(npu_tensors)92 torch._foreach_erfc_(npu_tensors)
79 93 
80- self.assertRtolEqual(cpu_tensors, npu_tensors)94+ self.assertRtolEqual(cpu_output, npu_tensors)
81 95 
82 @SupportedDevices(['Ascend910B'])96 @SupportedDevices(['Ascend910B'])
83 def test_foreach_erfc_inplace_bfloat16_shpae_tensor_num(self):97 def test_foreach_erfc_inplace_bfloat16_shpae_tensor_num(self):
@@ -87,7 +101,7 @@ class TestForeachErfc(TestCase):
87 torch._foreach_erfc_(cpu_tensors)101 torch._foreach_erfc_(cpu_tensors)
88 torch._foreach_erfc_(npu_tensors)102 torch._foreach_erfc_(npu_tensors)
89 103 
90- self.assertRtolEqual(cpu_tensors, npu_tensors)104+ self.assert_equal_bfloat16(cpu_tensors, npu_tensors)
91 105 
92 106 
93if __name__ == "__main__":107if __name__ == "__main__":
@@ -3,6 +3,7 @@ import random
3import torch3import torch
4import torch_npu4import torch_npu
5import hypothesis5import hypothesis
6+import numpy as np
6from torch_npu.testing.testcase import TestCase, run_tests7from torch_npu.testing.testcase import TestCase, run_tests
7from torch_npu.testing.common_utils import SupportedDevices8from torch_npu.testing.common_utils import SupportedDevices
8 9 
@@ -14,6 +15,17 @@ class TestForeachExp(TestCase):
14 "float32" : torch.float32,15 "float32" : torch.float32,
15 "bfloat16" : torch.bfloat16,16 "bfloat16" : torch.bfloat16,
16 }17 }
18+
19+ def assert_equal_bfloat16(self, cpu_outs, npu_outs):
20+ for cpu_out, npu_out in zip(cpu_outs, npu_outs):
21+ if (cpu_out.shape != npu_out.shape):
22+ self.fail("shape error")
23+ if (cpu_out.dtype != npu_out.dtype):
24+ self.fail("dtype error!")
25+ result = torch.allclose(cpu_out, npu_out.cpu(), rtol=0.001, atol=0.001)
26+ if not result:
27+ self.fail("result error!")
28+ return True
17 29 
18 def create_tensors(self, tensor_nums, dtype):30 def create_tensors(self, tensor_nums, dtype):
19 cpu_tensors = []31 cpu_tensors = []
@@ -26,7 +38,7 @@ class TestForeachExp(TestCase):
26 npu_tensors.append(t.npu())38 npu_tensors.append(t.npu())
27 return tuple(cpu_tensors), tuple(npu_tensors)39 return tuple(cpu_tensors), tuple(npu_tensors)
28 40 
29- @SupportedDevices(['Ascend910B'])41+
30 def test_foreach_exp_out_float32_shpae_tensor_num(self):42 def test_foreach_exp_out_float32_shpae_tensor_num(self):
31 tensor_num_list = [12, 62]43 tensor_num_list = [12, 62]
32 for tensor_num in tensor_num_list :44 for tensor_num in tensor_num_list :
@@ -36,12 +48,13 @@ class TestForeachExp(TestCase):
36 48 
37 self.assertRtolEqual(cpu_output, npu_output)49 self.assertRtolEqual(cpu_output, npu_output)
38 50
39- @SupportedDevices(['Ascend910B'])51+
40 def test_foreach_exp_out_float16_shpae_tensor_num(self):52 def test_foreach_exp_out_float16_shpae_tensor_num(self):
41 tensor_num_list = [12, 62]53 tensor_num_list = [12, 62]
42 for tensor_num in tensor_num_list :54 for tensor_num in tensor_num_list :
43 cpu_tensors, npu_tensors = self.create_tensors(tensor_num, "float16")55 cpu_tensors, npu_tensors = self.create_tensors(tensor_num, "float16")
44- cpu_output = torch._foreach_exp(cpu_tensors)56+ cpu_tensors = [cpu_tensor.numpy() for cpu_tensor in cpu_tensors]
57+ cpu_output = [torch.from_numpy(np.exp(cpu_tensors[i])) for i in range(len(cpu_tensors))]
45 npu_output = torch._foreach_exp(npu_tensors)58 npu_output = torch._foreach_exp(npu_tensors)
46 59 
47 self.assertRtolEqual(cpu_output, npu_output)60 self.assertRtolEqual(cpu_output, npu_output)
@@ -54,9 +67,9 @@ class TestForeachExp(TestCase):
54 cpu_output = torch._foreach_exp(cpu_tensors)67 cpu_output = torch._foreach_exp(cpu_tensors)
55 npu_output = torch._foreach_exp(npu_tensors)68 npu_output = torch._foreach_exp(npu_tensors)
56 69 
57- self.assertRtolEqual(cpu_output, npu_output)70+ self.assert_equal_bfloat16(cpu_output, npu_output)
58 71 
59- @SupportedDevices(['Ascend910B'])72+
60 def test_foreach_exp_inplace_float32_shpae_tensor_num(self):73 def test_foreach_exp_inplace_float32_shpae_tensor_num(self):
61 tensor_num_list = [12, 62]74 tensor_num_list = [12, 62]
62 for tensor_num in tensor_num_list :75 for tensor_num in tensor_num_list :
@@ -66,15 +79,16 @@ class TestForeachExp(TestCase):
66 79 
67 self.assertRtolEqual(cpu_tensors, npu_tensors)80 self.assertRtolEqual(cpu_tensors, npu_tensors)
68 81
69- @SupportedDevices(['Ascend910B'])82+
70 def test_foreach_exp_inplace_float16_shpae_tensor_num(self):83 def test_foreach_exp_inplace_float16_shpae_tensor_num(self):
71 tensor_num_list = [12, 62]84 tensor_num_list = [12, 62]
72 for tensor_num in tensor_num_list :85 for tensor_num in tensor_num_list :
73 cpu_tensors, npu_tensors = self.create_tensors(tensor_num, "float16")86 cpu_tensors, npu_tensors = self.create_tensors(tensor_num, "float16")
74- torch._foreach_exp_(cpu_tensors)87+ cpu_tensors = [cpu_tensor.numpy() for cpu_tensor in cpu_tensors]
88+ cpu_output = [torch.from_numpy(np.exp(cpu_tensors[i])) for i in range(len(cpu_tensors))]
75 torch._foreach_exp_(npu_tensors)89 torch._foreach_exp_(npu_tensors)
76 90 
77- self.assertRtolEqual(cpu_tensors, npu_tensors)91+ self.assertRtolEqual(cpu_output, npu_tensors)
78 92 
79 @SupportedDevices(['Ascend910B'])93 @SupportedDevices(['Ascend910B'])
80 def test_foreach_exp_inplace_bfloat16_shpae_tensor_num(self):94 def test_foreach_exp_inplace_bfloat16_shpae_tensor_num(self):
@@ -84,7 +98,7 @@ class TestForeachExp(TestCase):
84 torch._foreach_exp_(cpu_tensors)98 torch._foreach_exp_(cpu_tensors)
85 torch._foreach_exp_(npu_tensors)99 torch._foreach_exp_(npu_tensors)
86 100 
87- self.assertRtolEqual(cpu_tensors, npu_tensors)101+ self.assert_equal_bfloat16(cpu_tensors, npu_tensors)
88 102 
89 103 
90if __name__ == "__main__":104if __name__ == "__main__":
@@ -3,6 +3,7 @@ import random
3import torch3import torch
4import torch_npu4import torch_npu
5import hypothesis5import hypothesis
6+import numpy as np
6from torch_npu.testing.testcase import TestCase, run_tests7from torch_npu.testing.testcase import TestCase, run_tests
7from torch_npu.testing.common_utils import SupportedDevices8from torch_npu.testing.common_utils import SupportedDevices
8 9 
@@ -14,6 +15,17 @@ class TestForeachExpm1(TestCase):
14 "float32" : torch.float32,15 "float32" : torch.float32,
15 "bfloat16" : torch.bfloat16,16 "bfloat16" : torch.bfloat16,
16 }17 }
18+
19+ def assert_equal_bfloat16(self, cpu_outs, npu_outs):
20+ for cpu_out, npu_out in zip(cpu_outs, npu_outs):
21+ if (cpu_out.shape != npu_out.shape):
22+ self.fail("shape error")
23+ if (cpu_out.dtype != npu_out.dtype):
24+ self.fail("dtype error!")
25+ result = torch.allclose(cpu_out, npu_out.cpu(), rtol=0.001, atol=0.001)
26+ if not result:
27+ self.fail("result error!")
28+ return True
17 29 
18 def create_tensors(self, tensor_nums, dtype):30 def create_tensors(self, tensor_nums, dtype):
19 cpu_tensors = []31 cpu_tensors = []
@@ -26,7 +38,7 @@ class TestForeachExpm1(TestCase):
26 npu_tensors.append(t.npu())38 npu_tensors.append(t.npu())
27 return tuple(cpu_tensors), tuple(npu_tensors)39 return tuple(cpu_tensors), tuple(npu_tensors)
28 40 
29- @SupportedDevices(['Ascend910B'])41+
30 def test_foreach_expm1_out_float32_shpae_tensor_num(self):42 def test_foreach_expm1_out_float32_shpae_tensor_num(self):
31 tensor_num_list = [12, 62]43 tensor_num_list = [12, 62]
32 for tensor_num in tensor_num_list :44 for tensor_num in tensor_num_list :
@@ -36,12 +48,13 @@ class TestForeachExpm1(TestCase):
36 48 
37 self.assertRtolEqual(cpu_output, npu_output)49 self.assertRtolEqual(cpu_output, npu_output)
38 50
39- @SupportedDevices(['Ascend910B'])51+
40 def test_foreach_expm1_out_float16_shpae_tensor_num(self):52 def test_foreach_expm1_out_float16_shpae_tensor_num(self):
41 tensor_num_list = [12, 62]53 tensor_num_list = [12, 62]
42 for tensor_num in tensor_num_list :54 for tensor_num in tensor_num_list :
43 cpu_tensors, npu_tensors = self.create_tensors(tensor_num, "float16")55 cpu_tensors, npu_tensors = self.create_tensors(tensor_num, "float16")
44- cpu_output = torch._foreach_expm1(cpu_tensors)56+ cpu_tensors = [cpu_tensor.numpy() for cpu_tensor in cpu_tensors]
57+ cpu_output = [torch.from_numpy(np.expm1(cpu_tensors[i])) for i in range(len(cpu_tensors))]
45 npu_output = torch._foreach_expm1(npu_tensors)58 npu_output = torch._foreach_expm1(npu_tensors)
46 59 
47 self.assertRtolEqual(cpu_output, npu_output)60 self.assertRtolEqual(cpu_output, npu_output)
@@ -54,9 +67,9 @@ class TestForeachExpm1(TestCase):
54 cpu_output = torch._foreach_expm1(cpu_tensors)67 cpu_output = torch._foreach_expm1(cpu_tensors)
55 npu_output = torch._foreach_expm1(npu_tensors)68 npu_output = torch._foreach_expm1(npu_tensors)
56 69 
57- self.assertRtolEqual(cpu_output, npu_output)70+ self.assert_equal_bfloat16(cpu_output, npu_output)
58 71 
59- @SupportedDevices(['Ascend910B'])72+
60 def test_foreach_expm1_inplace_float32_shpae_tensor_num(self):73 def test_foreach_expm1_inplace_float32_shpae_tensor_num(self):
61 tensor_num_list = [12, 62]74 tensor_num_list = [12, 62]
62 for tensor_num in tensor_num_list :75 for tensor_num in tensor_num_list :
@@ -66,15 +79,16 @@ class TestForeachExpm1(TestCase):
66 79 
67 self.assertRtolEqual(cpu_tensors, npu_tensors)80 self.assertRtolEqual(cpu_tensors, npu_tensors)
68 81
69- @SupportedDevices(['Ascend910B'])82+
70 def test_foreach_expm1_inplace_float16_shpae_tensor_num(self):83 def test_foreach_expm1_inplace_float16_shpae_tensor_num(self):
71 tensor_num_list = [12, 62]84 tensor_num_list = [12, 62]
72 for tensor_num in tensor_num_list :85 for tensor_num in tensor_num_list :
73 cpu_tensors, npu_tensors = self.create_tensors(tensor_num, "float16")86 cpu_tensors, npu_tensors = self.create_tensors(tensor_num, "float16")
74- torch._foreach_expm1_(cpu_tensors)87+ cpu_tensors = [cpu_tensor.numpy() for cpu_tensor in cpu_tensors]
88+ cpu_output = [torch.from_numpy(np.expm1(cpu_tensors[i])) for i in range(len(cpu_tensors))]
75 torch._foreach_expm1_(npu_tensors)89 torch._foreach_expm1_(npu_tensors)
76 90 
77- self.assertRtolEqual(cpu_tensors, npu_tensors)91+ self.assertRtolEqual(cpu_output, npu_tensors)
78 92 
79 @SupportedDevices(['Ascend910B'])93 @SupportedDevices(['Ascend910B'])
80 def test_foreach_expm1_inplace_bfloat16_shpae_tensor_num(self):94 def test_foreach_expm1_inplace_bfloat16_shpae_tensor_num(self):
@@ -84,7 +98,7 @@ class TestForeachExpm1(TestCase):
84 torch._foreach_expm1_(cpu_tensors)98 torch._foreach_expm1_(cpu_tensors)
85 torch._foreach_expm1_(npu_tensors)99 torch._foreach_expm1_(npu_tensors)
86 100 
87- self.assertRtolEqual(cpu_tensors, npu_tensors)101+ self.assert_equal_bfloat16(cpu_tensors, npu_tensors)
88 102 
89 103 
90if __name__ == "__main__":104if __name__ == "__main__":
@@ -3,6 +3,7 @@ import random
3import torch3import torch
4import torch_npu4import torch_npu
5import hypothesis5import hypothesis
6+import numpy as np
6from torch_npu.testing.testcase import TestCase, run_tests7from torch_npu.testing.testcase import TestCase, run_tests
7from torch_npu.testing.common_utils import SupportedDevices8from torch_npu.testing.common_utils import SupportedDevices
8 9 
@@ -14,6 +15,17 @@ class TestForeachLog(TestCase):
14 "float32" : torch.float32,15 "float32" : torch.float32,
15 "bfloat16" : torch.bfloat16,16 "bfloat16" : torch.bfloat16,
16 }17 }
18+
19+ def assert_equal_bfloat16(self, cpu_outs, npu_outs):
20+ for cpu_out, npu_out in zip(cpu_outs, npu_outs):
21+ if (cpu_out.shape != npu_out.shape):
22+ self.fail("shape error")
23+ if (cpu_out.dtype != npu_out.dtype):
24+ self.fail("dtype error!")
25+ result = torch.allclose(cpu_out, npu_out.cpu(), rtol=0.001, atol=0.001)
26+ if not result:
27+ self.fail("result error!")
28+ return True
17 29 
18 def create_tensors(self, tensor_nums, dtype):30 def create_tensors(self, tensor_nums, dtype):
19 cpu_tensors = []31 cpu_tensors = []
@@ -21,12 +33,12 @@ class TestForeachLog(TestCase):
21 for i in range(tensor_nums):33 for i in range(tensor_nums):
22 m = random.randint(1, 100)34 m = random.randint(1, 100)
23 n = random.randint(1, 100)35 n = random.randint(1, 100)
24- t = torch.rand((m, n), dtype=self.torch_dtypes.get(dtype)) * 100 36+ t = torch.rand((m, n), dtype=self.torch_dtypes.get(dtype)) * 100 + 1
25 cpu_tensors.append(t)37 cpu_tensors.append(t)
26 npu_tensors.append(t.npu())38 npu_tensors.append(t.npu())
27 return tuple(cpu_tensors), tuple(npu_tensors)39 return tuple(cpu_tensors), tuple(npu_tensors)
28 40 
29- @SupportedDevices(['Ascend910B'])41+
30 def test_foreach_log_out_float32_shpae_tensor_num(self):42 def test_foreach_log_out_float32_shpae_tensor_num(self):
31 tensor_num_list = [12, 62]43 tensor_num_list = [12, 62]
32 for tensor_num in tensor_num_list :44 for tensor_num in tensor_num_list :
@@ -36,12 +48,13 @@ class TestForeachLog(TestCase):
36 48 
37 self.assertRtolEqual(cpu_output, npu_output)49 self.assertRtolEqual(cpu_output, npu_output)
38 50
39- @SupportedDevices(['Ascend910B'])51+
40 def test_foreach_log_out_float16_shpae_tensor_num(self):52 def test_foreach_log_out_float16_shpae_tensor_num(self):
41 tensor_num_list = [12, 62]53 tensor_num_list = [12, 62]
42 for tensor_num in tensor_num_list :54 for tensor_num in tensor_num_list :
43 cpu_tensors, npu_tensors = self.create_tensors(tensor_num, "float16")55 cpu_tensors, npu_tensors = self.create_tensors(tensor_num, "float16")
44- cpu_output = torch._foreach_log(cpu_tensors)56+ cpu_tensors = [cpu_tensor.numpy() for cpu_tensor in cpu_tensors]
57+ cpu_output = [torch.from_numpy(np.log(cpu_tensors[i])) for i in range(len(cpu_tensors))]
45 npu_output = torch._foreach_log(npu_tensors)58 npu_output = torch._foreach_log(npu_tensors)
46 59 
47 self.assertRtolEqual(cpu_output, npu_output)60 self.assertRtolEqual(cpu_output, npu_output)
@@ -54,9 +67,9 @@ class TestForeachLog(TestCase):
54 cpu_output = torch._foreach_log(cpu_tensors)67 cpu_output = torch._foreach_log(cpu_tensors)
55 npu_output = torch._foreach_log(npu_tensors)68 npu_output = torch._foreach_log(npu_tensors)
56 69 
57- self.assertRtolEqual(cpu_output, npu_output)70+ self.assert_equal_bfloat16(cpu_output, npu_output)
58 71 
59- @SupportedDevices(['Ascend910B'])72+
60 def test_foreach_log_inplace_float32_shpae_tensor_num(self):73 def test_foreach_log_inplace_float32_shpae_tensor_num(self):
61 tensor_num_list = [12, 62]74 tensor_num_list = [12, 62]
62 for tensor_num in tensor_num_list :75 for tensor_num in tensor_num_list :
@@ -66,15 +79,16 @@ class TestForeachLog(TestCase):
66 79 
67 self.assertRtolEqual(cpu_tensors, npu_tensors)80 self.assertRtolEqual(cpu_tensors, npu_tensors)
68 81
69- @SupportedDevices(['Ascend910B'])82+
70 def test_foreach_log_inplace_float16_shpae_tensor_num(self):83 def test_foreach_log_inplace_float16_shpae_tensor_num(self):
71 tensor_num_list = [12, 62]84 tensor_num_list = [12, 62]
72 for tensor_num in tensor_num_list :85 for tensor_num in tensor_num_list :
73 cpu_tensors, npu_tensors = self.create_tensors(tensor_num, "float16")86 cpu_tensors, npu_tensors = self.create_tensors(tensor_num, "float16")
74- torch._foreach_log_(cpu_tensors)87+ cpu_tensors = [cpu_tensor.numpy() for cpu_tensor in cpu_tensors]
88+ cpu_output = [torch.from_numpy(np.log(cpu_tensors[i])) for i in range(len(cpu_tensors))]
75 torch._foreach_log_(npu_tensors)89 torch._foreach_log_(npu_tensors)
76 90 
77- self.assertRtolEqual(cpu_tensors, npu_tensors)91+ self.assertRtolEqual(cpu_output, npu_tensors)
78 92 
79 @SupportedDevices(['Ascend910B'])93 @SupportedDevices(['Ascend910B'])
80 def test_foreach_log_inplace_bfloat16_shpae_tensor_num(self):94 def test_foreach_log_inplace_bfloat16_shpae_tensor_num(self):
@@ -84,7 +98,7 @@ class TestForeachLog(TestCase):
84 torch._foreach_log_(cpu_tensors)98 torch._foreach_log_(cpu_tensors)
85 torch._foreach_log_(npu_tensors)99 torch._foreach_log_(npu_tensors)
86 100 
87- self.assertRtolEqual(cpu_tensors, npu_tensors)101+ self.assert_equal_bfloat16(cpu_tensors, npu_tensors)
88 102 
89 103 
90if __name__ == "__main__":104if __name__ == "__main__":
@@ -3,6 +3,7 @@ import random
3import torch3import torch
4import torch_npu4import torch_npu
5import hypothesis5import hypothesis
6+import numpy as np
6from torch_npu.testing.testcase import TestCase, run_tests7from torch_npu.testing.testcase import TestCase, run_tests
7from torch_npu.testing.common_utils import SupportedDevices8from torch_npu.testing.common_utils import SupportedDevices
8 9 
@@ -14,6 +15,17 @@ class TestForeachLog10(TestCase):
14 "float32" : torch.float32,15 "float32" : torch.float32,
15 "bfloat16" : torch.bfloat16,16 "bfloat16" : torch.bfloat16,
16 }17 }
18+
19+ def assert_equal_bfloat16(self, cpu_outs, npu_outs):
20+ for cpu_out, npu_out in zip(cpu_outs, npu_outs):
21+ if (cpu_out.shape != npu_out.shape):
22+ self.fail("shape error")
23+ if (cpu_out.dtype != npu_out.dtype):
24+ self.fail("dtype error!")
25+ result = torch.allclose(cpu_out, npu_out.cpu(), rtol=0.001, atol=0.001)
26+ if not result:
27+ self.fail("result error!")
28+ return True
17 29 
18 def create_tensors(self, tensor_nums, dtype):30 def create_tensors(self, tensor_nums, dtype):
19 cpu_tensors = []31 cpu_tensors = []
@@ -26,7 +38,7 @@ class TestForeachLog10(TestCase):
26 npu_tensors.append(t.npu())38 npu_tensors.append(t.npu())
27 return tuple(cpu_tensors), tuple(npu_tensors)39 return tuple(cpu_tensors), tuple(npu_tensors)
28 40 
29- @SupportedDevices(['Ascend910B'])41+
30 def test_foreach_log10_out_float32_shpae_tensor_num(self):42 def test_foreach_log10_out_float32_shpae_tensor_num(self):
31 tensor_num_list = [12, 62]43 tensor_num_list = [12, 62]
32 for tensor_num in tensor_num_list :44 for tensor_num in tensor_num_list :
@@ -36,12 +48,13 @@ class TestForeachLog10(TestCase):
36 48 
37 self.assertRtolEqual(cpu_output, npu_output)49 self.assertRtolEqual(cpu_output, npu_output)
38 50
39- @SupportedDevices(['Ascend910B'])51+
40 def test_foreach_log10_out_float16_shpae_tensor_num(self):52 def test_foreach_log10_out_float16_shpae_tensor_num(self):
41 tensor_num_list = [12, 62]53 tensor_num_list = [12, 62]
42 for tensor_num in tensor_num_list :54 for tensor_num in tensor_num_list :
43 cpu_tensors, npu_tensors = self.create_tensors(tensor_num, "float16")55 cpu_tensors, npu_tensors = self.create_tensors(tensor_num, "float16")
44- cpu_output = torch._foreach_log10(cpu_tensors)56+ cpu_tensors = [cpu_tensor.numpy() for cpu_tensor in cpu_tensors]
57+ cpu_output = [torch.from_numpy(np.log10(cpu_tensors[i])) for i in range(len(cpu_tensors))]
45 npu_output = torch._foreach_log10(npu_tensors)58 npu_output = torch._foreach_log10(npu_tensors)
46 59 
47 self.assertRtolEqual(cpu_output, npu_output)60 self.assertRtolEqual(cpu_output, npu_output)
@@ -54,9 +67,9 @@ class TestForeachLog10(TestCase):
54 cpu_output = torch._foreach_log10(cpu_tensors)67 cpu_output = torch._foreach_log10(cpu_tensors)
55 npu_output = torch._foreach_log10(npu_tensors)68 npu_output = torch._foreach_log10(npu_tensors)
56 69 
57- self.assertRtolEqual(cpu_output, npu_output)70+ self.assert_equal_bfloat16(cpu_output, npu_output)
58 71 
59- @SupportedDevices(['Ascend910B'])72+
60 def test_foreach_log10_inplace_float32_shpae_tensor_num(self):73 def test_foreach_log10_inplace_float32_shpae_tensor_num(self):
61 tensor_num_list = [12, 62]74 tensor_num_list = [12, 62]
62 for tensor_num in tensor_num_list :75 for tensor_num in tensor_num_list :
@@ -66,15 +79,16 @@ class TestForeachLog10(TestCase):
66 79 
67 self.assertRtolEqual(cpu_tensors, npu_tensors)80 self.assertRtolEqual(cpu_tensors, npu_tensors)
68 81
69- @SupportedDevices(['Ascend910B'])82+
70 def test_foreach_log10_inplace_float16_shpae_tensor_num(self):83 def test_foreach_log10_inplace_float16_shpae_tensor_num(self):
71 tensor_num_list = [12, 62]84 tensor_num_list = [12, 62]
72 for tensor_num in tensor_num_list :85 for tensor_num in tensor_num_list :
73 cpu_tensors, npu_tensors = self.create_tensors(tensor_num, "float16")86 cpu_tensors, npu_tensors = self.create_tensors(tensor_num, "float16")
74- torch._foreach_log10_(cpu_tensors)87+ cpu_tensors = [cpu_tensor.numpy() for cpu_tensor in cpu_tensors]
88+ cpu_output = [torch.from_numpy(np.log10(cpu_tensors[i])) for i in range(len(cpu_tensors))]
75 torch._foreach_log10_(npu_tensors)89 torch._foreach_log10_(npu_tensors)
76 90 
77- self.assertRtolEqual(cpu_tensors, npu_tensors)91+ self.assertRtolEqual(cpu_output, npu_tensors)
78 92 
79 @SupportedDevices(['Ascend910B'])93 @SupportedDevices(['Ascend910B'])
80 def test_foreach_log10_inplace_bfloat16_shpae_tensor_num(self):94 def test_foreach_log10_inplace_bfloat16_shpae_tensor_num(self):
@@ -84,7 +98,7 @@ class TestForeachLog10(TestCase):
84 torch._foreach_log10_(cpu_tensors)98 torch._foreach_log10_(cpu_tensors)
85 torch._foreach_log10_(npu_tensors)99 torch._foreach_log10_(npu_tensors)
86 100 
87- self.assertRtolEqual(cpu_tensors, npu_tensors)101+ self.assert_equal_bfloat16(cpu_tensors, npu_tensors)
88 102 
89 103 
90if __name__ == "__main__":104if __name__ == "__main__":
@@ -3,6 +3,7 @@ import random
3import torch3import torch
4import torch_npu4import torch_npu
5import hypothesis5import hypothesis
6+import numpy as np
6from torch_npu.testing.testcase import TestCase, run_tests7from torch_npu.testing.testcase import TestCase, run_tests
7from torch_npu.testing.common_utils import SupportedDevices8from torch_npu.testing.common_utils import SupportedDevices
8 9 
@@ -14,6 +15,17 @@ class TestForeachLog1p(TestCase):
14 "float32" : torch.float32,15 "float32" : torch.float32,
15 "bfloat16" : torch.bfloat16,16 "bfloat16" : torch.bfloat16,
16 }17 }
18+
19+ def assert_equal_bfloat16(self, cpu_outs, npu_outs):
20+ for cpu_out, npu_out in zip(cpu_outs, npu_outs):
21+ if (cpu_out.shape != npu_out.shape):
22+ self.fail("shape error")
23+ if (cpu_out.dtype != npu_out.dtype):
24+ self.fail("dtype error!")
25+ result = torch.allclose(cpu_out, npu_out.cpu(), rtol=0.001, atol=0.001)
26+ if not result:
27+ self.fail("result error!")
28+ return True
17 29 
18 def create_tensors(self, tensor_nums, dtype):30 def create_tensors(self, tensor_nums, dtype):
19 cpu_tensors = []31 cpu_tensors = []
@@ -26,7 +38,7 @@ class TestForeachLog1p(TestCase):
26 npu_tensors.append(t.npu())38 npu_tensors.append(t.npu())
27 return tuple(cpu_tensors), tuple(npu_tensors)39 return tuple(cpu_tensors), tuple(npu_tensors)
28 40 
29- @SupportedDevices(['Ascend910B'])41+
30 def test_foreach_log1p_out_float32_shpae_tensor_num(self):42 def test_foreach_log1p_out_float32_shpae_tensor_num(self):
31 tensor_num_list = [12, 62]43 tensor_num_list = [12, 62]
32 for tensor_num in tensor_num_list :44 for tensor_num in tensor_num_list :
@@ -36,12 +48,13 @@ class TestForeachLog1p(TestCase):
36 48 
37 self.assertRtolEqual(cpu_output, npu_output)49 self.assertRtolEqual(cpu_output, npu_output)
38 50
39- @SupportedDevices(['Ascend910B'])51+
40 def test_foreach_log1p_out_float16_shpae_tensor_num(self):52 def test_foreach_log1p_out_float16_shpae_tensor_num(self):
41 tensor_num_list = [12, 62]53 tensor_num_list = [12, 62]
42 for tensor_num in tensor_num_list :54 for tensor_num in tensor_num_list :
43 cpu_tensors, npu_tensors = self.create_tensors(tensor_num, "float16")55 cpu_tensors, npu_tensors = self.create_tensors(tensor_num, "float16")
44- cpu_output = torch._foreach_log1p(cpu_tensors)56+ cpu_tensors = [cpu_tensor.numpy() for cpu_tensor in cpu_tensors]
57+ cpu_output = [torch.from_numpy(np.log1p(cpu_tensors[i])) for i in range(len(cpu_tensors))]
45 npu_output = torch._foreach_log1p(npu_tensors)58 npu_output = torch._foreach_log1p(npu_tensors)
46 59 
47 self.assertRtolEqual(cpu_output, npu_output)60 self.assertRtolEqual(cpu_output, npu_output)
@@ -54,9 +67,9 @@ class TestForeachLog1p(TestCase):
54 cpu_output = torch._foreach_log1p(cpu_tensors)67 cpu_output = torch._foreach_log1p(cpu_tensors)
55 npu_output = torch._foreach_log1p(npu_tensors)68 npu_output = torch._foreach_log1p(npu_tensors)
56 69 
57- self.assertRtolEqual(cpu_output, npu_output)70+ self.assert_equal_bfloat16(cpu_output, npu_output)
58 71 
59- @SupportedDevices(['Ascend910B'])72+
60 def test_foreach_log1p_inplace_float32_shpae_tensor_num(self):73 def test_foreach_log1p_inplace_float32_shpae_tensor_num(self):
61 tensor_num_list = [12, 62]74 tensor_num_list = [12, 62]
62 for tensor_num in tensor_num_list :75 for tensor_num in tensor_num_list :
@@ -66,15 +79,16 @@ class TestForeachLog1p(TestCase):
66 79 
67 self.assertRtolEqual(cpu_tensors, npu_tensors)80 self.assertRtolEqual(cpu_tensors, npu_tensors)
68 81
69- @SupportedDevices(['Ascend910B'])82+
70 def test_foreach_log1p_inplace_float16_shpae_tensor_num(self):83 def test_foreach_log1p_inplace_float16_shpae_tensor_num(self):
71 tensor_num_list = [12, 62]84 tensor_num_list = [12, 62]
72 for tensor_num in tensor_num_list :85 for tensor_num in tensor_num_list :
73 cpu_tensors, npu_tensors = self.create_tensors(tensor_num, "float16")86 cpu_tensors, npu_tensors = self.create_tensors(tensor_num, "float16")
74- torch._foreach_log1p_(cpu_tensors)87+ cpu_tensors = [cpu_tensor.numpy() for cpu_tensor in cpu_tensors]
88+ cpu_output = [torch.from_numpy(np.log1p(cpu_tensors[i])) for i in range(len(cpu_tensors))]
75 torch._foreach_log1p_(npu_tensors)89 torch._foreach_log1p_(npu_tensors)
76 90 
77- self.assertRtolEqual(cpu_tensors, npu_tensors)91+ self.assertRtolEqual(cpu_output, npu_tensors)
78 92 
79 @SupportedDevices(['Ascend910B'])93 @SupportedDevices(['Ascend910B'])
80 def test_foreach_log1p_inplace_bfloat16_shpae_tensor_num(self):94 def test_foreach_log1p_inplace_bfloat16_shpae_tensor_num(self):
@@ -84,7 +98,7 @@ class TestForeachLog1p(TestCase):
84 torch._foreach_log1p_(cpu_tensors)98 torch._foreach_log1p_(cpu_tensors)
85 torch._foreach_log1p_(npu_tensors)99 torch._foreach_log1p_(npu_tensors)
86 100 
87- self.assertRtolEqual(cpu_tensors, npu_tensors)101+ self.assert_equal_bfloat16(cpu_tensors, npu_tensors)
88 102 
89 103 
90if __name__ == "__main__":104if __name__ == "__main__":
@@ -3,6 +3,7 @@ import random
3import torch3import torch
4import torch_npu4import torch_npu
5import hypothesis5import hypothesis
6+import numpy as np
6from torch_npu.testing.testcase import TestCase, run_tests7from torch_npu.testing.testcase import TestCase, run_tests
7from torch_npu.testing.common_utils import SupportedDevices8from torch_npu.testing.common_utils import SupportedDevices
8 9 
@@ -14,6 +15,17 @@ class TestForeachLog2(TestCase):
14 "float32" : torch.float32,15 "float32" : torch.float32,
15 "bfloat16" : torch.bfloat16,16 "bfloat16" : torch.bfloat16,
16 }17 }
18+
19+ def assert_equal(self, cpu_outs, npu_outs):
20+ for cpu_out, npu_out in zip(cpu_outs, npu_outs):
21+ if (cpu_out.shape != npu_out.shape):
22+ self.fail("shape error")
23+ if (cpu_out.dtype != npu_out.dtype):
24+ self.fail("dtype error!")
25+ result = torch.allclose(cpu_out, npu_out.cpu(), rtol=0.001, atol=0.001)
26+ if not result:
27+ self.fail("result error!")
28+ return True
17 29 
18 def create_tensors(self, tensor_nums, dtype):30 def create_tensors(self, tensor_nums, dtype):
19 cpu_tensors = []31 cpu_tensors = []
@@ -26,7 +38,7 @@ class TestForeachLog2(TestCase):
26 npu_tensors.append(t.npu())38 npu_tensors.append(t.npu())
27 return tuple(cpu_tensors), tuple(npu_tensors)39 return tuple(cpu_tensors), tuple(npu_tensors)
28 40 
29- @SupportedDevices(['Ascend910B'])41+
30 def test_foreach_log2_out_float32_shpae_tensor_num(self):42 def test_foreach_log2_out_float32_shpae_tensor_num(self):
31 tensor_num_list = [12, 62]43 tensor_num_list = [12, 62]
32 for tensor_num in tensor_num_list :44 for tensor_num in tensor_num_list :
@@ -36,15 +48,16 @@ class TestForeachLog2(TestCase):
36 48 
37 self.assertRtolEqual(cpu_output, npu_output)49 self.assertRtolEqual(cpu_output, npu_output)
38 50
39- @SupportedDevices(['Ascend910B'])51+
40 def test_foreach_log2_out_float16_shpae_tensor_num(self):52 def test_foreach_log2_out_float16_shpae_tensor_num(self):
41 tensor_num_list = [12, 62]53 tensor_num_list = [12, 62]
42 for tensor_num in tensor_num_list :54 for tensor_num in tensor_num_list :
43 cpu_tensors, npu_tensors = self.create_tensors(tensor_num, "float16")55 cpu_tensors, npu_tensors = self.create_tensors(tensor_num, "float16")
44- cpu_output = torch._foreach_log2(cpu_tensors)56+ cpu_tensors = [cpu_tensor.numpy() for cpu_tensor in cpu_tensors]
57+ cpu_output = [torch.from_numpy(np.log2(cpu_tensor)) for cpu_tensor in cpu_tensors]
45 npu_output = torch._foreach_log2(npu_tensors)58 npu_output = torch._foreach_log2(npu_tensors)
46 59 
47- self.assertRtolEqual(cpu_output, npu_output)60+ self.assert_equal(cpu_output, npu_output)
48 61 
49 @SupportedDevices(['Ascend910B'])62 @SupportedDevices(['Ascend910B'])
50 def test_foreach_log2_out_bfloat16_shpae_tensor_num(self):63 def test_foreach_log2_out_bfloat16_shpae_tensor_num(self):
@@ -54,9 +67,9 @@ class TestForeachLog2(TestCase):
54 cpu_output = torch._foreach_log2(cpu_tensors)67 cpu_output = torch._foreach_log2(cpu_tensors)
55 npu_output = torch._foreach_log2(npu_tensors)68 npu_output = torch._foreach_log2(npu_tensors)
56 69 
57- self.assertRtolEqual(cpu_output, npu_output)70+ self.assert_equal(cpu_output, npu_output)
58 71 
59- @SupportedDevices(['Ascend910B'])72+
60 def test_foreach_log2_inplace_float32_shpae_tensor_num(self):73 def test_foreach_log2_inplace_float32_shpae_tensor_num(self):
61 tensor_num_list = [12, 62]74 tensor_num_list = [12, 62]
62 for tensor_num in tensor_num_list :75 for tensor_num in tensor_num_list :
@@ -66,15 +79,16 @@ class TestForeachLog2(TestCase):
66 79 
67 self.assertRtolEqual(cpu_tensors, npu_tensors)80 self.assertRtolEqual(cpu_tensors, npu_tensors)
68 81
69- @SupportedDevices(['Ascend910B'])82+
70 def test_foreach_log2_inplace_float16_shpae_tensor_num(self):83 def test_foreach_log2_inplace_float16_shpae_tensor_num(self):
71 tensor_num_list = [12, 62]84 tensor_num_list = [12, 62]
72 for tensor_num in tensor_num_list :85 for tensor_num in tensor_num_list :
73 cpu_tensors, npu_tensors = self.create_tensors(tensor_num, "float16")86 cpu_tensors, npu_tensors = self.create_tensors(tensor_num, "float16")
74- torch._foreach_log2_(cpu_tensors)87+ cpu_tensors = [cpu_tensor.numpy() for cpu_tensor in cpu_tensors]
75- torch._foreach_log2_(npu_tensors)88+ cpu_output = [torch.from_numpy(np.log2(cpu_tensor)) for cpu_tensor in cpu_tensors]
89+ npu_output = torch._foreach_log2(npu_tensors)
76 90 
77- self.assertRtolEqual(cpu_tensors, npu_tensors)91+ self.assert_equal(cpu_output, npu_output)
78 92 
79 @SupportedDevices(['Ascend910B'])93 @SupportedDevices(['Ascend910B'])
80 def test_foreach_log2_inplace_bfloat16_shpae_tensor_num(self):94 def test_foreach_log2_inplace_bfloat16_shpae_tensor_num(self):
@@ -84,7 +98,7 @@ class TestForeachLog2(TestCase):
84 torch._foreach_log2_(cpu_tensors)98 torch._foreach_log2_(cpu_tensors)
85 torch._foreach_log2_(npu_tensors)99 torch._foreach_log2_(npu_tensors)
86 100 
87- self.assertRtolEqual(cpu_tensors, npu_tensors)101+ self.assert_equal(cpu_tensors, npu_tensors)
88 102 
89 103 
90if __name__ == "__main__":104if __name__ == "__main__":
@@ -15,6 +15,17 @@ class TestForeachMulList(TestCase):
15 "int32" : torch.int32,15 "int32" : torch.int32,
16 "bfloat16" : torch.bfloat1616 "bfloat16" : torch.bfloat16
17 }17 }
18+
19+ def assert_equal_bfloat16(self, cpu_outs, npu_outs):
20+ for cpu_out, npu_out in zip(cpu_outs, npu_outs):
21+ if (cpu_out.shape != npu_out.shape):
22+ self.fail("shape error")
23+ if (cpu_out.dtype != npu_out.dtype):
24+ self.fail("dtype error!")
25+ result = torch.allclose(cpu_out, npu_out.cpu(), rtol=0.001, atol=0.001)
26+ if not result:
27+ self.fail("result error!")
28+ return True
18 29 
19 def create_tensors(self, dtype, shapes):30 def create_tensors(self, dtype, shapes):
20 cpu_tensors = []31 cpu_tensors = []
@@ -46,7 +57,7 @@ class TestForeachMulList(TestCase):
46 npu_inputs.append(npu_tensors)57 npu_inputs.append(npu_tensors)
47 return cpu_inputs, npu_inputs58 return cpu_inputs, npu_inputs
48 59 
49- @SupportedDevices(['Ascend910B'])60+
50 def test_foreach_mul_list_out_float32_shpae_tensor_num(self):61 def test_foreach_mul_list_out_float32_shpae_tensor_num(self):
51 tensor_num_list = [20, 50]62 tensor_num_list = [20, 50]
52 for tensor_num in tensor_num_list :63 for tensor_num in tensor_num_list :
@@ -57,7 +68,7 @@ class TestForeachMulList(TestCase):
57 68 
58 self.assertRtolEqual(cpu_output, npu_output)69 self.assertRtolEqual(cpu_output, npu_output)
59 70
60- @SupportedDevices(['Ascend910B'])71+
61 def test_foreach_mul_list_out_float16_shpae_tensor_num(self):72 def test_foreach_mul_list_out_float16_shpae_tensor_num(self):
62 tensor_num_list = [20, 50]73 tensor_num_list = [20, 50]
63 for tensor_num in tensor_num_list :74 for tensor_num in tensor_num_list :
@@ -77,9 +88,9 @@ class TestForeachMulList(TestCase):
77 cpu_output = torch._foreach_mul(cpu_tensors[0], cpu_tensors[1])88 cpu_output = torch._foreach_mul(cpu_tensors[0], cpu_tensors[1])
78 npu_output = torch._foreach_mul(npu_tensors[0], npu_tensors[1])89 npu_output = torch._foreach_mul(npu_tensors[0], npu_tensors[1])
79 90 
80- self.assertRtolEqual(cpu_output, npu_output)91+ self.assert_equal_bfloat16(cpu_output, npu_output)
81 92
82- @SupportedDevices(['Ascend910B'])93+
83 def test_foreach_mul_list_out_int32_shpae_tensor_num(self):94 def test_foreach_mul_list_out_int32_shpae_tensor_num(self):
84 tensor_num_list = [20, 50]95 tensor_num_list = [20, 50]
85 for tensor_num in tensor_num_list :96 for tensor_num in tensor_num_list :
@@ -90,7 +101,7 @@ class TestForeachMulList(TestCase):
90 101 
91 self.assertRtolEqual(cpu_output, npu_output)102 self.assertRtolEqual(cpu_output, npu_output)
92 103 
93- @SupportedDevices(['Ascend910B'])104+
94 def test_foreach_mul_list_inplace_float32_shpae_tensor_num(self):105 def test_foreach_mul_list_inplace_float32_shpae_tensor_num(self):
95 106
96 tensor_num_list = [20, 50]107 tensor_num_list = [20, 50]
@@ -102,7 +113,7 @@ class TestForeachMulList(TestCase):
102 113 
103 self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])114 self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])
104 115
105- @SupportedDevices(['Ascend910B'])116+
106 def test_foreach_mul_list_inplace_float16_shpae_tensor_num(self):117 def test_foreach_mul_list_inplace_float16_shpae_tensor_num(self):
107 tensor_num_list = [20, 50]118 tensor_num_list = [20, 50]
108 for tensor_num in tensor_num_list :119 for tensor_num in tensor_num_list :
@@ -122,9 +133,9 @@ class TestForeachMulList(TestCase):
122 torch._foreach_mul_(cpu_tensors[0], cpu_tensors[1])133 torch._foreach_mul_(cpu_tensors[0], cpu_tensors[1])
123 torch._foreach_mul_(npu_tensors[0], npu_tensors[1])134 torch._foreach_mul_(npu_tensors[0], npu_tensors[1])
124 135 
125- self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])136+ self.assert_equal_bfloat16(cpu_tensors[0], npu_tensors[0])
126 137 
127- @SupportedDevices(['Ascend910B'])138+
128 def test_foreach_mul_list_inplace_int32_shpae_tensor_num(self):139 def test_foreach_mul_list_inplace_int32_shpae_tensor_num(self):
129 tensor_num_list = [20, 50]140 tensor_num_list = [20, 50]
130 for tensor_num in tensor_num_list :141 for tensor_num in tensor_num_list :
@@ -16,6 +16,17 @@ class TestForeachMulScalar(TestCase):
16 "bfloat16" : torch.bfloat1616 "bfloat16" : torch.bfloat16
17 }17 }
18 18
19+ def assert_equal_bfloat16(self, cpu_outs, npu_outs):
20+ for cpu_out, npu_out in zip(cpu_outs, npu_outs):
21+ if (cpu_out.shape != npu_out.shape):
22+ self.fail("shape error")
23+ if (cpu_out.dtype != npu_out.dtype):
24+ self.fail("dtype error!")
25+ result = torch.allclose(cpu_out, npu_out.cpu(), rtol=0.001, atol=0.001)
26+ if not result:
27+ self.fail("result error!")
28+ return True
29+
19 def create_tensors(self, dtype, shapes):30 def create_tensors(self, dtype, shapes):
20 cpu_tensors = []31 cpu_tensors = []
21 npu_tensors = []32 npu_tensors = []
@@ -46,7 +57,7 @@ class TestForeachMulScalar(TestCase):
46 npu_inputs.append(npu_tensors)57 npu_inputs.append(npu_tensors)
47 return cpu_inputs, npu_inputs58 return cpu_inputs, npu_inputs
48 59 
49- @SupportedDevices(['Ascend910B'])60+
50 def test_foreach_mul_scalar_out_float32_shpae_tensor_num(self):61 def test_foreach_mul_scalar_out_float32_shpae_tensor_num(self):
51 tensor_num_list = [20, 50]62 tensor_num_list = [20, 50]
52 for tensor_num in tensor_num_list :63 for tensor_num in tensor_num_list :
@@ -57,7 +68,7 @@ class TestForeachMulScalar(TestCase):
57 68 
58 self.assertRtolEqual(cpu_output, npu_output)69 self.assertRtolEqual(cpu_output, npu_output)
59 70
60- @SupportedDevices(['Ascend910B'])71+
61 def test_foreach_mul_scalar_out_float16_shpae_tensor_num(self):72 def test_foreach_mul_scalar_out_float16_shpae_tensor_num(self):
62 tensor_num_list = [20, 50]73 tensor_num_list = [20, 50]
63 for tensor_num in tensor_num_list :74 for tensor_num in tensor_num_list :
@@ -77,9 +88,9 @@ class TestForeachMulScalar(TestCase):
77 cpu_output = torch._foreach_mul(cpu_tensors[0], scalar)88 cpu_output = torch._foreach_mul(cpu_tensors[0], scalar)
78 npu_output = torch._foreach_mul(npu_tensors[0], scalar)89 npu_output = torch._foreach_mul(npu_tensors[0], scalar)
79 90 
80- self.assertRtolEqual(cpu_output, npu_output)91+ self.assert_equal_bfloat16(cpu_output, npu_output)
81 92
82- @SupportedDevices(['Ascend910B'])93+
83 def test_foreach_mul_scalar_out_int32_shpae_tensor_num(self):94 def test_foreach_mul_scalar_out_int32_shpae_tensor_num(self):
84 tensor_num_list = [20, 50]95 tensor_num_list = [20, 50]
85 for tensor_num in tensor_num_list :96 for tensor_num in tensor_num_list :
@@ -90,7 +101,7 @@ class TestForeachMulScalar(TestCase):
90 101 
91 self.assertRtolEqual(cpu_output, npu_output)102 self.assertRtolEqual(cpu_output, npu_output)
92 103 
93- @SupportedDevices(['Ascend910B'])104+
94 def test_foreach_mul_scalar_inplace_float32_shpae_tensor_num(self):105 def test_foreach_mul_scalar_inplace_float32_shpae_tensor_num(self):
95 tensor_num_list = [20, 50]106 tensor_num_list = [20, 50]
96 for tensor_num in tensor_num_list :107 for tensor_num in tensor_num_list :
@@ -101,7 +112,7 @@ class TestForeachMulScalar(TestCase):
101 112 
102 self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])113 self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])
103 114
104- @SupportedDevices(['Ascend910B'])115+
105 def test_foreach_mul_scalar_inplace_float16_shpae_tensor_num(self):116 def test_foreach_mul_scalar_inplace_float16_shpae_tensor_num(self):
106 tensor_num_list = [20, 50]117 tensor_num_list = [20, 50]
107 for tensor_num in tensor_num_list :118 for tensor_num in tensor_num_list :
@@ -121,9 +132,9 @@ class TestForeachMulScalar(TestCase):
121 torch._foreach_mul_(cpu_tensors[0], scalar)132 torch._foreach_mul_(cpu_tensors[0], scalar)
122 torch._foreach_mul_(npu_tensors[0], scalar)133 torch._foreach_mul_(npu_tensors[0], scalar)
123 134 
124- self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])135+ self.assert_equal_bfloat16(cpu_tensors[0], npu_tensors[0])
125 136
126- @SupportedDevices(['Ascend910B'])137+
127 def test_foreach_mul_scalar_inplace_int32_shpae_tensor_num(self):138 def test_foreach_mul_scalar_inplace_int32_shpae_tensor_num(self):
128 tensor_num_list = [20, 50]139 tensor_num_list = [20, 50]
129 for tensor_num in tensor_num_list :140 for tensor_num in tensor_num_list :
@@ -15,6 +15,17 @@ class TestForeachMulScalarList(TestCase):
15 "bfloat16" : torch.bfloat16,15 "bfloat16" : torch.bfloat16,
16 "int32" : torch.int32,16 "int32" : torch.int32,
17 }17 }
18+
19+ def assert_equal_bfloat16(self, cpu_outs, npu_outs):
20+ for cpu_out, npu_out in zip(cpu_outs, npu_outs):
21+ if (cpu_out.shape != npu_out.shape):
22+ self.fail("shape error")
23+ if (cpu_out.dtype != npu_out.dtype):
24+ self.fail("dtype error!")
25+ result = torch.allclose(cpu_out, npu_out.cpu(), rtol=0.001, atol=0.001)
26+ if not result:
27+ self.fail("result error!")
28+ return True
18 29 
19 def create_tensors(self, dtype, shapes):30 def create_tensors(self, dtype, shapes):
20 cpu_tensors = []31 cpu_tensors = []
@@ -55,7 +66,7 @@ class TestForeachMulScalarList(TestCase):
55 sacalars.append(m)66 sacalars.append(m)
56 return tuple(sacalars)67 return tuple(sacalars)
57 68 
58- @SupportedDevices(['Ascend910B'])69+
59 def test_foreach_mul_scalar_list_out_float32_shpae_tensor_num(self):70 def test_foreach_mul_scalar_list_out_float32_shpae_tensor_num(self):
60 tensor_num_list = [20, 50]71 tensor_num_list = [20, 50]
61 for tensor_num in tensor_num_list :72 for tensor_num in tensor_num_list :
@@ -66,7 +77,7 @@ class TestForeachMulScalarList(TestCase):
66 77 
67 self.assertRtolEqual(cpu_output, npu_output)78 self.assertRtolEqual(cpu_output, npu_output)
68 79
69- @SupportedDevices(['Ascend910B'])80+
70 def test_foreach_mul_scalar_list_out_float16_shpae_tensor_num(self):81 def test_foreach_mul_scalar_list_out_float16_shpae_tensor_num(self):
71 tensor_num_list = [20, 50]82 tensor_num_list = [20, 50]
72 for tensor_num in tensor_num_list :83 for tensor_num in tensor_num_list :
@@ -86,9 +97,9 @@ class TestForeachMulScalarList(TestCase):
86 cpu_output = torch._foreach_mul(cpu_tensors[0], scalars)97 cpu_output = torch._foreach_mul(cpu_tensors[0], scalars)
87 npu_output = torch._foreach_mul(npu_tensors[0], scalars)98 npu_output = torch._foreach_mul(npu_tensors[0], scalars)
88 99 
89- self.assertRtolEqual(cpu_output, npu_output)100+ self.assert_equal_bfloat16(cpu_output, npu_output)
90 101
91- @SupportedDevices(['Ascend910B'])102+
92 def test_foreach_mul_scalar_list_out_int32_shpae_tensor_num(self):103 def test_foreach_mul_scalar_list_out_int32_shpae_tensor_num(self):
93 tensor_num_list = [20, 50]104 tensor_num_list = [20, 50]
94 for tensor_num in tensor_num_list :105 for tensor_num in tensor_num_list :
@@ -100,7 +111,7 @@ class TestForeachMulScalarList(TestCase):
100 self.assertRtolEqual(cpu_output, npu_output)111 self.assertRtolEqual(cpu_output, npu_output)
101 112
102 113 
103- @SupportedDevices(['Ascend910B'])114+
104 def test_foreach_mul_scalar_list_inplace_float32_shpae_tensor_num(self):115 def test_foreach_mul_scalar_list_inplace_float32_shpae_tensor_num(self):
105 tensor_num_list = [20, 50]116 tensor_num_list = [20, 50]
106 for tensor_num in tensor_num_list :117 for tensor_num in tensor_num_list :
@@ -111,7 +122,7 @@ class TestForeachMulScalarList(TestCase):
111 122 
112 self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])123 self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])
113 124
114- @SupportedDevices(['Ascend910B'])125+
115 def test_foreach_mul_scalar_list_inplace_float16_shpae_tensor_num(self):126 def test_foreach_mul_scalar_list_inplace_float16_shpae_tensor_num(self):
116 tensor_num_list = [20, 50]127 tensor_num_list = [20, 50]
117 for tensor_num in tensor_num_list :128 for tensor_num in tensor_num_list :
@@ -131,9 +142,9 @@ class TestForeachMulScalarList(TestCase):
131 torch._foreach_mul_(cpu_tensors[0], scalars)142 torch._foreach_mul_(cpu_tensors[0], scalars)
132 torch._foreach_mul_(npu_tensors[0], scalars)143 torch._foreach_mul_(npu_tensors[0], scalars)
133 144 
134- self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])145+ self.assert_equal_bfloat16(cpu_tensors[0], npu_tensors[0])
135 146
136- @SupportedDevices(['Ascend910B'])147+
137 def test_foreach_mul_scalar_list_inplace_int32_shpae_tensor_num(self):148 def test_foreach_mul_scalar_list_inplace_int32_shpae_tensor_num(self):
138 tensor_num_list = [20, 50]149 tensor_num_list = [20, 50]
139 for tensor_num in tensor_num_list :150 for tensor_num in tensor_num_list :
@@ -15,6 +15,17 @@ class TestForeachNeg(TestCase):
15 "bfloat16" : torch.bfloat16,15 "bfloat16" : torch.bfloat16,
16 "int32" : torch.int3216 "int32" : torch.int32
17 }17 }
18+
19+ def assert_equal_bfloat16(self, cpu_outs, npu_outs):
20+ for cpu_out, npu_out in zip(cpu_outs, npu_outs):
21+ if (cpu_out.shape != npu_out.shape):
22+ self.fail("shape error")
23+ if (cpu_out.dtype != npu_out.dtype):
24+ self.fail("dtype error!")
25+ result = torch.allclose(cpu_out, npu_out.cpu(), rtol=0.001, atol=0.001)
26+ if not result:
27+ self.fail("result error!")
28+ return True
18 29 
19 def assert_equal(self, cpu_outs, npu_outs):30 def assert_equal(self, cpu_outs, npu_outs):
20 for cpu_out, npu_out in zip(cpu_outs, npu_outs):31 for cpu_out, npu_out in zip(cpu_outs, npu_outs):
@@ -41,7 +52,7 @@ class TestForeachNeg(TestCase):
41 npu_tensors.append(t.npu())52 npu_tensors.append(t.npu())
42 return tuple(cpu_tensors), tuple(npu_tensors)53 return tuple(cpu_tensors), tuple(npu_tensors)
43 54 
44- @SupportedDevices(['Ascend910B'])55+
45 def test_foreach_neg_out_float32_shpae_tensor_num(self):56 def test_foreach_neg_out_float32_shpae_tensor_num(self):
46 tensor_num_list = [20, 50]57 tensor_num_list = [20, 50]
47 for tensor_num in tensor_num_list :58 for tensor_num in tensor_num_list :
@@ -51,7 +62,7 @@ class TestForeachNeg(TestCase):
51 62 
52 self.assertRtolEqual(cpu_output, npu_output)63 self.assertRtolEqual(cpu_output, npu_output)
53 64
54- @SupportedDevices(['Ascend910B'])65+
55 def test_foreach_neg_out_float16_shpae_tensor_num(self):66 def test_foreach_neg_out_float16_shpae_tensor_num(self):
56 tensor_num_list = [20, 50]67 tensor_num_list = [20, 50]
57 for tensor_num in tensor_num_list :68 for tensor_num in tensor_num_list :
@@ -71,7 +82,7 @@ class TestForeachNeg(TestCase):
71 82 
72 self.assert_equal(cpu_output, npu_output)83 self.assert_equal(cpu_output, npu_output)
73 84
74- @SupportedDevices(['Ascend910B'])85+
75 def test_foreach_neg_out_int32_shpae_tensor_num(self):86 def test_foreach_neg_out_int32_shpae_tensor_num(self):
76 tensor_num_list = [20, 50]87 tensor_num_list = [20, 50]
77 for tensor_num in tensor_num_list :88 for tensor_num in tensor_num_list :
@@ -81,7 +92,7 @@ class TestForeachNeg(TestCase):
81 92 
82 self.assertRtolEqual(cpu_output, npu_output)93 self.assertRtolEqual(cpu_output, npu_output)
83 94 
84- @SupportedDevices(['Ascend910B'])95+
85 def test_foreach_neg_inplace_float32_shpae_tensor_num(self):96 def test_foreach_neg_inplace_float32_shpae_tensor_num(self):
86 tensor_num_list = [20, 50]97 tensor_num_list = [20, 50]
87 for tensor_num in tensor_num_list :98 for tensor_num in tensor_num_list :
@@ -91,7 +102,7 @@ class TestForeachNeg(TestCase):
91 102 
92 self.assertRtolEqual(cpu_tensors, npu_tensors)103 self.assertRtolEqual(cpu_tensors, npu_tensors)
93 104
94- @SupportedDevices(['Ascend910B'])105+
95 def test_foreach_neg_inplace_float16_shpae_tensor_num(self):106 def test_foreach_neg_inplace_float16_shpae_tensor_num(self):
96 tensor_num_list = [20, 50]107 tensor_num_list = [20, 50]
97 for tensor_num in tensor_num_list :108 for tensor_num in tensor_num_list :
@@ -111,7 +122,7 @@ class TestForeachNeg(TestCase):
111 122 
112 self.assert_equal(cpu_tensors, npu_tensors)123 self.assert_equal(cpu_tensors, npu_tensors)
113 124
114- @SupportedDevices(['Ascend910B'])125+
115 def test_foreach_neg_inplace_int32_shpae_tensor_num(self):126 def test_foreach_neg_inplace_int32_shpae_tensor_num(self):
116 tensor_num_list = [20, 50]127 tensor_num_list = [20, 50]
117 for tensor_num in tensor_num_list :128 for tensor_num in tensor_num_list :
@@ -57,7 +57,7 @@ class TestForeachClampMaxList(TestCase):
57 npu_inputs.append(npu_tensors)57 npu_inputs.append(npu_tensors)
58 return cpu_inputs, npu_inputs58 return cpu_inputs, npu_inputs
59 59 
60- @SupportedDevices(['Ascend910B'])60+ 
61 def test_foreach_clamp_max_list_out_float32_shpae_tensor_num(self):61 def test_foreach_clamp_max_list_out_float32_shpae_tensor_num(self):
62 tensor_num_list = [20, 50]62 tensor_num_list = [20, 50]
63 for tensor_num in tensor_num_list :63 for tensor_num in tensor_num_list :
@@ -68,7 +68,7 @@ class TestForeachClampMaxList(TestCase):
68 68 
69 self.assertRtolEqual(cpu_output, npu_output)69 self.assertRtolEqual(cpu_output, npu_output)
70 70
71- @SupportedDevices(['Ascend910B'])71+ 
72 def test_foreach_clamp_max_list_out_float16_shpae_tensor_num(self):72 def test_foreach_clamp_max_list_out_float16_shpae_tensor_num(self):
73 tensor_num_list = [20, 50]73 tensor_num_list = [20, 50]
74 for tensor_num in tensor_num_list :74 for tensor_num in tensor_num_list :
@@ -89,8 +89,7 @@ class TestForeachClampMaxList(TestCase):
89 npu_output = torch._foreach_clamp_max(npu_tensors[0], npu_tensors[1])89 npu_output = torch._foreach_clamp_max(npu_tensors[0], npu_tensors[1])
90 90 
91 self.assert_equal(cpu_output, npu_output)91 self.assert_equal(cpu_output, npu_output)
92- 92+ 
93- @SupportedDevices(['Ascend910B'])
94 def test_foreach_clamp_max_list_out_int32_shpae_tensor_num(self):93 def test_foreach_clamp_max_list_out_int32_shpae_tensor_num(self):
95 tensor_num_list = [20, 50]94 tensor_num_list = [20, 50]
96 for tensor_num in tensor_num_list :95 for tensor_num in tensor_num_list :
@@ -101,7 +100,6 @@ class TestForeachClampMaxList(TestCase):
101 100 
102 self.assertRtolEqual(cpu_output, npu_output)101 self.assertRtolEqual(cpu_output, npu_output)
103 102 
104- @SupportedDevices(['Ascend910B'])
105 def test_foreach_clamp_max_list_inplace_float32_shpae_tensor_num(self):103 def test_foreach_clamp_max_list_inplace_float32_shpae_tensor_num(self):
106 tensor_num_list = [20, 50]104 tensor_num_list = [20, 50]
107 for tensor_num in tensor_num_list :105 for tensor_num in tensor_num_list :
@@ -111,8 +109,7 @@ class TestForeachClampMaxList(TestCase):
111 torch._foreach_clamp_max_(npu_tensors[0], npu_tensors[1])109 torch._foreach_clamp_max_(npu_tensors[0], npu_tensors[1])
112 110 
113 self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])111 self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])
114- 112+ 
115- @SupportedDevices(['Ascend910B'])
116 def test_foreach_clamp_max_list_inplace_float16_shpae_tensor_num(self):113 def test_foreach_clamp_max_list_inplace_float16_shpae_tensor_num(self):
117 tensor_num_list = [20, 50]114 tensor_num_list = [20, 50]
118 for tensor_num in tensor_num_list :115 for tensor_num in tensor_num_list :
@@ -134,7 +131,6 @@ class TestForeachClampMaxList(TestCase):
134 131 
135 self.assert_equal(cpu_tensors[0], npu_tensors[0])132 self.assert_equal(cpu_tensors[0], npu_tensors[0])
136 133 
137- @SupportedDevices(['Ascend910B'])
138 def test_foreach_clamp_max_list_inplace_int32_shpae_tensor_num(self):134 def test_foreach_clamp_max_list_inplace_int32_shpae_tensor_num(self):
139 tensor_num_list = [20, 50]135 tensor_num_list = [20, 50]
140 for tensor_num in tensor_num_list :136 for tensor_num in tensor_num_list :
@@ -66,7 +66,6 @@ class TestForeachClampMaxScalarList(TestCase):
66 sacalars.append(m)66 sacalars.append(m)
67 return tuple(sacalars)67 return tuple(sacalars)
68 68 
69- @SupportedDevices(['Ascend910B'])
70 def test_foreach_clamp_max_scalar_list_out_float32_shpae_tensor_num(self):69 def test_foreach_clamp_max_scalar_list_out_float32_shpae_tensor_num(self):
71 tensor_num_list = [20, 50]70 tensor_num_list = [20, 50]
72 for tensor_num in tensor_num_list :71 for tensor_num in tensor_num_list :
@@ -77,7 +76,6 @@ class TestForeachClampMaxScalarList(TestCase):
77 76 
78 self.assertRtolEqual(cpu_output, npu_output)77 self.assertRtolEqual(cpu_output, npu_output)
79 78
80- @SupportedDevices(['Ascend910B'])
81 def test_foreach_clamp_max_scalar_list_out_float16_shpae_tensor_num(self):79 def test_foreach_clamp_max_scalar_list_out_float16_shpae_tensor_num(self):
82 tensor_num_list = [20, 50]80 tensor_num_list = [20, 50]
83 for tensor_num in tensor_num_list :81 for tensor_num in tensor_num_list :
@@ -98,8 +96,7 @@ class TestForeachClampMaxScalarList(TestCase):
98 npu_output = torch._foreach_clamp_max(npu_tensors[0], scalars)96 npu_output = torch._foreach_clamp_max(npu_tensors[0], scalars)
99 97 
100 self.assert_equal(cpu_output, npu_output)98 self.assert_equal(cpu_output, npu_output)
101- 99+ 
102- @SupportedDevices(['Ascend910B'])
103 def test_foreach_clamp_max_scalar_list_out_int32_shpae_tensor_num(self):100 def test_foreach_clamp_max_scalar_list_out_int32_shpae_tensor_num(self):
104 tensor_num_list = [20, 50]101 tensor_num_list = [20, 50]
105 for tensor_num in tensor_num_list :102 for tensor_num in tensor_num_list :
@@ -109,9 +106,7 @@ class TestForeachClampMaxScalarList(TestCase):
109 npu_output = torch._foreach_clamp_max(npu_tensors[0], scalars)106 npu_output = torch._foreach_clamp_max(npu_tensors[0], scalars)
110 107 
111 self.assertRtolEqual(cpu_output, npu_output)108 self.assertRtolEqual(cpu_output, npu_output)
112-
113 109 
114- @SupportedDevices(['Ascend910B'])
115 def test_foreach_clamp_max_scalar_list_inplace_float32_shpae_tensor_num(self):110 def test_foreach_clamp_max_scalar_list_inplace_float32_shpae_tensor_num(self):
116 tensor_num_list = [20, 50]111 tensor_num_list = [20, 50]
117 for tensor_num in tensor_num_list :112 for tensor_num in tensor_num_list :
@@ -122,7 +117,6 @@ class TestForeachClampMaxScalarList(TestCase):
122 117 
123 self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])118 self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])
124 119
125- @SupportedDevices(['Ascend910B'])
126 def test_foreach_clamp_max_scalar_list_inplace_float16_shpae_tensor_num(self):120 def test_foreach_clamp_max_scalar_list_inplace_float16_shpae_tensor_num(self):
127 tensor_num_list = [20, 50]121 tensor_num_list = [20, 50]
128 for tensor_num in tensor_num_list :122 for tensor_num in tensor_num_list :
@@ -144,7 +138,6 @@ class TestForeachClampMaxScalarList(TestCase):
144 138 
145 self.assert_equal(cpu_tensors[0], npu_tensors[0])139 self.assert_equal(cpu_tensors[0], npu_tensors[0])
146 140
147- @SupportedDevices(['Ascend910B'])
148 def test_foreach_clamp_max_scalar_list_inplace_int32_shpae_tensor_num(self):141 def test_foreach_clamp_max_scalar_list_inplace_int32_shpae_tensor_num(self):
149 tensor_num_list = [20, 50]142 tensor_num_list = [20, 50]
150 for tensor_num in tensor_num_list :143 for tensor_num in tensor_num_list :
@@ -57,7 +57,6 @@ class TestForeachClampMinList(TestCase):
57 npu_inputs.append(npu_tensors)57 npu_inputs.append(npu_tensors)
58 return cpu_inputs, npu_inputs58 return cpu_inputs, npu_inputs
59 59 
60- @SupportedDevices(['Ascend910B'])
61 def test_foreach_clamp_min_list_out_float32_shpae_tensor_num(self):60 def test_foreach_clamp_min_list_out_float32_shpae_tensor_num(self):
62 tensor_num_list = [20, 50]61 tensor_num_list = [20, 50]
63 for tensor_num in tensor_num_list :62 for tensor_num in tensor_num_list :
@@ -68,7 +67,6 @@ class TestForeachClampMinList(TestCase):
68 67 
69 self.assertRtolEqual(cpu_output, npu_output)68 self.assertRtolEqual(cpu_output, npu_output)
70 69
71- @SupportedDevices(['Ascend910B'])
72 def test_foreach_clamp_min_list_out_float16_shpae_tensor_num(self):70 def test_foreach_clamp_min_list_out_float16_shpae_tensor_num(self):
73 tensor_num_list = [20, 50]71 tensor_num_list = [20, 50]
74 for tensor_num in tensor_num_list :72 for tensor_num in tensor_num_list :
@@ -90,7 +88,6 @@ class TestForeachClampMinList(TestCase):
90 88 
91 self.assert_equal(cpu_output, npu_output)89 self.assert_equal(cpu_output, npu_output)
92 90
93- @SupportedDevices(['Ascend910B'])
94 def test_foreach_clamp_min_list_out_int32_shpae_tensor_num(self):91 def test_foreach_clamp_min_list_out_int32_shpae_tensor_num(self):
95 tensor_num_list = [20, 50]92 tensor_num_list = [20, 50]
96 for tensor_num in tensor_num_list :93 for tensor_num in tensor_num_list :
@@ -101,7 +98,6 @@ class TestForeachClampMinList(TestCase):
101 98 
102 self.assertRtolEqual(cpu_output, npu_output)99 self.assertRtolEqual(cpu_output, npu_output)
103 100 
104- @SupportedDevices(['Ascend910B'])
105 def test_foreach_clamp_min_list_inplace_float32_shpae_tensor_num(self):101 def test_foreach_clamp_min_list_inplace_float32_shpae_tensor_num(self):
106 tensor_num_list = [20, 50]102 tensor_num_list = [20, 50]
107 for tensor_num in tensor_num_list :103 for tensor_num in tensor_num_list :
@@ -112,7 +108,6 @@ class TestForeachClampMinList(TestCase):
112 108 
113 self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])109 self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])
114 110
115- @SupportedDevices(['Ascend910B'])
116 def test_foreach_clamp_min_list_inplace_float16_shpae_tensor_num(self):111 def test_foreach_clamp_min_list_inplace_float16_shpae_tensor_num(self):
117 tensor_num_list = [20, 50]112 tensor_num_list = [20, 50]
118 for tensor_num in tensor_num_list :113 for tensor_num in tensor_num_list :
@@ -134,7 +129,6 @@ class TestForeachClampMinList(TestCase):
134 129 
135 self.assert_equal(cpu_tensors[0], npu_tensors[0])130 self.assert_equal(cpu_tensors[0], npu_tensors[0])
136 131 
137- @SupportedDevices(['Ascend910B'])
138 def test_foreach_clamp_min_list_inplace_int32_shpae_tensor_num(self):132 def test_foreach_clamp_min_list_inplace_int32_shpae_tensor_num(self):
139 tensor_num_list = [20, 50]133 tensor_num_list = [20, 50]
140 for tensor_num in tensor_num_list :134 for tensor_num in tensor_num_list :
@@ -66,7 +66,6 @@ class TestForeachClampMinScalarList(TestCase):
66 sacalars.append(m)66 sacalars.append(m)
67 return tuple(sacalars)67 return tuple(sacalars)
68 68 
69- @SupportedDevices(['Ascend910B'])
70 def test_foreach_clamp_min_scalar_list_out_float32_shpae_tensor_num(self):69 def test_foreach_clamp_min_scalar_list_out_float32_shpae_tensor_num(self):
71 tensor_num_list = [20, 50]70 tensor_num_list = [20, 50]
72 for tensor_num in tensor_num_list :71 for tensor_num in tensor_num_list :
@@ -77,7 +76,6 @@ class TestForeachClampMinScalarList(TestCase):
77 76 
78 self.assertRtolEqual(cpu_output, npu_output)77 self.assertRtolEqual(cpu_output, npu_output)
79 78
80- @SupportedDevices(['Ascend910B'])
81 def test_foreach_clamp_min_scalar_list_out_float16_shpae_tensor_num(self):79 def test_foreach_clamp_min_scalar_list_out_float16_shpae_tensor_num(self):
82 tensor_num_list = [20, 50]80 tensor_num_list = [20, 50]
83 for tensor_num in tensor_num_list :81 for tensor_num in tensor_num_list :
@@ -98,8 +96,7 @@ class TestForeachClampMinScalarList(TestCase):
98 npu_output = torch._foreach_clamp_min(npu_tensors[0], scalars)96 npu_output = torch._foreach_clamp_min(npu_tensors[0], scalars)
99 97 
100 self.assert_equal(cpu_output, npu_output)98 self.assert_equal(cpu_output, npu_output)
101- 99+
102- @SupportedDevices(['Ascend910B'])
103 def test_foreach_clamp_min_scalar_list_out_int32_shpae_tensor_num(self):100 def test_foreach_clamp_min_scalar_list_out_int32_shpae_tensor_num(self):
104 tensor_num_list = [20, 50]101 tensor_num_list = [20, 50]
105 for tensor_num in tensor_num_list :102 for tensor_num in tensor_num_list :
@@ -110,8 +107,6 @@ class TestForeachClampMinScalarList(TestCase):
110 107 
111 self.assertRtolEqual(cpu_output, npu_output)108 self.assertRtolEqual(cpu_output, npu_output)
112 109
113- 
114- @SupportedDevices(['Ascend910B'])
115 def test_foreach_clamp_min_scalar_list_inplace_float32_shpae_tensor_num(self):110 def test_foreach_clamp_min_scalar_list_inplace_float32_shpae_tensor_num(self):
116 tensor_num_list = [20, 50]111 tensor_num_list = [20, 50]
117 for tensor_num in tensor_num_list :112 for tensor_num in tensor_num_list :
@@ -121,8 +116,7 @@ class TestForeachClampMinScalarList(TestCase):
121 torch._foreach_clamp_min_(npu_tensors[0], scalars)116 torch._foreach_clamp_min_(npu_tensors[0], scalars)
122 117 
123 self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])118 self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])
124- 119+ 
125- @SupportedDevices(['Ascend910B'])
126 def test_foreach_clamp_min_scalar_list_inplace_float16_shpae_tensor_num(self):120 def test_foreach_clamp_min_scalar_list_inplace_float16_shpae_tensor_num(self):
127 tensor_num_list = [20, 50]121 tensor_num_list = [20, 50]
128 for tensor_num in tensor_num_list :122 for tensor_num in tensor_num_list :
@@ -132,7 +126,7 @@ class TestForeachClampMinScalarList(TestCase):
132 torch._foreach_clamp_min_(npu_tensors[0], scalars)126 torch._foreach_clamp_min_(npu_tensors[0], scalars)
133 127 
134 self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])128 self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])
135- 129+ 
136 @SupportedDevices(['Ascend910B'])130 @SupportedDevices(['Ascend910B'])
137 def test_foreach_clamp_min_scalar_list_inplace_bfloat16_shpae_tensor_num(self):131 def test_foreach_clamp_min_scalar_list_inplace_bfloat16_shpae_tensor_num(self):
138 tensor_num_list = [20, 50]132 tensor_num_list = [20, 50]
@@ -143,8 +137,7 @@ class TestForeachClampMinScalarList(TestCase):
143 torch._foreach_clamp_min_(npu_tensors[0], scalars)137 torch._foreach_clamp_min_(npu_tensors[0], scalars)
144 138 
145 self.assert_equal(cpu_tensors[0], npu_tensors[0])139 self.assert_equal(cpu_tensors[0], npu_tensors[0])
146- 140+ 
147- @SupportedDevices(['Ascend910B'])
148 def test_foreach_clamp_min_scalar_list_inplace_int32_shpae_tensor_num(self):141 def test_foreach_clamp_min_scalar_list_inplace_int32_shpae_tensor_num(self):
149 tensor_num_list = [20, 50]142 tensor_num_list = [20, 50]
150 for tensor_num in tensor_num_list :143 for tensor_num in tensor_num_list :
@@ -14,6 +14,17 @@ class TestForeachLerpList(TestCase):
14 "float32" : torch.float32,14 "float32" : torch.float32,
15 "bfloat16" : torch.bfloat1615 "bfloat16" : torch.bfloat16
16 }16 }
17+
18+ def assert_equal(self, cpu_outs, npu_outs):
19+ for cpu_out, npu_out in zip(cpu_outs, npu_outs):
20+ if (cpu_out.shape != npu_out.shape):
21+ self.fail("shape error")
22+ if (cpu_out.dtype != npu_out.dtype):
23+ self.fail("dtype error!")
24+ result = torch.allclose(cpu_out, npu_out.cpu(), rtol=0.001, atol=0.001)
25+ if not result:
26+ self.fail("result error!")
27+ return True
17 28 
18 def create_tensors(self, dtype, shapes):29 def create_tensors(self, dtype, shapes):
19 cpu_tensors = []30 cpu_tensors = []
@@ -39,7 +50,6 @@ class TestForeachLerpList(TestCase):
39 npu_inputs.append(npu_tensors)50 npu_inputs.append(npu_tensors)
40 return cpu_inputs, npu_inputs51 return cpu_inputs, npu_inputs
41 52 
42- @SupportedDevices(['Ascend910B'])
43 def test_foreach_lerp_list_out_float32_shpae_tensor_num(self):53 def test_foreach_lerp_list_out_float32_shpae_tensor_num(self):
44 tensor_num_list = [20, 50]54 tensor_num_list = [20, 50]
45 for tensor_num in tensor_num_list :55 for tensor_num in tensor_num_list :
@@ -49,7 +59,6 @@ class TestForeachLerpList(TestCase):
49 59
50 self.assertRtolEqual(cpu_output, npu_output)60 self.assertRtolEqual(cpu_output, npu_output)
51 61
52- @SupportedDevices(['Ascend910B'])
53 def test_foreach_lerp_list_out_float16_shpae_tensor_num(self):62 def test_foreach_lerp_list_out_float16_shpae_tensor_num(self):
54 tensor_num_list = [20, 50]63 tensor_num_list = [20, 50]
55 for tensor_num in tensor_num_list :64 for tensor_num in tensor_num_list :
@@ -67,9 +76,8 @@ class TestForeachLerpList(TestCase):
67 cpu_output = torch._foreach_lerp(cpu_tensors[0], cpu_tensors[1], cpu_tensors[2])76 cpu_output = torch._foreach_lerp(cpu_tensors[0], cpu_tensors[1], cpu_tensors[2])
68 npu_output = torch._foreach_lerp(npu_tensors[0], npu_tensors[1], npu_tensors[2])77 npu_output = torch._foreach_lerp(npu_tensors[0], npu_tensors[1], npu_tensors[2])
69 78 
70- self.assertRtolEqual(cpu_output, npu_output)79+ self.assert_equal(cpu_output, npu_output)
71 80 
72- @SupportedDevices(['Ascend910B'])
73 def test_foreach_lerp_list_inplace_float32_shpae_tensor_num(self):81 def test_foreach_lerp_list_inplace_float32_shpae_tensor_num(self):
74 tensor_num_list = [20, 50]82 tensor_num_list = [20, 50]
75 for tensor_num in tensor_num_list :83 for tensor_num in tensor_num_list :
@@ -79,7 +87,6 @@ class TestForeachLerpList(TestCase):
79 87 
80 self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])88 self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])
81 89
82- @SupportedDevices(['Ascend910B'])
83 def test_foreach_lerp_list_inplace_float16_shpae_tensor_num(self):90 def test_foreach_lerp_list_inplace_float16_shpae_tensor_num(self):
84 tensor_num_list = [20, 50]91 tensor_num_list = [20, 50]
85 for tensor_num in tensor_num_list :92 for tensor_num in tensor_num_list :
@@ -97,7 +104,7 @@ class TestForeachLerpList(TestCase):
97 torch._foreach_lerp_(cpu_tensors[0], cpu_tensors[1], cpu_tensors[2])104 torch._foreach_lerp_(cpu_tensors[0], cpu_tensors[1], cpu_tensors[2])
98 torch._foreach_lerp_(npu_tensors[0], npu_tensors[1], npu_tensors[2])105 torch._foreach_lerp_(npu_tensors[0], npu_tensors[1], npu_tensors[2])
99 106 
100- self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])107+ self.assert_equal(cpu_tensors[0], npu_tensors[0])
101 108 
102 109 
103if __name__ == "__main__":110if __name__ == "__main__":
@@ -15,6 +15,17 @@ class TestForeachLerpScalar(TestCase):
15 "bfloat16" : torch.bfloat1615 "bfloat16" : torch.bfloat16
16 }16 }
17 17 
18+ def assert_equal(self, cpu_outs, npu_outs):
19+ for cpu_out, npu_out in zip(cpu_outs, npu_outs):
20+ if (cpu_out.shape != npu_out.shape):
21+ self.fail("shape error")
22+ if (cpu_out.dtype != npu_out.dtype):
23+ self.fail("dtype error!")
24+ result = torch.allclose(cpu_out, npu_out.cpu(), rtol=0.001, atol=0.001)
25+ if not result:
26+ self.fail("result error!")
27+ return True
28+ 
18 def create_tensors(self, dtype, shapes):29 def create_tensors(self, dtype, shapes):
19 cpu_tensors = []30 cpu_tensors = []
20 npu_tensors = []31 npu_tensors = []
@@ -45,7 +56,6 @@ class TestForeachLerpScalar(TestCase):
45 npu_inputs.append(npu_tensors)56 npu_inputs.append(npu_tensors)
46 return cpu_inputs, npu_inputs57 return cpu_inputs, npu_inputs
47 58 
48- @SupportedDevices(['Ascend910B'])
49 def test_foreach_lerp_scalar_out_float32_shpae_tensor_num(self):59 def test_foreach_lerp_scalar_out_float32_shpae_tensor_num(self):
50 tensor_num_list = [20, 50]60 tensor_num_list = [20, 50]
51 for tensor_num in tensor_num_list :61 for tensor_num in tensor_num_list :
@@ -56,7 +66,6 @@ class TestForeachLerpScalar(TestCase):
56 66 
57 self.assertRtolEqual(cpu_output, npu_output)67 self.assertRtolEqual(cpu_output, npu_output)
58 68
59- @SupportedDevices(['Ascend910B'])
60 def test_foreach_lerp_scalar_out_float16_shpae_tensor_num(self):69 def test_foreach_lerp_scalar_out_float16_shpae_tensor_num(self):
61 tensor_num_list = [20, 50]70 tensor_num_list = [20, 50]
62 for tensor_num in tensor_num_list :71 for tensor_num in tensor_num_list :
@@ -76,9 +85,8 @@ class TestForeachLerpScalar(TestCase):
76 cpu_output = torch._foreach_lerp(cpu_tensors[0], cpu_tensors[1], scalar)85 cpu_output = torch._foreach_lerp(cpu_tensors[0], cpu_tensors[1], scalar)
77 npu_output = torch._foreach_lerp(npu_tensors[0], npu_tensors[1], scalar)86 npu_output = torch._foreach_lerp(npu_tensors[0], npu_tensors[1], scalar)
78 87 
79- self.assertRtolEqual(cpu_output, npu_output)88+ self.assert_equal(cpu_output, npu_output)
80 89 
81- @SupportedDevices(['Ascend910B'])
82 def test_foreach_lerp_scalar_inplace_float32_shpae_tensor_num(self):90 def test_foreach_lerp_scalar_inplace_float32_shpae_tensor_num(self):
83 tensor_num_list = [20, 50]91 tensor_num_list = [20, 50]
84 for tensor_num in tensor_num_list :92 for tensor_num in tensor_num_list :
@@ -89,7 +97,6 @@ class TestForeachLerpScalar(TestCase):
89 97 
90 self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])98 self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])
91 99
92- @SupportedDevices(['Ascend910B'])
93 def test_foreach_lerp_scalar_inplace_float16_shpae_tensor_num(self):100 def test_foreach_lerp_scalar_inplace_float16_shpae_tensor_num(self):
94 tensor_num_list = [20, 50]101 tensor_num_list = [20, 50]
95 for tensor_num in tensor_num_list :102 for tensor_num in tensor_num_list :
@@ -109,7 +116,7 @@ class TestForeachLerpScalar(TestCase):
109 torch._foreach_lerp_(cpu_tensors[0], cpu_tensors[1], scalar)116 torch._foreach_lerp_(cpu_tensors[0], cpu_tensors[1], scalar)
110 torch._foreach_lerp_(npu_tensors[0], npu_tensors[1], scalar)117 torch._foreach_lerp_(npu_tensors[0], npu_tensors[1], scalar)
111 118 
112- self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])119+ self.assert_equal(cpu_tensors[0], npu_tensors[0])
113 120 
114if __name__ == "__main__":121if __name__ == "__main__":
115 run_tests()122 run_tests()
@@ -16,6 +16,17 @@ class TestForeachMaximumList(TestCase):
16 "int32" : torch.int3216 "int32" : torch.int32
17 }17 }
18 18 
19+ def assert_equal(self, cpu_outs, npu_outs):
20+ for cpu_out, npu_out in zip(cpu_outs, npu_outs):
21+ if (cpu_out.shape != npu_out.shape):
22+ self.fail("shape error")
23+ if (cpu_out.dtype != npu_out.dtype):
24+ self.fail("dtype error!")
25+ result = torch.allclose(cpu_out, npu_out.cpu(), rtol=0.001, atol=0.001)
26+ if not result:
27+ self.fail("result error!")
28+ return True
29+
19 def create_tensors(self, dtype, shapes):30 def create_tensors(self, dtype, shapes):
20 cpu_tensors = []31 cpu_tensors = []
21 npu_tensors = []32 npu_tensors = []
@@ -46,7 +57,6 @@ class TestForeachMaximumList(TestCase):
46 npu_inputs.append(npu_tensors)57 npu_inputs.append(npu_tensors)
47 return cpu_inputs, npu_inputs58 return cpu_inputs, npu_inputs
48 59 
49- @SupportedDevices(['Ascend910B'])
50 def test_foreach_maximum_list_out_float32_shpae_tensor_num(self):60 def test_foreach_maximum_list_out_float32_shpae_tensor_num(self):
51 tensor_num_list = [20, 50]61 tensor_num_list = [20, 50]
52 for tensor_num in tensor_num_list :62 for tensor_num in tensor_num_list :
@@ -56,8 +66,7 @@ class TestForeachMaximumList(TestCase):
56 npu_output = torch._foreach_maximum(npu_tensors[0], npu_tensors[1])66 npu_output = torch._foreach_maximum(npu_tensors[0], npu_tensors[1])
57 67 
58 self.assertRtolEqual(cpu_output, npu_output)68 self.assertRtolEqual(cpu_output, npu_output)
59- 69+ 
60- @SupportedDevices(['Ascend910B'])
61 def test_foreach_maximum_list_out_float16_shpae_tensor_num(self):70 def test_foreach_maximum_list_out_float16_shpae_tensor_num(self):
62 tensor_num_list = [20, 50]71 tensor_num_list = [20, 50]
63 for tensor_num in tensor_num_list :72 for tensor_num in tensor_num_list :
@@ -77,9 +86,8 @@ class TestForeachMaximumList(TestCase):
77 cpu_output = torch._foreach_maximum(cpu_tensors[0], cpu_tensors[1])86 cpu_output = torch._foreach_maximum(cpu_tensors[0], cpu_tensors[1])
78 npu_output = torch._foreach_maximum(npu_tensors[0], npu_tensors[1])87 npu_output = torch._foreach_maximum(npu_tensors[0], npu_tensors[1])
79 88 
80- self.assertRtolEqual(cpu_output, npu_output)89+ self.assert_equal(cpu_output, npu_output)
81 90
82- @SupportedDevices(['Ascend910B'])
83 def test_foreach_maximum_list_out_int32_shpae_tensor_num(self):91 def test_foreach_maximum_list_out_int32_shpae_tensor_num(self):
84 tensor_num_list = [20, 50]92 tensor_num_list = [20, 50]
85 for tensor_num in tensor_num_list :93 for tensor_num in tensor_num_list :
@@ -90,7 +98,6 @@ class TestForeachMaximumList(TestCase):
90 98 
91 self.assertRtolEqual(cpu_output, npu_output)99 self.assertRtolEqual(cpu_output, npu_output)
92 100 
93- @SupportedDevices(['Ascend910B'])
94 def test_foreach_maximum_list_inplace_float32_shpae_tensor_num(self):101 def test_foreach_maximum_list_inplace_float32_shpae_tensor_num(self):
95 tensor_num_list = [20, 50]102 tensor_num_list = [20, 50]
96 for tensor_num in tensor_num_list :103 for tensor_num in tensor_num_list :
@@ -101,7 +108,6 @@ class TestForeachMaximumList(TestCase):
101 108 
102 self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])109 self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])
103 110
104- @SupportedDevices(['Ascend910B'])
105 def test_foreach_maximum_list_inplace_float16_shpae_tensor_num(self):111 def test_foreach_maximum_list_inplace_float16_shpae_tensor_num(self):
106 tensor_num_list = [20, 50]112 tensor_num_list = [20, 50]
107 for tensor_num in tensor_num_list :113 for tensor_num in tensor_num_list :
@@ -121,9 +127,8 @@ class TestForeachMaximumList(TestCase):
121 torch._foreach_maximum_(cpu_tensors[0], cpu_tensors[1])127 torch._foreach_maximum_(cpu_tensors[0], cpu_tensors[1])
122 torch._foreach_maximum_(npu_tensors[0], npu_tensors[1])128 torch._foreach_maximum_(npu_tensors[0], npu_tensors[1])
123 129 
124- self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])130+ self.assert_equal(cpu_tensors[0], npu_tensors[0])
125 131 
126- @SupportedDevices(['Ascend910B'])
127 def test_foreach_maximum_list_inplace_int32_shpae_tensor_num(self):132 def test_foreach_maximum_list_inplace_int32_shpae_tensor_num(self):
128 tensor_num_list = [20, 50]133 tensor_num_list = [20, 50]
129 for tensor_num in tensor_num_list :134 for tensor_num in tensor_num_list :
@@ -16,6 +16,17 @@ class TestForeachMaximumScalar(TestCase):
16 "bfloat16" : torch.bfloat1616 "bfloat16" : torch.bfloat16
17 }17 }
18 18
19+ def assert_equal(self, cpu_outs, npu_outs):
20+ for cpu_out, npu_out in zip(cpu_outs, npu_outs):
21+ if (cpu_out.shape != npu_out.shape):
22+ self.fail("shape error")
23+ if (cpu_out.dtype != npu_out.dtype):
24+ self.fail("dtype error!")
25+ result = torch.allclose(cpu_out, npu_out.cpu(), rtol=0.001, atol=0.001)
26+ if not result:
27+ self.fail("result error!")
28+ return True
29+ 
19 def create_tensors(self, dtype, shapes):30 def create_tensors(self, dtype, shapes):
20 cpu_tensors = []31 cpu_tensors = []
21 npu_tensors = []32 npu_tensors = []
@@ -46,7 +57,6 @@ class TestForeachMaximumScalar(TestCase):
46 npu_inputs.append(npu_tensors)57 npu_inputs.append(npu_tensors)
47 return cpu_inputs, npu_inputs58 return cpu_inputs, npu_inputs
48 59 
49- @SupportedDevices(['Ascend910B'])
50 def test_foreach_maximum_scalar_out_float32_shpae_tensor_num(self):60 def test_foreach_maximum_scalar_out_float32_shpae_tensor_num(self):
51 tensor_num_list = [20, 50]61 tensor_num_list = [20, 50]
52 for tensor_num in tensor_num_list :62 for tensor_num in tensor_num_list :
@@ -56,8 +66,7 @@ class TestForeachMaximumScalar(TestCase):
56 npu_output = torch._foreach_maximum(npu_tensors[0], scalar)66 npu_output = torch._foreach_maximum(npu_tensors[0], scalar)
57 67 
58 self.assertRtolEqual(cpu_output, npu_output)68 self.assertRtolEqual(cpu_output, npu_output)
59- 69+ 
60- @SupportedDevices(['Ascend910B'])
61 def test_foreach_maximum_scalar_out_float16_shpae_tensor_num(self):70 def test_foreach_maximum_scalar_out_float16_shpae_tensor_num(self):
62 tensor_num_list = [20, 50]71 tensor_num_list = [20, 50]
63 for tensor_num in tensor_num_list :72 for tensor_num in tensor_num_list :
@@ -77,9 +86,8 @@ class TestForeachMaximumScalar(TestCase):
77 cpu_output = torch._foreach_maximum(cpu_tensors[0], scalar)86 cpu_output = torch._foreach_maximum(cpu_tensors[0], scalar)
78 npu_output = torch._foreach_maximum(npu_tensors[0], scalar)87 npu_output = torch._foreach_maximum(npu_tensors[0], scalar)
79 88 
80- self.assertRtolEqual(cpu_output, npu_output)89+ self.assert_equal(cpu_output, npu_output)
81- 90+ 
82- @SupportedDevices(['Ascend910B'])
83 def test_foreach_maximum_scalar_out_int32_shpae_tensor_num(self):91 def test_foreach_maximum_scalar_out_int32_shpae_tensor_num(self):
84 tensor_num_list = [20, 50]92 tensor_num_list = [20, 50]
85 for tensor_num in tensor_num_list :93 for tensor_num in tensor_num_list :
@@ -90,7 +98,6 @@ class TestForeachMaximumScalar(TestCase):
90 98 
91 self.assertRtolEqual(cpu_output, npu_output)99 self.assertRtolEqual(cpu_output, npu_output)
92 100 
93- @SupportedDevices(['Ascend910B'])
94 def test_foreach_maximum_scalar_inplace_float32_shpae_tensor_num(self):101 def test_foreach_maximum_scalar_inplace_float32_shpae_tensor_num(self):
95 tensor_num_list = [20, 50]102 tensor_num_list = [20, 50]
96 for tensor_num in tensor_num_list :103 for tensor_num in tensor_num_list :
@@ -101,7 +108,6 @@ class TestForeachMaximumScalar(TestCase):
101 108 
102 self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])109 self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])
103 110
104- @SupportedDevices(['Ascend910B'])
105 def test_foreach_maximum_scalar_inplace_float16_shpae_tensor_num(self):111 def test_foreach_maximum_scalar_inplace_float16_shpae_tensor_num(self):
106 tensor_num_list = [20, 50]112 tensor_num_list = [20, 50]
107 for tensor_num in tensor_num_list :113 for tensor_num in tensor_num_list :
@@ -111,7 +117,7 @@ class TestForeachMaximumScalar(TestCase):
111 torch._foreach_maximum_(npu_tensors[0], scalar)117 torch._foreach_maximum_(npu_tensors[0], scalar)
112 118 
113 self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])119 self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])
114- 120+ 
115 @SupportedDevices(['Ascend910B'])121 @SupportedDevices(['Ascend910B'])
116 def test_foreach_maximum_scalar_inplace_bfloat16_shpae_tensor_num(self):122 def test_foreach_maximum_scalar_inplace_bfloat16_shpae_tensor_num(self):
117 tensor_num_list = [20, 50]123 tensor_num_list = [20, 50]
@@ -121,9 +127,8 @@ class TestForeachMaximumScalar(TestCase):
121 torch._foreach_maximum_(cpu_tensors[0], scalar)127 torch._foreach_maximum_(cpu_tensors[0], scalar)
122 torch._foreach_maximum_(npu_tensors[0], scalar)128 torch._foreach_maximum_(npu_tensors[0], scalar)
123 129 
124- self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])130+ self.assert_equal(cpu_tensors[0], npu_tensors[0])
125- 131+ 
126- @SupportedDevices(['Ascend910B'])
127 def test_foreach_maximum_scalar_inplace_int32_shpae_tensor_num(self):132 def test_foreach_maximum_scalar_inplace_int32_shpae_tensor_num(self):
128 tensor_num_list = [20, 50]133 tensor_num_list = [20, 50]
129 for tensor_num in tensor_num_list :134 for tensor_num in tensor_num_list :
@@ -15,6 +15,17 @@ class TestForeachMaximumScalarList(TestCase):
15 "bfloat16" : torch.bfloat16,15 "bfloat16" : torch.bfloat16,
16 "int32" : torch.int3216 "int32" : torch.int32
17 }17 }
18+
19+ def assert_equal(self, cpu_outs, npu_outs):
20+ for cpu_out, npu_out in zip(cpu_outs, npu_outs):
21+ if (cpu_out.shape != npu_out.shape):
22+ self.fail("shape error")
23+ if (cpu_out.dtype != npu_out.dtype):
24+ self.fail("dtype error!")
25+ result = torch.allclose(cpu_out, npu_out.cpu(), rtol=0.001, atol=0.001)
26+ if not result:
27+ self.fail("result error!")
28+ return True
18 29 
19 def create_tensors(self, dtype, shapes):30 def create_tensors(self, dtype, shapes):
20 cpu_tensors = []31 cpu_tensors = []
@@ -55,7 +66,6 @@ class TestForeachMaximumScalarList(TestCase):
55 sacalars.append(m)66 sacalars.append(m)
56 return tuple(sacalars)67 return tuple(sacalars)
57 68 
58- @SupportedDevices(['Ascend910B'])
59 def test_foreach_maximum_scalar_list_out_float32_shpae_tensor_num(self):69 def test_foreach_maximum_scalar_list_out_float32_shpae_tensor_num(self):
60 tensor_num_list = [20, 50]70 tensor_num_list = [20, 50]
61 for tensor_num in tensor_num_list :71 for tensor_num in tensor_num_list :
@@ -66,7 +76,6 @@ class TestForeachMaximumScalarList(TestCase):
66 76 
67 self.assertRtolEqual(cpu_output, npu_output)77 self.assertRtolEqual(cpu_output, npu_output)
68 78
69- @SupportedDevices(['Ascend910B'])
70 def test_foreach_maximum_scalar_list_out_float16_shpae_tensor_num(self):79 def test_foreach_maximum_scalar_list_out_float16_shpae_tensor_num(self):
71 tensor_num_list = [20, 50]80 tensor_num_list = [20, 50]
72 for tensor_num in tensor_num_list :81 for tensor_num in tensor_num_list :
@@ -86,9 +95,8 @@ class TestForeachMaximumScalarList(TestCase):
86 cpu_output = torch._foreach_maximum(cpu_tensors[0], scalars)95 cpu_output = torch._foreach_maximum(cpu_tensors[0], scalars)
87 npu_output = torch._foreach_maximum(npu_tensors[0], scalars)96 npu_output = torch._foreach_maximum(npu_tensors[0], scalars)
88 97 
89- self.assertRtolEqual(cpu_output, npu_output)98+ self.assert_equal(cpu_output, npu_output)
90- 99+
91- @SupportedDevices(['Ascend910B'])
92 def test_foreach_maximum_scalar_list_out_int32_shpae_tensor_num(self):100 def test_foreach_maximum_scalar_list_out_int32_shpae_tensor_num(self):
93 tensor_num_list = [20, 50]101 tensor_num_list = [20, 50]
94 for tensor_num in tensor_num_list :102 for tensor_num in tensor_num_list :
@@ -100,7 +108,6 @@ class TestForeachMaximumScalarList(TestCase):
100 self.assertRtolEqual(cpu_output, npu_output)108 self.assertRtolEqual(cpu_output, npu_output)
101 109
102 110 
103- @SupportedDevices(['Ascend910B'])
104 def test_foreach_maximum_scalar_list_inplace_float32_shpae_tensor_num(self):111 def test_foreach_maximum_scalar_list_inplace_float32_shpae_tensor_num(self):
105 tensor_num_list = [20, 50]112 tensor_num_list = [20, 50]
106 for tensor_num in tensor_num_list :113 for tensor_num in tensor_num_list :
@@ -111,7 +118,6 @@ class TestForeachMaximumScalarList(TestCase):
111 118 
112 self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])119 self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])
113 120
114- @SupportedDevices(['Ascend910B'])
115 def test_foreach_maximum_scalar_list_inplace_float16_shpae_tensor_num(self):121 def test_foreach_maximum_scalar_list_inplace_float16_shpae_tensor_num(self):
116 tensor_num_list = [20, 50]122 tensor_num_list = [20, 50]
117 for tensor_num in tensor_num_list :123 for tensor_num in tensor_num_list :
@@ -131,9 +137,8 @@ class TestForeachMaximumScalarList(TestCase):
131 torch._foreach_maximum_(cpu_tensors[0], scalars)137 torch._foreach_maximum_(cpu_tensors[0], scalars)
132 torch._foreach_maximum_(npu_tensors[0], scalars)138 torch._foreach_maximum_(npu_tensors[0], scalars)
133 139 
134- self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])140+ self.assert_equal(cpu_tensors[0], npu_tensors[0])
135- 141+ 
136- @SupportedDevices(['Ascend910B'])
137 def test_foreach_maximum_scalar_list_inplace_int32_shpae_tensor_num(self):142 def test_foreach_maximum_scalar_list_inplace_int32_shpae_tensor_num(self):
138 tensor_num_list = [20, 50]143 tensor_num_list = [20, 50]
139 for tensor_num in tensor_num_list :144 for tensor_num in tensor_num_list :
@@ -15,6 +15,17 @@ class TestForeachMinimumList(TestCase):
15 "bfloat16" : torch.bfloat16,15 "bfloat16" : torch.bfloat16,
16 "int32" : torch.int3216 "int32" : torch.int32
17 }17 }
18+
19+ def assert_equal(self, cpu_outs, npu_outs):
20+ for cpu_out, npu_out in zip(cpu_outs, npu_outs):
21+ if (cpu_out.shape != npu_out.shape):
22+ self.fail("shape error")
23+ if (cpu_out.dtype != npu_out.dtype):
24+ self.fail("dtype error!")
25+ result = torch.allclose(cpu_out, npu_out.cpu(), rtol=0.001, atol=0.001)
26+ if not result:
27+ self.fail("result error!")
28+ return True
18 29 
19 def create_tensors(self, dtype, shapes):30 def create_tensors(self, dtype, shapes):
20 cpu_tensors = []31 cpu_tensors = []
@@ -46,7 +57,7 @@ class TestForeachMinimumList(TestCase):
46 npu_inputs.append(npu_tensors)57 npu_inputs.append(npu_tensors)
47 return cpu_inputs, npu_inputs58 return cpu_inputs, npu_inputs
48 59 
49- @SupportedDevices(['Ascend910B'])60+ 
50 def test_foreach_minimum_list_out_float32_shpae_tensor_num(self):61 def test_foreach_minimum_list_out_float32_shpae_tensor_num(self):
51 tensor_num_list = [20, 50]62 tensor_num_list = [20, 50]
52 for tensor_num in tensor_num_list :63 for tensor_num in tensor_num_list :
@@ -57,7 +68,6 @@ class TestForeachMinimumList(TestCase):
57 68 
58 self.assertRtolEqual(cpu_output, npu_output)69 self.assertRtolEqual(cpu_output, npu_output)
59 70
60- @SupportedDevices(['Ascend910B'])
61 def test_foreach_minimum_list_out_float16_shpae_tensor_num(self):71 def test_foreach_minimum_list_out_float16_shpae_tensor_num(self):
62 tensor_num_list = [20, 50]72 tensor_num_list = [20, 50]
63 for tensor_num in tensor_num_list :73 for tensor_num in tensor_num_list :
@@ -77,9 +87,8 @@ class TestForeachMinimumList(TestCase):
77 cpu_output = torch._foreach_minimum(cpu_tensors[0], cpu_tensors[1])87 cpu_output = torch._foreach_minimum(cpu_tensors[0], cpu_tensors[1])
78 npu_output = torch._foreach_minimum(npu_tensors[0], npu_tensors[1])88 npu_output = torch._foreach_minimum(npu_tensors[0], npu_tensors[1])
79 89 
80- self.assertRtolEqual(cpu_output, npu_output)90+ self.assert_equal(cpu_output, npu_output)
81- 91+ 
82- @SupportedDevices(['Ascend910B'])
83 def test_foreach_minimum_list_out_int32_shpae_tensor_num(self):92 def test_foreach_minimum_list_out_int32_shpae_tensor_num(self):
84 tensor_num_list = [20, 50]93 tensor_num_list = [20, 50]
85 for tensor_num in tensor_num_list :94 for tensor_num in tensor_num_list :
@@ -90,7 +99,6 @@ class TestForeachMinimumList(TestCase):
90 99 
91 self.assertRtolEqual(cpu_output, npu_output)100 self.assertRtolEqual(cpu_output, npu_output)
92 101 
93- @SupportedDevices(['Ascend910B'])
94 def test_foreach_minimum_list_inplace_float32_shpae_tensor_num(self):102 def test_foreach_minimum_list_inplace_float32_shpae_tensor_num(self):
95 tensor_num_list = [20, 50]103 tensor_num_list = [20, 50]
96 for tensor_num in tensor_num_list :104 for tensor_num in tensor_num_list :
@@ -101,7 +109,6 @@ class TestForeachMinimumList(TestCase):
101 109 
102 self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])110 self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])
103 111
104- @SupportedDevices(['Ascend910B'])
105 def test_foreach_minimum_list_inplace_float16_shpae_tensor_num(self):112 def test_foreach_minimum_list_inplace_float16_shpae_tensor_num(self):
106 tensor_num_list = [20, 50]113 tensor_num_list = [20, 50]
107 for tensor_num in tensor_num_list :114 for tensor_num in tensor_num_list :
@@ -111,7 +118,7 @@ class TestForeachMinimumList(TestCase):
111 torch._foreach_minimum_(npu_tensors[0], npu_tensors[1])118 torch._foreach_minimum_(npu_tensors[0], npu_tensors[1])
112 119 
113 self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])120 self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])
114- 121+ 
115 @SupportedDevices(['Ascend910B'])122 @SupportedDevices(['Ascend910B'])
116 def test_foreach_minimum_list_inplace_bfloat16_shpae_tensor_num(self):123 def test_foreach_minimum_list_inplace_bfloat16_shpae_tensor_num(self):
117 tensor_num_list = [20, 50]124 tensor_num_list = [20, 50]
@@ -121,9 +128,8 @@ class TestForeachMinimumList(TestCase):
121 torch._foreach_minimum_(cpu_tensors[0], cpu_tensors[1])128 torch._foreach_minimum_(cpu_tensors[0], cpu_tensors[1])
122 torch._foreach_minimum_(npu_tensors[0], npu_tensors[1])129 torch._foreach_minimum_(npu_tensors[0], npu_tensors[1])
123 130 
124- self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])131+ self.assert_equal(cpu_tensors[0], npu_tensors[0])
125 132 
126- @SupportedDevices(['Ascend910B'])
127 def test_foreach_minimum_list_inplace_int32_shpae_tensor_num(self):133 def test_foreach_minimum_list_inplace_int32_shpae_tensor_num(self):
128 tensor_num_list = [20, 50]134 tensor_num_list = [20, 50]
129 for tensor_num in tensor_num_list :135 for tensor_num in tensor_num_list :
@@ -15,7 +15,18 @@ class TestForeachMinimumScalar(TestCase):
15 "int32" : torch.int32,15 "int32" : torch.int32,
16 "bfloat16" : torch.bfloat1616 "bfloat16" : torch.bfloat16
17 }17 }
18- 18+ 
19+ def assert_equal(self, cpu_outs, npu_outs):
20+ for cpu_out, npu_out in zip(cpu_outs, npu_outs):
21+ if (cpu_out.shape != npu_out.shape):
22+ self.fail("shape error")
23+ if (cpu_out.dtype != npu_out.dtype):
24+ self.fail("dtype error!")
25+ result = torch.allclose(cpu_out, npu_out.cpu(), rtol=0.001, atol=0.001)
26+ if not result:
27+ self.fail("result error!")
28+ return True
29+ 
19 def create_tensors(self, dtype, shapes):30 def create_tensors(self, dtype, shapes):
20 cpu_tensors = []31 cpu_tensors = []
21 npu_tensors = []32 npu_tensors = []
@@ -46,7 +57,6 @@ class TestForeachMinimumScalar(TestCase):
46 npu_inputs.append(npu_tensors)57 npu_inputs.append(npu_tensors)
47 return cpu_inputs, npu_inputs58 return cpu_inputs, npu_inputs
48 59 
49- @SupportedDevices(['Ascend910B'])
50 def test_foreach_maximum_scalar_out_float32_shpae_tensor_num(self):60 def test_foreach_maximum_scalar_out_float32_shpae_tensor_num(self):
51 tensor_num_list = [20, 50]61 tensor_num_list = [20, 50]
52 for tensor_num in tensor_num_list :62 for tensor_num in tensor_num_list :
@@ -57,7 +67,6 @@ class TestForeachMinimumScalar(TestCase):
57 67 
58 self.assertRtolEqual(cpu_output, npu_output)68 self.assertRtolEqual(cpu_output, npu_output)
59 69
60- @SupportedDevices(['Ascend910B'])
61 def test_foreach_maximum_scalar_out_float16_shpae_tensor_num(self):70 def test_foreach_maximum_scalar_out_float16_shpae_tensor_num(self):
62 tensor_num_list = [20, 50]71 tensor_num_list = [20, 50]
63 for tensor_num in tensor_num_list :72 for tensor_num in tensor_num_list :
@@ -77,9 +86,8 @@ class TestForeachMinimumScalar(TestCase):
77 cpu_output = torch._foreach_maximum(cpu_tensors[0], scalar)86 cpu_output = torch._foreach_maximum(cpu_tensors[0], scalar)
78 npu_output = torch._foreach_maximum(npu_tensors[0], scalar)87 npu_output = torch._foreach_maximum(npu_tensors[0], scalar)
79 88 
80- self.assertRtolEqual(cpu_output, npu_output)89+ self.assert_equal(cpu_output, npu_output)
81 90
82- @SupportedDevices(['Ascend910B'])
83 def test_foreach_maximum_scalar_out_int32_shpae_tensor_num(self):91 def test_foreach_maximum_scalar_out_int32_shpae_tensor_num(self):
84 tensor_num_list = [20, 50]92 tensor_num_list = [20, 50]
85 for tensor_num in tensor_num_list :93 for tensor_num in tensor_num_list :
@@ -90,7 +98,6 @@ class TestForeachMinimumScalar(TestCase):
90 98 
91 self.assertRtolEqual(cpu_output, npu_output)99 self.assertRtolEqual(cpu_output, npu_output)
92 100 
93- @SupportedDevices(['Ascend910B'])
94 def test_foreach_maximum_scalar_inplace_float32_shpae_tensor_num(self):101 def test_foreach_maximum_scalar_inplace_float32_shpae_tensor_num(self):
95 tensor_num_list = [20, 50]102 tensor_num_list = [20, 50]
96 for tensor_num in tensor_num_list :103 for tensor_num in tensor_num_list :
@@ -101,7 +108,6 @@ class TestForeachMinimumScalar(TestCase):
101 108 
102 self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])109 self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])
103 110
104- @SupportedDevices(['Ascend910B'])
105 def test_foreach_maximum_scalar_inplace_float16_shpae_tensor_num(self):111 def test_foreach_maximum_scalar_inplace_float16_shpae_tensor_num(self):
106 tensor_num_list = [20, 50]112 tensor_num_list = [20, 50]
107 for tensor_num in tensor_num_list :113 for tensor_num in tensor_num_list :
@@ -121,9 +127,8 @@ class TestForeachMinimumScalar(TestCase):
121 torch._foreach_maximum_(cpu_tensors[0], scalar)127 torch._foreach_maximum_(cpu_tensors[0], scalar)
122 torch._foreach_maximum_(npu_tensors[0], scalar)128 torch._foreach_maximum_(npu_tensors[0], scalar)
123 129 
124- self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])130+ self.assert_equal(cpu_tensors[0], npu_tensors[0])
125- 131+ 
126- @SupportedDevices(['Ascend910B'])
127 def test_foreach_maximum_scalar_inplace_int32_shpae_tensor_num(self):132 def test_foreach_maximum_scalar_inplace_int32_shpae_tensor_num(self):
128 tensor_num_list = [20, 50]133 tensor_num_list = [20, 50]
129 for tensor_num in tensor_num_list :134 for tensor_num in tensor_num_list :
@@ -16,6 +16,17 @@ class TestForeachMinimumScalarList(TestCase):
16 "int32" : torch.int3216 "int32" : torch.int32
17 }17 }
18 18 
19+ def assert_equal(self, cpu_outs, npu_outs):
20+ for cpu_out, npu_out in zip(cpu_outs, npu_outs):
21+ if (cpu_out.shape != npu_out.shape):
22+ self.fail("shape error")
23+ if (cpu_out.dtype != npu_out.dtype):
24+ self.fail("dtype error!")
25+ result = torch.allclose(cpu_out, npu_out.cpu(), rtol=0.001, atol=0.001)
26+ if not result:
27+ self.fail("result error!")
28+ return True
29+ 
19 def create_tensors(self, dtype, shapes):30 def create_tensors(self, dtype, shapes):
20 cpu_tensors = []31 cpu_tensors = []
21 npu_tensors = []32 npu_tensors = []
@@ -54,8 +65,7 @@ class TestForeachMinimumScalarList(TestCase):
54 m = float(m)65 m = float(m)
55 sacalars.append(m)66 sacalars.append(m)
56 return tuple(sacalars)67 return tuple(sacalars)
57- 68+
58- @SupportedDevices(['Ascend910B'])
59 def test_foreach_minimum_scalar_list_out_float32_shpae_tensor_num(self):69 def test_foreach_minimum_scalar_list_out_float32_shpae_tensor_num(self):
60 tensor_num_list = [20, 50]70 tensor_num_list = [20, 50]
61 for tensor_num in tensor_num_list :71 for tensor_num in tensor_num_list :
@@ -66,7 +76,6 @@ class TestForeachMinimumScalarList(TestCase):
66 76 
67 self.assertRtolEqual(cpu_output, npu_output)77 self.assertRtolEqual(cpu_output, npu_output)
68 78
69- @SupportedDevices(['Ascend910B'])
70 def test_foreach_minimum_scalar_list_out_float16_shpae_tensor_num(self):79 def test_foreach_minimum_scalar_list_out_float16_shpae_tensor_num(self):
71 tensor_num_list = [20, 50]80 tensor_num_list = [20, 50]
72 for tensor_num in tensor_num_list :81 for tensor_num in tensor_num_list :
@@ -86,9 +95,8 @@ class TestForeachMinimumScalarList(TestCase):
86 cpu_output = torch._foreach_minimum(cpu_tensors[0], scalars)95 cpu_output = torch._foreach_minimum(cpu_tensors[0], scalars)
87 npu_output = torch._foreach_minimum(npu_tensors[0], scalars)96 npu_output = torch._foreach_minimum(npu_tensors[0], scalars)
88 97 
89- self.assertRtolEqual(cpu_output, npu_output)98+ self.assert_equal(cpu_output, npu_output)
90- 99+ 
91- @SupportedDevices(['Ascend910B'])
92 def test_foreach_minimum_scalar_list_out_int32_shpae_tensor_num(self):100 def test_foreach_minimum_scalar_list_out_int32_shpae_tensor_num(self):
93 tensor_num_list = [20, 50]101 tensor_num_list = [20, 50]
94 for tensor_num in tensor_num_list :102 for tensor_num in tensor_num_list :
@@ -99,8 +107,6 @@ class TestForeachMinimumScalarList(TestCase):
99 107 
100 self.assertRtolEqual(cpu_output, npu_output)108 self.assertRtolEqual(cpu_output, npu_output)
101 109
102- 
103- @SupportedDevices(['Ascend910B'])
104 def test_foreach_minimum_scalar_list_inplace_float32_shpae_tensor_num(self):110 def test_foreach_minimum_scalar_list_inplace_float32_shpae_tensor_num(self):
105 tensor_num_list = [20, 50]111 tensor_num_list = [20, 50]
106 for tensor_num in tensor_num_list :112 for tensor_num in tensor_num_list :
@@ -111,7 +117,6 @@ class TestForeachMinimumScalarList(TestCase):
111 117 
112 self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])118 self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])
113 119
114- @SupportedDevices(['Ascend910B'])
115 def test_foreach_minimum_scalar_list_inplace_float16_shpae_tensor_num(self):120 def test_foreach_minimum_scalar_list_inplace_float16_shpae_tensor_num(self):
116 tensor_num_list = [20, 50]121 tensor_num_list = [20, 50]
117 for tensor_num in tensor_num_list :122 for tensor_num in tensor_num_list :
@@ -131,9 +136,8 @@ class TestForeachMinimumScalarList(TestCase):
131 torch._foreach_minimum_(cpu_tensors[0], scalars)136 torch._foreach_minimum_(cpu_tensors[0], scalars)
132 torch._foreach_minimum_(npu_tensors[0], scalars)137 torch._foreach_minimum_(npu_tensors[0], scalars)
133 138 
134- self.assertRtolEqual(cpu_tensors[0], npu_tensors[0])139+ self.assert_equal(cpu_tensors[0], npu_tensors[0])
135 140
136- @SupportedDevices(['Ascend910B'])
137 def test_foreach_minimum_scalar_list_inplace_int32_shpae_tensor_num(self):141 def test_foreach_minimum_scalar_list_inplace_int32_shpae_tensor_num(self):
138 tensor_num_list = [20, 50]142 tensor_num_list = [20, 50]
139 for tensor_num in tensor_num_list :143 for tensor_num in tensor_num_list :