forked from huawei/mindspore2022
!18328 [MS][LITE][TOD] replace internal API to CamelCase
Merge pull request !18328 from yonibaehr/export_yoni
This commit is contained in:
commit
beb66e483c
|
|
@ -183,9 +183,9 @@ class InnerKernel : public Kernel {
|
|||
|
||||
virtual bool IsEval() const { return !this->train_mode_; }
|
||||
|
||||
virtual void set_trainable(bool trainable = true) { this->trainable_ = trainable; }
|
||||
virtual void SetTrainable(bool trainable = true) { this->trainable_ = trainable; }
|
||||
|
||||
virtual bool is_trainable() const { return this->trainable_; }
|
||||
virtual bool IsTrainable() const { return this->trainable_; }
|
||||
|
||||
TypeId registry_data_type(void) { return registry_data_type_; }
|
||||
|
||||
|
|
|
|||
|
|
@ -192,17 +192,17 @@ class LiteKernel {
|
|||
return false;
|
||||
}
|
||||
|
||||
virtual void set_trainable(bool trainable = true) {
|
||||
virtual void SetTrainable(bool trainable = true) {
|
||||
MS_ASSERT(kernel_ != nullptr);
|
||||
if (desc_.provider == kBuiltin) {
|
||||
std::static_pointer_cast<InnerKernel>(kernel_)->set_trainable(trainable);
|
||||
std::static_pointer_cast<InnerKernel>(kernel_)->SetTrainable(trainable);
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool is_trainable() const {
|
||||
virtual bool IsTrainable() const {
|
||||
MS_ASSERT(kernel_ != nullptr);
|
||||
if (desc_.provider == kBuiltin) {
|
||||
return std::static_pointer_cast<InnerKernel>(kernel_)->is_trainable();
|
||||
return std::static_pointer_cast<InnerKernel>(kernel_)->IsTrainable();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,8 +61,8 @@ class ConvolutionBaseCPUKernel : public InnerKernel {
|
|||
void FreeAlignedData(void **ptr);
|
||||
|
||||
protected:
|
||||
bool IsRepack() { return is_repack_; }
|
||||
std::unordered_map<uintptr_t, void *> addr_map;
|
||||
bool is_repack() { return is_repack_; }
|
||||
void *bias_data_ = nullptr;
|
||||
const InnerContext *ctx_ = nullptr;
|
||||
ConvParameter *conv_param_ = nullptr;
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ int BiasAddCPUFp16Kernel::Run() {
|
|||
}
|
||||
}
|
||||
if (op_parameter_->is_train_session_) {
|
||||
if ((is_trainable() && (IsTrain() || is_repack())) || (bias_data_type_ == kNumberTypeFloat16)) {
|
||||
if ((IsTrainable() && (IsTrain() || IsRepack())) || (bias_data_type_ == kNumberTypeFloat16)) {
|
||||
PackWeight();
|
||||
is_repack_ = false;
|
||||
}
|
||||
|
|
@ -133,7 +133,7 @@ void BiasAddCPUFp16Kernel::PackWeight() {
|
|||
|
||||
int BiasAddCPUFp16Kernel::Eval() {
|
||||
InnerKernel::Eval();
|
||||
if (is_trainable()) {
|
||||
if (IsTrainable()) {
|
||||
is_repack_ = true;
|
||||
}
|
||||
return RET_OK;
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class BiasAddCPUFp16Kernel : public InnerKernel {
|
|||
private:
|
||||
int GetBiasData();
|
||||
void PackWeight();
|
||||
bool is_repack() { return is_repack_; }
|
||||
bool IsRepack() { return is_repack_; }
|
||||
ArithmeticParameter *bias_param_ = nullptr;
|
||||
float16_t *bias_data_ = nullptr;
|
||||
lite::Tensor *bias_tensor_ = nullptr;
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ int Convolution1x1FP16CPUKernel::InitWeightBias() {
|
|||
return RET_ERROR;
|
||||
}
|
||||
}
|
||||
void *bias_origin_tmp = is_trainable() ? in_tensors_.at(2)->data_c() : origin_bias_;
|
||||
void *bias_origin_tmp = IsTrainable() ? in_tensors_.at(2)->data_c() : origin_bias_;
|
||||
memcpy(bias_data_, bias_origin_tmp, output_channel * sizeof(float16_t));
|
||||
memset(reinterpret_cast<char *>(bias_data_) + bias_size, 0, size - bias_size);
|
||||
}
|
||||
|
|
@ -111,7 +111,7 @@ int Convolution1x1FP16CPUKernel::InitWeightBias() {
|
|||
return RET_ERROR;
|
||||
}
|
||||
}
|
||||
void *weight_origin_tmp = is_trainable() ? weight_tensor->data_c() : origin_weight_;
|
||||
void *weight_origin_tmp = IsTrainable() ? weight_tensor->data_c() : origin_weight_;
|
||||
memset(reinterpret_cast<char *>(weight_ptr_) + down_size, 0, size - down_size);
|
||||
ColMajor2Row8MajorFp16(weight_origin_tmp, weight_ptr_, input_channel, output_channel, true);
|
||||
|
||||
|
|
@ -240,7 +240,7 @@ int Convolution1x1FP16CPUKernel::Run() {
|
|||
return RET_MEMORY_FAILED;
|
||||
}
|
||||
|
||||
if (is_trainable() && (IsTrain() || is_repack())) {
|
||||
if (IsTrainable() && (IsTrain() || IsRepack())) {
|
||||
auto ret = InitWeightBias();
|
||||
if (ret != 0) {
|
||||
MS_LOG(ERROR) << "Convolution 1x1 fp16 repack weight failure";
|
||||
|
|
@ -283,7 +283,7 @@ int Convolution1x1FP16CPUKernel::Run() {
|
|||
}
|
||||
|
||||
int Convolution1x1FP16CPUKernel::Eval() {
|
||||
if (is_trainable()) {
|
||||
if (IsTrainable()) {
|
||||
is_repack_ = true;
|
||||
}
|
||||
return InnerKernel::Eval();
|
||||
|
|
|
|||
|
|
@ -55,9 +55,9 @@ class ConvolutionDelegateFP16CPUKernel : public InnerKernel {
|
|||
InnerKernel::Train();
|
||||
return fp16_conv_kernel_->Train();
|
||||
}
|
||||
void set_trainable(bool trainable) override {
|
||||
InnerKernel::set_trainable(trainable);
|
||||
return fp16_conv_kernel_->set_trainable(trainable);
|
||||
void SetTrainable(bool trainable) override {
|
||||
InnerKernel::SetTrainable(trainable);
|
||||
return fp16_conv_kernel_->SetTrainable(trainable);
|
||||
}
|
||||
|
||||
void set_in_tensor(lite::Tensor *in_tensor, int index) override {
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ static int ConvDwFp16Run(void *cdata, int task_id, float lhs_scale, float rhs_sc
|
|||
}
|
||||
|
||||
int ConvolutionDepthwiseFp16CPUKernel::Run() {
|
||||
if (is_trainable() && (IsTrain() || is_repack())) {
|
||||
if (IsTrainable() && (IsTrain() || IsRepack())) {
|
||||
auto ret = InitWeightBias();
|
||||
if (ret != 0) {
|
||||
MS_LOG(ERROR) << "Convolution depthwise fp16 repack weight failure";
|
||||
|
|
@ -125,7 +125,7 @@ int ConvolutionDepthwiseFp16CPUKernel::Run() {
|
|||
}
|
||||
|
||||
int ConvolutionDepthwiseFp16CPUKernel::Eval() {
|
||||
if (is_trainable()) {
|
||||
if (IsTrainable()) {
|
||||
is_repack_ = true;
|
||||
}
|
||||
return InnerKernel::Eval();
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ int ConvolutionDepthwiseSWFp16CPUKernel::Run() {
|
|||
packed_output_ = output_ptr;
|
||||
}
|
||||
|
||||
if (is_trainable() && (IsTrain() || is_repack())) {
|
||||
if (IsTrainable() && (IsTrain() || IsRepack())) {
|
||||
ret = InitWeightBias();
|
||||
if (ret != 0) {
|
||||
MS_LOG(ERROR) << "Convolution depthwise fp16 repack weight failure";
|
||||
|
|
@ -192,7 +192,7 @@ void ConvolutionDepthwiseSWFp16CPUKernel::FreePackedInputOutput() {
|
|||
}
|
||||
|
||||
int ConvolutionDepthwiseSWFp16CPUKernel::Eval() {
|
||||
if (is_trainable()) {
|
||||
if (IsTrainable()) {
|
||||
is_repack_ = true;
|
||||
}
|
||||
return InnerKernel::Eval();
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ int ConvolutionFP16CPUKernel::InitWeightBias() {
|
|||
}
|
||||
}
|
||||
memset(packed_weight_, 0, pack_weight_size * sizeof(float16_t));
|
||||
void *weight_origin_tmp = is_trainable() ? filter_tensor->data_c() : origin_weight_;
|
||||
void *weight_origin_tmp = IsTrainable() ? filter_tensor->data_c() : origin_weight_;
|
||||
RowMajor2Col8MajorFp16(weight_origin_tmp, packed_weight_, out_channel, in_channel * kernel_plane, false);
|
||||
|
||||
// init bias
|
||||
|
|
@ -60,7 +60,7 @@ int ConvolutionFP16CPUKernel::InitWeightBias() {
|
|||
memset(bias_data_, 0, oc8 * sizeof(float16_t));
|
||||
if (in_tensors_.size() == kInputSize2) {
|
||||
auto bias_tensor = in_tensors_.at(kBiasIndex);
|
||||
void *bias_origin_tmp = is_trainable() ? bias_tensor->data_c() : origin_bias_;
|
||||
void *bias_origin_tmp = IsTrainable() ? bias_tensor->data_c() : origin_bias_;
|
||||
memcpy(bias_data_, bias_origin_tmp, out_channel * sizeof(float16_t));
|
||||
}
|
||||
return RET_OK;
|
||||
|
|
@ -152,7 +152,7 @@ int ConvolutionFP16CPUKernel::Run() {
|
|||
return RET_ERROR;
|
||||
}
|
||||
|
||||
if (is_trainable() && (IsTrain() || is_repack())) {
|
||||
if (IsTrainable() && (IsTrain() || IsRepack())) {
|
||||
ret = InitWeightBias();
|
||||
if (ret != 0) {
|
||||
MS_LOG(ERROR) << "Convolution 1x1 fp16 repack weight failure";
|
||||
|
|
@ -170,7 +170,7 @@ int ConvolutionFP16CPUKernel::Run() {
|
|||
}
|
||||
|
||||
int ConvolutionFP16CPUKernel::Eval() {
|
||||
if (is_trainable()) {
|
||||
if (IsTrainable()) {
|
||||
is_repack_ = true;
|
||||
}
|
||||
return InnerKernel::Eval();
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ int ConvolutionWinogradFP16CPUKernel::InitWeightBias() {
|
|||
MS_LOG(ERROR) << "get matrix g from CookToomFilter failed.";
|
||||
return ret;
|
||||
}
|
||||
void *weight_origin_tmp = is_trainable() ? weight_tensor->data_c() : origin_weight_;
|
||||
void *weight_origin_tmp = IsTrainable() ? weight_tensor->data_c() : origin_weight_;
|
||||
ret = WinogradFilterTransformFp16(reinterpret_cast<float16_t *>(weight_origin_tmp), matrix_g, matrix_gt, col_tile_);
|
||||
if (ret != RET_OK) {
|
||||
MS_LOG(ERROR) << "winograd filter transform failed.";
|
||||
|
|
@ -84,7 +84,7 @@ int ConvolutionWinogradFP16CPUKernel::InitWeightBias() {
|
|||
memset(bias_data_, 0, oc_block_num * col_tile_ * sizeof(float16_t));
|
||||
if (in_tensors_.size() == kInputSize2) {
|
||||
auto bias_tensor = in_tensors_.at(kBiasIndex);
|
||||
void *bias_origin_tmp = is_trainable() ? bias_tensor->data_c() : origin_bias_;
|
||||
void *bias_origin_tmp = IsTrainable() ? bias_tensor->data_c() : origin_bias_;
|
||||
memcpy(bias_data_, bias_origin_tmp, out_channel * sizeof(float16_t));
|
||||
}
|
||||
return RET_OK;
|
||||
|
|
@ -229,7 +229,7 @@ int ConvolutionWinogradFP16CPUKernel::Run() {
|
|||
FreeTmpBuffer();
|
||||
return RET_ERROR;
|
||||
}
|
||||
if (is_trainable() && (IsTrain() || is_repack())) {
|
||||
if (IsTrainable() && (IsTrain() || IsRepack())) {
|
||||
ret = InitWeightBias();
|
||||
if (ret != 0) {
|
||||
MS_LOG(ERROR) << "ConvolutionWinogradFP16 repack weight failure";
|
||||
|
|
@ -246,7 +246,7 @@ int ConvolutionWinogradFP16CPUKernel::Run() {
|
|||
}
|
||||
|
||||
int ConvolutionWinogradFP16CPUKernel::Eval() {
|
||||
if (is_trainable()) {
|
||||
if (IsTrainable()) {
|
||||
is_repack_ = true;
|
||||
}
|
||||
return InnerKernel::Eval();
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ int FusedBatchnormFp16CPUKernel::DoExecute(int task_id) {
|
|||
Float32ToFloat16(reinterpret_cast<float *>(variance->data_c()), reinterpret_cast<float16_t *>(variance_fp16),
|
||||
variance->ElementsNum());
|
||||
|
||||
if (IsTrain() && is_trainable() && in_tensors_.size() >= 5) {
|
||||
if (IsTrain() && IsTrainable() && in_tensors_.size() >= 5) {
|
||||
CalcMeanVar(reinterpret_cast<float16_t *>(input_fp16), reinterpret_cast<float16_t *>(scale_fp16),
|
||||
reinterpret_cast<float16_t *>(offset_fp16), reinterpret_cast<float16_t *>(mean_fp16),
|
||||
reinterpret_cast<float16_t *>(variance_fp16));
|
||||
|
|
@ -108,7 +108,7 @@ int FusedBatchnormFp16CPUKernel::DoExecute(int task_id) {
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
if (IsTrain() && is_trainable() && in_tensors_.size() >= 5) {
|
||||
if (IsTrain() && IsTrainable() && in_tensors_.size() >= 5) {
|
||||
CalcMeanVar(
|
||||
static_cast<float16_t *>(in_tensors_.at(0)->data_c()), static_cast<float16_t *>(in_tensors_.at(1)->data_c()),
|
||||
static_cast<float16_t *>(in_tensors_.at(2)->data_c()), static_cast<float16_t *>(in_tensors_.at(3)->data_c()),
|
||||
|
|
|
|||
|
|
@ -270,13 +270,13 @@ int MatmulBaseFP16CPUKernel::RunImpl(int task_id) {
|
|||
int MatmulBaseFP16CPUKernel::Run() {
|
||||
auto c_ptr = reinterpret_cast<float16_t *>(out_tensors_.at(0)->data_c());
|
||||
|
||||
if ((params_->a_const_ == false) || is_repack()) {
|
||||
if ((params_->a_const_ == false) || IsRepack()) {
|
||||
if (RET_OK != InitBufferA()) {
|
||||
return RET_ERROR;
|
||||
}
|
||||
InitMatrixA(in_tensors_.at(0)->data_c());
|
||||
}
|
||||
if ((params_->b_const_ == false) || is_repack()) {
|
||||
if ((params_->b_const_ == false) || IsRepack()) {
|
||||
if (RET_OK != InitBufferB()) {
|
||||
FreeResizeBufA();
|
||||
return RET_ERROR;
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class MatmulBaseFP16CPUKernel : public InnerKernel {
|
|||
|
||||
protected:
|
||||
void InitParameter();
|
||||
bool is_repack() { return is_repack_; }
|
||||
bool IsRepack() { return is_repack_; }
|
||||
bool is_repack_ = false;
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ int MatmulFP16CPUKernel::ReSize() {
|
|||
}
|
||||
|
||||
int MatmulFP16CPUKernel::Run() {
|
||||
if (is_trainable() && (IsTrain())) {
|
||||
if (IsTrainable() && (IsTrain())) {
|
||||
is_repack_ = true;
|
||||
}
|
||||
auto ret = MatmulBaseFP16CPUKernel::Run();
|
||||
|
|
@ -99,7 +99,7 @@ int MatmulFP16CPUKernel::Run() {
|
|||
|
||||
int MatmulFP16CPUKernel::Eval() {
|
||||
InnerKernel::Eval();
|
||||
if (is_trainable()) {
|
||||
if (IsTrainable()) {
|
||||
is_repack_ = true;
|
||||
}
|
||||
return RET_OK;
|
||||
|
|
|
|||
|
|
@ -76,6 +76,9 @@ int ArithmeticCPUKernel::CheckDataType() {
|
|||
<< in0_dataType << " input 1 dataType: " << in1_dataType;
|
||||
return RET_ERROR;
|
||||
}
|
||||
if (op_parameter_->is_train_session_) {
|
||||
data_type_len_ = lite::DataTypeSize(in_tensors_.at(0)->data_type());
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -242,7 +242,7 @@ int Convolution1x1CPUKernel::Run() {
|
|||
MS_LOG(ERROR) << "Conv1x1 Malloc pack_input_ error!";
|
||||
return RET_MEMORY_FAILED;
|
||||
}
|
||||
if (IsTrain() && is_trainable()) {
|
||||
if (IsTrain() && IsTrainable()) {
|
||||
PackWeight();
|
||||
}
|
||||
|
||||
|
|
@ -294,7 +294,7 @@ int Convolution1x1CPUKernel::Eval() {
|
|||
MS_LOG(ERROR) << "eval failed!";
|
||||
return ret;
|
||||
}
|
||||
if (is_trainable()) {
|
||||
if (IsTrainable()) {
|
||||
PackWeight();
|
||||
}
|
||||
return RET_OK;
|
||||
|
|
|
|||
|
|
@ -88,9 +88,9 @@ class ConvolutionDelegateCPUKernel : public InnerKernel {
|
|||
InnerKernel::Train();
|
||||
return conv_kernel_->Train();
|
||||
}
|
||||
void set_trainable(bool trainable) override {
|
||||
InnerKernel::set_trainable(trainable);
|
||||
return conv_kernel_->set_trainable(trainable);
|
||||
void SetTrainable(bool trainable) override {
|
||||
InnerKernel::SetTrainable(trainable);
|
||||
return conv_kernel_->SetTrainable(trainable);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ int ConvolutionDepthwise3x3CPUKernel::Run() {
|
|||
return RET_MEMORY_FAILED;
|
||||
}
|
||||
|
||||
if (IsTrain() && is_trainable()) {
|
||||
if (IsTrain() && IsTrainable()) {
|
||||
if (InitWeightBias() != RET_OK) {
|
||||
ctx_->allocator->Free(buffer_);
|
||||
MS_LOG(ERROR) << "Convolution depthwise 3x3 run InitWeightBias failed.";
|
||||
|
|
@ -148,7 +148,7 @@ int ConvolutionDepthwise3x3CPUKernel::Eval() {
|
|||
MS_LOG(ERROR) << "eval failed!";
|
||||
return ret;
|
||||
}
|
||||
if (is_trainable()) {
|
||||
if (IsTrainable()) {
|
||||
if (InitWeightBias() != RET_OK) {
|
||||
MS_LOG(ERROR) << "Convolution depthwise 3x3 fp32 Eval:InitWeightBias failed.";
|
||||
return RET_ERROR;
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ int ConvDwRun(void *cdata, int task_id, float lhs_scale, float rhs_scale) {
|
|||
}
|
||||
|
||||
int ConvolutionDepthwiseCPUKernel::Run() {
|
||||
if (IsTrain() && is_trainable()) {
|
||||
if (IsTrain() && IsTrainable()) {
|
||||
PackWeight();
|
||||
}
|
||||
|
||||
|
|
@ -139,7 +139,7 @@ int ConvolutionDepthwiseCPUKernel::Eval() {
|
|||
MS_LOG(ERROR) << "eval failed!";
|
||||
return ret;
|
||||
}
|
||||
if (is_trainable()) {
|
||||
if (IsTrainable()) {
|
||||
PackWeight();
|
||||
}
|
||||
return RET_OK;
|
||||
|
|
|
|||
|
|
@ -194,7 +194,7 @@ int ConvolutionDepthwiseIndirectCPUKernel::Run() {
|
|||
packed_input_ = input_ptr;
|
||||
}
|
||||
|
||||
if (IsTrain() && is_trainable()) {
|
||||
if (IsTrain() && IsTrainable()) {
|
||||
PackWeight();
|
||||
}
|
||||
|
||||
|
|
@ -233,7 +233,7 @@ int ConvolutionDepthwiseIndirectCPUKernel::Eval() {
|
|||
MS_LOG(ERROR) << "eval failed!";
|
||||
return ret;
|
||||
}
|
||||
if (is_trainable()) {
|
||||
if (IsTrainable()) {
|
||||
PackWeight();
|
||||
}
|
||||
return RET_OK;
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ int ConvolutionDepthwiseSWCPUKernel::Run() {
|
|||
return RET_ERROR;
|
||||
}
|
||||
|
||||
if (IsTrain() && is_trainable()) {
|
||||
if (IsTrain() && IsTrainable()) {
|
||||
PackWeight();
|
||||
}
|
||||
|
||||
|
|
@ -207,7 +207,7 @@ int ConvolutionDepthwiseSWCPUKernel::Eval() {
|
|||
MS_LOG(ERROR) << "eval failed!";
|
||||
return ret;
|
||||
}
|
||||
if (is_trainable()) {
|
||||
if (IsTrainable()) {
|
||||
PackWeight();
|
||||
}
|
||||
return RET_OK;
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ int ConvolutionDepthwiseSWCPUKernelX86::Run() {
|
|||
return RET_ERROR;
|
||||
}
|
||||
|
||||
if (IsTrain() && is_trainable()) {
|
||||
if (IsTrain() && IsTrainable()) {
|
||||
PackWeight();
|
||||
}
|
||||
|
||||
|
|
@ -198,7 +198,7 @@ int ConvolutionDepthwiseSWCPUKernelX86::Eval() {
|
|||
MS_LOG(ERROR) << "eval failed!";
|
||||
return ret;
|
||||
}
|
||||
if (is_trainable()) {
|
||||
if (IsTrainable()) {
|
||||
PackWeight();
|
||||
}
|
||||
return RET_OK;
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@ int ConvolutionCPUKernel::Run() {
|
|||
FreeTmpBuffer();
|
||||
return RET_ERROR;
|
||||
}
|
||||
if (IsTrain() && is_trainable()) {
|
||||
if (IsTrain() && IsTrainable()) {
|
||||
PackWeight();
|
||||
}
|
||||
|
||||
|
|
@ -180,7 +180,7 @@ void ConvolutionCPUKernel::PackWeight() {
|
|||
|
||||
int ConvolutionCPUKernel::Eval() {
|
||||
InnerKernel::Eval();
|
||||
if (is_trainable()) {
|
||||
if (IsTrainable()) {
|
||||
PackWeight();
|
||||
}
|
||||
return RET_OK;
|
||||
|
|
|
|||
|
|
@ -216,7 +216,7 @@ int ConvolutionWinogradCPUKernel::Run() {
|
|||
FreeTmpBuffer();
|
||||
return RET_ERROR;
|
||||
}
|
||||
if (IsTrain() && is_trainable()) {
|
||||
if (IsTrain() && IsTrainable()) {
|
||||
ret = InitWeightBias();
|
||||
if (ret != RET_OK) {
|
||||
MS_LOG(ERROR) << "Init weight bias failed.";
|
||||
|
|
@ -239,7 +239,7 @@ int ConvolutionWinogradCPUKernel::Eval() {
|
|||
MS_LOG(ERROR) << "eval failed!";
|
||||
return ret;
|
||||
}
|
||||
if (is_trainable()) {
|
||||
if (IsTrainable()) {
|
||||
ret = InitWeightBias();
|
||||
if (ret != RET_OK) {
|
||||
MS_LOG(ERROR) << "Init weight bias failed.";
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ int FusedBatchnormCPUKernel::InitConstTensor() {
|
|||
|
||||
int FusedBatchnormCPUKernel::Run() {
|
||||
auto param = reinterpret_cast<BatchNormParameter *>(op_parameter_);
|
||||
if (IsTrain() && is_trainable() && in_tensors_.size() >= 5) {
|
||||
if (IsTrain() && IsTrainable() && in_tensors_.size() >= 5) {
|
||||
float *in = static_cast<float *>(in_tensors_[0]->MutableData());
|
||||
float *scale = static_cast<float *>(in_tensors_[1]->MutableData());
|
||||
float *offset = static_cast<float *>(in_tensors_[2]->MutableData());
|
||||
|
|
|
|||
|
|
@ -445,6 +445,7 @@ int Scheduler::FindCpuKernel(const std::vector<Tensor *> &in_tensors, const std:
|
|||
if (ret == RET_OK) {
|
||||
MS_LOG(DEBUG) << "Get TypeId(" << kernel_data_type << ") op success: " << PrimitiveCurVersionTypeName(op_type);
|
||||
if (is_train_session_) {
|
||||
(*kernel)->Init();
|
||||
RestoreTensorData(&restored_origin_tensors);
|
||||
} else {
|
||||
FreeRestoreTensors(&restored_origin_tensors);
|
||||
|
|
@ -721,7 +722,7 @@ int Scheduler::ScheduleSubGraphToKernels(size_t subgraph_index, std::vector<kern
|
|||
kernel = SchedulePartialToKernel(node);
|
||||
} else { // kernel
|
||||
kernel = ScheduleNodeToKernel(node, prefer_data_type);
|
||||
if (kernel != nullptr) {
|
||||
if ((kernel != nullptr) && (!is_train_session_)) {
|
||||
ret = kernel->Init();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,6 +61,10 @@ TrainSession::TrainSession() {
|
|||
|
||||
int TrainSession::Init(const Context *context, const TrainCfg *train_cfg) {
|
||||
if (train_cfg != nullptr) {
|
||||
if (train_cfg->mix_precision_cfg_.loss_scale_ <= 0) {
|
||||
MS_LOG(ERROR) << "illegal loss scale configuration";
|
||||
return RET_NULL_PTR;
|
||||
}
|
||||
cfg_ = *train_cfg;
|
||||
}
|
||||
return lite::LiteSession::Init(context);
|
||||
|
|
@ -115,6 +119,9 @@ void TrainSession::FreeWorkSpace() {
|
|||
|
||||
int TrainSession::InitCallBack() {
|
||||
sched_mix_precision_callback_ = [&](const Model::Node *node) {
|
||||
if (!context_->IsCpuFloat16Enabled()) {
|
||||
return false;
|
||||
}
|
||||
auto node_type = GetPrimitiveType(node->primitive_);
|
||||
if (node_type == schema::PrimitiveType_Cast) {
|
||||
return false;
|
||||
|
|
@ -548,7 +555,7 @@ void TrainSession::CompileOptimizedKernels() {
|
|||
if (!IsOptimizer(kernel)) {
|
||||
for (auto it : kernel->in_tensors()) {
|
||||
if (std::find(out_tensor.begin(), out_tensor.end(), it) != out_tensor.end()) {
|
||||
kernel->set_trainable(true);
|
||||
kernel->SetTrainable(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -610,7 +617,7 @@ int TrainSession::AdminSetupVirtualBatch(int virtual_batch_multiplier, float lr,
|
|||
}
|
||||
}
|
||||
|
||||
if (IsBN(kernel) && kernel->is_trainable()) {
|
||||
if (IsBN(kernel) && kernel->IsTrainable()) {
|
||||
auto batchnorm = static_cast<kernel::BatchnormCPUKernel *>(kernel->kernel());
|
||||
auto ret = RET_OK;
|
||||
if (mod == kernel::OptimizerKernel::WeightUpdateMode::VIRTUAL_BATCH) {
|
||||
|
|
@ -711,13 +718,6 @@ int TrainSession::Export(const std::string &file_name, ModelType model_type, Qua
|
|||
|
||||
session::LiteSession *session::LiteSession::CreateTrainSession(const std::string &fn, const lite::Context *context,
|
||||
bool train_mode, const lite::TrainCfg *cfg) {
|
||||
if (cfg != nullptr) {
|
||||
// test legal configuration
|
||||
if (cfg->mix_precision_cfg_.loss_scale_ <= 0) {
|
||||
MS_LOG(ERROR) << "illegal loss scale configuration";
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
auto session = std::make_unique<lite::TrainSession>();
|
||||
if (session == nullptr) {
|
||||
MS_LOG(ERROR) << "create session failed";
|
||||
|
|
|
|||
|
|
@ -23,15 +23,15 @@ effnet_tune weight_quant 7
|
|||
googlenet weight_quant 10
|
||||
densenet weight_quant 11
|
||||
shufflenetv2 weight_quant 3
|
||||
#mini_alexnet fp16 6
|
||||
#nin fp16 8.0
|
||||
mini_alexnet fp16 6
|
||||
nin fp16 8.0
|
||||
#lenet fp16 2
|
||||
mobilenetv1 fp16 2
|
||||
mobilenetv2 fp16 2
|
||||
#mobilenetv3 fp16 7
|
||||
mobilenetv3 fp16 7
|
||||
effnet fp16 2
|
||||
#effnet_tune fp16 5.0
|
||||
effnet_tune fp16 5.0
|
||||
resnet fp16 2
|
||||
#googlenet fp16 10
|
||||
googlenet fp16 10
|
||||
#xception fp16 20.0
|
||||
# LAST
|
||||
|
|
|
|||
|
|
@ -1060,12 +1060,17 @@ function Run_arm64() {
|
|||
model_prefix=${line_array[0]}
|
||||
model_name=${line_array[0]}'_train'
|
||||
accuracy_limit=0.5
|
||||
enable_fp16="false"
|
||||
if [[ $model_name == \#* ]]; then
|
||||
continue
|
||||
fi
|
||||
if [[ "${line_array[1]}" == "weight_quant" ]]; then
|
||||
model_name=${line_array[0]}'_train_quant'
|
||||
accuracy_limit=${line_array[2]}
|
||||
elif [[ "${line_array[1]}" == "fp16" ]]; then
|
||||
enable_fp16="true"
|
||||
suffix_print="_fp16"
|
||||
accuracy_limit=${line_array[2]}
|
||||
fi
|
||||
export_file="${tmp_dir}/${model_name}_tod"
|
||||
inference_file="${tmp_dir}/${model_name}_infer"
|
||||
|
|
@ -1086,6 +1091,7 @@ function Run_arm64() {
|
|||
--expectedDataFile=${tmp_dir}/${model_prefix}_output \
|
||||
--numThreads=${threads} \
|
||||
--accuracyThreshold=${accuracy_limit} \
|
||||
--enableFp16=${enable_fp16} \
|
||||
--inferenceFile=${inference_file} \
|
||||
--exportFile=${export_file}
|
||||
ENDM
|
||||
|
|
@ -1095,9 +1101,9 @@ ENDM
|
|||
adb -s ${device_id} shell < adb_run_cmd.txt >> ${run_arm64_fp32_log_file}
|
||||
# TODO: change to arm_type
|
||||
if [ $? = 0 ]; then
|
||||
run_result='arm64_train: '${model_name}' pass'; echo ${run_result} >> ${run_benchmark_train_result_file}
|
||||
run_result='arm64_train: '${model_name}''${suffix_print}' pass'; echo ${run_result} >> ${run_benchmark_train_result_file}
|
||||
else
|
||||
run_result='arm64_train: '${model_name}' failed'; echo ${run_result} >> ${run_benchmark_train_result_file};
|
||||
run_result='arm64_train: '${model_name}''${suffix_print}' failed'; echo ${run_result} >> ${run_benchmark_train_result_file};
|
||||
fail=1
|
||||
fi
|
||||
done < ${models_ms_train_config}
|
||||
|
|
@ -1183,6 +1189,8 @@ function Run_arm32() {
|
|||
if [[ "${line_array[1]}" == "weight_quant" ]]; then
|
||||
model_name=${line_array[0]}'_train_quant'
|
||||
accuracy_limit=${line_array[2]}
|
||||
elif [[ "${line_array[1]}" != "" ]]; then
|
||||
continue
|
||||
fi
|
||||
export_file="${tmp_dir}/${model_name}_tod"
|
||||
inference_file="${tmp_dir}/${model_name}_infer"
|
||||
|
|
|
|||
|
|
@ -737,6 +737,8 @@ function Run_x86() {
|
|||
if [[ "${line_array[1]}" == "weight_quant" ]]; then
|
||||
model_name=${line_array[0]}'_train_quant'
|
||||
accuracy_limit=${line_array[2]}
|
||||
elif [[ "${line_array[1]}" != "" ]]; then
|
||||
continue
|
||||
fi
|
||||
export_file="${ms_train_models_path}/${model_name}_tod"
|
||||
inference_file="${ms_train_models_path}/${model_name}_infer"
|
||||
|
|
|
|||
|
|
@ -194,7 +194,7 @@ TEST_F(TestBNGradFp32, BNTtrainFp32) {
|
|||
EXPECT_EQ(0, ret);
|
||||
|
||||
kernel_obj->Train();
|
||||
kernel_obj->set_trainable(true);
|
||||
kernel_obj->SetTrainable(true);
|
||||
kernel_obj->Run();
|
||||
|
||||
std::cout << "================save_mean==============================\n";
|
||||
|
|
|
|||
Loading…
Reference in New Issue