提交 f1637f11 编写于 作者: H hangq

1. clean review bot

2. fix nan bug
上级 bc4c5afc
......@@ -5,9 +5,9 @@ BASE_PATH=$(cd "$(dirname $0)"; pwd)
TOP_PATH="${BASE_PATH}/../../.."
get_version() {
VERSION_MAJOR=`grep "#define MS_VERSION_MAJOR" ../../include/version.h | tr -dc "[0-9]"`
VERSION_MINOR=`grep "#define MS_VERSION_MINOR" ../../include/version.h | tr -dc "[0-9]"`
VERSION_REVISION=`grep "#define MS_VERSION_REVISION" ../../include/version.h | tr -dc "[0-9]"`
VERSION_MAJOR=`grep "#define MS_VERSION_MAJOR" ../include/version.h | tr -dc "[0-9]"`
VERSION_MINOR=`grep "#define MS_VERSION_MINOR" ../include/version.h | tr -dc "[0-9]"`
VERSION_REVISION=`grep "#define MS_VERSION_REVISION" ../include/version.h | tr -dc "[0-9]"`
VERSION_STR=${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REVISION}
}
......
......@@ -232,6 +232,7 @@ void PackNCHWToNHWCFp16(const void *src, void *dst, int batch, int plane, int ch
void PackNHWCToNHWC4Fp16(const void *src, void *dst, int batch, int plane, int channel) {
int ic4 = UP_DIV(channel, C4NUM);
int c4_channel = ic4 * C4NUM;
int nhwc4_batch_unit_offset = ic4 * C4NUM * plane;
int ic_remainder_ = channel % C4NUM;
if (ic_remainder_ != 0) {
......@@ -239,8 +240,11 @@ void PackNHWCToNHWC4Fp16(const void *src, void *dst, int batch, int plane, int c
for (int b = 0; b < batch; b++) {
int batch_offset = b * channel * plane;
for (int i = 0; i < plane; i++) {
memcpy((float16_t *)dst + nhwc4_batch_offset + i * ic4 * C4NUM, (float16_t *)src + batch_offset + i * channel,
channel * sizeof(float16_t));
float16_t *dst_per_plane = (float16_t *)dst + nhwc4_batch_offset + i * c4_channel;
memcpy(dst_per_plane, (float16_t *)src + batch_offset + i * channel, channel * sizeof(float16_t));
for (int j = channel; j < c4_channel; ++j) {
dst_per_plane[j] = 0;
}
}
nhwc4_batch_offset += nhwc4_batch_unit_offset;
}
......
......@@ -611,6 +611,7 @@ void PackNCHWToNC4HW4Fp32(const void *src, void *dst, int batch, int plane, int
void PackNHWCToNHWC4Fp32(const void *src, void *dst, int batch, int plane, int channel) {
int c4 = UP_DIV(channel, C4NUM);
int c4_channel = c4 * C4NUM;
int nhwc4_batch_unit_offset = c4 * C4NUM * plane;
int ic_remainder_ = channel % C4NUM;
if (ic_remainder_ != 0) {
......@@ -618,8 +619,11 @@ void PackNHWCToNHWC4Fp32(const void *src, void *dst, int batch, int plane, int c
for (int b = 0; b < batch; b++) {
int batch_offset = b * channel * plane;
for (int i = 0; i < plane; i++) {
memcpy((float *)dst + nhwc4_batch_offset + i * c4 * C4NUM, (float *)src + batch_offset + i * channel,
channel * sizeof(float));
float *dst_per_plane = (float *)dst + nhwc4_batch_offset + i * c4_channel;
memcpy(dst_per_plane, (float *)src + batch_offset + i * channel, channel * sizeof(float));
for (int j = channel; j < c4_channel; ++j) {
dst_per_plane[j] = 0;
}
}
nhwc4_batch_offset += nhwc4_batch_unit_offset;
}
......
......@@ -37,8 +37,8 @@ Flags::Flags() {
AddFlag(&Flags::mean, "mean", "Mean value for aware-quantization", "-0.5");
AddFlag(&Flags::bitNum, "bitNum", "Weight quantization bitNum", "8");
AddFlag(&Flags::quantSize, "quantSize", "Weight quantization size threshold", "0");
AddFlag(&Flags::convWeightQuantChannelThreshold, "convWeightQuantChannelThreshold",
"convWeightQuantChannelThreshold", "16");
AddFlag(&Flags::convWeightQuantChannelThreshold, "convWeightQuantChannelThreshold", "convWeightQuantChannelThreshold",
"16");
AddFlag(&Flags::configFile, "config_file", "Configuration for post-training.", "");
AddFlag(&Flags::formatTrans, "formatTrans", "whether transform format. true | false", "true");
}
......
......@@ -21,8 +21,8 @@
#include "src/ir/tensor.h"
#include "src/ops/primitive_c.h"
using mindspore::lite::tensor::Tensor;
using mindspore::lite::PrimitiveC;
using mindspore::lite::tensor::Tensor;
namespace mindspore {
namespace lite {
namespace {
......@@ -33,7 +33,7 @@ std::vector<tensor::Tensor *> ConvertTensorToLiteTensor(MetaGraphT *graph, const
auto &tensorT = graph->allTensors.at(tensor_indexs[i]);
auto tensor_shape = tensorT->dims;
auto lite_tensor =
new(std::nothrow) tensor::Tensor(TypeId(tensorT->dataType), tensor_shape, tensorT->format, tensorT->nodeType);
std::make_unique<tensor::Tensor>(TypeId(tensorT->dataType), tensor_shape, tensorT->format, tensorT->nodeType);
if (lite_tensor == nullptr) {
MS_LOG(ERROR) << "lite tensor is nullptr";
return std::vector<tensor::Tensor *>();
......@@ -43,27 +43,23 @@ std::vector<tensor::Tensor *> ConvertTensorToLiteTensor(MetaGraphT *graph, const
auto lite_tensor_size = tensorT->data.size() * sizeof(uint8_t);
// when tensorT as param input
if (lite_tensor_size == 0) {
delete lite_tensor;
return std::vector<tensor::Tensor *>();
}
auto tensor_data = new(std::nothrow) char[lite_tensor_size / sizeof(char)];
auto tensor_data = std::unique_ptr<char[]>(new (std::nothrow) char[lite_tensor_size / sizeof(char)]);
if (tensor_data == nullptr) {
MS_LOG(ERROR) << "tensor_data is nullptr";
delete lite_tensor;
return std::vector<tensor::Tensor *>();
}
auto ret = memcpy_s(tensor_data, lite_tensor_size, tensorT->data.data(), lite_tensor_size);
auto ret = memcpy_s(tensor_data.get(), lite_tensor_size, tensorT->data.data(), lite_tensor_size);
if (ret != EOK) {
delete lite_tensor;
delete[] tensor_data;
MS_LOG(ERROR) << "memcpy error: " << ret;
return std::vector<tensor::Tensor *>();
}
lite_tensor->SetData(tensor_data);
lite_tensors.emplace_back(lite_tensor);
lite_tensor->SetData(tensor_data.release());
lite_tensors.emplace_back(lite_tensor.release());
continue;
}
lite_tensors.emplace_back(lite_tensor);
lite_tensors.emplace_back(lite_tensor.release());
}
return lite_tensors;
}
......@@ -95,17 +91,16 @@ STATUS InferShapePass::Run(MetaGraphT *graph) {
auto ret = primitiveC->InferShape(input_tensors, output_tensors);
if (ret == RET_INFER_INVALID) {
MS_LOG(INFO) << "InferShape shouldn't be done before runtime, name: " << node->name
<< ", type: " << schema::EnumNamePrimitiveType(node->primitive->value.type)
<< "flag set to false.";
<< ", type: " << schema::EnumNamePrimitiveType(node->primitive->value.type) << "flag set to false.";
} else if (ret != RET_OK) {
MS_LOG(WARNING) << "InferShape failed, name: " << node->name
<< ", type: " << schema::EnumNamePrimitiveType(node->primitive->value.type);
<< ", type: " << schema::EnumNamePrimitiveType(node->primitive->value.type);
return RET_INFER_ERR;
}
// copy output shape to tensorT
for (size_t i = 0; i < output_tensors.size(); i++) {
auto output_dims = output_tensors[i]->shape();
auto &output_tensor = graph->allTensors.at(node->outputIndex[i]);
auto &output_tensor = graph->allTensors.at(node->outputIndex[i]);
output_tensor->dims.swap(output_dims);
output_tensor->format = output_tensors[i]->GetFormat();
output_tensor->dataType = output_tensors[i]->data_type();
......
......@@ -26,10 +26,8 @@ namespace lite {
STATUS TfliteCustomParser::Parse(const std::unique_ptr<tflite::OperatorT> &tflite_op,
const std::vector<std::unique_ptr<tflite::TensorT>> &tflite_tensors,
const std::vector<std::unique_ptr<tflite::BufferT>> &tflite_model_buffer,
schema::CNodeT *op,
std::vector<int32_t> *tensors_id,
std::vector<schema::Format> *tensors_format,
std::map<int, int> *tensors_id_map) {
schema::CNodeT *op, std::vector<int32_t> *tensors_id,
std::vector<schema::Format> *tensors_format, std::map<int, int> *tensors_id_map) {
MS_LOG(DEBUG) << "parse TfliteCustomParser";
if (op == nullptr) {
MS_LOG(ERROR) << "op is null";
......@@ -80,12 +78,12 @@ STATUS TfliteCustomParser::Parse(const std::unique_ptr<tflite::OperatorT> &tflit
op->primitive->value.value = attr.release();
for (size_t i = 0; i < tflite_op->inputs.size(); ++i) {
AddOpInput(op, tensors_id, tensors_format, tensors_id_map,
tflite_op->inputs[i], tensors_id->size(), tflite_tensors.size(), schema::Format_NHWC);
AddOpInput(op, tensors_id, tensors_format, tensors_id_map, tflite_op->inputs[i], tensors_id->size(),
tflite_tensors.size(), schema::Format_NHWC);
}
for (size_t i = 0; i < tflite_op->outputs.size(); ++i) {
AddOpOutput(op, tensors_id, tensors_format, tensors_id_map,
tflite_op->outputs[i], tensors_id->size(), tflite_tensors.size(), schema::Format_NHWC);
AddOpOutput(op, tensors_id, tensors_format, tensors_id_map, tflite_op->outputs[i], tensors_id->size(),
tflite_tensors.size(), schema::Format_NHWC);
}
return RET_OK;
}
......@@ -93,4 +91,3 @@ STATUS TfliteCustomParser::Parse(const std::unique_ptr<tflite::OperatorT> &tflit
TfliteNodeRegister g_tfliteCustomParser("Custom", new TfliteCustomParser());
} // namespace lite
} // namespace mindspore
......@@ -190,8 +190,7 @@ STATUS QuantFilter(ParamValueLitePtr weight, std::shared_ptr<PrimitiveC> primiti
quant_datas[index] = quant_data;
}
}
auto ret = memcpy_s(raw_datas, weight->tensor_size(), quant_datas.data(),
elem_count * sizeof(T));
auto ret = memcpy_s(raw_datas, weight->tensor_size(), quant_datas.data(), elem_count * sizeof(T));
if (ret != EOK) {
MS_LOG(ERROR) << "memcpy error: " << ret;
return RET_ERROR;
......@@ -238,15 +237,13 @@ STATUS QuantFilter(ParamValueLitePtr weight, std::shared_ptr<PrimitiveC> primiti
quant_datas[index] = quant_data;
}
}
auto ret =
memcpy_s(raw_datas, weight->tensor_size(), quant_datas.data(), elem_count * sizeof(int8_t));
auto ret = memcpy_s(raw_datas, weight->tensor_size(), quant_datas.data(), elem_count * sizeof(int8_t));
if (ret != EOK) {
MS_LOG(ERROR) << "memcpy error: " << ret;
return RET_ERROR;
}
weight->set_tensor_size(elem_count * sizeof(T));
}
} else {
// per layer
float min = FLT_MAX;
......
......@@ -27,7 +27,6 @@ using std::vector;
namespace mindspore {
namespace lite {
namespace quant {
WeightQuantizer::WeightQuantizer(FuncGraphPtr graph, const string &weightSize,
const std::string &convWeightChannelThreshold, const std::string &bitNum)
: Quantizer(graph) {
......
......@@ -48,11 +48,11 @@ bool IsRealKernel(const AnfNodePtr &node) {
}
auto input = cnode->inputs()[0];
bool is_virtual_node = IsPrimitive(input, prim::kPrimImageSummary) || IsPrimitive(input, prim::kPrimScalarSummary) ||
IsPrimitive(input, prim::kPrimTensorSummary) ||
IsPrimitive(input, prim::kPrimHistogramSummary) || IsPrimitive(input, prim::kPrimMakeTuple) ||
IsPrimitive(input, prim::kPrimStateSetItem) || IsPrimitive(input, prim::kPrimDepend) ||
IsPrimitive(input, prim::kPrimTupleGetItem) || IsPrimitive(input, prim::kPrimControlDepend) ||
IsPrimitive(input, prim::kPrimReturn) || IsPrimitive(input, prim::kPrimPartial);
IsPrimitive(input, prim::kPrimTensorSummary) ||
IsPrimitive(input, prim::kPrimHistogramSummary) || IsPrimitive(input, prim::kPrimMakeTuple) ||
IsPrimitive(input, prim::kPrimStateSetItem) || IsPrimitive(input, prim::kPrimDepend) ||
IsPrimitive(input, prim::kPrimTupleGetItem) || IsPrimitive(input, prim::kPrimControlDepend) ||
IsPrimitive(input, prim::kPrimReturn) || IsPrimitive(input, prim::kPrimPartial);
return !is_virtual_node;
}
......@@ -159,8 +159,8 @@ bool AnfEqual(const BaseRef &a, const BaseRef &b) {
}
if (utils::isa<lite::PrimitiveC>(a_value_ptr) && utils::isa<lite::PrimitiveC>(b_value_ptr)) {
auto a_obj = (lite::PrimitiveC *) (a_value_ptr.get());
auto b_obj = (lite::PrimitiveC *) (b_value_ptr.get());
auto a_obj = (lite::PrimitiveC *)(a_value_ptr.get());
auto b_obj = (lite::PrimitiveC *)(b_value_ptr.get());
return (*a_obj) == (*b_obj);
} else {
return (*a_value_ptr) == (*b_value_ptr);
......@@ -319,7 +319,7 @@ schema::PrimitiveType GetCNodeType(const BaseRef &n) {
if (utils::isa<PrimitiveCPtr>(value)) {
auto primitive = value->cast<PrimitiveCPtr>();
MS_ASSERT(primitive != nullptr);
return (schema::PrimitiveType) primitive->Type();
return (schema::PrimitiveType)primitive->Type();
} else if (utils::isa<Primitive>(value)) {
auto primitive = value->cast<PrimitivePtr>();
MS_ASSERT(primitive != nullptr);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册