forked from mindspore-Ecosystem/mindspore
enhance sparse cpu error msg
This commit is contained in:
parent
32ecb8cbea
commit
5951d6d67b
2
akg
2
akg
|
@ -1 +1 @@
|
|||
Subproject commit 50d3082fdb2d084fff8509b6fbbdab5bc1e75e5c
|
||||
Subproject commit 61807d8cb4c0eb6bb7995ea42db1610fa66adeb3
|
|
@ -1050,6 +1050,7 @@ void ComputeCapability::GetComputeCapability() {
|
|||
#ifdef ENABLE_GPU
|
||||
if (Callback::Instance()->GetTargetFromContext() != kGPUDevice) {
|
||||
this->compute_capability_ = "Unknown";
|
||||
return;
|
||||
}
|
||||
int a, b;
|
||||
auto ret = cuDeviceGetAttribute(&a, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, 0);
|
||||
|
|
|
@ -239,7 +239,12 @@ void UpdateCustomKernelBuildInfo(const CNodePtr &kernel_node, bool is_akg_op) {
|
|||
MS_EXCEPTION_IF_NULL(kernel_node);
|
||||
auto builder = std::make_shared<kernel::KernelBuildInfo::KernelBuildInfoBuilder>();
|
||||
if (is_akg_op) {
|
||||
#ifndef USE_LLVM
|
||||
MS_LOG(EXCEPTION) << "When calling AKG-CPU operator, found LLVM 12.0.1 not installed, please check: "
|
||||
"https://www.mindspore.cn/install for installing LLVM on MindSpore.";
|
||||
#else
|
||||
builder->SetKernelType(KernelType::AKG_KERNEL);
|
||||
#endif
|
||||
} else {
|
||||
builder->SetKernelType(KernelType::CPU_KERNEL);
|
||||
}
|
||||
|
|
|
@ -384,8 +384,8 @@ AbstractBasePtr InferImplMakeCOOTensor(const AnalysisEnginePtr &, const Primitiv
|
|||
<< " dimension tensor";
|
||||
}
|
||||
if (indices_shp[0] != values_shp[0]) {
|
||||
MS_EXCEPTION(TypeError) << "The first dimension of indices must be the same with the first dimension of values "
|
||||
<< values_shp[0] << ", but got " << indices_shp[0];
|
||||
MS_EXCEPTION(TypeError) << "Indices and values must equal in their shape, but got indices shape: " << indices_shp[0]
|
||||
<< ", values shape: " << values_shp[0];
|
||||
}
|
||||
if (indices_shp[1] != kSizeTwo) {
|
||||
MS_EXCEPTION(ValueError) << "COOTensor only support " << kSizeTwo << " dimensions, but got " << indices_shp[1];
|
||||
|
@ -393,7 +393,7 @@ AbstractBasePtr InferImplMakeCOOTensor(const AnalysisEnginePtr &, const Primitiv
|
|||
|
||||
for (const auto &elem_type : dense_shape->ElementsType()) {
|
||||
if (!elem_type->isa<Int>()) {
|
||||
MS_EXCEPTION(TypeError) << "The element type of dense_shape must be Int, but got " << elem_type->ToString();
|
||||
MS_EXCEPTION(TypeError) << "The element type of shape must be Int, but got " << elem_type->ToString();
|
||||
}
|
||||
}
|
||||
auto dense_shape_value = dense_shape->BuildValue()->cast<ValueTuplePtr>();
|
||||
|
@ -413,9 +413,8 @@ AbstractBasePtr InferImplMakeCOOTensor(const AnalysisEnginePtr &, const Primitiv
|
|||
<< indices_shp[1] << ", but got " << dense_shape_vec.size();
|
||||
}
|
||||
for (auto dense_shape_elem : dense_shape_vec) {
|
||||
if (dense_shape_elem < 0) {
|
||||
MS_EXCEPTION(TypeError) << "The element of dense_shape must be positive, but got "
|
||||
<< dense_shape_value->ToString();
|
||||
if (dense_shape_elem <= 0) {
|
||||
MS_EXCEPTION(TypeError) << "The element of shape must be positive, but got " << dense_shape_value->ToString();
|
||||
}
|
||||
}
|
||||
auto ret = std::make_shared<AbstractCOOTensor>(values->element()->BuildType(), dense_shape_vec);
|
||||
|
@ -711,7 +710,7 @@ AbstractBasePtr InferImplMakeCSRTensor(const AnalysisEnginePtr &, const Primitiv
|
|||
MS_EXCEPTION(ValueError) << "Indptr must have length (1 + shape[0]), but got: " << indptr_shp[0];
|
||||
}
|
||||
for (size_t i = 0; i < shape_vec.size(); ++i) {
|
||||
if (shape_vec[i] < 0) {
|
||||
if (shape_vec[i] <= 0) {
|
||||
MS_EXCEPTION(TypeError) << "The element of shape must be positive, but got " << shape_value->ToString();
|
||||
}
|
||||
if ((i > 1) && (shape_vec[i] != values_shp[i - 1])) {
|
||||
|
|
|
@ -859,11 +859,33 @@ class Validator:
|
|||
def check_type_support(dtype, device, supported_dtypes):
|
||||
return dtype in supported_dtypes or not context.get_context('device_target') == device
|
||||
|
||||
@staticmethod
|
||||
def check_sparse_tensor_input(indices, values, shape):
|
||||
"""Common input check for SparseTensors."""
|
||||
if not isinstance(indices, Tensor_):
|
||||
raise TypeError(f"indices should be Tensor, but got {type(indices)}.")
|
||||
if not isinstance(values, Tensor_):
|
||||
raise TypeError(f"values should be Tensor, but got {type(values)}.")
|
||||
if not isinstance(shape, tuple):
|
||||
raise TypeError(f"shape should be tuple, but got {type(shape)}.")
|
||||
|
||||
@staticmethod
|
||||
def check_csr_tensor_input(indptr, indices, values, shape):
|
||||
"""Checks inputs type for CSRTensor."""
|
||||
if not isinstance(indptr, Tensor_):
|
||||
raise TypeError(f"indptr should be Tensor, but got {type(indices)}.")
|
||||
Validator.check_sparse_tensor_input(indices, values, shape)
|
||||
|
||||
@staticmethod
|
||||
def check_csr_tensor_shape(indptr_shp, indices_shp, values_shp, csr_shp):
|
||||
"""Checks input tensors' shapes for CSRTensor."""
|
||||
if len(csr_shp) != 2:
|
||||
raise ValueError("Currently only supports 2-dimensional csr tensor.")
|
||||
for item in csr_shp:
|
||||
if item <= 0:
|
||||
raise ValueError(f"The element of shape must be positive, but got {item}")
|
||||
if not isinstance(item, int):
|
||||
raise TypeError(f"The element type of shape must be int, but got {type(item)}")
|
||||
if len(values_shp) != 1:
|
||||
raise ValueError(f"Values must be a 1-dimensional tensor, but got a {len(values_shp)} dimension tensor.")
|
||||
if len(indices_shp) != 1:
|
||||
|
@ -872,6 +894,10 @@ class Validator:
|
|||
raise ValueError(f"Indptr must be a 1-dimensional tensor, but got a {len(indptr_shp)} dimension tensor.")
|
||||
if csr_shp[0] + 1 != indptr_shp[0]:
|
||||
raise ValueError(f"Indptr must have length (1 + shape[0]), but got: {indptr_shp[0]}")
|
||||
if indices_shp[0] != values_shp[0]:
|
||||
err_msg1 = "Indices and values must equal in their shape, "
|
||||
err_msg2 = f"but got indices shape: {indices_shp[0]}, values shape: {values_shp[0]}."
|
||||
raise ValueError(err_msg1 + err_msg2)
|
||||
|
||||
@staticmethod
|
||||
def check_csr_tensor_dtype(indptr_dtype, indices_dtype):
|
||||
|
@ -881,11 +907,21 @@ class Validator:
|
|||
if indices_dtype not in (mstype.int16, mstype.int32, mstype.int64):
|
||||
raise TypeError("Indices must have integer data type.")
|
||||
|
||||
@staticmethod
|
||||
def check_coo_tensor_input(indices, values, shape):
|
||||
"""Checks inputs type for COOTensor."""
|
||||
Validator.check_sparse_tensor_input(indices, values, shape)
|
||||
|
||||
@staticmethod
|
||||
def check_coo_tensor_shape(indices_shp, values_shp, coo_shp):
|
||||
"""Checks input tensors' shapes for COOTensor."""
|
||||
if len(coo_shp) != 2:
|
||||
raise ValueError("Currently only supports 2-dimensional coo tensor.")
|
||||
for item in coo_shp:
|
||||
if item <= 0:
|
||||
raise ValueError(f"The element of shape must be positive, but got {item}")
|
||||
if not isinstance(item, int):
|
||||
raise TypeError(f"The element type of shape must be int, but got {type(item)}")
|
||||
if len(indices_shp) != 2:
|
||||
raise ValueError(f"Indices must be a 2-dimensional tensor, but got a {len(indices_shp)} dimension tensor.")
|
||||
if len(values_shp) != 1:
|
||||
|
|
|
@ -2470,14 +2470,15 @@ class COOTensor(COOTensor_):
|
|||
"Init COOTensor"
|
||||
self.init_finished = False
|
||||
# Directly init a COOTensor from another COOTensor
|
||||
if indices is None and values is None and shape is None and coo_tensor is not None:
|
||||
if coo_tensor is not None:
|
||||
if not isinstance(coo_tensor, (COOTensor, COOTensor_)):
|
||||
raise TypeError("If only one input provided, it must be a COOTensor.")
|
||||
raise TypeError(f"Expect input `coo_tensor` to be a COOTensor, but got {type(coo_tensor)}")
|
||||
if not (indices is None and values is None and shape is None):
|
||||
raise TypeError("If input `coo_tensor` is provided, `indices`, `values`, `shapes` should all be `None`")
|
||||
COOTensor_.__init__(self, coo_tensor)
|
||||
# Init a COOTensor from indices, values and shape
|
||||
else:
|
||||
if not (isinstance(indices, Tensor) and isinstance(values, Tensor) and isinstance(shape, tuple)):
|
||||
raise TypeError("Inputs must follow: COOTensor(Tensor, Tensor, tuple).")
|
||||
validator.check_coo_tensor_input(indices, values, shape)
|
||||
validator.check_coo_tensor_shape(indices.shape, values.shape, shape)
|
||||
validator.check_coo_tensor_dtype(indices.dtype)
|
||||
if not (indices < Tensor(shape)).all() or (indices < 0).any():
|
||||
|
@ -2654,17 +2655,19 @@ class CSRTensor(CSRTensor_):
|
|||
"""
|
||||
|
||||
def __init__(self, indptr=None, indices=None, values=None, shape=None, csr_tensor=None):
|
||||
"Init CSRTensor"
|
||||
self.init_finished = False
|
||||
# Directly init a CSRTensor from another CSRTensor
|
||||
if indptr is None and indices is None and values is None and shape is None:
|
||||
if csr_tensor is not None:
|
||||
if not isinstance(csr_tensor, (CSRTensor, CSRTensor_)):
|
||||
raise TypeError("If only one input provided, it must be a CSRTensor.")
|
||||
raise TypeError(f"Expect input `csr_tensor` to be a CSRTensor, but got {type(csr_tensor)}")
|
||||
if not (indptr is None and indices is None and values is None and shape is None):
|
||||
raise TypeError(
|
||||
"If input `csr_tensor` is provided, `indptr`, `indices`, `values`, `shapes` should all be `None`")
|
||||
CSRTensor_.__init__(self, csr_tensor)
|
||||
# Init a CSRTensor from indptr, indices, values and shape
|
||||
else:
|
||||
if not (isinstance(indptr, Tensor) and isinstance(indices, Tensor) \
|
||||
and isinstance(values, Tensor) and isinstance(shape, tuple)):
|
||||
raise TypeError("Inputs must follow: CSRTensor(tensor, tensor, tensor, tuple).")
|
||||
validator.check_csr_tensor_input(indptr, indices, values, shape)
|
||||
validator.check_csr_tensor_shape(indptr.shape, indices.shape, values.shape, shape)
|
||||
validator.check_csr_tensor_dtype(indptr.dtype, indices.dtype)
|
||||
CSRTensor_.__init__(self, indptr, indices, values, shape)
|
||||
|
|
Loading…
Reference in New Issue