!1189 Decoupling py default param from Parameter
Merge pull request !1189 from leopz/masterpull/1189/MERGE
commit
04ac611fe8
@ -0,0 +1,103 @@
|
||||
/**
|
||||
* Copyright 2020 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 "ir/anf.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "ir/visitor.h"
|
||||
#include "pipeline/static_analysis/static_analysis.h"
|
||||
#include "operator/ops.h"
|
||||
#include "parallel/ops_info/ops_utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
// namespace to support intermediate representation definition
|
||||
// Methods of AnfNode
|
||||
TypePtr AnfNode::Type() const { return (abstract_ == nullptr) ? nullptr : abstract_->BuildType(); }
|
||||
BaseShapePtr AnfNode::Shape() const { return (abstract_ == nullptr) ? nullptr : abstract_->BuildShape(); }
|
||||
|
||||
std::string AnfNode::ToString() const {
|
||||
return mindspore::label_manage::Label(const_cast<AnfNode *>(this)->shared_from_base<AnfNode>()->debug_info());
|
||||
}
|
||||
|
||||
OperatorInfoPtr CNode::set_operator_info(const OperatorInfoPtr &operator_info) {
|
||||
if (operator_info_ != nullptr) {
|
||||
MS_LOG(WARNING) << "The CNode: " << ToString() << " has already been set OperatorInfo: " << operator_info_->name()
|
||||
<< ", using the new one: " << operator_info->name();
|
||||
auto old_ptr = operator_info_;
|
||||
operator_info_ = operator_info;
|
||||
return old_ptr;
|
||||
}
|
||||
operator_info_ = operator_info;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::string CNode::fullname_with_scope() {
|
||||
// if full name is set, return its name immediately
|
||||
if (!fullname_with_scope_.empty()) {
|
||||
return fullname_with_scope_;
|
||||
}
|
||||
|
||||
if (IsApply(prim::kPrimScalarSummary) || IsApply(prim::kPrimTensorSummary) || IsApply(prim::kPrimImageSummary) ||
|
||||
IsApply(prim::kPrimHistogramSummary)) {
|
||||
std::string tag = GetValue<std::string>(GetValueNode(input(1)));
|
||||
if (tag == "") {
|
||||
MS_LOG(EXCEPTION) << "The tag name is null, should be valid string";
|
||||
}
|
||||
std::string name;
|
||||
if (IsApply(prim::kPrimScalarSummary)) {
|
||||
name = tag + "[:Scalar]";
|
||||
} else if (IsApply(prim::kPrimImageSummary)) {
|
||||
name = tag + "[:Image]";
|
||||
} else if (IsApply(prim::kPrimHistogramSummary)) {
|
||||
name = tag + "[:Histogram]";
|
||||
} else {
|
||||
name = tag + "[:Tensor]";
|
||||
}
|
||||
fullname_with_scope_ = name;
|
||||
} else {
|
||||
// cnode input 0 should be primitive ptr
|
||||
auto value_ptr = input(0)->cast<ValueNodePtr>();
|
||||
if (value_ptr == nullptr) {
|
||||
MS_LOG(WARNING) << "Input 0 of cnode is not a value node, its type is " << input(0)->type_name() << ".";
|
||||
fullname_with_scope_ = id_generator::get_id(shared_from_base<CNode>());
|
||||
return fullname_with_scope_;
|
||||
}
|
||||
auto input_value = value_ptr->value();
|
||||
if (input_value == nullptr) {
|
||||
MS_LOG(WARNING) << "Value of input 0 of cnode is nullptr.";
|
||||
fullname_with_scope_ = id_generator::get_id(shared_from_base<CNode>());
|
||||
return fullname_with_scope_;
|
||||
}
|
||||
|
||||
PrimitivePtr prim = GetValue<PrimitivePtr>(input_value);
|
||||
MS_EXCEPTION_IF_NULL(scope());
|
||||
MS_EXCEPTION_IF_NULL(prim);
|
||||
fullname_with_scope_ =
|
||||
scope()->name() + "/" + prim->name() + "-op" + id_generator::get_id(shared_from_base<CNode>());
|
||||
}
|
||||
|
||||
return fullname_with_scope_;
|
||||
}
|
||||
|
||||
void CNode::accept(AnfVisitor *v) { v->Visit(shared_from_base<CNode>()); }
|
||||
void ValueNode::accept(AnfVisitor *v) { v->Visit(shared_from_base<ValueNode>()); }
|
||||
void Parameter::accept(AnfVisitor *v) { v->Visit(shared_from_base<Parameter>()); }
|
||||
|
||||
} // namespace mindspore
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Copyright 2020 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 "ir/dtype/type.h"
|
||||
#include "pipeline/static_analysis/abstract_value.h"
|
||||
|
||||
namespace mindspore {
|
||||
abstract::AbstractBasePtr Type::ToAbstract() {
|
||||
auto ptr = std::make_shared<abstract::AbstractType>(shared_from_base<Type>());
|
||||
return ptr;
|
||||
}
|
||||
} // namespace mindspore
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Copyright 2020 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_CCSRC_IR_PARAM_VALUE_MINNIE_H_
|
||||
#define MINDSPORE_CCSRC_IR_PARAM_VALUE_MINNIE_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "ir/anf.h"
|
||||
|
||||
namespace mindspore {
|
||||
class ParamValueMinnie : public ParamValue {
|
||||
public:
|
||||
ParamValueMinnie() : tensor_addr_(nullptr), tensor_size_(0) {}
|
||||
virtual ~ParamValueMinnie() = default;
|
||||
|
||||
size_t tensor_size() const { return tensor_size_; }
|
||||
void set_tensor_size(size_t size) { tensor_size_ = size; }
|
||||
|
||||
void *tensor_addr() const { return tensor_addr_; }
|
||||
void set_tensor_addr(void *addr) { tensor_addr_ = addr; }
|
||||
|
||||
private:
|
||||
void *tensor_addr_;
|
||||
size_t tensor_size_;
|
||||
};
|
||||
|
||||
using ParamValueMinniePtr = std::shared_ptr<ParamValueMinnie>;
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_CCSRC_IR_PARAM_VALUE_MINNIE_H_
|
@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Copyright 2020 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_CCSRC_IR_PARAM_VALUE_PY_H_
|
||||
#define MINDSPORE_CCSRC_IR_PARAM_VALUE_PY_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "ir/anf.h"
|
||||
#include "pybind11/pybind11.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace py = pybind11;
|
||||
|
||||
class ParamValuePy : public ParamValue {
|
||||
public:
|
||||
ParamValuePy() : value_(py::none()) {}
|
||||
explicit ParamValuePy(py::object value) : value_(value) {}
|
||||
virtual ~ParamValuePy() = default;
|
||||
|
||||
py::object value() { return value_; }
|
||||
void set_value(const py::object &obj) { value_ = obj; }
|
||||
|
||||
private:
|
||||
py::object value_;
|
||||
};
|
||||
|
||||
using ParamValuePyPtr = std::shared_ptr<ParamValuePy>;
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_CCSRC_IR_PARAM_VALUE_PY_H_
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue