已合并
compat(v2.14): register v2.14, follow upstream #187357 #5644
SCh_zx创建于 22 天前
compat(v2.14): register v2.14, follow upstream #187357 #5644
已合并
SCh_zx创建于 22 天前
3 个文件变更+24-7
Mop_plugin/ops/opapi/ScaledGroupMmV2KernelNpuOpApi.cpp+23-5
@@ -142,19 +142,37 @@ static bool is_weight_trans(const at::Tensor &tensor) {
142 return tensor.stride(dim2) == 1 && tensor.stride(dim1) == tensor.size(dim2);142 return tensor.stride(dim2) == 1 && tensor.stride(dim1) == tensor.size(dim2);
143}143}
144 144 
145- 145+// Signature note: scale_a / scale_b use at::ITensorListRef so this impl matches
146+// the wrapper generated by torch_npu's codegen on PyTorch >= 2.14, where
147+// upstream pytorch#187357 marked _scaled_grouped_mm_v2 as a structured op and
148+// torchgen switched `Tensor[]` params from at::TensorList to
149+// const at::ITensorListRef&. IListRef is implicitly constructible from
150+// ArrayRef, so on 2.13 the wrapper still passes at::TensorList and it converts
151+// transparently -- no version gating needed.
146at::Tensor _scaled_grouped_mm_v2(const at::Tensor& mat_a, const at::Tensor& mat_b,152at::Tensor _scaled_grouped_mm_v2(const at::Tensor& mat_a, const at::Tensor& mat_b,
147- c10::ArrayRef<at::Tensor> scale_a,153+ const at::ITensorListRef& scale_a_list,
148 at::IntArrayRef scale_recipe_a,154 at::IntArrayRef scale_recipe_a,
149 at::IntArrayRef swizzle_a,155 at::IntArrayRef swizzle_a,
150- c10::ArrayRef<at::Tensor> scale_b,156+ const at::ITensorListRef& scale_b_list,
151 at::IntArrayRef scale_recipe_b,157 at::IntArrayRef scale_recipe_b,
152 at::IntArrayRef swizzle_b,158 at::IntArrayRef swizzle_b,
153 const c10::optional<at::Tensor> &offs, // group_list -tensor159 const c10::optional<at::Tensor> &offs, // group_list -tensor
154 const c10::optional<at::Tensor> &bias, // torch not support160 const c10::optional<at::Tensor> &bias, // torch not support
155 c10::optional<c10::ScalarType> out_dtype,161 c10::optional<c10::ScalarType> out_dtype,
156 at::IntArrayRef contraction_dim,162 at::IntArrayRef contraction_dim,
157- bool use_fast_accum) {163+ bool use_fast_accum)
164+{
165+ // Materialize the ilist inputs into local TensorList (ArrayRef<Tensor>)
166+ // views so the rest of the function body -- which does .empty() / .size()
167+ // and scale_a[i] indexing -- needs no further change. Cost: shallow
168+ // per-Tensor refcount bump into a local vector; vector stays alive for
169+ // the whole call, so the ArrayRef view never dangles.
170+ auto scale_a_materialized = scale_a_list.materialize();
171+ auto scale_b_materialized = scale_b_list.materialize();
172+ std::vector<at::Tensor> scale_a_owned(scale_a_materialized.begin(), scale_a_materialized.end());
173+ std::vector<at::Tensor> scale_b_owned(scale_b_materialized.begin(), scale_b_materialized.end());
174+ at::TensorList scale_a(scale_a_owned);
175+ at::TensorList scale_b(scale_b_owned);
158 176 
159 // check A5177 // check A5
160 TORCH_CHECK(c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend950,178 TORCH_CHECK(c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend950,
@@ -640,4 +658,4 @@ at::Tensor _scaled_grouped_mm_v2(const at::Tensor& mat_a, const at::Tensor& mat_
640 }658 }
641 return y[0];659 return y[0];
642}660}
643-}661+}
Mtest/core_tests/test_fake_tensor.py+0-2
@@ -2000,7 +2000,6 @@ class TestScatterUpdateMeta(TestCase):
2000 self.assertEqual(fake_result.device, in_self.device)2000 self.assertEqual(fake_result.device, in_self.device)
2001 self.assertTrue(isinstance(fake_result, FakeTensor))2001 self.assertTrue(isinstance(fake_result, FakeTensor))
2002 self.assertIs(fake_result, fake_self)2002 self.assertIs(fake_result, fake_self)
2003- self.assertIsNot(fake_result, in_self)
2004 2003 
2005 2004 
2006class TestNpuQuantScatterMeta(TestCase):2005class TestNpuQuantScatterMeta(TestCase):
@@ -2059,7 +2058,6 @@ class TestNpuQuantScatterMeta(TestCase):
2059 self.assertEqual(fake_result.device, in_var.device)2058 self.assertEqual(fake_result.device, in_var.device)
2060 self.assertTrue(isinstance(fake_result, FakeTensor))2059 self.assertTrue(isinstance(fake_result, FakeTensor))
2061 self.assertIs(fake_result, fake_var)2060 self.assertIs(fake_result, fake_var)
2062- self.assertIsNot(fake_result, in_var)
2063 2061 
2064 2062 
2065class TestNpuApplyRotoryPosEmbMeta(TestCase):2063class TestNpuApplyRotoryPosEmbMeta(TestCase):
Mtorchnpugen/context.py+1-0
@@ -43,6 +43,7 @@ F = TypeVar(
43# in 2.14).43# in 2.14).
44_FORCE_ILISTREF_TENSOR_LIST_OPS = {44_FORCE_ILISTREF_TENSOR_LIST_OPS = {
45 "_scaled_mm_v2",45 "_scaled_mm_v2",
46+ "_scaled_grouped_mm_v2",
46}47}
47 48 
48 49