!13151 [MSLITE][TOD] Realign with code
From: @zhengjun10 Reviewed-by: Signed-off-by:pull/13151/MERGE
commit
9f3eb6676b
@ -0,0 +1,43 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ops/grad/layer_norm_grad.h"
|
||||||
|
#include "ops/op_utils.h"
|
||||||
|
#include "utils/check_convert_utils.h"
|
||||||
|
|
||||||
|
namespace mindspore {
|
||||||
|
namespace ops {
|
||||||
|
void LayerNormGrad::Init(const int64_t begin_norm_axis, const int64_t begin_params_axis) {
|
||||||
|
this->set_begin_norm_axis(begin_norm_axis);
|
||||||
|
this->set_begin_params_axis(begin_params_axis);
|
||||||
|
}
|
||||||
|
void LayerNormGrad::set_begin_norm_axis(const int64_t begin_norm_axis) {
|
||||||
|
this->AddAttr(kBeginNormAxis, MakeValue(begin_norm_axis));
|
||||||
|
}
|
||||||
|
void LayerNormGrad::set_begin_params_axis(const int64_t begin_params_axis) {
|
||||||
|
this->AddAttr(kBeginParamsAxis, MakeValue(begin_params_axis));
|
||||||
|
}
|
||||||
|
int64_t LayerNormGrad::get_begin_norm_axis() const {
|
||||||
|
auto value_ptr = this->GetAttr(kBeginNormAxis);
|
||||||
|
return GetValue<int64_t>(value_ptr);
|
||||||
|
}
|
||||||
|
int64_t LayerNormGrad::get_begin_params_axis() const {
|
||||||
|
auto value_ptr = this->GetAttr(kBeginParamsAxis);
|
||||||
|
return GetValue<int64_t>(value_ptr);
|
||||||
|
}
|
||||||
|
REGISTER_PRIMITIVE_C(kNameLayerNormGrad, LayerNormGrad);
|
||||||
|
} // namespace ops
|
||||||
|
} // namespace mindspore
|
@ -0,0 +1,43 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MINDSPORE_CORE_OPS_GRAD_LAYER_NORM_GRAD_H_
|
||||||
|
#define MINDSPORE_CORE_OPS_GRAD_LAYER_NORM_GRAD_H_
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "ops/primitive_c.h"
|
||||||
|
#include "abstract/abstract_value.h"
|
||||||
|
#include "utils/check_convert_utils.h"
|
||||||
|
|
||||||
|
namespace mindspore {
|
||||||
|
namespace ops {
|
||||||
|
constexpr auto kNameLayerNormGrad = "LayerNormGrad";
|
||||||
|
class LayerNormGrad : public PrimitiveC {
|
||||||
|
public:
|
||||||
|
LayerNormGrad() : PrimitiveC(kNameLayerNormGrad) {}
|
||||||
|
explicit LayerNormGrad(const std::string k_name) : PrimitiveC(k_name) {}
|
||||||
|
~LayerNormGrad() = default;
|
||||||
|
MS_DECLARE_PARENT(LayerNormGrad, PrimitiveC);
|
||||||
|
void Init(const int64_t begin_norm_axis = 1, const int64_t begin_params_axis = 1);
|
||||||
|
void set_begin_norm_axis(const int64_t begin_norm_axis);
|
||||||
|
void set_begin_params_axis(const int64_t begin_params_axis);
|
||||||
|
int64_t get_begin_norm_axis() const;
|
||||||
|
int64_t get_begin_params_axis() const;
|
||||||
|
};
|
||||||
|
} // namespace ops
|
||||||
|
} // namespace mindspore
|
||||||
|
|
||||||
|
#endif // MINDSPORE_CORE_OPS_GRAD_LAYER_NORM_GRAD_H_
|
@ -0,0 +1,52 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ops/grad/resize_grad.h"
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <memory>
|
||||||
|
#include "ops/op_utils.h"
|
||||||
|
#include "utils/check_convert_utils.h"
|
||||||
|
#include "abstract/primitive_infer_map.h"
|
||||||
|
|
||||||
|
namespace mindspore {
|
||||||
|
namespace ops {
|
||||||
|
void ResizeGrad::Init(const ResizeMethod method, const bool align_corners) {
|
||||||
|
this->set_method(method);
|
||||||
|
this->set_align_corners(align_corners);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResizeGrad::set_method(const ResizeMethod method) {
|
||||||
|
auto swi = (int64_t)method;
|
||||||
|
this->AddAttr(kMethod, MakeValue(swi));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResizeGrad::set_align_corners(const bool align_corners) { this->AddAttr(kAlignCorners, MakeValue(align_corners)); }
|
||||||
|
|
||||||
|
ResizeMethod ResizeGrad::get_method() const {
|
||||||
|
auto value_ptr = GetAttr(kMethod);
|
||||||
|
return ResizeMethod(GetValue<int64_t>(value_ptr));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ResizeGrad::get_align_corners() const {
|
||||||
|
auto value_ptr = GetAttr(kAlignCorners);
|
||||||
|
return GetValue<bool>(value_ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
REGISTER_PRIMITIVE_C(kNameResizeGrad, ResizeGrad);
|
||||||
|
} // namespace ops
|
||||||
|
} // namespace mindspore
|
@ -0,0 +1,46 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MINDSPORE_CORE_OPS_GRAD_RESIZE_GRAD_H_
|
||||||
|
#define MINDSPORE_CORE_OPS_GRAD_RESIZE_GRAD_H_
|
||||||
|
#include <vector>
|
||||||
|
#include <memory>
|
||||||
|
#include "ops/primitive_c.h"
|
||||||
|
#include "abstract/abstract_value.h"
|
||||||
|
#include "utils/check_convert_utils.h"
|
||||||
|
|
||||||
|
namespace mindspore {
|
||||||
|
namespace ops {
|
||||||
|
constexpr auto kNameResizeGrad = "ResizeGrad";
|
||||||
|
class ResizeGrad : public PrimitiveC {
|
||||||
|
public:
|
||||||
|
ResizeGrad() : PrimitiveC(kNameResizeGrad) {}
|
||||||
|
~ResizeGrad() = default;
|
||||||
|
MS_DECLARE_PARENT(ResizeGrad, PrimitiveC);
|
||||||
|
void Init(const ResizeMethod method, const bool align_corners);
|
||||||
|
void set_method(const ResizeMethod method);
|
||||||
|
void set_align_corners(const bool align_corners);
|
||||||
|
ResizeMethod get_method() const;
|
||||||
|
bool get_align_corners() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
AbstractBasePtr ResizeGradInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive,
|
||||||
|
const std::vector<AbstractBasePtr> &input_args);
|
||||||
|
using PrimResizeGradPtr = std::shared_ptr<ResizeGrad>;
|
||||||
|
} // namespace ops
|
||||||
|
} // namespace mindspore
|
||||||
|
|
||||||
|
#endif // MINDSPORE_CORE_OPS_GRAD_RESIZE_GRAD_H_
|
@ -0,0 +1,26 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ops/grad/rsqrt_grad.h"
|
||||||
|
#include "ops/op_utils.h"
|
||||||
|
#include "utils/check_convert_utils.h"
|
||||||
|
#include "abstract/primitive_infer_map.h"
|
||||||
|
|
||||||
|
namespace mindspore {
|
||||||
|
namespace ops {
|
||||||
|
REGISTER_PRIMITIVE_C(kNameRsqrtGrad, RsqrtGrad);
|
||||||
|
} // namespace ops
|
||||||
|
} // namespace mindspore
|
@ -0,0 +1,36 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MINDSPORE_CORE_OPS_GRAD_RSQRT_GRAD_H_
|
||||||
|
#define MINDSPORE_CORE_OPS_GRAD_RSQRT_GRAD_H_
|
||||||
|
#include "ops/primitive_c.h"
|
||||||
|
#include "abstract/abstract_value.h"
|
||||||
|
#include "utils/check_convert_utils.h"
|
||||||
|
|
||||||
|
namespace mindspore {
|
||||||
|
namespace ops {
|
||||||
|
constexpr auto kNameRsqrtGrad = "RsqrtGrad";
|
||||||
|
class RsqrtGrad : public PrimitiveC {
|
||||||
|
public:
|
||||||
|
RsqrtGrad() : PrimitiveC(kNameRsqrtGrad) { InitIOName({"out_backprop", "input"}, {"output"}); }
|
||||||
|
~RsqrtGrad() = default;
|
||||||
|
MS_DECLARE_PARENT(RsqrtGrad, PrimitiveC);
|
||||||
|
void Init() {}
|
||||||
|
};
|
||||||
|
} // namespace ops
|
||||||
|
} // namespace mindspore
|
||||||
|
|
||||||
|
#endif // MINDSPORE_CORE_OPS_GRAD_RSQRT_GRAD_H_
|
@ -0,0 +1,26 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ops/grad/sqrt_grad.h"
|
||||||
|
#include "ops/op_utils.h"
|
||||||
|
#include "utils/check_convert_utils.h"
|
||||||
|
#include "abstract/primitive_infer_map.h"
|
||||||
|
|
||||||
|
namespace mindspore {
|
||||||
|
namespace ops {
|
||||||
|
REGISTER_PRIMITIVE_C(kNameSqrtGrad, SqrtGrad);
|
||||||
|
} // namespace ops
|
||||||
|
} // namespace mindspore
|
@ -0,0 +1,36 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MINDSPORE_CORE_OPS_GRAD_SQRT_GRAD_H_
|
||||||
|
#define MINDSPORE_CORE_OPS_GRAD_SQRT_GRAD_H_
|
||||||
|
#include "ops/primitive_c.h"
|
||||||
|
#include "abstract/abstract_value.h"
|
||||||
|
#include "utils/check_convert_utils.h"
|
||||||
|
|
||||||
|
namespace mindspore {
|
||||||
|
namespace ops {
|
||||||
|
constexpr auto kNameSqrtGrad = "SqrtGrad";
|
||||||
|
class SqrtGrad : public PrimitiveC {
|
||||||
|
public:
|
||||||
|
SqrtGrad() : PrimitiveC(kNameSqrtGrad) { InitIOName({"out_backprop", "input"}, {"output"}); }
|
||||||
|
~SqrtGrad() = default;
|
||||||
|
MS_DECLARE_PARENT(SqrtGrad, PrimitiveC);
|
||||||
|
void Init() {}
|
||||||
|
};
|
||||||
|
} // namespace ops
|
||||||
|
} // namespace mindspore
|
||||||
|
|
||||||
|
#endif // MINDSPORE_CORE_OPS_GRAD_SQRT_GRAD_H_
|
@ -0,0 +1,39 @@
|
|||||||
|
# Copyright 2021 Huawei Technologies Co., Ltd
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
# ============================================================================
|
||||||
|
"""vgg_train_export."""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import numpy as np
|
||||||
|
from train_utils import SaveInOut, TrainWrap
|
||||||
|
from official.cv.vgg16.src.vgg import vgg16
|
||||||
|
import mindspore.common.dtype as mstype
|
||||||
|
from mindspore import context, Tensor, nn
|
||||||
|
from mindspore.train.serialization import export
|
||||||
|
|
||||||
|
context.set_context(mode=context.PYNATIVE_MODE, device_target="GPU", save_graphs=False)
|
||||||
|
|
||||||
|
batch = 2
|
||||||
|
|
||||||
|
n = vgg16(num_classes=10)
|
||||||
|
loss_fn = nn.SoftmaxCrossEntropyWithLogits(sparse=False)
|
||||||
|
optimizer = nn.Momentum(n.trainable_params(), 0.01, 0.9, use_nesterov=False)
|
||||||
|
net = TrainWrap(n, loss_fn, optimizer)
|
||||||
|
|
||||||
|
x = Tensor(np.random.randn(batch, 3, 224, 224), mstype.float32)
|
||||||
|
label = Tensor(np.zeros([batch, 10]).astype(np.float32))
|
||||||
|
export(net, x, label, file_name="mindir/vgg_train", file_format='MINDIR')
|
||||||
|
|
||||||
|
if len(sys.argv) > 1:
|
||||||
|
SaveInOut(sys.argv[1] + "vgg", x, label, n, net)
|
@ -0,0 +1,42 @@
|
|||||||
|
# Copyright 2021 Huawei Technologies Co., Ltd
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
# ============================================================================
|
||||||
|
"""inceptionv4_train_export"""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import numpy as np
|
||||||
|
from train_utils import SaveInOut, TrainWrap
|
||||||
|
from official.cv.xception.src.Xception import Xception
|
||||||
|
import mindspore.common.dtype as mstype
|
||||||
|
from mindspore import context, Tensor, nn
|
||||||
|
from mindspore.train.serialization import export
|
||||||
|
|
||||||
|
context.set_context(mode=context.PYNATIVE_MODE, device_target="GPU", save_graphs=False)
|
||||||
|
|
||||||
|
|
||||||
|
n = Xception(num_classes=1000)
|
||||||
|
n.dropout = nn.Dropout(keep_prob=1.0)
|
||||||
|
|
||||||
|
loss_fn = nn.SoftmaxCrossEntropyWithLogits(sparse=False)
|
||||||
|
optimizer = nn.SGD(n.trainable_params(), learning_rate=0.01, momentum=0.9, dampening=0.0, weight_decay=0.0,
|
||||||
|
nesterov=True, loss_scale=1.0)
|
||||||
|
net = TrainWrap(n, loss_fn, optimizer)
|
||||||
|
|
||||||
|
batch = 2
|
||||||
|
x = Tensor(np.random.randn(batch, 3, 299, 299), mstype.float32)
|
||||||
|
label = Tensor(np.zeros([batch, 1000]).astype(np.float32))
|
||||||
|
export(net, x, label, file_name="mindir/xception_train", file_format='MINDIR')
|
||||||
|
|
||||||
|
if len(sys.argv) > 1:
|
||||||
|
SaveInOut(sys.argv[1] + "xception", x, label, n, net)
|
@ -0,0 +1,5 @@
|
|||||||
|
*.mindir
|
||||||
|
*.ms
|
||||||
|
msl
|
||||||
|
package-*
|
||||||
|
dataset
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue