Merged
GMM支持a8w4支持新的数据类型: support float4 e1m2 for mx a8w4 #8748
GMM支持a8w4支持新的数据类型: support float4 e1m2 for mx a8w4 #8748
Merged
zhangzhizhuoAdd on Jul 15
Total: 11 files changed+968-901
@@ -96,7 +96,7 @@
96 y_i=x_i \times (weight_i * antiquant\_scale_i) + bias_i96 y_i=x_i \times (weight_i * antiquant\_scale_i) + bias_i
97 $$97 $$
98 98 
99- x为FLOAT8_E4M3FN输入,weight为FLOAT32(表示8个FLOAT4_E2M1)/FLOAT4_E2M1输入99+ x为FLOAT8_E4M3FN输入,weight为FLOAT32(表示8个FLOAT4_E2M1)/FLOAT4_E2M1/FLOAT4_E1M2输入
100 100 
101 $$101 $$
102 y_i=(x_i * per\_token\_scale_i) \times (weight_i * antiquant\_scale_i) + bias_i102 y_i=(x_i * per\_token\_scale_i) \times (weight_i * antiquant\_scale_i) + bias_i
@@ -612,10 +612,10 @@ aclnnStatus aclnnGroupedMatmulWeightNz(
612 |:-------:|:-------:|:-------------------:|:-------:|:--------------------:|:-----------:|:---------------------:|:------------:|:-------:|:---------------------------:|:------------:|:---------------------------:|:------------------:|:--------:|612 |:-------:|:-------:|:-------------------:|:-------:|:--------------------:|:-----------:|:---------------------:|:------------:|:-------:|:---------------------------:|:------------:|:---------------------------:|:------------------:|:--------:|
613 |0 |BFLOAT16 |null |FLOAT4_E2M1 |FLOAT8_E8M0 |null |null |BFLOAT16/FLOAT32/null |BFLOAT16 |null |(g, K, N) |(g, K/groupSize, N) |null |(g, N) |613 |0 |BFLOAT16 |null |FLOAT4_E2M1 |FLOAT8_E8M0 |null |null |BFLOAT16/FLOAT32/null |BFLOAT16 |null |(g, K, N) |(g, K/groupSize, N) |null |(g, N) |
614 |0 |FLOAT16 |null |FLOAT4_E2M1 |FLOAT8_E8M0 |null |null |FLOAT16/null |FLOAT16 |null |(g, K, N) |(g, K/groupSize, N) |null |(g, N) |614 |0 |FLOAT16 |null |FLOAT4_E2M1 |FLOAT8_E8M0 |null |null |FLOAT16/null |FLOAT16 |null |(g, K, N) |(g, K/groupSize, N) |null |(g, N) |
615- |0 |FLOAT8_E4M3FN |FLOAT8_E8M0 |FLOAT4_E2M1 |FLOAT8_E8M0 |null |null |FLOAT16/null |FLOAT16 |(M, K/groupSize/2, 2) |(g, N, K) |(g, N, K/groupSize/2, 2) |null |(g, N) |615+ |0 |FLOAT8_E4M3FN |FLOAT8_E8M0 |FLOAT4_E2M1/FLOAT4_E1M2 |FLOAT8_E8M0 |null |null |FLOAT16/null |FLOAT16 |(M, K/groupSize/2, 2) |(g, N, K) |(g, N, K/groupSize/2, 2) |null |(g, N) |
616- |0 |FLOAT8_E4M3FN |FLOAT8_E8M0 |FLOAT4_E2M1 |FLOAT8_E8M0 |null |null |BFLOAT16/null |BFLOAT16 |(M, K/groupSize/2, 2) |(g, N, K) |(g, N, K/groupSize/2, 2) |null |(g, N) |616+ |0 |FLOAT8_E4M3FN |FLOAT8_E8M0 |FLOAT4_E2M1/FLOAT4_E1M2 |FLOAT8_E8M0 |null |null |BFLOAT16/null |BFLOAT16 |(M, K/groupSize/2, 2) |(g, N, K) |(g, N, K/groupSize/2, 2) |null |(g, N) |
617- |0 |FLOAT8_E4M3FN |FLOAT8_E8M0 |FLOAT4_E2M1 |FLOAT8_E8M0 |null |null |FLOAT16/null |FLOAT16 |(M, K/groupSize/2, 2) |(N, K) |(N, K/groupSize/2, 2) |null |(N) |617+ |0 |FLOAT8_E4M3FN |FLOAT8_E8M0 |FLOAT4_E2M1/FLOAT4_E1M2 |FLOAT8_E8M0 |null |null |FLOAT16/null |FLOAT16 |(M, K/groupSize/2, 2) |(N, K) |(N, K/groupSize/2, 2) |null |(N) |
618- |0 |FLOAT8_E4M3FN |FLOAT8_E8M0 |FLOAT4_E2M1 |FLOAT8_E8M0 |null |null |BFLOAT16/null |BFLOAT16 |(M, K/groupSize/2, 2) |(N, K) |(N, K/groupSize/2, 2) |null |(N) |618+ |0 |FLOAT8_E4M3FN |FLOAT8_E8M0 |FLOAT4_E2M1/FLOAT4_E1M2 |FLOAT8_E8M0 |null |null |BFLOAT16/null |BFLOAT16 |(M, K/groupSize/2, 2) |(N, K) |(N, K/groupSize/2, 2) |null |(N) |
619 |0 |INT8 |FLOAT32 |INT4 |FLOAT16 |FLOAT32 |null |FLOAT32/null |BFLOAT16 |(M) |(g, K, N) |(g, K/groupSize, N) |(g, N) |(g, N) |619 |0 |INT8 |FLOAT32 |INT4 |FLOAT16 |FLOAT32 |null |FLOAT32/null |BFLOAT16 |(M) |(g, K, N) |(g, K/groupSize, N) |(g, N) |(g, N) |
620 |0 |INT8 |FLOAT32 |INT4 |FLOAT16 |FLOAT32 |null |FLOAT32/null |FLOAT16 |(M) |(g, K, N) |(g, K/groupSize, N) |(g, N) |(g, N) |620 |0 |INT8 |FLOAT32 |INT4 |FLOAT16 |FLOAT32 |null |FLOAT32/null |FLOAT16 |(M) |(g, K, N) |(g, K/groupSize, N) |(g, N) |(g, N) |
621 |0 |BFLOAT16 |null |FLOAT32 |FLOAT8_E8M0 |null |null |BFLOAT16/FLOAT32/null |BFLOAT16 |null |(g, K, N/8) |(g, K/groupSize, N) |null |(g, N) |621 |0 |BFLOAT16 |null |FLOAT32 |FLOAT8_E8M0 |null |null |BFLOAT16/FLOAT32/null |BFLOAT16 |null |(g, K, N/8) |(g, K/groupSize, N) |null |(g, N) |
@@ -626,13 +626,14 @@ aclnnStatus aclnnGroupedMatmulWeightNz(
626 |0 |INT8 |FLOAT32 |INT32 |FLOAT16 |FLOAT32 |null |FLOAT32/null |FLOAT16 |(M) |(g, K, N/8) |(g, K/groupSize, N) |(g, N) |(g, N) |626 |0 |INT8 |FLOAT32 |INT32 |FLOAT16 |FLOAT32 |null |FLOAT32/null |FLOAT16 |(M) |(g, K, N/8) |(g, K/groupSize, N) |(g, N) |(g, N) |
627 627 
628 - 约束说明:628 - 约束说明:
629- - 当x为FLOAT8_E4M3FN/FLOAT16/BFLOAT16,weight为FLOAT4_E2M1/FLOAT32的场景, groupSize只支持32。629+ - 当x为FLOAT16/BFLOAT16,weight为FLOAT4_E2M1/FLOAT32的场景,groupSize只支持32。
630+ - 当x为FLOAT8_E4M3FN,weight为FLOAT4_E2M1/FLOAT4_E1M2/FLOAT32的场景,groupSize只支持32。
630 - 当x为INT8, weight为INT4/INT32的场景, groupSize只支持128、192、256、512。631 - 当x为INT8, weight为INT4/INT32的场景, groupSize只支持128、192、256、512。
631 - 当x的shape固定为(M, K), out的shape固定为(M, N)。632 - 当x的shape固定为(M, K), out的shape固定为(M, N)。
632 - mx伪量化和K-CG伪量化场景,weight的K轴和N轴均要求32B对齐。633 - mx伪量化和K-CG伪量化场景,weight的K轴和N轴均要求32B对齐。
633- - 当x和weight的类型分别为BFLOAT16/FLOAT16和FLOAT4_E2M1/FLOAT32时,或为INT8和INT4/INT32时,仅支持x、weight均不转置,为FLOAT8_E4M3FN和FLOAT4_E2M1/FLOAT32时仅支持x不转置且weight转置。634+ - 当x和weight的类型分别为BFLOAT16/FLOAT16和FLOAT4_E2M1/FLOAT32时,或为INT8和INT4/INT32时,仅支持x、weight均不转置,为FLOAT8_E4M3FN和FLOAT4_E2M1/FLOAT4_E1M2/FLOAT32时仅支持x不转置且weight转置。
634 - antiquantScale的转置与否和weight保持一致。635 - antiquantScale的转置与否和weight保持一致。
635- - 当x为FLOAT8_E4M3FN,weight为FLOAT4_E2M1,weight shape为(N, K)的场景,属于单多单场景, weight支持多tensor(个数大于等于1),antiquantScaleOptional、antiquantOffsetOptional、biasOptional的tensor个数和weight一致。636+ - 当x为FLOAT8_E4M3FN,weight为FLOAT4_E2M1/FLOAT4_E1M2,weight shape为(N, K)的场景,属于单多单场景, weight支持多tensor(个数大于等于1),antiquantScaleOptional、antiquantOffsetOptional、biasOptional的tensor个数和weight一致。
636 637 
637 - 静态量化场景支持的输入类型与shape为:638 - 静态量化场景支持的输入类型与shape为:
638 - 以下入参为空:offsetOptional、antiquantScaleOptional、antiquantOffsetOptional、perTokenScaleOptional、activationInputOptional、activationQuantScaleOptional、activationQuantOffsetOptional、activationFeatureOutOptional639 - 以下入参为空:offsetOptional、antiquantScaleOptional、antiquantOffsetOptional、perTokenScaleOptional、activationInputOptional、activationQuantScaleOptional、activationQuantOffsetOptional、activationFeatureOutOptional
@@ -43,17 +43,17 @@
43 43 
44using namespace op;44using namespace op;
45 45 
46-#define DEPRECATED_API_WARN_ONCE(oldApiName, newApiName) \46+#define DEPRECATED_API_WARN_ONCE(oldApiName, newApiName) \
47- do { \47+ do { \
48- static bool isFirstWarn = true; \48+ static bool isFirstWarn = true; \
49- if (isFirstWarn) { \49+ if (isFirstWarn) { \
50- OP_LOGW("%s is scheduled to be deprecated in a post-December 2026 version update, " \50+ OP_LOGW("%s is scheduled to be deprecated in a post-December 2026 version update, " \
51- "and will be replaced by the %s. " \51+ "and will be replaced by the %s. " \
52- "We apologize for any inconvenience caused and appreciate your timely migration to the new " \52+ "We apologize for any inconvenience caused and appreciate your timely migration to the new " \
53- "interface.", \53+ "interface.", \
54- (oldApiName), (newApiName)); \54+ (oldApiName), (newApiName)); \
55- isFirstWarn = false; \55+ isFirstWarn = false; \
56- } \56+ } \
57 } while (0)57 } while (0)
58 58 
59#ifdef __cplusplus59#ifdef __cplusplus
@@ -1008,10 +1008,10 @@ static aclnnStatus CheckGroupedMatmulAntiQuant(const gmm::GroupedMatmulParams &g
1008 ACLNN_ERR_PARAM_INVALID, "In op [%s], when %s, [%s] tensor list is invalid.", opName, scenario,1008 ACLNN_ERR_PARAM_INVALID, "In op [%s], when %s, [%s] tensor list is invalid.", opName, scenario,
1009 "antiquantScale");1009 "antiquantScale");
1010 if (gmmParams.antiquantOffsetOptional != nullptr) {1010 if (gmmParams.antiquantOffsetOptional != nullptr) {
1011- CHECK_COND(CheckOptionalTensorList(gmmParams, gmmParams.antiquantOffsetOptional, "antiquantOffset") ==1011+ CHECK_COND(
1012- ACLNN_SUCCESS,1012+ CheckOptionalTensorList(gmmParams, gmmParams.antiquantOffsetOptional, "antiquantOffset") == ACLNN_SUCCESS,
1013- ACLNN_ERR_PARAM_INVALID, "In op [%s], when %s, [%s] tensor list is invalid.", opName, scenario,1013+ ACLNN_ERR_PARAM_INVALID, "In op [%s], when %s, [%s] tensor list is invalid.", opName, scenario,
1014- "antiquantOffset");1014+ "antiquantOffset");
1015 }1015 }
1016 // check perGroupNum1016 // check perGroupNum
1017 if (isAntiquantInt4) {1017 if (isAntiquantInt4) {
@@ -1676,12 +1676,12 @@ static aclnnStatus SplitMSingleXSingleWeightSingleY(const gmm::GroupedMatmulPara
1676 "In op [%s], when groupType == 0(split-M) with single x, single weight and single y, [%s] dim num "1676 "In op [%s], when groupType == 0(split-M) with single x, single weight and single y, [%s] dim num "
1677 "or format is invalid.",1677 "or format is invalid.",
1678 opName, "x");1678 opName, "x");
1679- CHECK_COND(CheckDimNumAndFormat(gmmParams, gmmParams.weight, gmm::SPLIT_M_SINGLE_WEIGHT_DIM, "weight") ==1679+ CHECK_COND(
1680- ACLNN_SUCCESS,1680+ CheckDimNumAndFormat(gmmParams, gmmParams.weight, gmm::SPLIT_M_SINGLE_WEIGHT_DIM, "weight") == ACLNN_SUCCESS,
1681- ACLNN_ERR_PARAM_INVALID,1681+ ACLNN_ERR_PARAM_INVALID,
1682- "In op [%s], when groupType == 0(split-M) with single x, single weight and single y, [%s] dim num "1682+ "In op [%s], when groupType == 0(split-M) with single x, single weight and single y, [%s] dim num "
1683- "or format is invalid.",1683+ "or format is invalid.",
1684- opName, "weight");1684+ opName, "weight");
1685 1685 
1686 CHECK_COND(CheckDimNumAndFormat(gmmParams, gmmParams.y, gmm::MIN_FM_DIM, "y") == ACLNN_SUCCESS,1686 CHECK_COND(CheckDimNumAndFormat(gmmParams, gmmParams.y, gmm::MIN_FM_DIM, "y") == ACLNN_SUCCESS,
1687 ACLNN_ERR_PARAM_INVALID,1687 ACLNN_ERR_PARAM_INVALID,
@@ -1710,13 +1710,13 @@ static aclnnStatus SplitMSingleXSingleWeightSingleY(const gmm::GroupedMatmulPara
1710 "In op [%s], when groupType == 0(split-M) with single x, single weight and single y, N dim value of "1710 "In op [%s], when groupType == 0(split-M) with single x, single weight and single y, N dim value of "
1711 "[%s] and [%s] is mismatched.",1711 "[%s] and [%s] is mismatched.",
1712 opName, "weight", "y");1712 opName, "weight", "y");
1713- CHECK_COND(CheckWeightShapeInnerAxisEven(gmmParams.weight, gmmParams.weight->Size(),1713+ CHECK_COND(
1714- gmmParams.transposeWeight ? 1 : 2,1714+ CheckWeightShapeInnerAxisEven(gmmParams.weight, gmmParams.weight->Size(), gmmParams.transposeWeight ? 1 : 2,
1715- opName) == ACLNN_SUCCESS, // 2: axis index1715+ opName) == ACLNN_SUCCESS, // 2: axis index
1716- ACLNN_ERR_PARAM_INVALID,1716+ ACLNN_ERR_PARAM_INVALID,
1717- "In op [%s], when groupType == 0(split-M) with single x, single weight and single y, weight inner axis "1717+ "In op [%s], when groupType == 0(split-M) with single x, single weight and single y, weight inner axis "
1718- "check failed.",1718+ "check failed.",
1719- opName);1719+ opName);
1720 // check groupList1720 // check groupList
1721 size_t batchSizeWeight = (*gmmParams.weight)[0]->GetViewShape().GetDim(0);1721 size_t batchSizeWeight = (*gmmParams.weight)[0]->GetViewShape().GetDim(0);
1722 CHECK_COND(CheckGroupListSplitM(gmmParams, true, false, false, batchSizeWeight, opName) == ACLNN_SUCCESS,1722 CHECK_COND(CheckGroupListSplitM(gmmParams, true, false, false, batchSizeWeight, opName) == ACLNN_SUCCESS,
@@ -2393,7 +2393,8 @@ static aclnnStatus TransWeightToNzCheckAlign(gmm::GroupedMatmulParams &gmmParams
2393 } else if (weight->GetDataType() == DataType::DT_INT4) {2393 } else if (weight->GetDataType() == DataType::DT_INT4) {
2394 k_align = gmmParams.transposeWeight ? k % ALIGN_NZ_4BIT_N == 0 : k % ALIGN_NZ_K == 0;2394 k_align = gmmParams.transposeWeight ? k % ALIGN_NZ_4BIT_N == 0 : k % ALIGN_NZ_K == 0;
2395 n_align = gmmParams.transposeWeight ? n % ALIGN_NZ_K == 0 : n % ALIGN_NZ_4BIT_N == 0;2395 n_align = gmmParams.transposeWeight ? n % ALIGN_NZ_K == 0 : n % ALIGN_NZ_4BIT_N == 0;
2396- } else if (weight->GetDataType() == DataType::DT_FLOAT4_E2M1 &&2396+ } else if ((weight->GetDataType() == DataType::DT_FLOAT4_E2M1 ||
2397+ weight->GetDataType() == DataType::DT_FLOAT4_E1M2) &&
2397 (xDtype == DataType::DT_FLOAT16 || xDtype == DataType::DT_BF16 ||2398 (xDtype == DataType::DT_FLOAT16 || xDtype == DataType::DT_BF16 ||
2398 xDtype == DataType::DT_FLOAT8_E4M3FN)) {2399 xDtype == DataType::DT_FLOAT8_E4M3FN)) {
2399 k_align = k % ALIGN_NZ_4BIT_K == 0;2400 k_align = k % ALIGN_NZ_4BIT_K == 0;
@@ -2517,7 +2518,6 @@ static aclnnStatus CheckZeroShapeSplitK(gmm::GroupedMatmulParams &params, uint64
2517 return ACLNN_SUCCESS;2518 return ACLNN_SUCCESS;
2518}2519}
2519 2520 
2520- 
2521static void SetAntiQuantParamsTensorEmptyDAV3510(gmm::GroupedMatmulParams &params, aclOpExecutor *executor)2521static void SetAntiQuantParamsTensorEmptyDAV3510(gmm::GroupedMatmulParams &params, aclOpExecutor *executor)
2522{2522{
2523 DataType weightDtype = (*params.weight)[0]->GetDataType();2523 DataType weightDtype = (*params.weight)[0]->GetDataType();
@@ -2634,9 +2634,9 @@ static aclnnStatus SetTransposedScaleTensorListContiguous(gmm::GroupedMatmulPara
2634 std::vector<aclTensor *> scaleTensorList;2634 std::vector<aclTensor *> scaleTensorList;
2635 if ((*params.scaleOptional)[0] != nullptr &&2635 if ((*params.scaleOptional)[0] != nullptr &&
2636 (*params.scaleOptional)[0]->GetDataType() == DataType::DT_FLOAT8_E8M0) {2636 (*params.scaleOptional)[0]->GetDataType() == DataType::DT_FLOAT8_E8M0) {
2637- CHECK_RET(gmm::CreateContiguousTensorListForMXTypeMScale(params.scaleOptional, scaleTensorList,2637+ CHECK_RET(
2638- executorPtr),2638+ gmm::CreateContiguousTensorListForMXTypeMScale(params.scaleOptional, scaleTensorList, executorPtr),
2639- ACLNN_ERR_INNER_NULLPTR);2639+ ACLNN_ERR_INNER_NULLPTR);
2640 params.scaleOptional = executorPtr->AllocTensorList(scaleTensorList.data(), scaleTensorList.size());2640 params.scaleOptional = executorPtr->AllocTensorList(scaleTensorList.data(), scaleTensorList.size());
2641 CHECK_RET(params.scaleOptional != nullptr, ACLNN_ERR_INNER_NULLPTR);2641 CHECK_RET(params.scaleOptional != nullptr, ACLNN_ERR_INNER_NULLPTR);
2642 } else if (isPerTileQuantMode) {2642 } else if (isPerTileQuantMode) {
@@ -2669,83 +2669,86 @@ static aclnnStatus SetTransposedScaleTensorListContiguous(gmm::GroupedMatmulPara
2669 2669 
2670static aclnnStatus SetTransposedTensorListContiguous(gmm::GroupedMatmulParams &params, aclOpExecutor *executorPtr)2670static aclnnStatus SetTransposedTensorListContiguous(gmm::GroupedMatmulParams &params, aclOpExecutor *executorPtr)
2671{2671{
2672- bool isPerTileQuantMode = IsPerTileQuantMode(params);2672+ bool isPerTileQuantMode = IsPerTileQuantMode(params);
2673- DataType weightDtype = (*params.weight)[0]->GetDataType();2673+ DataType weightDtype = (*params.weight)[0]->GetDataType();
2674- if (params.transposeX) {2674+ if (params.transposeX) {
2675- std::vector<aclTensor*> xTensorList;2675+ std::vector<aclTensor *> xTensorList;
2676- CHECK_RET(gmm::CreateContiguousTensorList(params.x, xTensorList, executorPtr), ACLNN_ERR_INNER_NULLPTR);2676+ CHECK_RET(gmm::CreateContiguousTensorList(params.x, xTensorList, executorPtr), ACLNN_ERR_INNER_NULLPTR);
2677- params.x = executorPtr->AllocTensorList(xTensorList.data(), xTensorList.size());2677+ params.x = executorPtr->AllocTensorList(xTensorList.data(), xTensorList.size());
2678- CHECK_RET(params.x != nullptr, ACLNN_ERR_INNER_NULLPTR);2678+ CHECK_RET(params.x != nullptr, ACLNN_ERR_INNER_NULLPTR);
2679- if (params.perTokenScaleOptional != nullptr &&2679+ if (params.perTokenScaleOptional != nullptr &&
2680- ((*params.perTokenScaleOptional)[0]->GetDataType() == DataType::DT_FLOAT8_E8M0 || isPerTileQuantMode)) {2680+ ((*params.perTokenScaleOptional)[0]->GetDataType() == DataType::DT_FLOAT8_E8M0 || isPerTileQuantMode)) {
2681- std::vector<aclTensor*> perTokenScaleTensorList;2681+ std::vector<aclTensor *> perTokenScaleTensorList;
2682- if (isPerTileQuantMode) {2682+ if (isPerTileQuantMode) {
2683- CHECK_RET(gmm::CreateContiguousTensorList(params.perTokenScaleOptional, perTokenScaleTensorList, executorPtr),2683+ CHECK_RET(
2684+ gmm::CreateContiguousTensorList(params.perTokenScaleOptional, perTokenScaleTensorList, executorPtr),
2684 ACLNN_ERR_INNER_NULLPTR);2685 ACLNN_ERR_INNER_NULLPTR);
2685- } else {2686+ } else {
2686- CHECK_RET(gmm::CreateContiguousTensorListForPertoken(params.perTokenScaleOptional, perTokenScaleTensorList,2687+ CHECK_RET(gmm::CreateContiguousTensorListForPertoken(params.perTokenScaleOptional,
2687- executorPtr),2688+ perTokenScaleTensorList, executorPtr),
2688- ACLNN_ERR_INNER_NULLPTR);2689+ ACLNN_ERR_INNER_NULLPTR);
2689- }2690+ }
2690- params.perTokenScaleOptional = executorPtr->AllocTensorList(perTokenScaleTensorList.data(), perTokenScaleTensorList.size());2691+ params.perTokenScaleOptional =
2691- CHECK_RET(params.perTokenScaleOptional != nullptr, ACLNN_ERR_INNER_NULLPTR);2692+ executorPtr->AllocTensorList(perTokenScaleTensorList.data(), perTokenScaleTensorList.size());
2692- }2693+ CHECK_RET(params.perTokenScaleOptional != nullptr, ACLNN_ERR_INNER_NULLPTR);
2693- }
2694- if (params.transposeWeight) {
2695- std::vector<aclTensor *> weightTensorList;
2696- std::vector<op::Shape> nZShapes;
2697- for (uint64_t idx = 0; idx < (*params.weight).Size(); idx++) {
2698- nZShapes.push_back((*params.weight)[idx]->GetStorageShape());
2699- }
2700- CHECK_RET(gmm::CreateContiguousTensorList(params.weight, weightTensorList, executorPtr), ACLNN_ERR_INNER_NULLPTR);
2701- params.weight = executorPtr->AllocTensorList(weightTensorList.data(), weightTensorList.size());
2702- CHECK_RET(params.weight != nullptr, ACLNN_ERR_INNER_NULLPTR);
2703- if (op::GetCurrentPlatformInfo().GetCurNpuArch() == NpuArch::DAV_3510 &&
2704- ((IsQuant(params.xDtype, weightDtype) &&
2705- (*params.weight)[0]->GetStorageFormat() == op::Format::FORMAT_FRACTAL_NZ) ||
2706- (params.apiVersion == gmm::GMMApiVersion::WeightNz && IsWeightQuant(params.xDtype, weightDtype)))) {
2707- for (uint64_t idx = 0; idx < (*params.weight).Size(); idx++) {
2708- (*params.weight)[idx]->SetStorageShape(nZShapes[idx]);
2709 }2694 }
2710 }2695 }
2711- CHECK_RET(SetTransposedScaleTensorListContiguous(params, executorPtr, isPerTileQuantMode) == ACLNN_SUCCESS,2696+ if (params.transposeWeight) {
2712- ACLNN_ERR_INNER_NULLPTR);2697+ std::vector<aclTensor *> weightTensorList;
2713- }2698+ std::vector<op::Shape> nZShapes;
2699+ for (uint64_t idx = 0; idx < (*params.weight).Size(); idx++) {
2700+ nZShapes.push_back((*params.weight)[idx]->GetStorageShape());
2701+ }
2702+ CHECK_RET(gmm::CreateContiguousTensorList(params.weight, weightTensorList, executorPtr),
2703+ ACLNN_ERR_INNER_NULLPTR);
2704+ params.weight = executorPtr->AllocTensorList(weightTensorList.data(), weightTensorList.size());
2705+ CHECK_RET(params.weight != nullptr, ACLNN_ERR_INNER_NULLPTR);
2706+ if (op::GetCurrentPlatformInfo().GetCurNpuArch() == NpuArch::DAV_3510 &&
2707+ ((IsQuant(params.xDtype, weightDtype) &&
2708+ (*params.weight)[0]->GetStorageFormat() == op::Format::FORMAT_FRACTAL_NZ) ||
2709+ (params.apiVersion == gmm::GMMApiVersion::WeightNz && IsWeightQuant(params.xDtype, weightDtype)))) {
2710+ for (uint64_t idx = 0; idx < (*params.weight).Size(); idx++) {
2711+ (*params.weight)[idx]->SetStorageShape(nZShapes[idx]);
2712+ }
2713+ }
2714+ CHECK_RET(SetTransposedScaleTensorListContiguous(params, executorPtr, isPerTileQuantMode) == ACLNN_SUCCESS,
2715+ ACLNN_ERR_INNER_NULLPTR);
2716+ }
2714 return ACLNN_SUCCESS;2717 return ACLNN_SUCCESS;
2715}2718}
2716 2719 
2717static aclnnStatus ParamsDataContiguous(gmm::GroupedMatmulParams &params, aclOpExecutor *executorPtr)2720static aclnnStatus ParamsDataContiguous(gmm::GroupedMatmulParams &params, aclOpExecutor *executorPtr)
2718{2721{
2719- CHECK_COND(DataContiguous(params.x, executorPtr) == ACLNN_SUCCESS, ACLNN_ERR_PARAM_INVALID,2722+ CHECK_COND(DataContiguous(params.x, executorPtr) == ACLNN_SUCCESS, ACLNN_ERR_PARAM_INVALID,
2720- "Contiguous x failed."); // make x contiguous2723+ "Contiguous x failed."); // make x contiguous
2721- DataType xDtype = (*params.x)[0]->GetDataType();2724+ DataType xDtype = (*params.x)[0]->GetDataType();
2722- DataType weightDtype = (*params.weight)[0]->GetDataType();2725+ DataType weightDtype = (*params.weight)[0]->GetDataType();
2723- if (!(op::GetCurrentPlatformInfo().GetCurNpuArch() == NpuArch::DAV_3510 &&2726+ if (!(op::GetCurrentPlatformInfo().GetCurNpuArch() == NpuArch::DAV_3510 &&
2724- ((IsQuant(xDtype, weightDtype) && (*params.weight)[0]->GetStorageFormat() == op::Format::FORMAT_FRACTAL_NZ) ||2727+ ((IsQuant(xDtype, weightDtype) && (*params.weight)[0]->GetStorageFormat() == op::Format::FORMAT_FRACTAL_NZ) ||
2725- (params.apiVersion == gmm::GMMApiVersion::WeightNz && IsWeightQuant(xDtype, weightDtype))))) {2728+ (params.apiVersion == gmm::GMMApiVersion::WeightNz && IsWeightQuant(xDtype, weightDtype))))) {
2726- CHECK_COND(DataContiguous(params.weight, executorPtr) == ACLNN_SUCCESS, ACLNN_ERR_PARAM_INVALID,2729+ CHECK_COND(DataContiguous(params.weight, executorPtr) == ACLNN_SUCCESS, ACLNN_ERR_PARAM_INVALID,
2727- "Contiguous weight failed."); // make w contiguous2730+ "Contiguous weight failed."); // make w contiguous
2728- }2731+ }
2729- CHECK_COND(DataContiguous(params.biasOptional, executorPtr) == ACLNN_SUCCESS, ACLNN_ERR_PARAM_INVALID,2732+ CHECK_COND(DataContiguous(params.biasOptional, executorPtr) == ACLNN_SUCCESS, ACLNN_ERR_PARAM_INVALID,
2730- "Contiguous biasOptional failed.");2733+ "Contiguous biasOptional failed.");
2731- CHECK_COND(DataContiguous(params.scaleOptional, executorPtr) == ACLNN_SUCCESS, ACLNN_ERR_PARAM_INVALID,2734+ CHECK_COND(DataContiguous(params.scaleOptional, executorPtr) == ACLNN_SUCCESS, ACLNN_ERR_PARAM_INVALID,
2732- "Contiguous scaleOptional failed.");2735+ "Contiguous scaleOptional failed.");
2733- CHECK_COND(DataContiguous(params.offsetOptional, executorPtr) == ACLNN_SUCCESS, ACLNN_ERR_PARAM_INVALID,2736+ CHECK_COND(DataContiguous(params.offsetOptional, executorPtr) == ACLNN_SUCCESS, ACLNN_ERR_PARAM_INVALID,
2734- "Contiguous offsetOptional failed.");2737+ "Contiguous offsetOptional failed.");
2735- CHECK_COND(DataContiguous(params.antiquantScaleOptional, executorPtr) == ACLNN_SUCCESS, ACLNN_ERR_PARAM_INVALID,2738+ CHECK_COND(DataContiguous(params.antiquantScaleOptional, executorPtr) == ACLNN_SUCCESS, ACLNN_ERR_PARAM_INVALID,
2736- "Contiguous antiquantScaleOptional failed.");2739+ "Contiguous antiquantScaleOptional failed.");
2737- if (params.antiquantOffsetOptional != nullptr) {2740+ if (params.antiquantOffsetOptional != nullptr) {
2738- CHECK_COND(DataContiguous(params.antiquantOffsetOptional, executorPtr) == ACLNN_SUCCESS, ACLNN_ERR_PARAM_INVALID,2741+ CHECK_COND(DataContiguous(params.antiquantOffsetOptional, executorPtr) == ACLNN_SUCCESS,
2739- "Contiguous antiquantOffsetOptional failed.");2742+ ACLNN_ERR_PARAM_INVALID, "Contiguous antiquantOffsetOptional failed.");
2740- }2743+ }
2741- CHECK_COND(DataContiguous(params.perTokenScaleOptional, executorPtr) == ACLNN_SUCCESS, ACLNN_ERR_PARAM_INVALID,2744+ CHECK_COND(DataContiguous(params.perTokenScaleOptional, executorPtr) == ACLNN_SUCCESS, ACLNN_ERR_PARAM_INVALID,
2742- "Contiguous perTokenScaleOptional failed.");2745+ "Contiguous perTokenScaleOptional failed.");
2743- if (params.groupTensorOptional != nullptr) {2746+ if (params.groupTensorOptional != nullptr) {
2744- params.groupTensorOptional = l0op::Contiguous(params.groupTensorOptional, executorPtr);2747+ params.groupTensorOptional = l0op::Contiguous(params.groupTensorOptional, executorPtr);
2745- CHECK_COND(params.groupTensorOptional != nullptr, ACLNN_ERR_PARAM_INVALID,2748+ CHECK_COND(params.groupTensorOptional != nullptr, ACLNN_ERR_PARAM_INVALID,
2746- "Contiguous groupTensorOptional failed.");2749+ "Contiguous groupTensorOptional failed.");
2747- }2750+ }
2748- return ACLNN_SUCCESS;2751+ return ACLNN_SUCCESS;
2749}2752}
2750 2753 
2751static aclnnStatus CheckWeightQuantGMMWeightNz(DataType x1Dtype, DataType weightDtype, DataType yDtype,2754static aclnnStatus CheckWeightQuantGMMWeightNz(DataType x1Dtype, DataType weightDtype, DataType yDtype,
@@ -2770,12 +2773,13 @@ static aclnnStatus CheckWeightQuantGMMWeightNz(DataType x1Dtype, DataType weight
2770 opName, "x, weight, y", gmm::dTypeToString(x1Dtype).c_str(), gmm::dTypeToString(weightDtype).c_str(),2773 opName, "x, weight, y", gmm::dTypeToString(x1Dtype).c_str(), gmm::dTypeToString(weightDtype).c_str(),
2771 gmm::dTypeToString(yDtype).c_str());2774 gmm::dTypeToString(yDtype).c_str());
2772 return ACLNN_SUCCESS;2775 return ACLNN_SUCCESS;
2773- } else if (x1Dtype == DataType::DT_FLOAT8_E4M3FN && weightDtype == DataType::DT_FLOAT4_E2M1) {2776+ } else if (x1Dtype == DataType::DT_FLOAT8_E4M3FN &&
2777+ (weightDtype == DataType::DT_FLOAT4_E2M1 || weightDtype == DataType::DT_FLOAT4_E1M2)) {
2774 CHECK_COND(2778 CHECK_COND(
2775 yDtype == DataType::DT_BF16 || yDtype == DataType::DT_FLOAT16, ACLNN_ERR_PARAM_INVALID,2779 yDtype == DataType::DT_BF16 || yDtype == DataType::DT_FLOAT16, ACLNN_ERR_PARAM_INVALID,
2776 "In op [%s], when MxA8W4 antiquant, the data types of [%s...] are mismatched, the reason is: [x dtype "2780 "In op [%s], when MxA8W4 antiquant, the data types of [%s...] are mismatched, the reason is: [x dtype "
2777 "%s, weight dtype %s, y dtype %s]. Constraint:[supported x-weight-y combination is "2781 "%s, weight dtype %s, y dtype %s]. Constraint:[supported x-weight-y combination is "
2778- "Fp8_e4m3fn-Fp4_e2m1-BF16/Fp16].",2782+ "Fp8_e4m3fn-Fp4_e2m1/Fp4_e1m2-BF16/Fp16].",
2779 opName, "x, weight, y", gmm::dTypeToString(x1Dtype).c_str(), gmm::dTypeToString(weightDtype).c_str(),2783 opName, "x, weight, y", gmm::dTypeToString(x1Dtype).c_str(), gmm::dTypeToString(weightDtype).c_str(),
2780 gmm::dTypeToString(yDtype).c_str());2784 gmm::dTypeToString(yDtype).c_str());
2781 return ACLNN_SUCCESS;2785 return ACLNN_SUCCESS;
@@ -3261,12 +3265,12 @@ aclnnStatus aclnnGroupedMatmulV4GetWorkspaceSize(
3261 CHECK_COND(CheckNotNull(x, weight, out) == ACLNN_SUCCESS, ACLNN_ERR_PARAM_NULLPTR,3265 CHECK_COND(CheckNotNull(x, weight, out) == ACLNN_SUCCESS, ACLNN_ERR_PARAM_NULLPTR,
3262 "In op [%s], required inputs must not be nullptr.", opName);3266 "In op [%s], required inputs must not be nullptr.", opName);
3263 // Standard syntax, Check parameters.3267 // Standard syntax, Check parameters.
3264- L2_DFX_PHASE_1(aclnnGroupedMatmulV4,3268+ L2_DFX_PHASE_1(
3265- DFX_IN(x, weight, biasOptional, scaleOptional, offsetOptional, antiquantScaleOptional,3269+ aclnnGroupedMatmulV4,
3266- antiquantOffsetOptional, perTokenScaleOptional, activationInputOptional,3270+ DFX_IN(x, weight, biasOptional, scaleOptional, offsetOptional, antiquantScaleOptional, antiquantOffsetOptional,
3267- activationQuantScaleOptional, activationQuantOffsetOptional, groupListOptional, splitItem,3271+ perTokenScaleOptional, activationInputOptional, activationQuantScaleOptional,
3268- groupType, groupListType, actType),3272+ activationQuantOffsetOptional, groupListOptional, splitItem, groupType, groupListType, actType),
3269- DFX_OUT(out, activationFeatureOutOptional, dynQuantScaleOutOptional));3273+ DFX_OUT(out, activationFeatureOutOptional, dynQuantScaleOutOptional));
3270 if ((*weight)[0]->GetDataType() == DataType::DT_INT32) {3274 if ((*weight)[0]->GetDataType() == DataType::DT_INT32) {
3271 // convert weight from int32 to int43275 // convert weight from int32 to int4
3272 UnpackB32ToB4(weight, "weight");3276 UnpackB32ToB4(weight, "weight");
@@ -58,7 +58,8 @@ bool AclnnGroupedMatmulWeightQuantDAV3510Checker::IsA16MxFp4NZ() const
58 58 
59bool AclnnGroupedMatmulWeightQuantDAV3510Checker::IsMxA8W4NZ() const59bool AclnnGroupedMatmulWeightQuantDAV3510Checker::IsMxA8W4NZ() const
60{60{
61- return xDtype_ == ge::DT_FLOAT8_E4M3FN && weightDtype_ == ge::DT_FLOAT4_E2M1;61+ return xDtype_ == ge::DT_FLOAT8_E4M3FN &&
62+ (weightDtype_ == ge::DT_FLOAT4_E2M1 || weightDtype_ == ge::DT_FLOAT4_E1M2);
panzhija
panzhijapanzhijaJul 28

[文档][建议改进] 💡 同步 E1M2 诊断文本 该谓词已把 E1M2 纳入 MxA8W4,但本文件 CheckDimNumAndFormat、CheckTransposeStatus 和 CheckQuantParams 的错误信息仍只列出 fp4_e2m1。E1M2 参数触发校验失败时会得到不完整的约束说明,建议一并更新。

likedislike
zhangzhizhuo
zhangzhizhuo
Jul 28 Comments:
likedislike
62}63}
63 64 
64bool AclnnGroupedMatmulWeightQuantDAV3510Checker::IsA16W8ND() const65bool AclnnGroupedMatmulWeightQuantDAV3510Checker::IsA16W8ND() const
@@ -130,9 +131,9 @@ aclnnStatus AclnnGroupedMatmulWeightQuantDAV3510Checker::CheckTensorNotNullPtr(c
130{131{
131 const aclTensor *tensor = (*tensorList)[idx];132 const aclTensor *tensor = (*tensorList)[idx];
132 if (unlikely(tensor == nullptr)) {133 if (unlikely(tensor == nullptr)) {
133- OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(GetAclnnName(), tensorType, "nullptr",134+ OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(
134- tensorType + "[" + std::to_string(idx) +135+ GetAclnnName(), tensorType, "nullptr",
135- "] is null, which is not supported");136+ tensorType + "[" + std::to_string(idx) + "] is null, which is not supported");
136 return ACLNN_ERR_PARAM_NULLPTR;137 return ACLNN_ERR_PARAM_NULLPTR;
137 }138 }
138 return ACLNN_SUCCESS;139 return ACLNN_SUCCESS;
@@ -352,7 +353,7 @@ aclnnStatus AclnnGroupedMatmulWeightQuantDAV3510Checker::CheckDimNumAndFormat(si
352 }353 }
353 if (IsMxA8W4NZ()) {354 if (IsMxA8W4NZ()) {
354 if (unlikely(weightDimNum != MULTI_WEIGHT_DIM && weightDimNum != SPLIT_M_SINGLE_WEIGHT_DIM)) {355 if (unlikely(weightDimNum != MULTI_WEIGHT_DIM && weightDimNum != SPLIT_M_SINGLE_WEIGHT_DIM)) {
355- std::string reason = "In weight quant case fp8_e4m3-fp4_e2m1, The shape dim of weight[" +356+ std::string reason = "In weight quant case fp8_e4m3-fp4_e2m1/fp4_e1m2, The shape dim of weight[" +
356 std::to_string(wIdx) + "] must be 2 or 3";357 std::to_string(wIdx) + "] must be 2 or 3";
357 OP_LOGE_FOR_INVALID_SHAPEDIM_WITH_REASON(GetAclnnName(), "weight", std::to_string(weightDimNum),358 OP_LOGE_FOR_INVALID_SHAPEDIM_WITH_REASON(GetAclnnName(), "weight", std::to_string(weightDimNum),
358 reason);359 reason);
@@ -400,10 +401,9 @@ aclnnStatus AclnnGroupedMatmulWeightQuantDAV3510Checker::CheckTransposeStatus()
400 401 
401 if (IsA16F8ND() || IsMxA8W4NZ()) {402 if (IsA16F8ND() || IsMxA8W4NZ()) {
402 if (unlikely(!gmmParams_.transposeWeight)) {403 if (unlikely(!gmmParams_.transposeWeight)) {
403- OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(404+ OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(GetAclnnName(), "transposeWeight", "false",
404- GetAclnnName(), "transposeWeight", "false",405+ "In weight quant case fp16/bf16-int8, fp16/bf16-fp8/hif8 and "
405- "In weight quant case fp16/bf16-int8, fp16/bf16-fp8/hif8 and fp8_e4m3-fp4_e2m1, weight must be "406+ "fp8_e4m3-fp4_e2m1/fp4_e1m2, weight must be transposed");
406- "transposed");
407 return ACLNN_ERR_PARAM_INVALID;407 return ACLNN_ERR_PARAM_INVALID;
408 }408 }
409 } else if (IsA16MxFp4NZ() || IsS8S4NZ()) {409 } else if (IsA16MxFp4NZ() || IsS8S4NZ()) {
@@ -559,9 +559,9 @@ aclnnStatus AclnnGroupedMatmulWeightQuantDAV3510Checker::CheckBiasDtype()
559 if (unlikely(biasDtype_ != yDtype_)) {559 if (unlikely(biasDtype_ != yDtype_)) {
560 std::string incorrectDtypes =560 std::string incorrectDtypes =
561 std::string(op::ToString(biasDtype_).GetString()) + ", " + op::ToString(yDtype_).GetString();561 std::string(op::ToString(biasDtype_).GetString()) + ", " + op::ToString(yDtype_).GetString();
562- OP_LOGE_FOR_INVALID_DTYPES_WITH_REASON(GetAclnnName(), "bias, y", incorrectDtypes,562+ OP_LOGE_FOR_INVALID_DTYPES_WITH_REASON(
563- "The dtype of bias must be equal to the dtype of y, " +563+ GetAclnnName(), "bias, y", incorrectDtypes,
564- GetDataFlowString());564+ "The dtype of bias must be equal to the dtype of y, " + GetDataFlowString());
565 return ACLNN_ERR_PARAM_INVALID;565 return ACLNN_ERR_PARAM_INVALID;
566 }566 }
567 } else if (IsS8S4NZ()) {567 } else if (IsS8S4NZ()) {
@@ -580,9 +580,9 @@ aclnnStatus AclnnGroupedMatmulWeightQuantDAV3510Checker::CheckAntiQuantDtype(siz
580{580{
581 if (gmmParams_.antiquantScaleOptional != nullptr) {581 if (gmmParams_.antiquantScaleOptional != nullptr) {
582 if (IsA16W8ND() || IsA16F8ND() || IsA16W4()) {582 if (IsA16W8ND() || IsA16F8ND() || IsA16W4()) {
583- CHECK_RET(CheckTensorDtype(gmmParams_.antiquantScaleOptional, xDtype_, idx, "antiquantScale") ==583+ CHECK_RET(
584- ACLNN_SUCCESS,584+ CheckTensorDtype(gmmParams_.antiquantScaleOptional, xDtype_, idx, "antiquantScale") == ACLNN_SUCCESS,
585- ACLNN_ERR_PARAM_INVALID);585+ ACLNN_ERR_PARAM_INVALID);
586 } else if (IsA16MxFp4NZ() || IsMxA8W4NZ()) {586 } else if (IsA16MxFp4NZ() || IsMxA8W4NZ()) {
587 CHECK_RET(CheckTensorDtype(gmmParams_.antiquantScaleOptional, ge::DT_FLOAT8_E8M0, idx, "antiquantScale") ==587 CHECK_RET(CheckTensorDtype(gmmParams_.antiquantScaleOptional, ge::DT_FLOAT8_E8M0, idx, "antiquantScale") ==
588 ACLNN_SUCCESS,588 ACLNN_SUCCESS,
@@ -597,9 +597,9 @@ aclnnStatus AclnnGroupedMatmulWeightQuantDAV3510Checker::CheckAntiQuantDtype(siz
597 597 
598 if (gmmParams_.antiquantOffsetOptional != nullptr) {598 if (gmmParams_.antiquantOffsetOptional != nullptr) {
599 // 当前有antiquantOffset的数据流,antiquantOffset的数据类型均和x一致599 // 当前有antiquantOffset的数据流,antiquantOffset的数据类型均和x一致
600- CHECK_RET(CheckTensorDtype(gmmParams_.antiquantOffsetOptional, xDtype_, idx, "antiquantOffset") ==600+ CHECK_RET(
601- ACLNN_SUCCESS,601+ CheckTensorDtype(gmmParams_.antiquantOffsetOptional, xDtype_, idx, "antiquantOffset") == ACLNN_SUCCESS,
602- ACLNN_ERR_PARAM_INVALID);602+ ACLNN_ERR_PARAM_INVALID);
603 }603 }
604 return ACLNN_SUCCESS;604 return ACLNN_SUCCESS;
605}605}
@@ -634,9 +634,9 @@ aclnnStatus AclnnGroupedMatmulWeightQuantDAV3510Checker::CheckDimValueAllOne(con
634 }634 }
635 635 
636 if (dimValueAllOne) {636 if (dimValueAllOne) {
637- OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(GetAclnnName(), paramName, "true",637+ OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(
638- "When xDtype-weightDtype is fp16/bf16-int4, The dim value of " +638+ GetAclnnName(), paramName, "true",
639- paramName + " not support all be 1");639+ "When xDtype-weightDtype is fp16/bf16-int4, The dim value of " + paramName + " not support all be 1");
640 return ACLNN_ERR_PARAM_INVALID;640 return ACLNN_ERR_PARAM_INVALID;
641 }641 }
642 642 
@@ -807,8 +807,8 @@ aclnnStatus AclnnGroupedMatmulWeightQuantDAV3510Checker::CheckUnsupportedApi() c
807 "Only AclnnGroupedMatmulV4/V5 support fp16/bf16-fp8/hif8/int4 for xDtype-weightDtype.");807 "Only AclnnGroupedMatmulV4/V5 support fp16/bf16-fp8/hif8/int4 for xDtype-weightDtype.");
808 } else if (IsA16MxFp4NZ() || IsMxA8W4NZ() || IsS8S4NZ()) {808 } else if (IsA16MxFp4NZ() || IsMxA8W4NZ() || IsS8S4NZ()) {
809 CHECK_COND(gmmParams_.apiVersion == GMMApiVersion::WeightNz, ACLNN_ERR_PARAM_INVALID,809 CHECK_COND(gmmParams_.apiVersion == GMMApiVersion::WeightNz, ACLNN_ERR_PARAM_INVALID,
810- "Only AclnnGroupedMatmulNz supports fp16/bf16-fp4_e2m1, fp8_e4m3fn-fp4_e2m1 and int8-int4 for "810+ "Only AclnnGroupedMatmulNz supports fp16/bf16-fp4_e2m1, "
811- "xDtype-weightDtype.");811+ "fp8_e4m3fn-fp4_e2m1/fp4_e1m2 and int8-int4 for xDtype-weightDtype.");
812 } else {812 } else {
813 OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Weight quant case with x dtype [%s] and weight dtype [%s] is not supported.",813 OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Weight quant case with x dtype [%s] and weight dtype [%s] is not supported.",
814 op::ToString(xDtype_).GetString(), op::ToString(weightDtype_).GetString());814 op::ToString(xDtype_).GetString(), op::ToString(weightDtype_).GetString());
@@ -45,7 +45,8 @@ bool GroupedMatmulWeightQuantChecker::IsA16MxFp4NZ(const ge::DataType xDtype, co
45 45 
46bool GroupedMatmulWeightQuantChecker::IsMxA8W4NZ(const ge::DataType xDtype, const ge::DataType weightDtype) const46bool GroupedMatmulWeightQuantChecker::IsMxA8W4NZ(const ge::DataType xDtype, const ge::DataType weightDtype) const
47{47{
48- return xDtype == ge::DT_FLOAT8_E4M3FN && (weightDtype == ge::DT_FLOAT4_E2M1 || weightDtype == ge::DT_FLOAT);48+ return xDtype == ge::DT_FLOAT8_E4M3FN &&
49+ (weightDtype == ge::DT_FLOAT4_E2M1 || weightDtype == ge::DT_FLOAT4_E1M2 || weightDtype == ge::DT_FLOAT);
49}50}
50 51 
51bool GroupedMatmulWeightQuantChecker::IsS8S4NZ(const ge::DataType xDtype, const ge::DataType weightDtype) const52bool GroupedMatmulWeightQuantChecker::IsS8S4NZ(const ge::DataType xDtype, const ge::DataType weightDtype) const
@@ -139,10 +140,10 @@ ge::graphStatus GroupedMatmulWeightQuantChecker::GetXAndWeightDimValue(const ger
139 140 
140 xMDim_ = gmmAttrs.transposeX ? xShape->GetDim(xdimNum_ - 1) : xShape->GetDim(xdimNum_ - PENULTIMATE_DIM);141 xMDim_ = gmmAttrs.transposeX ? xShape->GetDim(xdimNum_ - 1) : xShape->GetDim(xdimNum_ - PENULTIMATE_DIM);
141 xKDim_ = gmmAttrs.transposeX ? xShape->GetDim(xdimNum_ - PENULTIMATE_DIM) : xShape->GetDim(xdimNum_ - 1);142 xKDim_ = gmmAttrs.transposeX ? xShape->GetDim(xdimNum_ - PENULTIMATE_DIM) : xShape->GetDim(xdimNum_ - 1);
142- weightKDim_ = gmmAttrs.transposeWeight ? weightShape->GetDim(weightdimNum_ - 1)143+ weightKDim_ = gmmAttrs.transposeWeight ? weightShape->GetDim(weightdimNum_ - 1) :
143- : weightShape->GetDim(weightdimNum_ - PENULTIMATE_DIM);144+ weightShape->GetDim(weightdimNum_ - PENULTIMATE_DIM);
144- weightNDim_ = gmmAttrs.transposeWeight ? weightShape->GetDim(weightdimNum_ - PENULTIMATE_DIM)145+ weightNDim_ = gmmAttrs.transposeWeight ? weightShape->GetDim(weightdimNum_ - PENULTIMATE_DIM) :
145- : weightShape->GetDim(weightdimNum_ - 1);146+ weightShape->GetDim(weightdimNum_ - 1);
146 147 
147 // 1个float32/int32表示8个float4_e2m1/int4,推导shape时,尾轴扩大8倍148 // 1个float32/int32表示8个float4_e2m1/int4,推导shape时,尾轴扩大8倍
148 if ((weightDtype_ == ge::DT_FLOAT || weightDtype_ == ge::DT_INT32) && weightKDim_ > 0 && xKDim_ > 0) {149 if ((weightDtype_ == ge::DT_FLOAT || weightDtype_ == ge::DT_INT32) && weightKDim_ > 0 && xKDim_ > 0) {
@@ -180,7 +181,8 @@ ge::graphStatus GroupedMatmulWeightQuantChecker::CheckShapeForXAndWeight(const g
180 OP_LOGE(context->GetNodeName(),181 OP_LOGE(context->GetNodeName(),
181 "The k dim value should not be negative, but the actual value is [%ld].", weightKDim_),182 "The k dim value should not be negative, but the actual value is [%ld].", weightKDim_),
182 return ge::GRAPH_FAILED);183 return ge::GRAPH_FAILED);
183- if (weightDtype_ == ge::DT_FLOAT4_E2M1 || weightDtype_ == ge::DT_FLOAT || IsS8S4NZ(xDtype_, weightDtype_)) {184+ if (weightDtype_ == ge::DT_FLOAT4_E2M1 || weightDtype_ == ge::DT_FLOAT4_E1M2 || weightDtype_ == ge::DT_FLOAT ||
185+ IsS8S4NZ(xDtype_, weightDtype_)) {
184 // A16MxF4/MxA8W4/S8S4校验32B对齐186 // A16MxF4/MxA8W4/S8S4校验32B对齐
185 OP_CHECK_IF(187 OP_CHECK_IF(
186 !((weightNDim_ % GMM_N_K_ALIGN_VALUE_WEIGHT_QUANT_4BIT == 0) &&188 !((weightNDim_ % GMM_N_K_ALIGN_VALUE_WEIGHT_QUANT_4BIT == 0) &&
@@ -394,7 +396,7 @@ ge::graphStatus GroupedMatmulWeightQuantChecker::CheckCaseMultiScenario(const ge
394 for (size_t i = 0; i < xSize; i++) {396 for (size_t i = 0; i < xSize; i++) {
395 xShape = context->GetDynamicInputShape(GMM_INDEX_IN_X, i);397 xShape = context->GetDynamicInputShape(GMM_INDEX_IN_X, i);
396 size_t xDimNum = xShape->GetDimNum();398 size_t xDimNum = xShape->GetDimNum();
397- int64_t xKDimValue = xShape->GetDim(xDimNum - 1); // x always is not transposed399+ int64_t xKDimValue = xShape->GetDim(xDimNum - 1); // x always is not transposed
398 400 
399 wShape = context->GetDynamicInputShape(GMM_INDEX_IN_WEIGHT, i);401 wShape = context->GetDynamicInputShape(GMM_INDEX_IN_WEIGHT, i);
400 weightKDimValue = wShape->GetDim(wKDimIdx);402 weightKDimValue = wShape->GetDim(wKDimIdx);
@@ -408,10 +410,10 @@ ge::graphStatus GroupedMatmulWeightQuantChecker::CheckCaseMultiScenario(const ge
408 return ge::GRAPH_FAILED);410 return ge::GRAPH_FAILED);
409 }411 }
410 // 校验K轴和N轴非不确定值412 // 校验K轴和N轴非不确定值
411- OP_CHECK_IF(413+ OP_CHECK_IF(xKDimValue < 0,
412- xKDimValue < 0,414+ OP_LOGE(context->GetNodeName(), "x[%zu] dim %zu value %ld should not be negative.", i, xDimNum - 1,
413- OP_LOGE(context->GetNodeName(), "x[%zu] dim %zu value %ld should not be negative.", i, xDimNum - 1, xKDimValue),415+ xKDimValue),
414- return ge::GRAPH_FAILED);416+ return ge::GRAPH_FAILED);
415 OP_CHECK_IF(weightNDimValue < 0,417 OP_CHECK_IF(weightNDimValue < 0,
416 OP_LOGE(context->GetNodeName(), "w[%zu] dim %zu value %ld should not be negative.", i, wNDimIdx,418 OP_LOGE(context->GetNodeName(), "w[%zu] dim %zu value %ld should not be negative.", i, wNDimIdx,
417 weightNDimValue),419 weightNDimValue),
@@ -438,18 +440,17 @@ ge::graphStatus GroupedMatmulWeightQuantChecker::CheckCaseMultiScenario(const ge
438 OP_CHECK_NULL_WITH_CONTEXT(context, wShape_i);440 OP_CHECK_NULL_WITH_CONTEXT(context, wShape_i);
439 int64_t kSize = wShape_i->GetDim(wKDimIdx);441 int64_t kSize = wShape_i->GetDim(wKDimIdx);
440 int64_t groupNum = antiquantScaleShape->GetDim(0);442 int64_t groupNum = antiquantScaleShape->GetDim(0);
441- OP_CHECK_IF(groupNum <= 0,443+ OP_CHECK_IF(groupNum <= 0, OP_LOGE(context->GetNodeName(), "GroupNum must be greater than 0."),
442- OP_LOGE(context->GetNodeName(), "GroupNum must be greater than 0."),
443 return ge::GRAPH_FAILED);444 return ge::GRAPH_FAILED);
444 OP_CHECK_IF(kSize % groupNum != 0,445 OP_CHECK_IF(kSize % groupNum != 0,
445 OP_LOGE(context->GetNodeName(), "GroupNum must be multiple of the k axis of weight."),446 OP_LOGE(context->GetNodeName(), "GroupNum must be multiple of the k axis of weight."),
446 return ge::GRAPH_FAILED);447 return ge::GRAPH_FAILED);
447 int64_t groupSize = kSize / groupNum;448 int64_t groupSize = kSize / groupNum;
448- OP_CHECK_IF(groupSize != 32 && groupSize != 64 && groupSize != 128 && groupSize != 256,449+ OP_CHECK_IF(
449- OP_LOGE(context->GetNodeName(),450+ groupSize != 32 && groupSize != 64 && groupSize != 128 && groupSize != 256,
450- "groupSize must be 32/64/128/256 on Ascend 950PR, but current groupSize is (%ld).",451+ OP_LOGE(context->GetNodeName(),
451- groupSize),452+ "groupSize must be 32/64/128/256 on Ascend 950PR, but current groupSize is (%ld).", groupSize),
452- return ge::GRAPH_FAILED);453+ return ge::GRAPH_FAILED);
453 }454 }
454 }455 }
455 456 
@@ -467,7 +468,7 @@ ge::graphStatus GroupedMatmulWeightQuantChecker::CheckScenarioValid(const gert::
467 gmmAttrs.groupType),468 gmmAttrs.groupType),
468 return ge::GRAPH_FAILED);469 return ge::GRAPH_FAILED);
469 470 
470- if (gmmAttrs.groupType == GMM_SPLIT_M) { // single/single/single or single/multi/single Scenario471+ if (gmmAttrs.groupType == GMM_SPLIT_M) { // single/single/single or single/multi/single Scenario
471 OP_CHECK_IF(IsNonEmpty(xSecondTensorShape),472 OP_CHECK_IF(IsNonEmpty(xSecondTensorShape),
472 OP_LOGE(context->GetNodeName(), "The second tensor of tensor list x is not empty."),473 OP_LOGE(context->GetNodeName(), "The second tensor of tensor list x is not empty."),
473 return ge::GRAPH_FAILED);474 return ge::GRAPH_FAILED);
@@ -482,7 +483,7 @@ ge::graphStatus GroupedMatmulWeightQuantChecker::CheckScenarioValid(const gert::
482 OP_LOGE(context->GetNodeName(),483 OP_LOGE(context->GetNodeName(),
483 "Invalid splitItem, which can only be one of 2 or 3, but it is [%ld].", gmmAttrs.splitItem),484 "Invalid splitItem, which can only be one of 2 or 3, but it is [%ld].", gmmAttrs.splitItem),
484 return ge::GRAPH_FAILED);485 return ge::GRAPH_FAILED);
485- } else { // multi/multi/multi Scenario486+ } else { // multi/multi/multi Scenario
486 // check split item value valid487 // check split item value valid
487 OP_CHECK_IF(488 OP_CHECK_IF(
488 !IsA16W8(xDtype_, weightDtype_) && !IsA16W4(xDtype_, weightDtype_),489 !IsA16W8(xDtype_, weightDtype_) && !IsA16W4(xDtype_, weightDtype_),
@@ -572,8 +573,8 @@ ge::graphStatus GroupedMatmulWeightQuantChecker::CheckShapeForTensorList(const g
572 (IsA16MxFp4NZ(xDtype_, weightDtype_) || IsS8S4NZ(xDtype_, weightDtype_))) {573 (IsA16MxFp4NZ(xDtype_, weightDtype_) || IsS8S4NZ(xDtype_, weightDtype_))) {
573 expectedDimNum = ANTIQUANT_PARAM_DIM_NUM_PER_GROUP_SINGLE;574 expectedDimNum = ANTIQUANT_PARAM_DIM_NUM_PER_GROUP_SINGLE;
574 } else if ((gmm_index == GMM_INDEX_IN_ANTIQUANT_SCALE) && IsMxA8W4NZ(xDtype_, weightDtype_)) {575 } else if ((gmm_index == GMM_INDEX_IN_ANTIQUANT_SCALE) && IsMxA8W4NZ(xDtype_, weightDtype_)) {
575- expectedDimNum = isMultiTensorWeight_ ? ANTIQUANT_PARAM_DIM_NUM_PER_GROUP_SINGLE576+ expectedDimNum =
576- : ANTIQUANT_PARAM_DIM_NUM_MX;577+ isMultiTensorWeight_ ? ANTIQUANT_PARAM_DIM_NUM_PER_GROUP_SINGLE : ANTIQUANT_PARAM_DIM_NUM_MX;
577 } else if ((gmm_index == GMM_INDEX_IN_ANTIQUANT_SCALE || gmm_index == GMM_INDEX_IN_ANTIQUANT_OFFSET) &&578 } else if ((gmm_index == GMM_INDEX_IN_ANTIQUANT_SCALE || gmm_index == GMM_INDEX_IN_ANTIQUANT_OFFSET) &&
578 IsA16W4(xDtype_, weightDtype_)) {579 IsA16W4(xDtype_, weightDtype_)) {
579 if (tensorDimNum != OPTIONAL_PARAM_DIM_NUM_DEFAULT_SINGLE &&580 if (tensorDimNum != OPTIONAL_PARAM_DIM_NUM_DEFAULT_SINGLE &&
@@ -608,9 +609,8 @@ ge::graphStatus GroupedMatmulWeightQuantChecker::CheckShapeForTensorList(const g
608 if (expectedDimNum == ANTIQUANT_PARAM_DIM_NUM_PER_GROUP_SINGLE && gmmAttrs.transposeWeight) {609 if (expectedDimNum == ANTIQUANT_PARAM_DIM_NUM_PER_GROUP_SINGLE && gmmAttrs.transposeWeight) {
609 tensorNDimIdx = tensorDimNum - PENULTIMATE_DIM;610 tensorNDimIdx = tensorDimNum - PENULTIMATE_DIM;
610 } else if (expectedDimNum == ANTIQUANT_PARAM_DIM_NUM_MX) {611 } else if (expectedDimNum == ANTIQUANT_PARAM_DIM_NUM_MX) {
611- tensorNDimIdx = gmmAttrs.transposeWeight ?612+ tensorNDimIdx =
612- tensorDimNum - ANTEPENULTIMATE_DIM :613+ gmmAttrs.transposeWeight ? tensorDimNum - ANTEPENULTIMATE_DIM : tensorDimNum - PENULTIMATE_DIM;
613- tensorDimNum - PENULTIMATE_DIM;
614 } else if (isMultiTensorWeight_ && gmm_index == GMM_INDEX_IN_ANTIQUANT_SCALE) {614 } else if (isMultiTensorWeight_ && gmm_index == GMM_INDEX_IN_ANTIQUANT_SCALE) {
615 tensorNDimIdx = gmmAttrs.transposeWeight ? 0 : tensorDimNum - PENULTIMATE_DIM;615 tensorNDimIdx = gmmAttrs.transposeWeight ? 0 : tensorDimNum - PENULTIMATE_DIM;
616 }616 }
@@ -624,9 +624,11 @@ ge::graphStatus GroupedMatmulWeightQuantChecker::CheckShapeForTensorList(const g
624 return ge::GRAPH_SUCCESS;624 return ge::GRAPH_SUCCESS;
625}625}
626 626 
627-ge::graphStatus GroupedMatmulWeightQuantChecker::CheckShapeForTensorListAtIndex(627+ge::graphStatus GroupedMatmulWeightQuantChecker::CheckShapeForTensorListAtIndex(const gert::InferShapeContext *context,
628- const gert::InferShapeContext *context, size_t gmm_index,628+ size_t gmm_index,
629- const std::string &tensorType, const GMMAttrs &gmmAttrs, size_t tensorIdx) const629+ const std::string &tensorType,
630+ const GMMAttrs &gmmAttrs,
631+ size_t tensorIdx) const
630{632{
631 auto tensorShape = context->GetDynamicInputShape(gmm_index, tensorIdx);633 auto tensorShape = context->GetDynamicInputShape(gmm_index, tensorIdx);
632 if (IsNonEmpty(tensorShape)) {634 if (IsNonEmpty(tensorShape)) {
@@ -668,13 +670,14 @@ ge::graphStatus GroupedMatmulWeightQuantChecker::CheckShapeForWeightQuantParam(c
668 auto perTokenScaleShape = context->GetDynamicInputShape(GMM_INDEX_IN_PERTOKEN_SCALE, 0);670 auto perTokenScaleShape = context->GetDynamicInputShape(GMM_INDEX_IN_PERTOKEN_SCALE, 0);
669 auto antiquantScaleShape = context->GetDynamicInputShape(GMM_INDEX_IN_ANTIQUANT_SCALE, 0);671 auto antiquantScaleShape = context->GetDynamicInputShape(GMM_INDEX_IN_ANTIQUANT_SCALE, 0);
670 auto antiquantOffsetShape = context->GetDynamicInputShape(GMM_INDEX_IN_ANTIQUANT_OFFSET, 0);672 auto antiquantOffsetShape = context->GetDynamicInputShape(GMM_INDEX_IN_ANTIQUANT_OFFSET, 0);
671- OP_CHECK_IF(IsNonEmpty(antiquantOffsetShape) && (FP8_SUPPORT_SET.find(weightDtype_) != FP8_SUPPORT_SET.end() ||673+ OP_CHECK_IF(
672- weightDtype_ == ge::DT_FLOAT4_E2M1 ||674+ IsNonEmpty(antiquantOffsetShape) &&
673- weightDtype_ == ge::DT_FLOAT || IsS8S4NZ(xDtype_, weightDtype_)),675+ (FP8_SUPPORT_SET.find(weightDtype_) != FP8_SUPPORT_SET.end() || weightDtype_ == ge::DT_FLOAT4_E2M1 ||
674- OP_LOGE(context->GetNodeName(),676+ weightDtype_ == ge::DT_FLOAT4_E1M2 || weightDtype_ == ge::DT_FLOAT || IsS8S4NZ(xDtype_, weightDtype_)),
675- "In weight quant case, only support antiquantOffset is none when weightDtype is fp8/hif8/fp4 "677+ OP_LOGE(context->GetNodeName(),
676- "or xDtype-weightDtype is int8-int4."),678+ "In weight quant case, only support antiquantOffset is none when weightDtype is fp8/hif8/fp4 "
677- return ge::GRAPH_FAILED);679+ "or xDtype-weightDtype is int8-int4."),
680+ return ge::GRAPH_FAILED);
678 OP_CHECK_IF(IsNonEmpty(scaleShape) && !IsS8S4NZ(xDtype_, weightDtype_),681 OP_CHECK_IF(IsNonEmpty(scaleShape) && !IsS8S4NZ(xDtype_, weightDtype_),
679 OP_LOGE(context->GetNodeName(), "In weight quant case, scale must be empty."), return ge::GRAPH_FAILED);682 OP_LOGE(context->GetNodeName(), "In weight quant case, scale must be empty."), return ge::GRAPH_FAILED);
680 OP_CHECK_IF(!IsNonEmpty(scaleShape) && IsS8S4NZ(xDtype_, weightDtype_),683 OP_CHECK_IF(!IsNonEmpty(scaleShape) && IsS8S4NZ(xDtype_, weightDtype_),
@@ -684,8 +687,8 @@ ge::graphStatus GroupedMatmulWeightQuantChecker::CheckShapeForWeightQuantParam(c
684 return ge::GRAPH_FAILED);687 return ge::GRAPH_FAILED);
685 OP_CHECK_IF(688 OP_CHECK_IF(
686 IsNonEmpty(perTokenScaleShape) && (!IsMxA8W4NZ(xDtype_, weightDtype_) && !IsS8S4NZ(xDtype_, weightDtype_)),689 IsNonEmpty(perTokenScaleShape) && (!IsMxA8W4NZ(xDtype_, weightDtype_) && !IsS8S4NZ(xDtype_, weightDtype_)),
687- OP_LOGE(context->GetNodeName(),690+ OP_LOGE(context->GetNodeName(), "If xDtype-weightDtype is not fp8_e4m3-fp4_e2m1/fp4_e1m2 or int8-int4, "
688- "If xDtype-weightDtype is not fp8_e4m3-fp4_e2m1 or int8-int4, pertokenscale must be empty."),691+ "pertokenscale must be empty."),
689 return ge::GRAPH_FAILED);692 return ge::GRAPH_FAILED);
690 OP_CHECK_IF(693 OP_CHECK_IF(
691 !IsNonEmpty(perTokenScaleShape) && (IsMxA8W4NZ(xDtype_, weightDtype_) || IsS8S4NZ(xDtype_, weightDtype_)),694 !IsNonEmpty(perTokenScaleShape) && (IsMxA8W4NZ(xDtype_, weightDtype_) || IsS8S4NZ(xDtype_, weightDtype_)),
@@ -715,8 +718,8 @@ ge::graphStatus GroupedMatmulWeightQuantChecker::CheckShapeForWeightQuantParam(c
715ge::graphStatus GroupedMatmulWeightQuantChecker::CheckGroupSize(const gert::InferShapeContext *context,718ge::graphStatus GroupedMatmulWeightQuantChecker::CheckGroupSize(const gert::InferShapeContext *context,
716 const GMMAttrs &gmmAttrs, const size_t tensorIdx) const719 const GMMAttrs &gmmAttrs, const size_t tensorIdx) const
717{720{
718- if (!(IsA16MxFp4NZ(xDtype_, weightDtype_) || IsMxA8W4NZ(xDtype_, weightDtype_) ||721+ if (!(IsA16MxFp4NZ(xDtype_, weightDtype_) || IsMxA8W4NZ(xDtype_, weightDtype_) || IsS8S4NZ(xDtype_, weightDtype_) ||
719- IsS8S4NZ(xDtype_, weightDtype_) || IsA16W4Pergroup(xDtype_, weightDtype_, context, tensorIdx))) {722+ IsA16W4Pergroup(xDtype_, weightDtype_, context, tensorIdx))) {
720 return ge::GRAPH_SUCCESS;723 return ge::GRAPH_SUCCESS;
721 }724 }
722 725 
@@ -754,8 +757,7 @@ ge::graphStatus GroupedMatmulWeightQuantChecker::CheckGroupSize(const gert::Infe
754 } else if (IsA16W4Pergroup(xDtype_, weightDtype_, context, tensorIdx)) {757 } else if (IsA16W4Pergroup(xDtype_, weightDtype_, context, tensorIdx)) {
755 // 伪量化A16W4 pergroup场景支持groupsize为32/64/128/256758 // 伪量化A16W4 pergroup场景支持groupsize为32/64/128/256
756 OP_CHECK_IF(groupSize != 32 && groupSize != 64 && groupSize != 128 && groupSize != 256,759 OP_CHECK_IF(groupSize != 32 && groupSize != 64 && groupSize != 128 && groupSize != 256,
757- OP_LOGE(context->GetNodeName(),760+ OP_LOGE(context->GetNodeName(), "groupSize must be 32/64/128/256, but current groupSize is (%ld).",
758- "groupSize must be 32/64/128/256, but current groupSize is (%ld).",
759 groupSize),761 groupSize),
760 return ge::GRAPH_FAILED);762 return ge::GRAPH_FAILED);
761 } else {763 } else {
@@ -860,12 +862,12 @@ ge::graphStatus GroupedMatmulWeightQuantChecker::CheckShapeValid(const gert::Inf
860 OP_LOGE(context->GetNodeName(), "CheckShapeForXAndWeight failed."), return ge::GRAPH_FAILED);862 OP_LOGE(context->GetNodeName(), "CheckShapeForXAndWeight failed."), return ge::GRAPH_FAILED);
861 if (isMultiTensorWeight_) {863 if (isMultiTensorWeight_) {
862 for (size_t i = 0; i < numWeight_; i++) {864 for (size_t i = 0; i < numWeight_; i++) {
863- OP_CHECK_IF(CheckShapeForTensorListAtIndex(context, GMM_INDEX_IN_BIAS, "bias", gmmAttrs, i)865+ OP_CHECK_IF(CheckShapeForTensorListAtIndex(context, GMM_INDEX_IN_BIAS, "bias", gmmAttrs, i) !=
864- != ge::GRAPH_SUCCESS,866+ ge::GRAPH_SUCCESS,
865 OP_LOGE(context->GetNodeName(), "CheckShapeForBias at index [%zu] failed.", i),867 OP_LOGE(context->GetNodeName(), "CheckShapeForBias at index [%zu] failed.", i),
866 return ge::GRAPH_FAILED);868 return ge::GRAPH_FAILED);
867- OP_CHECK_IF(CheckShapeForTensorListAtIndex(context, GMM_INDEX_IN_ANTIQUANT_SCALE,869+ OP_CHECK_IF(CheckShapeForTensorListAtIndex(context, GMM_INDEX_IN_ANTIQUANT_SCALE, "antiquantScale",
868- "antiquantScale", gmmAttrs, i) != ge::GRAPH_SUCCESS,870+ gmmAttrs, i) != ge::GRAPH_SUCCESS,
869 OP_LOGE(context->GetNodeName(), "CheckShapeForAntiquantScale at index [%zu] failed.", i),871 OP_LOGE(context->GetNodeName(), "CheckShapeForAntiquantScale at index [%zu] failed.", i),
870 return ge::GRAPH_FAILED);872 return ge::GRAPH_FAILED);
871 OP_CHECK_IF(CheckShapeForTensorListAtIndex(context, GMM_INDEX_IN_ANTIQUANT_OFFSET, "antiquantOffset",873 OP_CHECK_IF(CheckShapeForTensorListAtIndex(context, GMM_INDEX_IN_ANTIQUANT_OFFSET, "antiquantOffset",
@@ -873,7 +875,7 @@ ge::graphStatus GroupedMatmulWeightQuantChecker::CheckShapeValid(const gert::Inf
873 OP_LOGE(context->GetNodeName(), "CheckShapeForAntiquantOffset failed."),875 OP_LOGE(context->GetNodeName(), "CheckShapeForAntiquantOffset failed."),
874 return ge::GRAPH_FAILED);876 return ge::GRAPH_FAILED);
875 OP_CHECK_IF(CheckGroupSize(context, gmmAttrs, i) != ge::GRAPH_SUCCESS,877 OP_CHECK_IF(CheckGroupSize(context, gmmAttrs, i) != ge::GRAPH_SUCCESS,
876- OP_LOGE(context->GetNodeName(), "CheckGroupSize failed."), return ge::GRAPH_FAILED);878+ OP_LOGE(context->GetNodeName(), "CheckGroupSize failed."), return ge::GRAPH_FAILED);
877 }879 }
878 } else {880 } else {
879 OP_CHECK_IF(CheckShapeForTensorList(context, GMM_INDEX_IN_BIAS, "bias", gmmAttrs) != ge::GRAPH_SUCCESS,881 OP_CHECK_IF(CheckShapeForTensorList(context, GMM_INDEX_IN_BIAS, "bias", gmmAttrs) != ge::GRAPH_SUCCESS,
@@ -974,12 +976,12 @@ ge::graphStatus GroupedMatmulWeightQuantChecker::UpdateShapeYMultiDim(gert::Infe
974 976 
975 OP_CHECK_NULL_WITH_CONTEXT(context, weightShape);977 OP_CHECK_NULL_WITH_CONTEXT(context, weightShape);
976 if (transposeWPtr != nullptr && *transposeWPtr) {978 if (transposeWPtr != nullptr && *transposeWPtr) {
977- yShape->SetDim(dimY - 1, weightShape->GetDim(weightShape->GetDimNum() - 2)); // -2: transpose weight979+ yShape->SetDim(dimY - 1, weightShape->GetDim(weightShape->GetDimNum() - 2)); // -2: transpose weight
978 } else {980 } else {
979 yShape->SetDim(dimY - 1, weightShape->GetDim(weightShape->GetDimNum() - 1));981 yShape->SetDim(dimY - 1, weightShape->GetDim(weightShape->GetDimNum() - 1));
980 }982 }
981 if (transposeXPtr != nullptr && *transposeXPtr) {983 if (transposeXPtr != nullptr && *transposeXPtr) {
982- yShape->SetDim(dimY - 2, xShape->GetDim(xShape->GetDimNum() - 1)); // -2: last two dim of Y984+ yShape->SetDim(dimY - 2, xShape->GetDim(xShape->GetDimNum() - 1)); // -2: last two dim of Y
983 }985 }
984 return ge::GRAPH_SUCCESS;986 return ge::GRAPH_SUCCESS;
985}987}
@@ -1171,4 +1173,4 @@ ge::graphStatus GroupedMatmulWeightQuantChecker::InferOutDtype(gert::InferDataTy
1171 return ge::GRAPH_SUCCESS;1173 return ge::GRAPH_SUCCESS;
1172}1174}
1173 1175 
1174-} // namespace ops1176+} // namespace ops
@@ -125,17 +125,17 @@ bool GroupedWeightQuantBatchMatmulTiling::CheckTensorListSize() const
125 "The size of antiquantScaleOptional does not match the expected value"),125 "The size of antiquantScaleOptional does not match the expected value"),
126 return false);126 return false);
127 if (hasAntiquantOffset_) {127 if (hasAntiquantOffset_) {
128- OP_CHECK_IF(isSingleMultiSingle_,128+ OP_CHECK_IF(
129- OP_LOGE_FOR_INVALID_LISTSIZE(OP_NAME, "antiquantOffsetOptional",129+ isSingleMultiSingle_,
130- std::to_string(numAntiquantOffset_),130+ OP_LOGE_FOR_INVALID_LISTSIZE(OP_NAME, "antiquantOffsetOptional", std::to_string(numAntiquantOffset_),
131- "When x-weight is float8_e4m3fn-float4_e2m1/fp32 in "131+ "When x-weight is float8_e4m3fn-float4_e2m1/fp32 in "
132- "single-multi-single mode, antiquantOffsetOptional must be empty"),132+ "single-multi-single mode, antiquantOffsetOptional must be empty"),
133- return false);133+ return false);
134- OP_CHECK_IF(numAntiquantOffset_ != expectedParamNum,134+ OP_CHECK_IF(
135- OP_LOGE_FOR_INVALID_LISTSIZE(OP_NAME, "antiquantOffsetOptional",135+ numAntiquantOffset_ != expectedParamNum,
136- std::to_string(numAntiquantOffset_),136+ OP_LOGE_FOR_INVALID_LISTSIZE(OP_NAME, "antiquantOffsetOptional", std::to_string(numAntiquantOffset_),
137- "antiquantOffsetOptional size does not match the expected value"),137+ "antiquantOffsetOptional size does not match the expected value"),
138- return false);138+ return false);
139 }139 }
140 if (hasBias_) {140 if (hasBias_) {
141 OP_CHECK_IF(numBias_ != expectedParamNum,141 OP_CHECK_IF(numBias_ != expectedParamNum,
@@ -155,13 +155,13 @@ bool GroupedWeightQuantBatchMatmulTiling::CheckTensorDtype(const gert::TilingCon
155 }155 }
156 auto tmpDesc = context->GetDynamicInputDesc(attrIdx, idx);156 auto tmpDesc = context->GetDynamicInputDesc(attrIdx, idx);
157 auto tmpDType = tmpDesc->GetDataType();157 auto tmpDType = tmpDesc->GetDataType();
158- OP_CHECK_IF(tmpDType != tensorDtype,158+ OP_CHECK_IF(
159- OP_LOGE_FOR_INVALID_DTYPE_WITH_REASON(159+ tmpDType != tensorDtype,
160- OP_NAME, tensorType, ge::TypeUtils::DataTypeToSerialString(tmpDType),160+ OP_LOGE_FOR_INVALID_DTYPE_WITH_REASON(
161- std::string("The dtype of each tensor in ") + tensorType + " tensor list must be consistent. " +161+ OP_NAME, tensorType, ge::TypeUtils::DataTypeToSerialString(tmpDType),
162- tensorType + "[" + std::to_string(idx) +162+ std::string("The dtype of each tensor in ") + tensorType + " tensor list must be consistent. " +
163- "]'s dtype is different from the first tensor's dtype."),163+ tensorType + "[" + std::to_string(idx) + "]'s dtype is different from the first tensor's dtype."),
164- return false);164+ return false);
165 return true;165 return true;
166}166}
167 167 
@@ -172,13 +172,13 @@ bool GroupedWeightQuantBatchMatmulTiling::CheckTensorDtypeSingleXMultiWeightSing
172{172{
173 auto tmpDesc = context->GetDynamicInputDesc(attrIdx, idx);173 auto tmpDesc = context->GetDynamicInputDesc(attrIdx, idx);
174 auto tmpDType = tmpDesc->GetDataType();174 auto tmpDType = tmpDesc->GetDataType();
175- OP_CHECK_IF(tmpDType != tensorDtype,175+ OP_CHECK_IF(
176- OP_LOGE_FOR_INVALID_DTYPE_WITH_REASON(176+ tmpDType != tensorDtype,
177- OP_NAME, tensorType, ge::TypeUtils::DataTypeToSerialString(tmpDType),177+ OP_LOGE_FOR_INVALID_DTYPE_WITH_REASON(
178- std::string("The dtype of each tensor in ") + tensorType + " tensor list must be consistent. " +178+ OP_NAME, tensorType, ge::TypeUtils::DataTypeToSerialString(tmpDType),
179- tensorType + "[" + std::to_string(idx) +179+ std::string("The dtype of each tensor in ") + tensorType + " tensor list must be consistent. " +
180- "]'s dtype is different from the first tensor's dtype."),180+ tensorType + "[" + std::to_string(idx) + "]'s dtype is different from the first tensor's dtype."),
181- return false);181+ return false);
182 return true;182 return true;
183}183}
184 184 
@@ -246,12 +246,12 @@ bool GroupedWeightQuantBatchMatmulTiling::CheckTensorDimEqualTarget(const gert::
246 OP_LOGE(context->GetNodeName(), "%s[%zu] shape is nullptr.", tensorType.c_str(), idx), return false);246 OP_LOGE(context->GetNodeName(), "%s[%zu] shape is nullptr.", tensorType.c_str(), idx), return false);
247 auto tmpShape = tmpShapePtr->GetStorageShape();247 auto tmpShape = tmpShapePtr->GetStorageShape();
248 uint32_t tmpDimNum = static_cast<uint32_t>(tmpShape.GetDimNum());248 uint32_t tmpDimNum = static_cast<uint32_t>(tmpShape.GetDimNum());
249- OP_CHECK_IF(tmpDimNum != targetDim,249+ OP_CHECK_IF(
250- OP_LOGE_FOR_INVALID_SHAPEDIM_WITH_REASON(OP_NAME, tensorType + "[" + std::to_string(idx) + "]",250+ tmpDimNum != targetDim,
251- std::to_string(tmpDimNum),251+ OP_LOGE_FOR_INVALID_SHAPEDIM_WITH_REASON(
252- "The shape dim of " + tensorType + "[" + std::to_string(idx) +252+ OP_NAME, tensorType + "[" + std::to_string(idx) + "]", std::to_string(tmpDimNum),
253- "] must be " + std::to_string(targetDim)),253+ "The shape dim of " + tensorType + "[" + std::to_string(idx) + "] must be " + std::to_string(targetDim)),
254- return false);254+ return false);
255 return true;255 return true;
256}256}
257 257 
@@ -438,9 +438,9 @@ bool GroupedWeightQuantBatchMatmulTiling::CheckTensorShapeSingleXMultiWeightSing
438 " must be greater than 0 and divisible by kSize[" + std::to_string(kSize) + "]"),438 " must be greater than 0 and divisible by kSize[" + std::to_string(kSize) + "]"),
439 return false);439 return false);
440 OP_CHECK_IF(kSize % MX_GROUP_SIZE != 0 || scaleGroupNum != static_cast<int64_t>(kSize / MX_GROUP_SIZE),440 OP_CHECK_IF(kSize % MX_GROUP_SIZE != 0 || scaleGroupNum != static_cast<int64_t>(kSize / MX_GROUP_SIZE),
441- OP_LOGE_FOR_INVALID_SHAPE_WITH_REASON(OP_NAME, tensorType, Ops::Base::ToString(tensorShape),441+ OP_LOGE_FOR_INVALID_SHAPE_WITH_REASON(
442- "The groupSize of " + tensorType + " must be " +442+ OP_NAME, tensorType, Ops::Base::ToString(tensorShape),
443- std::to_string(MX_GROUP_SIZE)),443+ "The groupSize of " + tensorType + " must be " + std::to_string(MX_GROUP_SIZE)),
444 return false);444 return false);
445 }445 }
446 return true;446 return true;
@@ -933,7 +933,8 @@ void GroupedWeightQuantBatchMatmulTiling::SetMatMulTiling()
933 tilingData_.mmTilingData.stepKb = STEP_K_3;933 tilingData_.mmTilingData.stepKb = STEP_K_3;
934 }934 }
935 OP_LOGI("SetMatMulTiling", "stepKb = %u", tilingData_.mmTilingData.stepKb);935 OP_LOGI("SetMatMulTiling", "stepKb = %u", tilingData_.mmTilingData.stepKb);
936- } else if (xDType_ == ge::DT_FLOAT8_E4M3FN && weightDtype_ == ge::DT_FLOAT4_E2M1 &&936+ } else if (xDType_ == ge::DT_FLOAT8_E4M3FN &&
937+ (weightDtype_ == ge::DT_FLOAT4_E2M1 || weightDtype_ == ge::DT_FLOAT4_E1M2) &&
937 antiquantScaleDtype_ == ge::DT_FLOAT8_E8M0) {938 antiquantScaleDtype_ == ge::DT_FLOAT8_E8M0) {
938 // MxA8W4场景配置mxTypePara939 // MxA8W4场景配置mxTypePara
939 tilingData_.mmTilingData.mxTypePara = (SCALE_FACTOR_DEFAULT << SCALE_FACTOR_N_BIT) +940 tilingData_.mmTilingData.mxTypePara = (SCALE_FACTOR_DEFAULT << SCALE_FACTOR_N_BIT) +
@@ -983,7 +984,8 @@ void GroupedWeightQuantBatchMatmulTiling::SetTilingKey(gert::TilingContext *cont
983 if (groupSize_ == 192u) {984 if (groupSize_ == 192u) {
984 tilingKeyConfig_.templateCustom = static_cast<uint8_t>(Mte2Configuration::MTE2_INNER_SIZE_384_BUF_NUM_3);985 tilingKeyConfig_.templateCustom = static_cast<uint8_t>(Mte2Configuration::MTE2_INNER_SIZE_384_BUF_NUM_3);
985 }986 }
986- } else if (xDType_ == ge::DT_FLOAT8_E4M3FN && weightDtype_ == ge::DT_FLOAT4_E2M1 &&987+ } else if (xDType_ == ge::DT_FLOAT8_E4M3FN &&
988+ (weightDtype_ == ge::DT_FLOAT4_E2M1 || weightDtype_ == ge::DT_FLOAT4_E1M2) &&
987 antiquantScaleDtype_ == ge::DT_FLOAT8_E8M0) {989 antiquantScaleDtype_ == ge::DT_FLOAT8_E8M0) {
988 tilingKeyConfig_.templateCustom = static_cast<uint8_t>(Mte2Configuration::MTE2_INNER_SIZE_DYNAMIC_BUF_NUM_4);990 tilingKeyConfig_.templateCustom = static_cast<uint8_t>(Mte2Configuration::MTE2_INNER_SIZE_DYNAMIC_BUF_NUM_4);
989 tilingKeyConfig_.isSingleMultiSingle = isSingleMultiSingle_;991 tilingKeyConfig_.isSingleMultiSingle = isSingleMultiSingle_;
@@ -1021,14 +1023,12 @@ bool GroupedWeightQuantBatchMatmulTiling::IsA16W4ND() const
1021 return false;1023 return false;
1022}1024}
1023 1025 
1024-bool GroupedWeightQuantBatchMatmulTiling::IsA16W4NDPergroup() const1026+bool GroupedWeightQuantBatchMatmulTiling::IsA16W4NDPergroup() const { return IsA16W4ND() && groupSize_ > 0; }
1025-{
1026- return IsA16W4ND() && groupSize_ > 0;
1027-}
1028 1027 
1029bool GroupedWeightQuantBatchMatmulTiling::IsMxA8W4() const1028bool GroupedWeightQuantBatchMatmulTiling::IsMxA8W4() const
1030{1029{
1031- if (xDType_ == ge::DT_FLOAT8_E4M3FN && (weightDtype_ == ge::DT_FLOAT4_E2M1 || weightDtype_ == ge::DT_FLOAT) &&1030+ if (xDType_ == ge::DT_FLOAT8_E4M3FN &&
1031+ (weightDtype_ == ge::DT_FLOAT4_E2M1 || weightDtype_ == ge::DT_FLOAT4_E1M2 || weightDtype_ == ge::DT_FLOAT) &&
1032 antiquantScaleDtype_ == ge::DT_FLOAT8_E8M0) {1032 antiquantScaleDtype_ == ge::DT_FLOAT8_E8M0) {
1033 return true;1033 return true;
1034 }1034 }
@@ -1081,14 +1081,16 @@ bool GroupedWeightQuantBatchMatmulTiling::CheckUnsupportedRemainingCases() const
1081 "(In weight quant, when x-weight is int8-int4)"),1081 "(In weight quant, when x-weight is int8-int4)"),
1082 return false);1082 return false);
1083 } else if (xDType_ == ge::DT_FLOAT8_E4M3FN &&1083 } else if (xDType_ == ge::DT_FLOAT8_E4M3FN &&
1084- (weightDtype_ == ge::DT_FLOAT4_E2M1 || weightDtype_ == ge::DT_FLOAT) &&1084+ (weightDtype_ == ge::DT_FLOAT4_E2M1 || weightDtype_ == ge::DT_FLOAT4_E1M2 ||
1085+ weightDtype_ == ge::DT_FLOAT) &&
1085 antiquantScaleDtype_ == ge::DT_FLOAT8_E8M0) {1086 antiquantScaleDtype_ == ge::DT_FLOAT8_E8M0) {
1086 OP_CHECK_IF(!(weightNzFlag_ && transB_),1087 OP_CHECK_IF(!(weightNzFlag_ && transB_),
1087 OP_LOGE_FOR_INVALID_FORMAT(OP_NAME, "weight",1088 OP_LOGE_FOR_INVALID_FORMAT(OP_NAME, "weight",
1088 std::string("format=") + (weightNzFlag_ ? "NZ" : "ND") +1089 std::string("format=") + (weightNzFlag_ ? "NZ" : "ND") +
1089 ", transpose=" + (transB_ ? "true" : "false"),1090 ", transpose=" + (transB_ ? "true" : "false"),
1090 "transposed and FRACTAL_NZ-format "1091 "transposed and FRACTAL_NZ-format "
1091- "(In weight quant, when x-weight is float8_e4m3fn-float4_e2m1/fp32)"),1092+ "(In weight quant, when x-weight is "
1093+ "float8_e4m3fn-float4_e2m1/float4_e1m2/fp32)"),
1092 return false);1094 return false);
1093 }1095 }
1094 return true;1096 return true;
@@ -1117,7 +1119,6 @@ bool GroupedWeightQuantBatchMatmulTiling::CheckAntiQuantDtype() const
1117 return true;1119 return true;
1118}1120}
1119 1121 
1120- 
1121bool GroupedWeightQuantBatchMatmulTiling::CheckPerTokenScale(const gert::TilingContext *context) const1122bool GroupedWeightQuantBatchMatmulTiling::CheckPerTokenScale(const gert::TilingContext *context) const
1122{1123{
1123 if (IsMxA8W4()) {1124 if (IsMxA8W4()) {
@@ -1126,11 +1127,11 @@ bool GroupedWeightQuantBatchMatmulTiling::CheckPerTokenScale(const gert::TilingC
1126 OP_LOGE(context->GetNodeName(), "perTokenScaleShapePtr is nullptr."), return false);1127 OP_LOGE(context->GetNodeName(), "perTokenScaleShapePtr is nullptr."), return false);
1127 gert::Shape perTokenScaleShape = perTokenScaleShapePtr->GetStorageShape();1128 gert::Shape perTokenScaleShape = perTokenScaleShapePtr->GetStorageShape();
1128 int64_t perTokenScaleDimNum = perTokenScaleShape.GetDimNum();1129 int64_t perTokenScaleDimNum = perTokenScaleShape.GetDimNum();
1129- OP_CHECK_IF(perTokenScaleDimNum != 3,1130+ OP_CHECK_IF(
1130- OP_LOGE_FOR_INVALID_SHAPEDIM_WITH_REASON(OP_NAME, "perTokenScale",1131+ perTokenScaleDimNum != 3,
1131- std::to_string(perTokenScaleDimNum),1132+ OP_LOGE_FOR_INVALID_SHAPEDIM_WITH_REASON(OP_NAME, "perTokenScale", std::to_string(perTokenScaleDimNum),
1132- "The shape dim of perTokenScaleShape must be 3"),1133+ "The shape dim of perTokenScaleShape must be 3"),
1133- return false);1134+ return false);
1134 OP_CHECK_IF(perTokenScaleShape.GetDim(0) != static_cast<int64_t>(mSize_) ||1135 OP_CHECK_IF(perTokenScaleShape.GetDim(0) != static_cast<int64_t>(mSize_) ||
1135 perTokenScaleShape.GetDim(1) != static_cast<int64_t>(kSize_) / (MX_GROUP_SIZE * 2) ||1136 perTokenScaleShape.GetDim(1) != static_cast<int64_t>(kSize_) / (MX_GROUP_SIZE * 2) ||
1136 perTokenScaleShape.GetDim(2) != 2UL,1137 perTokenScaleShape.GetDim(2) != 2UL,
@@ -1147,11 +1148,11 @@ bool GroupedWeightQuantBatchMatmulTiling::CheckBiasDtype() const
1147{1148{
1148 if (IsA16W4ND()) {1149 if (IsA16W4ND()) {
1149 if (hasBias_) {1150 if (hasBias_) {
1150- OP_CHECK_IF(BIAS_TYPE_SUPPORT_MAP.find(xDType_) == BIAS_TYPE_SUPPORT_MAP.end(),1151+ OP_CHECK_IF(
1151- OP_LOGE_FOR_INVALID_DTYPE_WITH_REASON(OP_NAME, "x",1152+ BIAS_TYPE_SUPPORT_MAP.find(xDType_) == BIAS_TYPE_SUPPORT_MAP.end(),
1152- ge::TypeUtils::DataTypeToSerialString(xDType_),1153+ OP_LOGE_FOR_INVALID_DTYPE_WITH_REASON(OP_NAME, "x", ge::TypeUtils::DataTypeToSerialString(xDType_),
1153- "Cannot find bias dtype match with dtype of x"),1154+ "Cannot find bias dtype match with dtype of x"),
1154- return false);1155+ return false);
1155 OP_CHECK_IF(BIAS_TYPE_SUPPORT_MAP.at(xDType_).find(biasDtype_) == BIAS_TYPE_SUPPORT_MAP.at(xDType_).end(),1156 OP_CHECK_IF(BIAS_TYPE_SUPPORT_MAP.at(xDType_).find(biasDtype_) == BIAS_TYPE_SUPPORT_MAP.at(xDType_).end(),
1156 OP_LOGE_FOR_INVALID_DTYPE_WITH_REASON(1157 OP_LOGE_FOR_INVALID_DTYPE_WITH_REASON(
1157 OP_NAME, "bias", ge::TypeUtils::DataTypeToSerialString(biasDtype_),1158 OP_NAME, "bias", ge::TypeUtils::DataTypeToSerialString(biasDtype_),
@@ -1249,10 +1250,10 @@ bool GroupedWeightQuantBatchMatmulTiling::CheckEmptyTensorSingleXMultiWeightSing
1249 // k不能单独为01250 // k不能单独为0
1250 OP_CHECK_IF(1251 OP_CHECK_IF(
1251 ((m != 0) && (n != 0)) && k == 0,1252 ((m != 0) && (n != 0)) && k == 0,
1252- OP_LOGE_FOR_INVALID_SHAPES_WITH_REASON(OP_NAME, "x[0], weight[" + std::to_string(i) + "]",1253+ OP_LOGE_FOR_INVALID_SHAPES_WITH_REASON(
1253- Ops::Base::ToString(xShape) + ", " + Ops::Base::ToString(wShape),1254+ OP_NAME, "x[0], weight[" + std::to_string(i) + "]",
1254- "K of x[0] cannot be 0 when M of x[0] is not 0 and N of weight[" +1255+ Ops::Base::ToString(xShape) + ", " + Ops::Base::ToString(wShape),
1255- std::to_string(i) + "] is not 0"),1256+ "K of x[0] cannot be 0 when M of x[0] is not 0 and N of weight[" + std::to_string(i) + "] is not 0"),
1256 return false);1257 return false);
1257 }1258 }
1258 return true;1259 return true;
@@ -1526,14 +1527,14 @@ bool GroupedWeightQuantBatchMatmulTiling::DeriveGroupSizeSingle(const gert::Tili
1526 return true;1527 return true;
1527 }1528 }
1528 1529 
1529- OP_CHECK_IF(groupNum <= 0 || kSize_ % groupNum > 0,1530+ OP_CHECK_IF(
1530- OP_LOGE_FOR_INVALID_SHAPE_WITH_REASON(OP_NAME, "antiquantScaleShape",1531+ groupNum <= 0 || kSize_ % groupNum > 0,
1531- Ops::Base::ToString(antiquantScaleShape),1532+ OP_LOGE_FOR_INVALID_SHAPE_WITH_REASON(OP_NAME, "antiquantScaleShape", Ops::Base::ToString(antiquantScaleShape),
1532- "The groupNum[" + std::to_string(groupNum) +1533+ "The groupNum[" + std::to_string(groupNum) +
1533- "] of antiquantScaleShape must be "1534+ "] of antiquantScaleShape must be "
1534- "greater than 0 and divisible by kSize[" +1535+ "greater than 0 and divisible by kSize[" +
1535- std::to_string(kSize_) + "]"),1536+ std::to_string(kSize_) + "]"),
1536- return false);1537+ return false);
1537 groupSize_ = groupNum > 0 ? kSize_ / static_cast<uint64_t>(groupNum) : 0;1538 groupSize_ = groupNum > 0 ? kSize_ / static_cast<uint64_t>(groupNum) : 0;
1538 OP_CHECK_IF(IsA16W4ND() && !CheckAntiquantOffsetMatchScale(context, 0, antiquantScaleShape),1539 OP_CHECK_IF(IsA16W4ND() && !CheckAntiquantOffsetMatchScale(context, 0, antiquantScaleShape),
1539 OP_LOGE(context->GetNodeName(), "CheckAntiquantOffsetMatchScale failed for tensor[0]."), return false);1540 OP_LOGE(context->GetNodeName(), "CheckAntiquantOffsetMatchScale failed for tensor[0]."), return false);
@@ -1629,13 +1630,13 @@ bool GroupedWeightQuantBatchMatmulTiling::CheckA16W4MultiPergroupScaleShape(cons
1629 1630 
1630 int64_t scaleNDim = scaleShape.GetDim(1);1631 int64_t scaleNDim = scaleShape.GetDim(1);
1631 int64_t nSize = static_cast<int64_t>(nList_[idx]);1632 int64_t nSize = static_cast<int64_t>(nList_[idx]);
1632- OP_CHECK_IF(scaleNDim != nSize,1633+ OP_CHECK_IF(
1633- OP_LOGE_FOR_INVALID_SHAPE_WITH_REASON(1634+ scaleNDim != nSize,
1634- OP_NAME, "antiquantScale[" + std::to_string(idx) + "]", Ops::Base::ToString(scaleShape),1635+ OP_LOGE_FOR_INVALID_SHAPE_WITH_REASON(
1635- "The N dimension[" + std::to_string(scaleNDim) + "] of antiquantScale[" + std::to_string(idx) +1636+ OP_NAME, "antiquantScale[" + std::to_string(idx) + "]", Ops::Base::ToString(scaleShape),
1636- "] must be equal to nSize[" + std::to_string(nSize) + "] of weight[" + std::to_string(idx) +1637+ "The N dimension[" + std::to_string(scaleNDim) + "] of antiquantScale[" + std::to_string(idx) +
1637- "]"),1638+ "] must be equal to nSize[" + std::to_string(nSize) + "] of weight[" + std::to_string(idx) + "]"),
1638- return false);1639+ return false);
1639 OP_CHECK_IF(!CheckAntiquantOffsetMatchScale(context, idx, scaleShape),1640 OP_CHECK_IF(!CheckAntiquantOffsetMatchScale(context, idx, scaleShape),
1640 OP_LOGE(context->GetNodeName(), "CheckAntiquantOffsetMatchScale failed for tensor[%u].", idx),1641 OP_LOGE(context->GetNodeName(), "CheckAntiquantOffsetMatchScale failed for tensor[%u].", idx),
1641 return false);1642 return false);
@@ -1660,14 +1661,14 @@ bool GroupedWeightQuantBatchMatmulTiling::CheckAntiquantOffsetMatchScale(const g
1660 "] must be equal to the dimension of antiquantScale[" + std::to_string(idx) + "]"),1661 "] must be equal to the dimension of antiquantScale[" + std::to_string(idx) + "]"),
1661 return false);1662 return false);
1662 for (int64_t dimIdx = 0; dimIdx < offsetShape.GetDimNum(); ++dimIdx) {1663 for (int64_t dimIdx = 0; dimIdx < offsetShape.GetDimNum(); ++dimIdx) {
1663- OP_CHECK_IF(offsetShape.GetDim(dimIdx) != scaleShape.GetDim(dimIdx),1664+ OP_CHECK_IF(
1664- OP_LOGE_FOR_INVALID_SHAPES_WITH_REASON(1665+ offsetShape.GetDim(dimIdx) != scaleShape.GetDim(dimIdx),
1665- OP_NAME,1666+ OP_LOGE_FOR_INVALID_SHAPES_WITH_REASON(
1666- "antiquantOffset[" + std::to_string(idx) + "], antiquantScale[" + std::to_string(idx) + "]",1667+ OP_NAME, "antiquantOffset[" + std::to_string(idx) + "], antiquantScale[" + std::to_string(idx) + "]",
1667- Ops::Base::ToString(offsetShape) + ", " + Ops::Base::ToString(scaleShape),1668+ Ops::Base::ToString(offsetShape) + ", " + Ops::Base::ToString(scaleShape),
1668- "The shape of antiquantOffset[" + std::to_string(idx) +1669+ "The shape of antiquantOffset[" + std::to_string(idx) +
1669- "] must be equal to the shape of antiquantScale[" + std::to_string(idx) + "]"),1670+ "] must be equal to the shape of antiquantScale[" + std::to_string(idx) + "]"),
1670- return false);1671+ return false);
1671 }1672 }
1672 return true;1673 return true;
1673}1674}
@@ -1686,13 +1687,13 @@ bool GroupedWeightQuantBatchMatmulTiling::CheckMultiA16W4PerChannelShape(const g
1686 "Expected dimension 1 for perchannel"),1687 "Expected dimension 1 for perchannel"),
1687 return false);1688 return false);
1688 int64_t nI = static_cast<int64_t>(nList_[i]);1689 int64_t nI = static_cast<int64_t>(nList_[i]);
1689- OP_CHECK_IF(scaleShape.GetDim(0) != nI,1690+ OP_CHECK_IF(
1690- OP_LOGE_FOR_INVALID_SHAPE_WITH_REASON(1691+ scaleShape.GetDim(0) != nI,
1691- OP_NAME, "antiquantScale[" + std::to_string(i) + "]", Ops::Base::ToString(scaleShape),1692+ OP_LOGE_FOR_INVALID_SHAPE_WITH_REASON(
1692- "The N dimension[" + std::to_string(scaleShape.GetDim(0)) + "] of antiquantScale[" +1693+ OP_NAME, "antiquantScale[" + std::to_string(i) + "]", Ops::Base::ToString(scaleShape),
1693- std::to_string(i) + "] must be equal to nSize[" + std::to_string(nI) + "] of weight[" +1694+ "The N dimension[" + std::to_string(scaleShape.GetDim(0)) + "] of antiquantScale[" + std::to_string(i) +
1694- std::to_string(i) + "]"),1695+ "] must be equal to nSize[" + std::to_string(nI) + "] of weight[" + std::to_string(i) + "]"),
1695- return false);1696+ return false);
1696 OP_CHECK_IF(!CheckAntiquantOffsetMatchScale(context, i, scaleShape),1697 OP_CHECK_IF(!CheckAntiquantOffsetMatchScale(context, i, scaleShape),
1697 OP_LOGE(context->GetNodeName(), "CheckAntiquantOffsetMatchScale failed for tensor[%u].", i),1698 OP_LOGE(context->GetNodeName(), "CheckAntiquantOffsetMatchScale failed for tensor[%u].", i),
1698 return false);1699 return false);
@@ -86,8 +86,11 @@ static constexpr MicroAPI::CastTrait CAST_FP4_TO_BF16_TRAIT = {MicroAPI::RegLayo
86 MicroAPI::MaskMergeMode::ZEROING,86 MicroAPI::MaskMergeMode::ZEROING,
87 AscendC::RoundMode::UNKNOWN};87 AscendC::RoundMode::UNKNOWN};
88static constexpr uint32_t E2M1_SHIFT_RIGHT_SIZE = 0x2;88static constexpr uint32_t E2M1_SHIFT_RIGHT_SIZE = 0x2;
89+// Embed packed E1M2 (s|e|mm) into the byte lanes consumed by the MX matmul path.
90+static constexpr uint32_t E1M2_SHIFT_RIGHT_SIZE = 0x3;
89static constexpr uint32_t SHIFT_LEFT_SIZE = 0x4;91static constexpr uint32_t SHIFT_LEFT_SIZE = 0x4;
90static constexpr uint32_t E2M1_AND_MASK = 0x9C;92static constexpr uint32_t E2M1_AND_MASK = 0x9C;
93+static constexpr uint32_t E1M2_AND_MASK = 0x8E;
91 94 
92template <typename xType>95template <typename xType>
93__aicore__ inline void MxScaleVf(RegTensor<uint8_t> &antiQuantScaleE8m0Vreg0,96__aicore__ inline void MxScaleVf(RegTensor<uint8_t> &antiQuantScaleE8m0Vreg0,
@@ -166,12 +169,12 @@ __aicore__ inline void MxNkScaleVf(MxFp4NdScaleParams<xType> &mxFp4NdNkScalePara
166 MxScaleVf(antiQuantScaleE8m0Vreg0, antiQuantScaleE8m0Vreg1, antiQuantScaleF16Vreg0, antiQuantScaleF16Vreg1,169 MxScaleVf(antiQuantScaleE8m0Vreg0, antiQuantScaleE8m0Vreg1, antiQuantScaleF16Vreg0, antiQuantScaleF16Vreg1,
167 maskAll);170 maskAll);
168 171 
169- MicroAPI::DataCopy<xType, MicroAPI::StoreDist::DIST_NORM_B16>(mxFp4NdNkScaleParams.antiQuantScaleF16PhyAddr0 +172+ MicroAPI::DataCopy<xType, MicroAPI::StoreDist::DIST_NORM_B16>(
170- ubLoopNIdx * VECTOR_REG_WIDTH,173+ mxFp4NdNkScaleParams.antiQuantScaleF16PhyAddr0 + ubLoopNIdx * VECTOR_REG_WIDTH, antiQuantScaleF16Vreg0,
171- antiQuantScaleF16Vreg0, maskAll);174+ maskAll);
172- MicroAPI::DataCopy<xType, MicroAPI::StoreDist::DIST_NORM_B16>(mxFp4NdNkScaleParams.antiQuantScaleF16PhyAddr1 +175+ MicroAPI::DataCopy<xType, MicroAPI::StoreDist::DIST_NORM_B16>(
173- ubLoopNIdx * VECTOR_REG_WIDTH,176+ mxFp4NdNkScaleParams.antiQuantScaleF16PhyAddr1 + ubLoopNIdx * VECTOR_REG_WIDTH, antiQuantScaleF16Vreg1,
174- antiQuantScaleF16Vreg1, maskAll);177+ maskAll);
175 }178 }
176}179}
177 180 
@@ -195,12 +198,12 @@ __aicore__ inline void MxKnScaleVf(MxFp4NdScaleParams<xType> &mxFp4NdScaleParams
195 MxScaleVf(antiQuantScaleE8m0Vreg0, antiQuantScaleE8m0Vreg1, antiQuantScaleF16Vreg0, antiQuantScaleF16Vreg1,198 MxScaleVf(antiQuantScaleE8m0Vreg0, antiQuantScaleE8m0Vreg1, antiQuantScaleF16Vreg0, antiQuantScaleF16Vreg1,
196 maskAll);199 maskAll);
197 200 
198- MicroAPI::DataCopy<xType, MicroAPI::StoreDist::DIST_NORM_B16>(mxFp4NdScaleParams.antiQuantScaleF16PhyAddr0 +201+ MicroAPI::DataCopy<xType, MicroAPI::StoreDist::DIST_NORM_B16>(
199- ubLoopKIdx * VECTOR_REG_WIDTH,202+ mxFp4NdScaleParams.antiQuantScaleF16PhyAddr0 + ubLoopKIdx * VECTOR_REG_WIDTH, antiQuantScaleF16Vreg0,
200- antiQuantScaleF16Vreg0, maskAll);203+ maskAll);
201- MicroAPI::DataCopy<xType, MicroAPI::StoreDist::DIST_NORM_B16>(mxFp4NdScaleParams.antiQuantScaleF16PhyAddr1 +204+ MicroAPI::DataCopy<xType, MicroAPI::StoreDist::DIST_NORM_B16>(
202- ubLoopKIdx * VECTOR_REG_WIDTH,205+ mxFp4NdScaleParams.antiQuantScaleF16PhyAddr1 + ubLoopKIdx * VECTOR_REG_WIDTH, antiQuantScaleF16Vreg1,
203- antiQuantScaleF16Vreg1, maskAll);206+ maskAll);
204 }207 }
205}208}
206 209 
@@ -222,12 +225,12 @@ __aicore__ inline void MxNkWeightVf(MxFp4NdWeightParams<xType, wType> &mxFp4NdNk
222 // Vn 1 2 3 4 5 6 7 8225 // Vn 1 2 3 4 5 6 7 8
223 // Vd226 // Vd
224 // 11111111111111112222222222222233333333333333334444444444444444455555555555555666666666666666677777777777777227 // 11111111111111112222222222222233333333333333334444444444444444455555555555555666666666666666677777777777777
225- MicroAPI::DataCopy<xType, MicroAPI::LoadDist::DIST_E2B_B16>(antiQuantScaleF16Vreg0,228+ MicroAPI::DataCopy<xType, MicroAPI::LoadDist::DIST_E2B_B16>(
226- mxFp4NdNkWeightParams.antiQuantScaleF16PhyAddr0 +229+ antiQuantScaleF16Vreg0,
227- ubLoopNIdx * (VECTOR_REG_WIDTH >> 2));230+ mxFp4NdNkWeightParams.antiQuantScaleF16PhyAddr0 + ubLoopNIdx * (VECTOR_REG_WIDTH >> 2));
228- MicroAPI::DataCopy<xType, MicroAPI::LoadDist::DIST_E2B_B16>(antiQuantScaleF16Vreg1,231+ MicroAPI::DataCopy<xType, MicroAPI::LoadDist::DIST_E2B_B16>(
229- mxFp4NdNkWeightParams.antiQuantScaleF16PhyAddr1 +232+ antiQuantScaleF16Vreg1,
230- ubLoopNIdx * (VECTOR_REG_WIDTH >> 2));233+ mxFp4NdNkWeightParams.antiQuantScaleF16PhyAddr1 + ubLoopNIdx * (VECTOR_REG_WIDTH >> 2));
231 234 
232 // DIST_UNPK_B8 表示按照如下形式载入, 其中Vn中一个数字为4bit:235 // DIST_UNPK_B8 表示按照如下形式载入, 其中Vn中一个数字为4bit:
233 // Vn 1 2 3 4 5 6 7 8 9 a b c d e f g .....236 // Vn 1 2 3 4 5 6 7 8 9 a b c d e f g .....
@@ -370,9 +373,12 @@ __simd_vf__ inline void AntiQuantMxA8W4NzNkVf(MxA8W4NzParams<xType, wType, biasT
370 MicroAPI::MaskReg preg = MicroAPI::CreateMask<uint8_t, AscendC::MicroAPI::MaskPattern::ALL>();373 MicroAPI::MaskReg preg = MicroAPI::CreateMask<uint8_t, AscendC::MicroAPI::MaskPattern::ALL>();
371 MicroAPI::MaskReg pregVsel = MicroAPI::CreateMask<uint16_t, AscendC::MicroAPI::MaskPattern::ALL>();374 MicroAPI::MaskReg pregVsel = MicroAPI::CreateMask<uint16_t, AscendC::MicroAPI::MaskPattern::ALL>();
372 375 
373- MicroAPI::Duplicate<int8_t, AscendC::MicroAPI::MaskMergeMode::ZEROING>(wShrReg, E2M1_SHIFT_RIGHT_SIZE, preg);376+ constexpr uint32_t shiftRightSize =
377+ IsSameType<wType, fp4x2_e1m2_t>::value ? E1M2_SHIFT_RIGHT_SIZE : E2M1_SHIFT_RIGHT_SIZE;
378+ constexpr uint32_t andMask = IsSameType<wType, fp4x2_e1m2_t>::value ? E1M2_AND_MASK : E2M1_AND_MASK;
panzhija
panzhijapanzhijaJul 28

[测试][必须修复] 🔴 补充 E1M2 解码精度验证 新增测试只覆盖 API、InferShape 和 Tiling,均不会执行这里的 shiftRightSize/andMask 分支;位移或掩码错误时现有新增用例仍可全部通过。请增加 Kernel/ST Golden 用例,覆盖正负、零和 E1M2 编码边界,验证解包后的实际计算结果。

likedislike
zhangzhizhuo
zhangzhizhuo
Jul 28 Comments:
likedislike
379+ MicroAPI::Duplicate<int8_t, AscendC::MicroAPI::MaskMergeMode::ZEROING>(wShrReg, shiftRightSize, preg);
374 MicroAPI::Duplicate<int8_t, AscendC::MicroAPI::MaskMergeMode::ZEROING>(wShlReg, SHIFT_LEFT_SIZE, preg);380 MicroAPI::Duplicate<int8_t, AscendC::MicroAPI::MaskMergeMode::ZEROING>(wShlReg, SHIFT_LEFT_SIZE, preg);
375- MicroAPI::Duplicate<int8_t, AscendC::MicroAPI::MaskMergeMode::ZEROING>(wAndReg, E2M1_AND_MASK, preg);381+ MicroAPI::Duplicate<int8_t, AscendC::MicroAPI::MaskMergeMode::ZEROING>(wAndReg, andMask, preg);
376 382 
377 for (uint16_t loopKIdx = 0; loopKIdx < mxA8W4NzParams.loopKNum; ++loopKIdx) {383 for (uint16_t loopKIdx = 0; loopKIdx < mxA8W4NzParams.loopKNum; ++loopKIdx) {
378 for (uint16_t innerLoopIdx = 0; innerLoopIdx < mxA8W4NzParams.innerLoopNum; ++innerLoopIdx) {384 for (uint16_t innerLoopIdx = 0; innerLoopIdx < mxA8W4NzParams.innerLoopNum; ++innerLoopIdx) {
@@ -27,145 +27,146 @@
27#include "kernel_tiling/kernel_tiling.h"27#include "kernel_tiling/kernel_tiling.h"
28#include "lib/matmul_intf.h"28#include "lib/matmul_intf.h"
29#if ((defined(__CCE_AICORE__) && (__CCE_AICORE__ == 310)) && !(defined(__NPU_ARCH__) && __NPU_ARCH__ == 3113))29#if ((defined(__CCE_AICORE__) && (__CCE_AICORE__ == 310)) && !(defined(__NPU_ARCH__) && __NPU_ARCH__ == 3113))
30- #if defined(ORIG_DTYPE_X) && defined(DT_INT8) && ORIG_DTYPE_X == DT_INT830+#if defined(ORIG_DTYPE_X) && defined(DT_INT8) && ORIG_DTYPE_X == DT_INT8
31- #define DTYPE_L0C_LOCAL int32_t31+#define DTYPE_L0C_LOCAL int32_t
32- #else32+#else
33- #define DTYPE_L0C_LOCAL float33+#define DTYPE_L0C_LOCAL float
34- #endif34+#endif
35- #if defined(ORIG_DTYPE_X) && defined(ORIG_DTYPE_WEIGHT) && defined(DT_FLOAT8_E5M2) && defined(DT_FLOAT8_E4M3FN) && \35+#if defined(ORIG_DTYPE_X) && defined(ORIG_DTYPE_WEIGHT) && defined(DT_FLOAT8_E5M2) && defined(DT_FLOAT8_E4M3FN) && \
36- defined(DT_HIFLOAT8) && defined(DT_INT8) && defined(DT_FLOAT4_E2M1) && defined(DT_INT4) && \36+ defined(DT_HIFLOAT8) && defined(DT_INT8) && defined(DT_FLOAT4_E2M1) && defined(DT_INT4) && \
37- ((ORIG_DTYPE_X == DT_INT8 && ORIG_DTYPE_WEIGHT == DT_INT8) || \37+ ((ORIG_DTYPE_X == DT_INT8 && ORIG_DTYPE_WEIGHT == DT_INT8) || \
38- (ORIG_DTYPE_X == DT_HIFLOAT8 && ORIG_DTYPE_WEIGHT == DT_HIFLOAT8) || \38+ (ORIG_DTYPE_X == DT_HIFLOAT8 && ORIG_DTYPE_WEIGHT == DT_HIFLOAT8) || \
39- ((ORIG_DTYPE_X == DT_FLOAT8_E5M2 || ORIG_DTYPE_X == DT_FLOAT8_E4M3FN) && \39+ ((ORIG_DTYPE_X == DT_FLOAT8_E5M2 || ORIG_DTYPE_X == DT_FLOAT8_E4M3FN) && \
40- (ORIG_DTYPE_WEIGHT == DT_FLOAT8_E5M2 || ORIG_DTYPE_WEIGHT == DT_FLOAT8_E4M3FN)) || \40+ (ORIG_DTYPE_WEIGHT == DT_FLOAT8_E5M2 || ORIG_DTYPE_WEIGHT == DT_FLOAT8_E4M3FN)) || \
41- ((ORIG_DTYPE_X == DT_FLOAT4_E2M1 || ORIG_DTYPE_X == DT_FLOAT4_E1M2) && \41+ ((ORIG_DTYPE_X == DT_FLOAT4_E2M1 || ORIG_DTYPE_X == DT_FLOAT4_E1M2) && \
42- (ORIG_DTYPE_WEIGHT == DT_FLOAT4_E2M1 || ORIG_DTYPE_WEIGHT == DT_FLOAT4_E1M2)) || \42+ (ORIG_DTYPE_WEIGHT == DT_FLOAT4_E2M1 || ORIG_DTYPE_WEIGHT == DT_FLOAT4_E1M2)) || \
43- (ORIG_DTYPE_X == DT_INT4 && ORIG_DTYPE_WEIGHT == DT_INT4))43+ (ORIG_DTYPE_X == DT_INT4 && ORIG_DTYPE_WEIGHT == DT_INT4))
44- #define V310_GMM_QUANT44+#define V310_GMM_QUANT
45- #if defined(ORIG_DTYPE_SCALE) && defined(DT_FLOAT8_E8M0) && ORIG_DTYPE_SCALE == DT_FLOAT8_E8M045+#if defined(ORIG_DTYPE_SCALE) && defined(DT_FLOAT8_E8M0) && ORIG_DTYPE_SCALE == DT_FLOAT8_E8M0
46- #define V310_GMM_QUANT_MX46+#define V310_GMM_QUANT_MX
47- #elif defined(ORIG_DTYPE_SCALE) && defined(DT_UINT64) && defined(DT_INT64) && \47+#elif defined(ORIG_DTYPE_SCALE) && defined(DT_UINT64) && defined(DT_INT64) && \
48- (ORIG_DTYPE_SCALE != DT_UINT64 && ORIG_DTYPE_SCALE != DT_INT64)48+ (ORIG_DTYPE_SCALE != DT_UINT64 && ORIG_DTYPE_SCALE != DT_INT64)
49- #define V310_GMM_QUANT_MIX49+#define V310_GMM_QUANT_MIX
50- #define V310_GMM_QUANT_PERTENSOR_CUBE50+#define V310_GMM_QUANT_PERTENSOR_CUBE
51- #if (ORIG_DTYPE_X != DT_INT8 && ORIG_DTYPE_SCALE == DT_FLOAT)51+#if (ORIG_DTYPE_X != DT_INT8 && ORIG_DTYPE_SCALE == DT_FLOAT)
52- #define V310_GMM_QUANT_PERTILE52+#define V310_GMM_QUANT_PERTILE
53- #endif53+#endif
54- #else54+#else
55- #define V310_GMM_QUANT_CUBE55+#define V310_GMM_QUANT_CUBE
56- #endif56+#endif
57- #endif57+#endif
58 58 
59- #if defined(ORIG_DTYPE_X) && defined(ORIG_DTYPE_WEIGHT) && ORIG_DTYPE_X != ORIG_DTYPE_WEIGHT59+#if defined(ORIG_DTYPE_X) && defined(ORIG_DTYPE_WEIGHT) && ORIG_DTYPE_X != ORIG_DTYPE_WEIGHT
60- #if ((ORIG_DTYPE_X == DT_FLOAT16 || ORIG_DTYPE_X == DT_BF16) && \60+#if ((ORIG_DTYPE_X == DT_FLOAT16 || ORIG_DTYPE_X == DT_BF16) && \
61- (ORIG_DTYPE_WEIGHT == DT_FLOAT8_E5M2 || ORIG_DTYPE_WEIGHT == DT_FLOAT8_E4M3FN || \61+ (ORIG_DTYPE_WEIGHT == DT_FLOAT8_E5M2 || ORIG_DTYPE_WEIGHT == DT_FLOAT8_E4M3FN || \
62- ORIG_DTYPE_WEIGHT == DT_HIFLOAT8 || ORIG_DTYPE_WEIGHT == DT_INT8 || ORIG_DTYPE_WEIGHT == DT_FLOAT4_E2M1 || \62+ ORIG_DTYPE_WEIGHT == DT_HIFLOAT8 || ORIG_DTYPE_WEIGHT == DT_INT8 || ORIG_DTYPE_WEIGHT == DT_FLOAT4_E2M1 || \
63- ORIG_DTYPE_WEIGHT == DT_FLOAT || ORIG_DTYPE_WEIGHT == DT_INT32 || \63+ ORIG_DTYPE_WEIGHT == DT_FLOAT || ORIG_DTYPE_WEIGHT == DT_INT32 || ORIG_DTYPE_WEIGHT == DT_INT4)) || \
64- ORIG_DTYPE_WEIGHT == DT_INT4)) || \64+ (ORIG_DTYPE_X == DT_INT8 && (ORIG_DTYPE_WEIGHT == DT_INT4 || ORIG_DTYPE_WEIGHT == DT_INT32)) || \
65- (ORIG_DTYPE_X == DT_INT8 && (ORIG_DTYPE_WEIGHT == DT_INT4 || ORIG_DTYPE_WEIGHT == DT_INT32)) || \65+ (ORIG_DTYPE_X == DT_FLOAT8_E4M3FN && \
66- (ORIG_DTYPE_X == DT_FLOAT8_E4M3FN && (ORIG_DTYPE_WEIGHT == DT_FLOAT4_E2M1 || ORIG_DTYPE_WEIGHT == DT_FLOAT))66+ (ORIG_DTYPE_WEIGHT == DT_FLOAT4_E2M1 || ORIG_DTYPE_WEIGHT == DT_FLOAT4_E1M2 || ORIG_DTYPE_WEIGHT == DT_FLOAT))
67- #define V310_GMM_ANTI_QUANT67+#define V310_GMM_ANTI_QUANT
68- #endif68+#endif
69- #endif69+#endif
70#endif70#endif
71 71 
72#if defined(ORIG_DTYPE_X) && defined(ORIG_DTYPE_WEIGHT) && defined(ORIG_DTYPE_Y) && defined(DT_INT8) && \72#if defined(ORIG_DTYPE_X) && defined(ORIG_DTYPE_WEIGHT) && defined(ORIG_DTYPE_Y) && defined(DT_INT8) && \
73 defined(DT_BF16) && defined(DT_INT4)73 defined(DT_BF16) && defined(DT_INT4)
74- #if ORIG_DTYPE_X == ORIG_DTYPE_WEIGHT74+#if ORIG_DTYPE_X == ORIG_DTYPE_WEIGHT
75- #if ORIG_DTYPE_X == DT_INT875+#if ORIG_DTYPE_X == DT_INT8
76- #if ORIG_DTYPE_Y == DT_BF1676+#if ORIG_DTYPE_Y == DT_BF16
77- #define GMM_QUANT_BF1677+#define GMM_QUANT_BF16
78- #define MM_DTYPE_Y int32_t78+#define MM_DTYPE_Y int32_t
79- #elif ORIG_DTYPE_Y == DT_FLOAT1679+#elif ORIG_DTYPE_Y == DT_FLOAT16
80- #define GMM_QUANT_FLOAT1680+#define GMM_QUANT_FLOAT16
81- #define MM_DTYPE_Y int32_t81+#define MM_DTYPE_Y int32_t
82- #elif ORIG_DTYPE_Y == DT_INT3282+#elif ORIG_DTYPE_Y == DT_INT32
83- #define GMM_QUANT_INT3283+#define GMM_QUANT_INT32
84- #else84+#else
85- #define GMM_QUANT_INT885+#define GMM_QUANT_INT8
86- #endif86+#endif
87- #elif ORIG_DTYPE_X == DT_INT487+#elif ORIG_DTYPE_X == DT_INT4
88- #define GMM_A4W488+#define GMM_A4W4
89- #define MM_DTYPE_Y half89+#define MM_DTYPE_Y half
90- #if ORIG_DTYPE_Y == DT_BF1690+#if ORIG_DTYPE_Y == DT_BF16
91- #define GMM_A4W4_BF1691+#define GMM_A4W4_BF16
92- #elif ORIG_DTYPE_Y == DT_FLOAT1692+#elif ORIG_DTYPE_Y == DT_FLOAT16
93- #define GMM_A4W4_FP1693+#define GMM_A4W4_FP16
94- #endif94+#endif
95- #else95+#else
96- #define GMM_FLOAT96+#define GMM_FLOAT
97- #endif97+#endif
98- #else98+#else
99- #define GMM_ANTI_QUANT99+#define GMM_ANTI_QUANT
100- #if ORIG_DTYPE_X == DT_INT8 && ORIG_DTYPE_WEIGHT == DT_INT4100+#if ORIG_DTYPE_X == DT_INT8 && ORIG_DTYPE_WEIGHT == DT_INT4
101- #define GMM_ANTI_QUANT_A8W4_MSD101+#define GMM_ANTI_QUANT_A8W4_MSD
102- #define GMM_ANTI_QUANT_A8W4102+#define GMM_ANTI_QUANT_A8W4
103- #if ORIG_DTYPE_Y == DT_BF16103+#if ORIG_DTYPE_Y == DT_BF16
104- #define GMM_ANTI_QUANT_A8W4_MSD_OUT_BF16104+#define GMM_ANTI_QUANT_A8W4_MSD_OUT_BF16
105- #else105+#else
106- #define GMM_ANTI_QUANT_A8W4_MSD_OUT_FP16106+#define GMM_ANTI_QUANT_A8W4_MSD_OUT_FP16
107- #endif107+#endif
108- #define MM_DTYPE_Y int32_t108+#define MM_DTYPE_Y int32_t
109- #else109+#else
110- #define GMM_ANTI_QUANT110+#define GMM_ANTI_QUANT
111- #endif111+#endif
112- #endif112+#endif
113#endif113#endif
114 114 
115#if defined(DTYPE_Y) && !defined(MM_DTYPE_Y)115#if defined(DTYPE_Y) && !defined(MM_DTYPE_Y)
116- #define MM_DTYPE_Y DTYPE_Y116+#define MM_DTYPE_Y DTYPE_Y
117#endif117#endif
118 118 
119-#if (defined(__CCE_AICORE__) && __CCE_AICORE__ == 220) || (defined(__NPU_ARCH__) && (__NPU_ARCH__ == 3003 || __NPU_ARCH__ == 3113))119+#if (defined(__CCE_AICORE__) && __CCE_AICORE__ == 220) || \
120- #ifdef GMM_ANTI_QUANT_A8W4_MSD_OUT_BF16120+ (defined(__NPU_ARCH__) && (__NPU_ARCH__ == 3003 || __NPU_ARCH__ == 3113))
121- #undef DTYPE_SCALE121+#ifdef GMM_ANTI_QUANT_A8W4_MSD_OUT_BF16
122- #define DTYPE_SCALE bfloat16_t122+#undef DTYPE_SCALE
123- #elif defined(GMM_ANTI_QUANT_A8W4_MSD_OUT_FP16)123+#define DTYPE_SCALE bfloat16_t
124- #undef DTYPE_SCALE124+#elif defined(GMM_ANTI_QUANT_A8W4_MSD_OUT_FP16)
125- #define DTYPE_SCALE float125+#undef DTYPE_SCALE
126- #endif126+#define DTYPE_SCALE float
@@ -146,6 +146,10 @@ Ascend950,wq950_a16w4_bf16_v5,64:128,BF16,ND,1:128:32,INT4,ND,NONE,FLOAT,ND,NONE
146Ascend950,wq950_a16f8_f16_trans_v5,64:128,FLOAT16,ND,1:128:32#4096:1:128,FLOAT8_E5M2,ND,NONE,FLOAT,ND,NONE,FLOAT16,ND,NONE,FLOAT,ND,1,64,INT64,ND,64:32,FLOAT16,ND,3,0,0,0,0,false,false,V5,false,false,0,0,FLOAT,ND,1:32,FLOAT16,ND,0,FLOAT16,ND146Ascend950,wq950_a16f8_f16_trans_v5,64:128,FLOAT16,ND,1:128:32#4096:1:128,FLOAT8_E5M2,ND,NONE,FLOAT,ND,NONE,FLOAT16,ND,NONE,FLOAT,ND,1,64,INT64,ND,64:32,FLOAT16,ND,3,0,0,0,0,false,false,V5,false,false,0,0,FLOAT,ND,1:32,FLOAT16,ND,0,FLOAT16,ND
147Ascend950,wq950_a16mxfp4_weightnz,64:128,BF16,ND,1:128:64,FLOAT4_E2M1,FRACTAL_NZ,NONE,FLOAT,ND,NONE,BF16,ND,NONE,FLOAT8_E8M0,ND,1,64,INT64,ND,64:64,BF16,ND,3,0,0,0,0,false,false,WeightNz,false,false,0,0,FLOAT,ND,1:4:64,FLOAT8_E8M0,ND,0,FLOAT16,ND147Ascend950,wq950_a16mxfp4_weightnz,64:128,BF16,ND,1:128:64,FLOAT4_E2M1,FRACTAL_NZ,NONE,FLOAT,ND,NONE,BF16,ND,NONE,FLOAT8_E8M0,ND,1,64,INT64,ND,64:64,BF16,ND,3,0,0,0,0,false,false,WeightNz,false,false,0,0,FLOAT,ND,1:4:64,FLOAT8_E8M0,ND,0,FLOAT16,ND
148Ascend950,wq950_mxa8w4_weightnz,64:128,FLOAT8_E4M3FN,ND,1:128:64#8192:1:128,FLOAT4_E2M1,FRACTAL_NZ,NONE,FLOAT,ND,NONE,BF16,ND,64:2:2,FLOAT8_E8M0,ND,1,64,INT64,ND,64:64,BF16,ND,3,0,0,0,0,false,true,WeightNz,false,false,0,0,FLOAT,ND,1:2:64:2,FLOAT8_E8M0,ND,0,FLOAT16,ND148Ascend950,wq950_mxa8w4_weightnz,64:128,FLOAT8_E4M3FN,ND,1:128:64#8192:1:128,FLOAT4_E2M1,FRACTAL_NZ,NONE,FLOAT,ND,NONE,BF16,ND,64:2:2,FLOAT8_E8M0,ND,1,64,INT64,ND,64:64,BF16,ND,3,0,0,0,0,false,true,WeightNz,false,false,0,0,FLOAT,ND,1:2:64:2,FLOAT8_E8M0,ND,0,FLOAT16,ND
149+Ascend950,wq950_mxa8w4_e1m2_weightnz,64:128,FLOAT8_E4M3FN,ND,1:128:64#8192:1:128,FLOAT4_E1M2,FRACTAL_NZ,NONE,FLOAT,ND,NONE,BF16,ND,64:2:2,FLOAT8_E8M0,ND,1,64,INT64,ND,64:64,BF16,ND,3,0,0,0,0,false,true,WeightNz,false,false,0,0,FLOAT,ND,1:2:64:2,FLOAT8_E8M0,ND,0,FLOAT16,ND
150+Ascend950,wq950_mxa8w4_e1m2_pertoken_null,64:128,FLOAT8_E4M3FN,ND,1:128:64#8192:1:128,FLOAT4_E1M2,FRACTAL_NZ,NONE,FLOAT,ND,NONE,BF16,ND,64:2:2,FLOAT8_E8M0,ND,1,64,INT64,ND,64:64,BF16,ND,3,0,0,0,161002,false,false,WeightNz,true,false,0,0,FLOAT,ND,1:2:64:2,FLOAT8_E8M0,ND,0,FLOAT16,ND
151+Ascend950,wq950_mxa8w4_e1m2_bad_pertoken_dtype,64:128,FLOAT8_E4M3FN,ND,1:128:64#8192:1:128,FLOAT4_E1M2,FRACTAL_NZ,NONE,FLOAT,ND,NONE,BF16,ND,64:2:2,FLOAT,ND,1,64,INT64,ND,64:64,BF16,ND,3,0,0,0,161002,false,true,WeightNz,true,false,0,0,FLOAT,ND,1:2:64:2,FLOAT8_E8M0,ND,0,FLOAT16,ND
152+Ascend950,wq950_mxa8w4_e1m2_bad_antiscale_dtype,64:128,FLOAT8_E4M3FN,ND,1:128:64#8192:1:128,FLOAT4_E1M2,FRACTAL_NZ,NONE,FLOAT,ND,NONE,BF16,ND,64:2:2,FLOAT8_E8M0,ND,1,64,INT64,ND,64:64,BF16,ND,3,0,0,0,161002,false,true,WeightNz,true,false,0,0,FLOAT,ND,1:2:64:2,FLOAT16,ND,0,FLOAT16,ND
149Ascend950,wq950_s8s4_weightnz,64:128,INT8,ND,1:128:64,INT4,FRACTAL_NZ,1:64,FLOAT,ND,NONE,FLOAT,ND,64,FLOAT,ND,1,64,INT64,ND,64:64,BF16,ND,3,0,0,0,0,false,true,WeightNz,false,true,0,0,FLOAT,ND,1:1:64,FLOAT16,ND,0,FLOAT16,ND153Ascend950,wq950_s8s4_weightnz,64:128,INT8,ND,1:128:64,INT4,FRACTAL_NZ,1:64,FLOAT,ND,NONE,FLOAT,ND,64,FLOAT,ND,1,64,INT64,ND,64:64,BF16,ND,3,0,0,0,0,false,true,WeightNz,false,true,0,0,FLOAT,ND,1:1:64,FLOAT16,ND,0,FLOAT16,ND
150Ascend950,wq950_v1_a16w8_nosplit_multilist,32:128;32:128,BF16,ND,128:32;128:32,INT8,ND,NONE,FLOAT,ND,NONE,BF16,ND,NONE,FLOAT,ND,2,32|64,INT64,ND,32:32;32:32,BF16,ND,0,-1,0,0,0,false,false,V1,false,false,0,0,FLOAT,ND,32;32,BF16,ND,32;32,BF16,ND154Ascend950,wq950_v1_a16w8_nosplit_multilist,32:128;32:128,BF16,ND,128:32;128:32,INT8,ND,NONE,FLOAT,ND,NONE,BF16,ND,NONE,FLOAT,ND,2,32|64,INT64,ND,32:32;32:32,BF16,ND,0,-1,0,0,0,false,false,V1,false,false,0,0,FLOAT,ND,32;32,BF16,ND,32;32,BF16,ND
151Ascend950,wq950_v2_a16w8_splitm,64:128,BF16,ND,1:128:32,INT8,ND,NONE,FLOAT,ND,NONE,BF16,ND,NONE,FLOAT,ND,1,64,INT64,ND,64:32,BF16,ND,3,0,0,0,0,false,false,V2,false,false,0,0,FLOAT,ND,1:32,BF16,ND,0,FLOAT16,ND155Ascend950,wq950_v2_a16w8_splitm,64:128,BF16,ND,1:128:32,INT8,ND,NONE,FLOAT,ND,NONE,BF16,ND,NONE,FLOAT,ND,1,64,INT64,ND,64:32,BF16,ND,3,0,0,0,0,false,false,V2,false,false,0,0,FLOAT,ND,1:32,BF16,ND,0,FLOAT16,ND
@@ -2,6 +2,9 @@ socVersion,caseName,enable,prefix,caseType,expectSuccess,expectOutputShape,xShap
2Ascend910B,grouped_matmul_infershape_0,true,base_nonquant_success,non_quant,true,345:567,345:1280,2:1280:567,2:567,ZERO,ZERO,ZERO,ZERO,2,ZERO,FLOAT16,FLOAT16,FLOAT,FLOAT,FLOAT,FLOAT,FLOAT,INT64,FLOAT,FLOAT,ND,ND,ND,ND,ND,ND,ND,ND,ND,ND,3,0,false,false,0,0,02Ascend910B,grouped_matmul_infershape_0,true,base_nonquant_success,non_quant,true,345:567,345:1280,2:1280:567,2:567,ZERO,ZERO,ZERO,ZERO,2,ZERO,FLOAT16,FLOAT16,FLOAT,FLOAT,FLOAT,FLOAT,FLOAT,INT64,FLOAT,FLOAT,ND,ND,ND,ND,ND,ND,ND,ND,ND,ND,3,0,false,false,0,0,0
3Ascend950,weight_quant_invalid_group_size,true,weight_quant_invalid_group_size,weight_quant,false,3:1280,3:1280,2:1280:1280,2:1280,ZERO,ZERO,2:1280:80,ZERO,2,3:40,FLOAT8_E4M3FN,FLOAT4_E2M1,BF16,FLOAT,FLOAT,FLOAT8_E8M0,FLOAT,INT64,FLOAT8_E8M0,BF16,ND,FRACTAL_NZ,ND,ND,ND,ND,ND,ND,ND,ND,3,0,true,false,0,0,03Ascend950,weight_quant_invalid_group_size,true,weight_quant_invalid_group_size,weight_quant,false,3:1280,3:1280,2:1280:1280,2:1280,ZERO,ZERO,2:1280:80,ZERO,2,3:40,FLOAT8_E4M3FN,FLOAT4_E2M1,BF16,FLOAT,FLOAT,FLOAT8_E8M0,FLOAT,INT64,FLOAT8_E8M0,BF16,ND,FRACTAL_NZ,ND,ND,ND,ND,ND,ND,ND,ND,3,0,true,false,0,0,0
4Ascend950,weight_quant_invalid_pertokenscale_dim,true,weight_quant_invalid_pertokenscale_dim,weight_quant,false,3:1280,3:1280,2:1280:1280,2:1280,ZERO,ZERO,2:1280:40,ZERO,2,3:1:40,FLOAT8_E4M3FN,FLOAT4_E2M1,BF16,FLOAT,FLOAT,FLOAT8_E8M0,FLOAT,INT64,FLOAT8_E8M0,BF16,ND,FRACTAL_NZ,ND,ND,ND,ND,ND,ND,ND,ND,3,0,true,false,0,0,04Ascend950,weight_quant_invalid_pertokenscale_dim,true,weight_quant_invalid_pertokenscale_dim,weight_quant,false,3:1280,3:1280,2:1280:1280,2:1280,ZERO,ZERO,2:1280:40,ZERO,2,3:1:40,FLOAT8_E4M3FN,FLOAT4_E2M1,BF16,FLOAT,FLOAT,FLOAT8_E8M0,FLOAT,INT64,FLOAT8_E8M0,BF16,ND,FRACTAL_NZ,ND,ND,ND,ND,ND,ND,ND,ND,3,0,true,false,0,0,0
5+Ascend950,weight_quant_mxa8w4_e1m2_success,true,weight_quant_mxa8w4_e1m2_success,weight_quant,true,64:64,64:128,2:64:128,ZERO,ZERO,ZERO,2:64:2:2,ZERO,2,64:2:2,FLOAT8_E4M3FN,FLOAT4_E1M2,BF16,FLOAT,FLOAT,FLOAT8_E8M0,FLOAT,INT64,FLOAT8_E8M0,BF16,ND,FRACTAL_NZ,ND,ND,ND,ND,ND,ND,ND,ND,3,0,true,false,0,0,0,32|64
jayshu
jayshujayshuJul 28

同上,补充异常用例

likedislike
6+Ascend950,weight_quant_mxa8w4_e1m2_pertoken_null,true,weight_quant_mxa8w4_e1m2_pertoken_null,weight_quant,false,NONE,64:128,2:64:128,ZERO,ZERO,ZERO,2:64:2:2,ZERO,2,ZERO,FLOAT8_E4M3FN,FLOAT4_E1M2,BF16,FLOAT,FLOAT,FLOAT8_E8M0,FLOAT,INT64,FLOAT8_E8M0,BF16,ND,FRACTAL_NZ,ND,ND,ND,ND,ND,ND,ND,ND,3,0,true,false,0,0,0,32|64
7+Ascend950,weight_quant_mxa8w4_e1m2_bad_antiscale_n,true,weight_quant_mxa8w4_e1m2_bad_antiscale_n,weight_quant,false,NONE,64:128,2:64:128,ZERO,ZERO,ZERO,2:63:2:2,ZERO,2,64:2:2,FLOAT8_E4M3FN,FLOAT4_E1M2,BF16,FLOAT,FLOAT,FLOAT8_E8M0,FLOAT,INT64,FLOAT8_E8M0,BF16,ND,FRACTAL_NZ,ND,ND,ND,ND,ND,ND,ND,ND,3,0,true,false,0,0,0,32|64
5Ascend950,weight_quant_invalid_group_type,true,weight_quant_invalid_group_type,weight_quant,false,3:1280,3:1280,2:1280:1280,2:1280,ZERO,ZERO,2:1280,ZERO,2,ZERO,FLOAT16,INT4,FLOAT16,FLOAT,FLOAT,FLOAT16,FLOAT16,INT64,FLOAT,FLOAT16,ND,ND,ND,ND,ND,ND,ND,ND,ND,ND,0,0,true,false,-1,0,08Ascend950,weight_quant_invalid_group_type,true,weight_quant_invalid_group_type,weight_quant,false,3:1280,3:1280,2:1280:1280,2:1280,ZERO,ZERO,2:1280,ZERO,2,ZERO,FLOAT16,INT4,FLOAT16,FLOAT,FLOAT,FLOAT16,FLOAT16,INT64,FLOAT,FLOAT16,ND,ND,ND,ND,ND,ND,ND,ND,ND,ND,0,0,true,false,-1,0,0
6Ascend950,weight_quant_invalid_antiquant_scale_dim,true,weight_quant_invalid_antiquant_scale_dim,weight_quant,false,3:1280,3:1280,2:1280:1280,2:1280,ZERO,ZERO,2:1:1280,ZERO,2,ZERO,FLOAT16,INT8,FLOAT16,FLOAT,FLOAT,FLOAT16,FLOAT16,INT64,FLOAT,FLOAT16,ND,ND,ND,ND,ND,ND,ND,ND,ND,ND,3,0,true,false,0,0,09Ascend950,weight_quant_invalid_antiquant_scale_dim,true,weight_quant_invalid_antiquant_scale_dim,weight_quant,false,3:1280,3:1280,2:1280:1280,2:1280,ZERO,ZERO,2:1:1280,ZERO,2,ZERO,FLOAT16,INT8,FLOAT16,FLOAT,FLOAT,FLOAT16,FLOAT16,INT64,FLOAT,FLOAT16,ND,ND,ND,ND,ND,ND,ND,ND,ND,ND,3,0,true,false,0,0,0
7Ascend950,weight_quant_invalid_mx_antiquant_scale_dim,true,weight_quant_invalid_mx_antiquant_scale_dim,weight_quant,false,3:1280,3:1280,2:1280:160,2:1280,ZERO,ZERO,2:1280,ZERO,2,ZERO,FLOAT16,FLOAT,FLOAT16,FLOAT,FLOAT,FLOAT8_E8M0,FLOAT16,INT64,FLOAT,FLOAT16,ND,FRACTAL_NZ,ND,ND,ND,ND,ND,ND,ND,ND,3,0,false,false,0,0,010Ascend950,weight_quant_invalid_mx_antiquant_scale_dim,true,weight_quant_invalid_mx_antiquant_scale_dim,weight_quant,false,3:1280,3:1280,2:1280:160,2:1280,ZERO,ZERO,2:1280,ZERO,2,ZERO,FLOAT16,FLOAT,FLOAT16,FLOAT,FLOAT,FLOAT8_E8M0,FLOAT16,INT64,FLOAT,FLOAT16,ND,FRACTAL_NZ,ND,ND,ND,ND,ND,ND,ND,ND,3,0,false,false,0,0,0
@@ -8,7 +8,6 @@
8 * See LICENSE in the root of the software repository for the full text of the License.8 * See LICENSE in the root of the software repository for the full text of the License.
9 */9 */
10 10 
11- 
12/*!11/*!
13 * \file test_grouped_weight_quant_arch35_tiling.cpp12 * \file test_grouped_weight_quant_arch35_tiling.cpp
14 * \brief Unit tests for GroupedWeightQuantBatchMatmulTiling13 * \brief Unit tests for GroupedWeightQuantBatchMatmulTiling
@@ -27,15 +26,9 @@ using namespace ge;
27 26 
28class GroupedWeightQuantBatchMatmulTilingTest : public testing::Test {27class GroupedWeightQuantBatchMatmulTilingTest : public testing::Test {
29protected:28protected:
30- static void SetUpTestCase()29+ static void SetUpTestCase() { std::cout << "GroupedWeightQuantBatchMatmulTiling SetUp" << std::endl; }
31- {
32- std::cout << "GroupedWeightQuantBatchMatmulTiling SetUp" << std::endl;
33- }
34 30 
35- static void TearDownTestCase()31+ static void TearDownTestCase() { std::cout << "GroupedWeightQuantBatchMatmulTiling TearDown" << std::endl; }
36- {
37- std::cout << "GroupedWeightQuantBatchMatmulTiling TearDown" << std::endl;
38- }
39};32};
40 33 
41namespace {34namespace {
@@ -78,10 +71,7 @@ size_t GetConfiguredSize(int64_t configuredSize, size_t defaultSize)
78 return configuredSize == DEFAULT_DYNAMIC_SIZE ? defaultSize : static_cast<size_t>(configuredSize);71 return configuredSize == DEFAULT_DYNAMIC_SIZE ? defaultSize : static_cast<size_t>(configuredSize);
79}72}
80 73 
81-size_t GetNumWeight(const MxA8W4SmsTilingParam &param)74+size_t GetNumWeight(const MxA8W4SmsTilingParam &param) { return GetConfiguredSize(param.numWeight, param.groupNum); }
82-{
83- return GetConfiguredSize(param.numWeight, param.groupNum);
84-}
85 75 
86size_t GetNumAntiquantScale(const MxA8W4SmsTilingParam &param)76size_t GetNumAntiquantScale(const MxA8W4SmsTilingParam &param)
87{77{
@@ -164,8 +154,8 @@ std::vector<TensorDescription> MakeMxA8W4SmsInputs(const MxA8W4SmsTilingParam &p
164 inputs.reserve(numX + numWeight + numBias + numAntiquantScale + 2);154 inputs.reserve(numX + numWeight + numBias + numAntiquantScale + 2);
165 155 
166 for (size_t i = 0; i < numX; ++i) {156 for (size_t i = 0; i < numX; ++i) {
167- inputs.emplace_back(MakeTensorDesc({static_cast<int64_t>(param.m), static_cast<int64_t>(param.k)},157+ inputs.emplace_back(MakeTensorDesc({static_cast<int64_t>(param.m), static_cast<int64_t>(param.k)}, param.xDtype,
168- param.xDtype, ge::FORMAT_ND));158+ ge::FORMAT_ND));
169 }159 }
170 160 
171 std::vector<int64_t> weightShape = MakeDefaultWeightShape(param);161 std::vector<int64_t> weightShape = MakeDefaultWeightShape(param);
@@ -173,48 +163,52 @@ std::vector<TensorDescription> MakeMxA8W4SmsInputs(const MxA8W4SmsTilingParam &p
173 inputs.emplace_back(MakeTensorDesc(weightShape, weightShape, param.weightDtype, param.weightFormat));163 inputs.emplace_back(MakeTensorDesc(weightShape, weightShape, param.weightDtype, param.weightFormat));
174 }164 }
175 165 
176- std::vector<int64_t> biasOriginShape = param.biasOriginShape.empty() ?166+ std::vector<int64_t> biasOriginShape =
177- std::vector<int64_t>{static_cast<int64_t>(param.n)} : param.biasOriginShape;167+ param.biasOriginShape.empty() ? std::vector<int64_t>{static_cast<int64_t>(param.n)} : param.biasOriginShape;
178 std::vector<int64_t> biasStorageShape = param.biasStorageShape.empty() ? biasOriginShape : param.biasStorageShape;168 std::vector<int64_t> biasStorageShape = param.biasStorageShape.empty() ? biasOriginShape : param.biasStorageShape;
179 for (size_t i = 0; i < numBias; ++i) {169 for (size_t i = 0; i < numBias; ++i) {
180 inputs.emplace_back(MakeTensorDesc(biasOriginShape, biasStorageShape, ge::DT_BF16, ge::FORMAT_ND));170 inputs.emplace_back(MakeTensorDesc(biasOriginShape, biasStorageShape, ge::DT_BF16, ge::FORMAT_ND));
181 }171 }
182 172 
183 std::vector<int64_t> scaleOriginShape = param.antiquantScaleOriginShape.empty() ?173 std::vector<int64_t> scaleOriginShape = param.antiquantScaleOriginShape.empty() ?
184- MakeDefaultAntiquantScaleShape(param) : param.antiquantScaleOriginShape;174+ MakeDefaultAntiquantScaleShape(param) :
185- std::vector<int64_t> scaleStorageShape = param.antiquantScaleStorageShape.empty() ? scaleOriginShape :175+ param.antiquantScaleOriginShape;
186- param.antiquantScaleStorageShape;176+ std::vector<int64_t> scaleStorageShape =
177+ param.antiquantScaleStorageShape.empty() ? scaleOriginShape : param.antiquantScaleStorageShape;
187 for (size_t i = 0; i < numAntiquantScale; ++i) {178 for (size_t i = 0; i < numAntiquantScale; ++i) {
188- inputs.emplace_back(MakeTensorDesc(scaleOriginShape, scaleStorageShape, param.antiquantScaleDtype, ge::FORMAT_ND));179+ inputs.emplace_back(
180+ MakeTensorDesc(scaleOriginShape, scaleStorageShape, param.antiquantScaleDtype, ge::FORMAT_ND));
189 }181 }
190 182 
191 inputs.emplace_back(MakeTensorDesc({static_cast<int64_t>(GetGroupListSize(param))}, ge::DT_INT64, ge::FORMAT_ND));183 inputs.emplace_back(MakeTensorDesc({static_cast<int64_t>(GetGroupListSize(param))}, ge::DT_INT64, ge::FORMAT_ND));
192- std::vector<int64_t> perTokenScaleOriginShape = param.perTokenScaleOriginShape.empty() ?184+ std::vector<int64_t> perTokenScaleOriginShape =
193- MakeDefaultPerTokenScaleShape(param) : param.perTokenScaleOriginShape;185+ param.perTokenScaleOriginShape.empty() ? MakeDefaultPerTokenScaleShape(param) : param.perTokenScaleOriginShape;
194- std::vector<int64_t> perTokenScaleStorageShape = param.perTokenScaleStorageShape.empty() ?186+ std::vector<int64_t> perTokenScaleStorageShape =
195- perTokenScaleOriginShape : param.perTokenScaleStorageShape;187+ param.perTokenScaleStorageShape.empty() ? perTokenScaleOriginShape : param.perTokenScaleStorageShape;
196- inputs.emplace_back(MakeTensorDesc(perTokenScaleOriginShape, perTokenScaleStorageShape, ge::DT_FLOAT8_E8M0,188+ inputs.emplace_back(
197- ge::FORMAT_ND));189+ MakeTensorDesc(perTokenScaleOriginShape, perTokenScaleStorageShape, ge::DT_FLOAT8_E8M0, ge::FORMAT_ND));
198 return inputs;190 return inputs;
199}191}
200 192 
201std::vector<uint32_t> MakeMxA8W4SmsInputInstanceNums(const MxA8W4SmsTilingParam &param)193std::vector<uint32_t> MakeMxA8W4SmsInputInstanceNums(const MxA8W4SmsTilingParam &param)
202{194{
203- return {static_cast<uint32_t>(GetConfiguredSize(param.numX, 1U)), static_cast<uint32_t>(GetNumWeight(param)),195+ return {static_cast<uint32_t>(GetConfiguredSize(param.numX, 1U)),
204- static_cast<uint32_t>(GetNumBias(param)), 0U, 0U, static_cast<uint32_t>(GetNumAntiquantScale(param)),196+ static_cast<uint32_t>(GetNumWeight(param)),
205- 0U, 1U, 1U};197+ static_cast<uint32_t>(GetNumBias(param)),
198+ 0U,
199+ 0U,
200+ static_cast<uint32_t>(GetNumAntiquantScale(param)),
201+ 0U,
202+ 1U,
203+ 1U};
206}204}
207 205 
208gert::TilingContextPara MakeMxA8W4SmsContext(const MxA8W4SmsTilingParam &param, optiling::GMMCompileInfo *compileInfo)206gert::TilingContextPara MakeMxA8W4SmsContext(const MxA8W4SmsTilingParam &param, optiling::GMMCompileInfo *compileInfo)
209{207{
210 return gert::TilingContextPara(208 return gert::TilingContextPara(
211- "GroupedMatmul",209+ "GroupedMatmul", MakeMxA8W4SmsInputs(param),
212- MakeMxA8W4SmsInputs(param),
213 {MakeTensorDesc({static_cast<int64_t>(param.m), static_cast<int64_t>(param.n)}, ge::DT_BF16, ge::FORMAT_ND)},210 {MakeTensorDesc({static_cast<int64_t>(param.m), static_cast<int64_t>(param.n)}, ge::DT_BF16, ge::FORMAT_ND)},
214- MakeMxA8W4SmsAttrs(param),211+ MakeMxA8W4SmsAttrs(param), MakeMxA8W4SmsInputInstanceNums(param), {1U}, compileInfo);
215- MakeMxA8W4SmsInputInstanceNums(param),
216- {1U},
217- compileInfo);
218}212}
219 213 
220uint64_t GetTilingKeyIndex(uint64_t value, std::initializer_list<uint64_t> supportedValues)214uint64_t GetTilingKeyIndex(uint64_t value, std::initializer_list<uint64_t> supportedValues)
@@ -254,8 +248,9 @@ uint64_t MakeExpectedMxA8W4TilingKey(bool isSingleMultiSingle)
254 append(GetTilingKeyIndex(static_cast<uint64_t>(optiling::OptimizationAlgorithmSubCategory::N_FIRST_TAIL_RESPLIT),248 append(GetTilingKeyIndex(static_cast<uint64_t>(optiling::OptimizationAlgorithmSubCategory::N_FIRST_TAIL_RESPLIT),
255 {0, 1, 2, 3}),249 {0, 1, 2, 3}),
256 4);250 4);
257- append(GetTilingKeyIndex(static_cast<uint64_t>(optiling::OptimizationAlgorithmCategory::VECTOR_ANTIQUANT), {0, 1, 2}),251+ append(
258- 4);252+ GetTilingKeyIndex(static_cast<uint64_t>(optiling::OptimizationAlgorithmCategory::VECTOR_ANTIQUANT), {0, 1, 2}),
253+ 4);
259 return tilingKey;254 return tilingKey;
260}255}
261 256 
@@ -317,11 +312,10 @@ gert::TilingContextPara MakeMxA8W4SssContext(optiling::GMMCompileInfo *compileIn
317 "GroupedMatmul",312 "GroupedMatmul",
318 {313 {
319 MakeTensorDesc({static_cast<int64_t>(m), static_cast<int64_t>(k)}, ge::DT_FLOAT8_E4M3FN, ge::FORMAT_ND),314 MakeTensorDesc({static_cast<int64_t>(m), static_cast<int64_t>(k)}, ge::DT_FLOAT8_E4M3FN, ge::FORMAT_ND),
320- MakeTensorDesc({static_cast<int64_t>(groupNum), static_cast<int64_t>(k / 32),315+ MakeTensorDesc(
321- static_cast<int64_t>(n / 16), 16, 32},316+ {static_cast<int64_t>(groupNum), static_cast<int64_t>(k / 32), static_cast<int64_t>(n / 16), 16, 32},
322- {static_cast<int64_t>(groupNum), static_cast<int64_t>(k / 32),317+ {static_cast<int64_t>(groupNum), static_cast<int64_t>(k / 32), static_cast<int64_t>(n / 16), 16, 32},
323- static_cast<int64_t>(n / 16), 16, 32},318+ ge::DT_FLOAT4_E2M1, ge::FORMAT_FRACTAL_NZ),
324- ge::DT_FLOAT4_E2M1, ge::FORMAT_FRACTAL_NZ),
325 MakeTensorDesc({static_cast<int64_t>(groupNum), static_cast<int64_t>(n), static_cast<int64_t>(k / 64), 2},319 MakeTensorDesc({static_cast<int64_t>(groupNum), static_cast<int64_t>(n), static_cast<int64_t>(k / 64), 2},
326 ge::DT_FLOAT8_E8M0, ge::FORMAT_ND),320 ge::DT_FLOAT8_E8M0, ge::FORMAT_ND),
327 MakeTensorDesc({static_cast<int64_t>(groupNum)}, ge::DT_INT64, ge::FORMAT_ND),321 MakeTensorDesc({static_cast<int64_t>(groupNum)}, ge::DT_INT64, ge::FORMAT_ND),
@@ -329,10 +323,7 @@ gert::TilingContextPara MakeMxA8W4SssContext(optiling::GMMCompileInfo *compileIn
329 ge::FORMAT_ND),323 ge::FORMAT_ND),
330 },324 },
331 {MakeTensorDesc({static_cast<int64_t>(m), static_cast<int64_t>(n)}, ge::DT_BF16, ge::FORMAT_ND)},325 {MakeTensorDesc({static_cast<int64_t>(m), static_cast<int64_t>(n)}, ge::DT_BF16, ge::FORMAT_ND)},
332- MakeMxA8W4SmsAttrs(MxA8W4SmsTilingParam{}),326+ MakeMxA8W4SmsAttrs(MxA8W4SmsTilingParam{}), {1U, 1U, 0U, 0U, 0U, 1U, 0U, 1U, 1U}, {1U}, compileInfo);
333- {1U, 1U, 0U, 0U, 0U, 1U, 0U, 1U, 1U},
334- {1U},
335- compileInfo);
336}327}
337} // namespace328} // namespace
338 329 
@@ -343,6 +334,14 @@ TEST_F(GroupedWeightQuantBatchMatmulTilingTest, test_tiling_mxa8w4_sms_scale3d_n
343 ExpectMxA8W4SmsTilingSuccess(param);334 ExpectMxA8W4SmsTilingSuccess(param);
344}335}
345 336 
337+// MxA8W4 NZ - FLOAT4_E1M2 weight reuses the E2M1 tiling strategy and selects a different kernel decode path.
338+TEST_F(GroupedWeightQuantBatchMatmulTilingTest, test_tiling_mxa8w4_e1m2_sms_scale3d_no_bias)
339+{
340+ MxA8W4SmsTilingParam param;
341+ param.weightDtype = ge::DT_FLOAT4_E1M2;
342+ ExpectMxA8W4SmsTilingSuccess(param);
343+}
344+ 
346// MxA8W4 NZ场景 - 单多单模式, 带bias多tensor345// MxA8W4 NZ场景 - 单多单模式, 带bias多tensor
347TEST_F(GroupedWeightQuantBatchMatmulTilingTest, test_tiling_mxa8w4_sms_with_bias)346TEST_F(GroupedWeightQuantBatchMatmulTilingTest, test_tiling_mxa8w4_sms_with_bias)
348{347{
@@ -521,10 +520,6 @@ TEST_F(GroupedWeightQuantBatchMatmulTilingTest, test_tiling_mxa8w4_sms_antiquant
521 ExpectMxA8W4SmsTilingFailure(param);520 ExpectMxA8W4SmsTilingFailure(param);
522}521}
523 522 
524- 
525- 
526- 
527- 
528// A16W4 ND场景 - BF16输入, INT4权重, 单单单模式, Split M523// A16W4 ND场景 - BF16输入, INT4权重, 单单单模式, Split M
529TEST_F(GroupedWeightQuantBatchMatmulTilingTest, test_tiling_a16w4_bf16_nd_single_single_single_splitm)524TEST_F(GroupedWeightQuantBatchMatmulTilingTest, test_tiling_a16w4_bf16_nd_single_single_single_splitm)
530{525{
@@ -715,10 +710,10 @@ TEST_F(GroupedWeightQuantBatchMatmulTilingTest, test_tiling_a8w4_nz_int8_int4)
715 {{{}, {}}, ge::DT_FLOAT, ge::FORMAT_ND}, // bias710 {{{}, {}}, ge::DT_FLOAT, ge::FORMAT_ND}, // bias
716 {{{}, {}}, ge::DT_FLOAT, ge::FORMAT_ND}, // scale711 {{{}, {}}, ge::DT_FLOAT, ge::FORMAT_ND}, // scale
717 {{{}, {}}, ge::DT_FLOAT, ge::FORMAT_ND}, // offset712 {{{}, {}}, ge::DT_FLOAT, ge::FORMAT_ND}, // offset
718- {{{E, K / 128, N}, {E, K / 128, N}}, ge::DT_UINT64, ge::FORMAT_ND}, // antiquantScale (groupsize=128)713+ {{{E, K / 128, N}, {E, K / 128, N}}, ge::DT_UINT64, ge::FORMAT_ND}, // antiquantScale (groupsize=128)
719- {{{}, {}}, ge::DT_FLOAT16, ge::FORMAT_ND}, // antiquantOffset714+ {{{}, {}}, ge::DT_FLOAT16, ge::FORMAT_ND}, // antiquantOffset
720- {{{E}, {E}}, ge::DT_INT64, ge::FORMAT_ND}, // groupList715+ {{{E}, {E}}, ge::DT_INT64, ge::FORMAT_ND}, // groupList
721- {{{}, {}}, ge::DT_FLOAT, ge::FORMAT_ND}, // perTokenScale716+ {{{}, {}}, ge::DT_FLOAT, ge::FORMAT_ND}, // perTokenScale
722 },717 },
723 {// output info718 {// output info
724 {{{M, N}, {M, N}}, ge::DT_BF16, ge::FORMAT_ND}},719 {{{M, N}, {M, N}}, ge::DT_BF16, ge::FORMAT_ND}},
@@ -876,10 +871,10 @@ TEST_F(GroupedWeightQuantBatchMatmulTilingTest, test_tiling_a8w4_nz_groupsize_19
876 {{{}, {}}, ge::DT_FLOAT, ge::FORMAT_ND}, // bias871 {{{}, {}}, ge::DT_FLOAT, ge::FORMAT_ND}, // bias
877 {{{}, {}}, ge::DT_FLOAT, ge::FORMAT_ND}, // scale872 {{{}, {}}, ge::DT_FLOAT, ge::FORMAT_ND}, // scale
878 {{{}, {}}, ge::DT_FLOAT, ge::FORMAT_ND}, // offset873 {{{}, {}}, ge::DT_FLOAT, ge::FORMAT_ND}, // offset
879- {{{E, K / 192, N}, {E, K / 192, N}}, ge::DT_UINT64, ge::FORMAT_ND}, // antiquantScale (groupsize=192)874+ {{{E, K / 192, N}, {E, K / 192, N}}, ge::DT_UINT64, ge::FORMAT_ND}, // antiquantScale (groupsize=192)
880- {{{}, {}}, ge::DT_FLOAT16, ge::FORMAT_ND}, // antiquantOffset875+ {{{}, {}}, ge::DT_FLOAT16, ge::FORMAT_ND}, // antiquantOffset
881- {{{E}, {E}}, ge::DT_INT64, ge::FORMAT_ND}, // groupList876+ {{{E}, {E}}, ge::DT_INT64, ge::FORMAT_ND}, // groupList
882- {{{}, {}}, ge::DT_FLOAT, ge::FORMAT_ND}, // perTokenScale877+ {{{}, {}}, ge::DT_FLOAT, ge::FORMAT_ND}, // perTokenScale
883 },878 },
884 {// output info879 {// output info
885 {{{M, N}, {M, N}}, ge::DT_BF16, ge::FORMAT_ND}},880 {{{M, N}, {M, N}}, ge::DT_BF16, ge::FORMAT_ND}},
@@ -1066,7 +1061,7 @@ TEST_F(GroupedWeightQuantBatchMatmulTilingTest, test_tiling_a16w4_bf16_nd_large_
1066TEST_F(GroupedWeightQuantBatchMatmulTilingTest, test_tiling_a16w4_bf16_nd_k0_mn_not_zero)1061TEST_F(GroupedWeightQuantBatchMatmulTilingTest, test_tiling_a16w4_bf16_nd_k0_mn_not_zero)
1067{1062{
1068 size_t M = 256;1063 size_t M = 256;
1069- size_t K = 0; // K=01064+ size_t K = 0; // K=0
1070 size_t N = 512;1065 size_t N = 512;
1071 size_t E = 2;1066 size_t E = 2;
1072 optiling::GMMCompileInfo compileInfo = {1067 optiling::GMMCompileInfo compileInfo = {
@@ -1117,8 +1112,8 @@ TEST_F(GroupedWeightQuantBatchMatmulTilingTest, test_tiling_a16w4_bf16_nd_k0_mn_
1117// A16W4 ND场景 - K=0且M=0时应通过(空tensor场景)1112// A16W4 ND场景 - K=0且M=0时应通过(空tensor场景)
1118TEST_F(GroupedWeightQuantBatchMatmulTilingTest, test_tiling_a16w4_bf16_nd_k0_m0)1113TEST_F(GroupedWeightQuantBatchMatmulTilingTest, test_tiling_a16w4_bf16_nd_k0_m0)
1119{1114{
1120- size_t M = 0; // M=01115+ size_t M = 0; // M=0
1121- size_t K = 0; // K=01116+ size_t K = 0; // K=0
1122 size_t N = 512;1117 size_t N = 512;
1123 size_t E = 2;1118 size_t E = 2;
1124 optiling::GMMCompileInfo compileInfo = {1119 optiling::GMMCompileInfo compileInfo = {
@@ -1196,10 +1191,10 @@ TEST_F(GroupedWeightQuantBatchMatmulTilingTest, test_tiling_a8w4_nz_groupsize_25
1196 {{{}, {}}, ge::DT_FLOAT, ge::FORMAT_ND}, // bias1191 {{{}, {}}, ge::DT_FLOAT, ge::FORMAT_ND}, // bias
1197 {{{}, {}}, ge::DT_FLOAT, ge::FORMAT_ND}, // scale1192 {{{}, {}}, ge::DT_FLOAT, ge::FORMAT_ND}, // scale
1198 {{{}, {}}, ge::DT_FLOAT, ge::FORMAT_ND}, // offset1193 {{{}, {}}, ge::DT_FLOAT, ge::FORMAT_ND}, // offset
1199- {{{E, K / 256, N}, {E, K / 256, N}}, ge::DT_UINT64, ge::FORMAT_ND}, // antiquantScale (groupsize=256)1194+ {{{E, K / 256, N}, {E, K / 256, N}}, ge::DT_UINT64, ge::FORMAT_ND}, // antiquantScale (groupsize=256)
1200- {{{}, {}}, ge::DT_FLOAT16, ge::FORMAT_ND}, // antiquantOffset1195+ {{{}, {}}, ge::DT_FLOAT16, ge::FORMAT_ND}, // antiquantOffset
1201- {{{E}, {E}}, ge::DT_INT64, ge::FORMAT_ND}, // groupList1196+ {{{E}, {E}}, ge::DT_INT64, ge::FORMAT_ND}, // groupList
1202- {{{}, {}}, ge::DT_FLOAT, ge::FORMAT_ND}, // perTokenScale1197+ {{{}, {}}, ge::DT_FLOAT, ge::FORMAT_ND}, // perTokenScale
1203 },1198 },
1204 {// output info1199 {// output info
1205 {{{M, N}, {M, N}}, ge::DT_BF16, ge::FORMAT_ND}},1200 {{{M, N}, {M, N}}, ge::DT_BF16, ge::FORMAT_ND}},