已合并
修复SwigluGroup/Quant空Tensor校验失效问题 #9557
taochangmin创建于 9 天前
修复SwigluGroup/Quant空Tensor校验失效问题 #9557
已合并
共 4 个文件变更+28-1
| @@ -45,6 +45,8 @@ public: | |||
| 45 | .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}); | 45 | .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}); |
| 46 | this->Attr("clamp_limit").AttrType(OPTIONAL).Float(DEFAULT_CLAMP_LIMIT); | 46 | this->Attr("clamp_limit").AttrType(OPTIONAL).Float(DEFAULT_CLAMP_LIMIT); |
| 47 | 47 | ||
| 48 | + this->AICore().LaunchWithZeroEleOutputTensors(true); | ||
| 49 | + | ||
| 48 | OpAICoreConfig aicoreConfig; | 50 | OpAICoreConfig aicoreConfig; |
| 49 | aicoreConfig.DynamicCompileStaticFlag(true) | 51 | aicoreConfig.DynamicCompileStaticFlag(true) |
| 50 | .DynamicFormatFlag(false) | 52 | .DynamicFormatFlag(false) |
| @@ -14,9 +14,18 @@ from torch.library import impl | |||
| 14 | from cann_ops_nn.op_builder import OpBuilder, get_as_library | 14 | from cann_ops_nn.op_builder import OpBuilder, get_as_library |
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | +def _check_not_empty_tensor(tensor, name): | ||
| 18 | + if tensor is None: | ||
| 19 | + return | ||
| 20 | + for dim in tensor.shape: | ||
| 21 | + if isinstance(dim, int) and dim == 0: | ||
| 22 | + raise RuntimeError(f"input {name} is empty tensor, which is not supported") | ||
| 23 | + | ||
| 24 | + | ||
| 17 | def _swiglu_shape(x): | 25 | def _swiglu_shape(x): |
| 18 | if x.dim() < 1: | 26 | if x.dim() < 1: |
| 19 | raise RuntimeError("x rank should be greater than 0") | 27 | raise RuntimeError("x rank should be greater than 0") |
| 28 | + _check_not_empty_tensor(x, "x") | ||
| 20 | last_dim = x.size(x.dim() - 1) | 29 | last_dim = x.size(x.dim() - 1) |
| 21 | if last_dim % 2 != 0: | 30 | if last_dim % 2 != 0: |
| 22 | raise RuntimeError("x last dim size should be even") | 31 | raise RuntimeError("x last dim size should be even") |
| @@ -41,6 +50,8 @@ class SwigluGroupOpBuilder(OpBuilder): | |||
| 41 | def register_meta(self): | 50 | def register_meta(self): |
| 42 | 51 | ||
| 43 | def swiglu_group_meta(x, weight=None, group_index=None, *, clamp_limit=-1.0): | 52 | def swiglu_group_meta(x, weight=None, group_index=None, *, clamp_limit=-1.0): |
| 53 | + _check_not_empty_tensor(weight, "weight") | ||
| 54 | + _check_not_empty_tensor(group_index, "group_index") | ||
| 44 | return x.new_empty(_swiglu_shape(x)) | 55 | return x.new_empty(_swiglu_shape(x)) |
| 45 | 56 | ||
| 46 | 57 | ||
| @@ -110,6 +110,8 @@ public: | |||
| 110 | this->Attr("dst_type_max").AttrType(OPTIONAL).Float(DEFAULT_DST_TYPE_MAX); | 110 | this->Attr("dst_type_max").AttrType(OPTIONAL).Float(DEFAULT_DST_TYPE_MAX); |
| 111 | this->Attr("output_origin").AttrType(OPTIONAL).Bool(false); | 111 | this->Attr("output_origin").AttrType(OPTIONAL).Bool(false); |
| 112 | 112 | ||
| 113 | + this->AICore().LaunchWithZeroEleOutputTensors(true); | ||
| 114 | + | ||
| 113 | OpAICoreConfig aicoreConfig; | 115 | OpAICoreConfig aicoreConfig; |
| 114 | aicoreConfig.DynamicCompileStaticFlag(true) | 116 | aicoreConfig.DynamicCompileStaticFlag(true) |
| 115 | .DynamicFormatFlag(false) | 117 | .DynamicFormatFlag(false) |
| @@ -123,4 +125,4 @@ public: | |||
| 123 | }; | 125 | }; |
| 124 | 126 | ||
| 125 | OP_ADD(SwigluGroupQuant); | 127 | OP_ADD(SwigluGroupQuant); |
| 126 | -} // namespace ops | 128 | +} // namespace ops |
| @@ -32,9 +32,18 @@ def _ceil_div(value, factor): | |||
| 32 | return (value + factor - 1) // factor | 32 | return (value + factor - 1) // factor |
| 33 | 33 | ||
| 34 | 34 | ||
| 35 | +def _check_not_empty_tensor(tensor, name): | ||
| 36 | + if tensor is None: | ||
| 37 | + return | ||
| 38 | + for dim in tensor.shape: | ||
| 39 | + if isinstance(dim, int) and dim == 0: | ||
| 40 | + raise RuntimeError(f"input {name} is empty tensor, which is not supported") | ||
| 41 | + | ||
| 42 | + | ||
| 35 | def _swiglu_shape(x): | 43 | def _swiglu_shape(x): |
| 36 | if x.dim() < 1: | 44 | if x.dim() < 1: |
| 37 | raise RuntimeError("x rank should be greater than 0") | 45 | raise RuntimeError("x rank should be greater than 0") |
| 46 | + _check_not_empty_tensor(x, "x") | ||
| 38 | last_dim = x.size(x.dim() - 1) | 47 | last_dim = x.size(x.dim() - 1) |
| 39 | if last_dim % 2 != 0: | 48 | if last_dim % 2 != 0: |
| 40 | raise RuntimeError("x last dim size should be even") | 49 | raise RuntimeError("x last dim size should be even") |
| @@ -117,6 +126,9 @@ class SwigluGroupQuantOpBuilder(OpBuilder): | |||
| 117 | dst_type_max=15.0, | 126 | dst_type_max=15.0, |
| 118 | output_origin=False, | 127 | output_origin=False, |
| 119 | ): | 128 | ): |
| 129 | + _check_not_empty_tensor(weight, "weight") | ||
| 130 | + _check_not_empty_tensor(group_index, "group_index") | ||
| 131 | + _check_not_empty_tensor(scale, "scale") | ||
| 120 | y = x.new_empty( | 132 | y = x.new_empty( |
| 121 | _quant_output_shape(x, dst_type, quant_mode), | 133 | _quant_output_shape(x, dst_type, quant_mode), |
| 122 | dtype=_quant_output_dtype(dst_type, quant_mode), | 134 | dtype=_quant_output_dtype(dst_type, quant_mode), |