diff --git a/oneflow/core/eager/lazy_ref_blob_object.h b/oneflow/core/eager/lazy_ref_blob_object.h index fa83f82def4afd7ae7231766475cb3b46a014ede..5d89ea3524bd145ba95254c0181ba15a35db8cb0 100644 --- a/oneflow/core/eager/lazy_ref_blob_object.h +++ b/oneflow/core/eager/lazy_ref_blob_object.h @@ -28,8 +28,8 @@ class LazyRefBlobObject : public BlobObject { LazyRefBlobObject(Blob* blob) : BlobObject(std::make_shared<MemoryCase>(blob->mem_case()), blob->data_type()) { const auto& rt_blob_desc = blob->blob_desc(); - blob_desc_ = BlobDesc(rt_blob_desc.body(), rt_blob_desc.is_tensor_list(), - rt_blob_desc.is_body_disabled(), rt_blob_desc.is_dynamic()); + blob_desc_ = + BlobDesc(rt_blob_desc.body(), rt_blob_desc.is_tensor_list(), rt_blob_desc.is_dynamic()); ref_blob_ = blob; } virtual ~LazyRefBlobObject() override = default; diff --git a/oneflow/core/graph/chain_graph.cpp b/oneflow/core/graph/chain_graph.cpp index c41930fd8421bd265e2938c98953e0863e01f06b..83b1ac3f42c20b21f403ad0af51b4523c435c6f2 100644 --- a/oneflow/core/graph/chain_graph.cpp +++ b/oneflow/core/graph/chain_graph.cpp @@ -165,15 +165,6 @@ bool NoOutRegstConsumedByBwNode(TaskNode* node) { return true; }; -bool IsNonSoleKeepHeaderOnlyEdge(TaskNode* src_task, TaskNode* dst_task) { - if (dst_task->in_edges().size() <= 1) { return false; } - const auto* src_comp_task = dynamic_cast<CompTaskNode*>(src_task); - if (src_comp_task == nullptr) { return false; } - if (src_comp_task->logical_node()->op_vec().size() != 1) { return false; } - const auto& src_op = *src_comp_task->logical_node()->SoleOp(); - return src_op.op_conf().has_keep_header_only_conf(); -} - void CollectIgnoreTaskEdgesInFirstMergedChains(const std::vector<std::vector<TaskNode*>>& chains, HashSet<TaskEdge*>* ignore_edges) { auto HasGpuVariableOpInChain = [&](const std::vector<TaskNode*>& chain) -> bool { @@ -312,7 +303,6 @@ void ChainGraph::CollectTaskNodeAncestors(const TaskGraph& task_gph, if (ignore_edges && ignore_edges->find(in_edge) != ignore_edges->end()) { continue; } TaskNode* in_node = in_edge->src_node(); if (in_node->GetTaskType() == TaskType::kTick) { continue; } - if (IsNonSoleKeepHeaderOnlyEdge(in_node, node)) { continue; } (*node2ancestors)[node].insert(in_node); (*node2ancestors)[node].insert((*node2ancestors)[in_node].begin(), (*node2ancestors)[in_node].end()); diff --git a/oneflow/core/graph/op_graph.cpp b/oneflow/core/graph/op_graph.cpp index c8ff8c1160960f1034cd43484567fdc6fc075e48..19bedf0038cf98e70a28f55bd87d169bc427b486 100644 --- a/oneflow/core/graph/op_graph.cpp +++ b/oneflow/core/graph/op_graph.cpp @@ -247,11 +247,11 @@ void OpNode::ConcatBlobDesc(const ParallelDesc& blob_parallel_desc, FOR_RANGE(int64_t, i, 1, same_blob_descs.size()) { CHECK(*same_blob_descs.at(i) == *same_blob_descs.at(0)); } - concatenated_blob_desc->CopyAllFrom(*same_blob_descs.at(0)); + concatenated_blob_desc->CopyFrom(*same_blob_descs.at(0)); } else { FOR_RANGE(int64_t, i, 1, blob_descs.size()) { CHECK(*blob_descs.at(i) == *blob_descs.at(0)); } // select first BlobDesc - concatenated_blob_desc->CopyAllFrom(*blob_descs.at(0)); + concatenated_blob_desc->CopyFrom(*blob_descs.at(0)); } } diff --git a/oneflow/core/graph/task_graph.cpp b/oneflow/core/graph/task_graph.cpp index 19de764b0ae54744377dd18d4a836cbdb4b796c1..3816c5fa9fe801a23d93f7b417a7e238816ef189 100644 --- a/oneflow/core/graph/task_graph.cpp +++ b/oneflow/core/graph/task_graph.cpp @@ -58,8 +58,8 @@ bool IsConnectToTickOp(const TaskNode* node) { bool IsSpecialOpNotConsiderMergeInChain(const Operator* op) { const OperatorConf& op_conf = op->op_conf(); - if (op_conf.has_variable_conf() || op_conf.has_keep_header_only_conf() || op_conf.has_tick_conf() - || op_conf.has_device_tick_conf() || op_conf.has_partial_tick_conf()) { + if (op_conf.has_variable_conf() || op_conf.has_tick_conf() || op_conf.has_device_tick_conf() + || op_conf.has_partial_tick_conf()) { return true; } return false; diff --git a/oneflow/core/job/job_conf.proto b/oneflow/core/job/job_conf.proto index c42ccd33cfb65e3deded89eed313162f6c86f7a6..157e4c4eae24e964cc144df975eceb1c929df251 100644 --- a/oneflow/core/job/job_conf.proto +++ b/oneflow/core/job/job_conf.proto @@ -224,8 +224,6 @@ message JobConfigProto { optional bool enable_auto_mixed_precision = 602 [default = false]; optional bool enable_quantization_aware_training = 603 [default = false]; - optional bool enable_keep_header_only = 700 [default = false]; - optional int64 concurrency_width = 1000 [default = 128]; map<string, AttrValue> flag_name2flag_value = 2000; diff --git a/oneflow/core/job/job_desc.h b/oneflow/core/job/job_desc.h index 04abdec2892b839d00221a549a934ffc26d62f83..eb8c44883962195656bbe45145cac166344a426e 100644 --- a/oneflow/core/job/job_desc.h +++ b/oneflow/core/job/job_desc.h @@ -68,8 +68,6 @@ class JobDesc final { bool prune_cast_to_static_shape_ops() const { return job_conf_.prune_cast_to_static_shape_ops(); } int64_t cudnn_buf_limit_mbyte() const { return job_conf_.cudnn_buf_limit_mbyte(); } - bool enable_keep_header_only() const { return job_conf_.enable_keep_header_only(); } - bool has_xrt_config() const { return job_conf_.has_xrt_config(); } const XrtConfig& xrt_config() const { return job_conf_.xrt_config(); } diff --git a/oneflow/core/job/oneflow.cpp b/oneflow/core/job/oneflow.cpp index c2b1c236fa144b18801513ec0382bd88e060e10b..558ed10c8bbe16cb6a4f281eb8ef600eba798def 100644 --- a/oneflow/core/job/oneflow.cpp +++ b/oneflow/core/job/oneflow.cpp @@ -866,8 +866,7 @@ void AddJobName2JobId(const std::string& job_name, int64_t job_id) { } bool NeedAllocateMemory(const RegstDescTypeProto& regst_desc_type) { - return regst_desc_type.has_data_regst_desc() - && regst_desc_type.data_regst_desc().packed_blob_desc().is_body_disabled() == false; + return regst_desc_type.has_data_regst_desc(); } void FinishGlobalCriticalSectionDesc(const Plan& plan, int64_t job_size) { diff --git a/oneflow/core/job_rewriter/add_keep_header_only_op_conf.cpp b/oneflow/core/job_rewriter/add_keep_header_only_op_conf.cpp deleted file mode 100644 index 5383bb190638e547b50496c87def8894c1484b33..0000000000000000000000000000000000000000 --- a/oneflow/core/job_rewriter/add_keep_header_only_op_conf.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* -Copyright 2020 The OneFlow Authors. All rights reserved. - -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 "oneflow/core/job_rewriter/add_keep_header_only_op_conf.h" -#include "oneflow/core/job/job_desc.h" - -namespace oneflow { - -void AddKeepHeaderOnlyOp(const OpGraph& op_graph, JobBuilder* job_builder) { - std::vector<OperatorConf> op_confs; - op_graph.TopoForEachNode([&](OpNode* node) { - const PbRpf<std::string>& ibns = node->op().input_bns(); - std::vector<std::string> header_only_ibns; - for (const std::string& ibn : ibns) { - if (node->op().InputBlobModifier4Ibn(ibn).use_header_only()) { - header_only_ibns.push_back(ibn); - } - } - if (header_only_ibns.empty()) { return; } - CHECK(node->op().op_conf().has_tick_conf() == false); - auto OpEdge4Lbi = [node](const LogicalBlobId& lbi) -> OpEdge* { - for (OpEdge* edge : node->in_edges()) { - for (const LogicalBlobId& edge_lbi : edge->lbis()) { - if (lbi == edge_lbi) { return edge; } - } - } - UNIMPLEMENTED(); - return nullptr; - }; - HashMap<OpNode*, std::vector<std::string>> src_node2ibns; - for (const std::string& ibn : header_only_ibns) { - const LogicalBlobId& lbi = node->op().BnInOp2Lbi(ibn); - OpNode* src_node = OpEdge4Lbi(lbi)->src_node(); - if (src_node->parallel_desc() != node->parallel_desc()) { - LOG(WARNING) << "can not enable KeepHeaderOnly for " << ibn << " of " - << node->op().op_name(); - continue; - } - if (src_node->SbpParallel4Lbi(lbi) != node->SbpParallel4BnInOp(ibn)) { - LOG(WARNING) << "can not enable KeepHeaderOnly for " << ibn << " of " - << node->op().op_name(); - continue; - } - src_node2ibns[src_node].push_back(ibn); - } - OperatorConf dst_op_conf = node->op().op_conf(); - for (const auto& pair : src_node2ibns) { - OpNode* src_node = pair.first; - const std::vector<std::string>& cur_ibns = pair.second; - const LogicalBlobId& lbi = node->op().BnInOp2Lbi(cur_ibns.at(0)); - OpEdge* edge = OpEdge4Lbi(lbi); - - for (const std::string& ibn : cur_ibns) { - const LogicalBlobId& cur_lbi = node->op().BnInOp2Lbi(ibn); - OpEdge* cur_edge = OpEdge4Lbi(cur_lbi); - CHECK(lbi.op_name() == cur_lbi.op_name()); - CHECK(edge == cur_edge); - - OperatorConf op_conf; - op_conf.set_name("SrcOp-" + src_node->op().op_name() + "-SrcBlob-" + cur_lbi.blob_name() - + "-DstOp-" + node->op().op_name() + "-DstBlob-" + ibn - + "-keep_header_only"); - KeepHeaderOnlyOpConf* kho_conf = op_conf.mutable_keep_header_only_conf(); - - *(kho_conf->mutable_in()->Add()) = GenLogicalBlobName(cur_lbi); - *(kho_conf->mutable_out()->Add()) = cur_lbi.blob_name(); - - std::string lbn = op_conf.name() + "/" + cur_lbi.blob_name(); - const auto& old_val = ReplaceInputLbnInOpCustomizedConf(&dst_op_conf, ibn, lbn); - CHECK_EQ(GenLogicalBlobName(cur_lbi), old_val); - job_builder->AddOps(src_node->parallel_desc().parallel_conf(), - std::vector<OperatorConf>{op_conf}); - } - } - // make sure an op_conf can only be udpated once - job_builder->MutOpsOnlyOnce(std::vector<OperatorConf>{dst_op_conf}); - }); -} - -} // namespace oneflow diff --git a/oneflow/core/job_rewriter/add_keep_header_only_op_conf.h b/oneflow/core/job_rewriter/add_keep_header_only_op_conf.h deleted file mode 100644 index 82a263b823212f106d31ea554dbf84cd2fb2745b..0000000000000000000000000000000000000000 --- a/oneflow/core/job_rewriter/add_keep_header_only_op_conf.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -Copyright 2020 The OneFlow Authors. All rights reserved. - -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 ONEFLOW_CORE_JOB_REWRITER_ADD_KEEP_HEADER_ONLY_H_ -#define ONEFLOW_CORE_JOB_REWRITER_ADD_KEEP_HEADER_ONLY_H_ - -#include "oneflow/core/graph/op_graph.h" - -namespace oneflow { - -class OpGraph; -class Job; - -void AddKeepHeaderOnlyOp(const OpGraph& op_graph, JobBuilder* job_builder); - -} // namespace oneflow - -#endif // ONEFLOW_CORE_JOB_REWRITER_ADD_KEEP_HEADER_ONLY_H_ diff --git a/oneflow/core/job_rewriter/auto_mixed_precision_lists.cpp b/oneflow/core/job_rewriter/auto_mixed_precision_lists.cpp index 566cc0501ca2dd23c9103aff0bb1f743fb8d15db..8af9f2bb341bcaecb4ed9a917ce5710803599233 100644 --- a/oneflow/core/job_rewriter/auto_mixed_precision_lists.cpp +++ b/oneflow/core/job_rewriter/auto_mixed_precision_lists.cpp @@ -40,7 +40,7 @@ const AMPList& AutoMixedPrecisionLists::GrayList() { } const AMPList& AutoMixedPrecisionLists::ClearList() { - // TODO(niuchong): identity, tuple_identity, keep_header_only? + // TODO(niuchong): identity, tuple_identity? static AMPList clear_list = {"gather", "max_pool_1d", "max_pool_2d", diff --git a/oneflow/core/job_rewriter/job_completer.cpp b/oneflow/core/job_rewriter/job_completer.cpp index 80aa0d1e33df99b61e5e6ab0488a4944f3ea15b5..c1da7ed6618a5f3c5cd3e43987d705ccd4e062ca 100644 --- a/oneflow/core/job_rewriter/job_completer.cpp +++ b/oneflow/core/job_rewriter/job_completer.cpp @@ -17,7 +17,6 @@ limitations under the License. #include "oneflow/core/job_rewriter/job_pass.h" #include "oneflow/core/job_rewriter/autograd.h" #include "oneflow/core/job_rewriter/autotick.h" -#include "oneflow/core/job_rewriter/add_keep_header_only_op_conf.h" #include "oneflow/core/job/job_desc.h" #include "oneflow/core/job/global_for.h" #include "oneflow/core/job_rewriter/group_boxing_by_dst_parallel.h" @@ -98,9 +97,6 @@ void JobCompleter::Complete(Job* job) const { JobPassCtx job_pass_ctx(GlobalJobDesc()); JobPass4Name("DumpTimeShapeAndBlobParallelConfPass")(job, &job_pass_ctx); WithOpGraphAndMutJobBuilder(job, &GroupBoxingByDstParallel); - if (GlobalJobDesc().enable_keep_header_only()) { - WithOpGraphAndMutJobBuilder(job, &AddKeepHeaderOnlyOp); - } WithOpGraphAndMutJobBuilder(job, &SetCtrlInOpName4VariableOp); // complete tick ops WithOpGraphAndMutJobBuilder(job, &AutoPrependTick); diff --git a/oneflow/core/kernel/keep_header_only_kernel.cpp b/oneflow/core/kernel/keep_header_only_kernel.cpp deleted file mode 100644 index 0bd30b728f5ce4f08b2ca39d9b56a25a8f992674..0000000000000000000000000000000000000000 --- a/oneflow/core/kernel/keep_header_only_kernel.cpp +++ /dev/null @@ -1,22 +0,0 @@ -/* -Copyright 2020 The OneFlow Authors. All rights reserved. - -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 "oneflow/core/kernel/keep_header_only_kernel.h" - -namespace oneflow { - -ADD_DEVICE_TYPE_KERNEL_CREATOR(OperatorConf::kKeepHeaderOnlyConf, KeepHeaderOnlyKernel); - -} // namespace oneflow diff --git a/oneflow/core/kernel/keep_header_only_kernel.h b/oneflow/core/kernel/keep_header_only_kernel.h deleted file mode 100644 index c498c3a10f7300dcb7889925b0d649b44fd1dab8..0000000000000000000000000000000000000000 --- a/oneflow/core/kernel/keep_header_only_kernel.h +++ /dev/null @@ -1,38 +0,0 @@ -/* -Copyright 2020 The OneFlow Authors. All rights reserved. - -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 ONEFLOW_CORE_KERNEL_KEEP_HEADER_ONLY_KERNEL_H_ -#define ONEFLOW_CORE_KERNEL_KEEP_HEADER_ONLY_KERNEL_H_ - -#include "oneflow/core/kernel/kernel.h" -#include "oneflow/core/kernel/kernel_context.h" - -namespace oneflow { - -template<DeviceType device_type> -class KeepHeaderOnlyKernel final : public KernelIf<device_type> { - public: - OF_DISALLOW_COPY_AND_MOVE(KeepHeaderOnlyKernel); - KeepHeaderOnlyKernel() = default; - ~KeepHeaderOnlyKernel() = default; - - private: - void ForwardDataContent(const KernelCtx&, - std::function<Blob*(const std::string&)>) const override {} -}; - -} // namespace oneflow - -#endif // ONEFLOW_CORE_KERNEL_KEEP_HEADER_ONLY_KERNEL_H_ diff --git a/oneflow/core/kernel/runtime_blob_shape_infer_helper.cpp b/oneflow/core/kernel/runtime_blob_shape_infer_helper.cpp index da1bef1ab38b2d01b342ac7d639eee56baf2dc54..728d1647782e0c814cd2880bb8f0a4aa41cff39a 100644 --- a/oneflow/core/kernel/runtime_blob_shape_infer_helper.cpp +++ b/oneflow/core/kernel/runtime_blob_shape_infer_helper.cpp @@ -57,8 +57,8 @@ BlobDesc* RuntimeBlobShapeInferHelper::BlobDesc4BnInOp(const std::string& bn_in_ const RtBlobDesc& rt_blob_desc) { BlobDesc* blob_desc = bn_in_op2blob_desc_.at(bn_in_op).get(); if (blob_desc != nullptr) { return blob_desc; } - blob_desc = new BlobDesc(rt_blob_desc.body(), rt_blob_desc.is_tensor_list(), - rt_blob_desc.is_body_disabled(), rt_blob_desc.is_dynamic()); + blob_desc = + new BlobDesc(rt_blob_desc.body(), rt_blob_desc.is_tensor_list(), rt_blob_desc.is_dynamic()); bn_in_op2blob_desc_.at(bn_in_op).reset(blob_desc); return blob_desc; } @@ -82,7 +82,6 @@ void RuntimeBlobShapeInferHelper::InferShape(std::function<Blob*(const std::stri if (blob == nullptr) { continue; } CHECK_EQ(blob->data_type(), blob_desc->data_type()); CHECK_EQ(blob->blob_desc().is_dynamic(), blob_desc->is_dynamic()); - CHECK_EQ(blob->blob_desc().is_body_disabled(), blob_desc->is_body_disabled()); } return std::shared_ptr<const OpInferCacheValue>(ret); }; diff --git a/oneflow/core/kernel/user_kernel.cpp b/oneflow/core/kernel/user_kernel.cpp index d4e4a188f7d2c3f57970ccaaf0802d1d623c5bce..7625577eaae46356dafc377e623a80da35d116ac 100644 --- a/oneflow/core/kernel/user_kernel.cpp +++ b/oneflow/core/kernel/user_kernel.cpp @@ -39,7 +39,6 @@ void FillTensorDescWithBlob(const Blob* blob, user_op::TensorDesc* tensor_desc) blob->blob_desc().header_pod_desc().ToProto(proto.mutable_header()); blob->blob_desc().body().ToProto(proto.mutable_body()); proto.set_is_tensor_list(blob->blob_desc().is_tensor_list()); - proto.set_is_body_disabled(blob->blob_desc().is_body_disabled()); proto.set_is_dynamic(blob->blob_desc().is_dynamic()); proto.set_header_is_opaque(blob->blob_desc().header_is_opaque()); *tensor_desc = proto; diff --git a/oneflow/core/operator/arg_modifier_signature.proto b/oneflow/core/operator/arg_modifier_signature.proto index 91fb9e5ef06ec0ca1f0f2e3a263f5dd781c6742a..f36f51ce5dc0caf2e8e2d2902a79878182b06bc0 100644 --- a/oneflow/core/operator/arg_modifier_signature.proto +++ b/oneflow/core/operator/arg_modifier_signature.proto @@ -3,7 +3,6 @@ package oneflow; message InputBlobModifier { optional bool is_mutable = 1 [default = false]; - optional bool use_header_only = 2 [default = false]; optional bool requires_grad = 3 [default = false]; } diff --git a/oneflow/core/operator/broadcast_to_compatible_with_op.cpp b/oneflow/core/operator/broadcast_to_compatible_with_op.cpp index c386a2aadacf1e58fa391e614c760065c1824925..51a29155358e63cb13a02610a9b45b62f4e73106 100644 --- a/oneflow/core/operator/broadcast_to_compatible_with_op.cpp +++ b/oneflow/core/operator/broadcast_to_compatible_with_op.cpp @@ -47,10 +47,6 @@ class BroadcastToCompatibleWithOp final : public Operator { CHECK(op_conf().has_broadcast_to_compatible_with_conf()); EnrollInputBn("x"); EnrollRepeatedInputBn("compatible", false); - FOR_RANGE(int, i, 0, op_conf().broadcast_to_compatible_with_conf().compatible_size()) { - InputBlobModifier* modifer = MutInputBlobModifier4Ibn(GenRepeatedBn("compatible", i)); - modifer->set_use_header_only(true); - } EnrollOutputBn("y"); } @@ -65,7 +61,7 @@ class BroadcastToCompatibleWithOp final : public Operator { GetBroadcastShape(broadcasted_shape, compatible_i->shape(), &broadcasted_shape); } BlobDesc* y_desc = GetBlobDesc4BnInOp("y"); - y_desc->CopyMetaFrom(*x_desc); + y_desc->CopyFrom(*x_desc); y_desc->mut_shape() = broadcasted_shape; return Maybe<void>::Ok(); } diff --git a/oneflow/core/operator/dynamic_reshape_op.cpp b/oneflow/core/operator/dynamic_reshape_op.cpp index 92661cfb4c560bbf00a4cdabb032ff0ed00cdb35..40b46226c97d1c8a2345f70423fd4fc9d886bdd2 100644 --- a/oneflow/core/operator/dynamic_reshape_op.cpp +++ b/oneflow/core/operator/dynamic_reshape_op.cpp @@ -93,14 +93,14 @@ class DynamicReshapeLikeOp final : public Operator { CHECK(op_conf().has_dynamic_reshape_like_conf()); EnrollInputBn("x"); EnrollOutputBn("y"); - EnrollInputBn("like", false)->set_use_header_only(true); + EnrollInputBn("like", false); } Maybe<void> InferOutBlobDescs(std::function<BlobDesc*(const std::string&)> GetBlobDesc4BnInOp, const ParallelContext* parallel_ctx, const SbpSignature* sbp_signature) const override { CHECK_EQ_OR_RETURN(GetBlobDesc4BnInOp("x")->shape().elem_cnt(), GetBlobDesc4BnInOp("like")->shape().elem_cnt()); - GetBlobDesc4BnInOp("y")->CopyMetaFrom(*GetBlobDesc4BnInOp("like")); + GetBlobDesc4BnInOp("y")->CopyFrom(*GetBlobDesc4BnInOp("like")); return Maybe<void>::Ok(); } diff --git a/oneflow/core/operator/keep_header_only_op.cpp b/oneflow/core/operator/keep_header_only_op.cpp deleted file mode 100644 index 9aba44d2eee2cffff9f95f88a2a7c353ad470c38..0000000000000000000000000000000000000000 --- a/oneflow/core/operator/keep_header_only_op.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* -Copyright 2020 The OneFlow Authors. All rights reserved. - -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 "oneflow/core/operator/keep_header_only_op.h" -#include "oneflow/core/job/sbp_signature_builder.h" - -namespace oneflow { - -void KeepHeaderOnlyOp::InitFromOpConf() { - CHECK(op_conf().has_keep_header_only_conf()); - CHECK_EQ(op_conf().keep_header_only_conf().in().size(), - op_conf().keep_header_only_conf().out().size()); - EnrollRepeatedInputBn("in", false); - EnrollRepeatedOutputBn("out", false); -} - -Maybe<void> KeepHeaderOnlyOp::InferOutBlobDescs( - std::function<BlobDesc*(const std::string&)> GetBlobDesc4BnInOp, - const ParallelContext* parallel_ctx, const SbpSignature* sbp_signature) const { - size_t in_num = op_conf().keep_header_only_conf().in().size(); - for (size_t i = 0; i < in_num; ++i) { - BlobDesc* out = GetBlobDesc4BnInOp(GenRepeatedBn("out", i)); - *out = *GetBlobDesc4BnInOp(GenRepeatedBn("in", i)); - out->set_is_body_disabled(true); - } - return Maybe<void>::Ok(); -} - -Maybe<void> KeepHeaderOnlyOp::InferBatchAxis( - std::function<OptInt64*(const std::string&)> BatchAxis4BnInOp) const { - size_t in_num = op_conf().keep_header_only_conf().in().size(); - for (size_t i = 0; i < in_num; ++i) { - *BatchAxis4BnInOp(GenRepeatedBn("out", i)) = *BatchAxis4BnInOp(GenRepeatedBn("in", i)); - } - return Maybe<void>::Ok(); -} - -Maybe<void> KeepHeaderOnlyOp::GetSbpSignatures( - const std::function<Maybe<const BlobDesc&>(const std::string&)>& LogicalBlobDesc4Ibn, - SbpSignatureList* sbp_sig_list) const { - int64_t num_axes = JUST(LogicalBlobDesc4Ibn(SoleIbn())).shape().NumAxes(); - SbpSignatureBuilder() - .Split(input_bns(), 0) - .Split(output_bns(), 0) - .MakeSplitSignatureListBuilder(num_axes) - .Build(sbp_sig_list); - SbpSignatureBuilder() - .PartialSum(input_bns()) - .PartialSum(output_bns()) - .Build(sbp_sig_list->mutable_sbp_signature()->Add()); - return Maybe<void>::Ok(); -} - -REGISTER_OP(OperatorConf::kKeepHeaderOnlyConf, KeepHeaderOnlyOp); -REGISTER_OP_SAME_OUTPUT_BLOB_REGST_NUM(OperatorConf::kKeepHeaderOnlyConf, 100); -} // namespace oneflow diff --git a/oneflow/core/operator/keep_header_only_op.h b/oneflow/core/operator/keep_header_only_op.h deleted file mode 100644 index da7d04238f360e6e5ca14e2d8d465d55537e188d..0000000000000000000000000000000000000000 --- a/oneflow/core/operator/keep_header_only_op.h +++ /dev/null @@ -1,46 +0,0 @@ -/* -Copyright 2020 The OneFlow Authors. All rights reserved. - -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 ONEFLOW_CORE_OPERATOR_KEEP_HEADER_ONLY_OP_H_ -#define ONEFLOW_CORE_OPERATOR_KEEP_HEADER_ONLY_OP_H_ - -#include "oneflow/core/graph/logical_node.h" - -namespace oneflow { - -class KeepHeaderOnlyOp final : public Operator { - public: - OF_DISALLOW_COPY_AND_MOVE(KeepHeaderOnlyOp); - KeepHeaderOnlyOp() = default; - ~KeepHeaderOnlyOp() override = default; - - void InitFromOpConf() override; - - Maybe<void> InferOutBlobDescs(std::function<BlobDesc*(const std::string&)> GetBlobDesc4BnInOp, - const ParallelContext* parallel_ctx, - const SbpSignature* sbp_signature) const override; - - private: - Maybe<void> InferBatchAxis( - std::function<OptInt64*(const std::string&)> BatchAxis4BnInOp) const override; - - Maybe<void> GetSbpSignatures( - const std::function<Maybe<const BlobDesc&>(const std::string&)>& LogicalBlobDesc4Ibn, - SbpSignatureList* sbp_sig_list) const override; -}; - -} // namespace oneflow - -#endif // ONEFLOW_CORE_OPERATOR_KEEP_HEADER_ONLY_OP_H_ diff --git a/oneflow/core/operator/op_conf.proto b/oneflow/core/operator/op_conf.proto index 105b7b8a77bac270a01e36d28e1462e57052f3a0..8e546774f86ac9823e9829095a14bc5fb036b5c0 100644 --- a/oneflow/core/operator/op_conf.proto +++ b/oneflow/core/operator/op_conf.proto @@ -305,11 +305,6 @@ message SinkTickOpConf { required string out = 2; } -message KeepHeaderOnlyOpConf { - repeated string in = 1; - repeated string out = 2; -} - message TotalLossInstanceNumOpConf { repeated string in = 1; required string out = 2; @@ -619,7 +614,6 @@ message OperatorConf { AccumulateOpConf accumulate_conf = 117; VariableOpConf variable_conf = 122; TickOpConf tick_conf = 124; - KeepHeaderOnlyOpConf keep_header_only_conf = 125; TotalLossInstanceNumOpConf total_loss_instance_num_conf = 126; ShapeElemCntOpConf shape_elem_cnt_conf = 132; SrcSubsetTickOpConf src_subset_tick_conf = 133; diff --git a/oneflow/core/operator/shape_elem_cnt_op.cpp b/oneflow/core/operator/shape_elem_cnt_op.cpp index cd7290b47a3b6c161a519ae9b6e4df77e971b232..9fb16a4eb171e327f5971ebdbc7c86116b31c48e 100644 --- a/oneflow/core/operator/shape_elem_cnt_op.cpp +++ b/oneflow/core/operator/shape_elem_cnt_op.cpp @@ -50,7 +50,7 @@ HashSet<int32_t> GetInclusiveAxes(const ShapeElemCntOpConf& conf, int32_t num_ax } // namespace void ShapeElemCntOp::InitFromOpConf() { - EnrollInputBn("x", false)->set_use_header_only(true); + EnrollInputBn("x", false); EnrollOutputBn("y", false); } diff --git a/oneflow/core/operator/user_op.cpp b/oneflow/core/operator/user_op.cpp index 63c9361d983ec2f2bc2553935aa8ac5fe1ba0474..668176368493b6bfe4900259582c233b497a0bb0 100644 --- a/oneflow/core/operator/user_op.cpp +++ b/oneflow/core/operator/user_op.cpp @@ -428,7 +428,7 @@ Maybe<void> UserOp::InferOutBlobDescs( BlobDesc* first_in_blob_desc = FindValidBlobDescOfBnsInOp(GetBlobDesc4BnInOp, input_bns()); if (first_in_blob_desc) { for (const std::string& obn : output_bns()) { - GetBlobDesc4BnInOp(obn)->CopyMetaFrom(*first_in_blob_desc); + GetBlobDesc4BnInOp(obn)->CopyFrom(*first_in_blob_desc); } } diff --git a/oneflow/core/register/blob_desc.cpp b/oneflow/core/register/blob_desc.cpp index f0b22544b403c1865c5a21f79432b9afd0246a56..fc236565c3259bfd660fc1b64f2e113c2ce3638b 100644 --- a/oneflow/core/register/blob_desc.cpp +++ b/oneflow/core/register/blob_desc.cpp @@ -32,7 +32,6 @@ std::unique_ptr<BlobDesc> ComputePackedBlobDesc( } RtBlobDesc rt_blob_desc(*(pair.second)); // CHECK(!rt_blob_desc.is_dynamic()); - CHECK(!rt_blob_desc.is_body_disabled()); body_byte_size += rt_blob_desc.AlignedByteSizeOfBlobBody(); *opaque_header_pod_desc.MutStructField(NewFieldId(pair.first)) = rt_blob_desc.header_pod_desc(); } @@ -48,11 +47,7 @@ bool CompareLbiBlobDescPair(const LbiBlobDescPair& lhs, const LbiBlobDescPair& r } BlobDesc::BlobDesc(const Shape& shape, DataType dtype) - : body_(shape, dtype), - is_tensor_list_(false), - is_body_disabled_(false), - is_dynamic_(false), - opaque_header_() {} + : body_(shape, dtype), is_tensor_list_(false), is_dynamic_(false), opaque_header_() {} BlobDesc::BlobDesc(const BlobDescProto& proto) { InitFromProto(proto); } @@ -61,7 +56,6 @@ BlobDesc::BlobDesc(const BlobDesc& other) { // body_.set_data_type(other.body_.data_type()); // header_ = other.header_; // is_tensor_list_ = other.is_tensor_list_; - // is_body_disabled_ = other.is_body_disabled_; BlobDescProto proto; other.ToProto(&proto); InitFromProto(proto); @@ -70,7 +64,6 @@ BlobDesc::BlobDesc(const BlobDesc& other) { void BlobDesc::InitFromProto(const BlobDescProto& proto) { body_.InitFromProto(proto.body()); is_tensor_list_ = proto.is_tensor_list(); - is_body_disabled_ = proto.is_body_disabled(); is_dynamic_ = proto.is_dynamic(); if (proto.header_is_opaque()) { opaque_header_.reset(new StructPodDesc(proto.header())); @@ -82,7 +75,6 @@ void BlobDesc::InitFromProto(const BlobDescProto& proto) { void BlobDesc::ToProto(BlobDescProto* proto) const { body_.ToProto(proto->mutable_body()); proto->set_is_tensor_list(is_tensor_list_); - proto->set_is_body_disabled(is_body_disabled_); proto->set_is_dynamic(is_dynamic_); if (opaque_header_) { @@ -113,7 +105,6 @@ void BlobDesc::ToProto(BlobDescProto* proto) const { } BlobDesc& BlobDesc::operator=(const BlobDesc& rhs) { - CHECK(rhs.is_body_disabled() == false); // prevent from misuse this->CopyFrom(rhs); return *this; } @@ -124,13 +115,6 @@ void BlobDesc::CopyFrom(const BlobDesc& other) { this->InitFromProto(proto); } -// TODO(niuchong) : remove is_body_disabled from blob into register -void BlobDesc::CopyMetaFrom(const BlobDesc& other) { - bool tmp = is_body_disabled_; - CopyFrom(other); - is_body_disabled_ = tmp; -} - void BlobDesc::SetOpaqueHeader(const StructPodDesc& header_pod_desc) { CHECK(!is_dynamic_); CHECK_EQ(is_tensor_list_, false); @@ -145,8 +129,7 @@ void BlobDesc::set_is_dynamic(bool is_dynamic) { bool BlobDesc::operator==(const BlobDesc& rhs) const { return (body_ == rhs.body_) && (is_tensor_list_ == rhs.is_tensor_list_) - && (is_body_disabled_ == rhs.is_body_disabled_) && (is_dynamic_ == rhs.is_dynamic_) - && (opaque_header_ == rhs.opaque_header_); + && (is_dynamic_ == rhs.is_dynamic_) && (opaque_header_ == rhs.opaque_header_); } } // namespace oneflow diff --git a/oneflow/core/register/blob_desc.h b/oneflow/core/register/blob_desc.h index b0e2649d1931556671068177b86cc70cfc6bda94..a5079941b81a50930ef2512f04b944b66b90bef4 100644 --- a/oneflow/core/register/blob_desc.h +++ b/oneflow/core/register/blob_desc.h @@ -33,11 +33,8 @@ class BlobDesc final { explicit BlobDesc(DataType dtype) : BlobDesc(Shape(), dtype) {} explicit BlobDesc(const BlobDescProto& proto); explicit BlobDesc(const BlobDesc&); - BlobDesc(const TensorPodDesc& body, bool is_tensor_list, bool is_body_disabled, bool is_dynamic) - : body_(body), - is_tensor_list_(is_tensor_list), - is_body_disabled_(is_body_disabled), - is_dynamic_(is_dynamic) {} + BlobDesc(const TensorPodDesc& body, bool is_tensor_list, bool is_dynamic) + : body_(body), is_tensor_list_(is_tensor_list), is_dynamic_(is_dynamic) {} static const int32_t kAlignSize = 512; @@ -53,8 +50,6 @@ class BlobDesc final { void set_data_type(DataType val) { body_.set_data_type(val); } bool is_tensor_list() const { return is_tensor_list_; } - bool is_body_disabled() const { return is_body_disabled_; } - void set_is_body_disabled(bool val) { is_body_disabled_ = val; } bool header_is_opaque() const { return opaque_header_ != nullptr; } bool is_dynamic() const { return is_dynamic_; } void set_is_dynamic(bool); @@ -63,16 +58,12 @@ class BlobDesc final { void ToProto(BlobDescProto*) const; void CopyFrom(const BlobDesc&); - // legacy interface, shouldn't use in new code - void CopyMetaFrom(const BlobDesc& other); - void CopyAllFrom(const BlobDesc& other) { CopyFrom(other); } private: void InitFromProto(const BlobDescProto& proto); TensorPodDesc body_; bool is_tensor_list_; - bool is_body_disabled_; bool is_dynamic_; // TODO(niuchong): remove opaque_header diff --git a/oneflow/core/register/blob_desc.proto b/oneflow/core/register/blob_desc.proto index a7d1482419a05e92ce0a4907bdcc6c49c260ed63..da2378c2b309f9f9e96a085ef5e2514e61466d9b 100644 --- a/oneflow/core/register/blob_desc.proto +++ b/oneflow/core/register/blob_desc.proto @@ -7,7 +7,6 @@ message BlobDescProto { required StructPodProto header = 1; required TensorPodProto body = 2; required bool is_tensor_list = 3; - required bool is_body_disabled = 4; required bool is_dynamic = 5; required bool header_is_opaque = 6; } diff --git a/oneflow/core/register/register_manager.cpp b/oneflow/core/register/register_manager.cpp index 418222732dc716249c3b4342f753372d2800da33..e36fc33610701a6f58604e742affed6307d87c01 100644 --- a/oneflow/core/register/register_manager.cpp +++ b/oneflow/core/register/register_manager.cpp @@ -29,8 +29,6 @@ namespace { void CheckBlobInRegstNotDisabled(const RegstDescProto& regst_desc) { CHECK(regst_desc.regst_desc_type().has_data_regst_desc()); - CHECK(regst_desc.regst_desc_type().data_regst_desc().packed_blob_desc().is_body_disabled() - == false); } struct PackedChunkInfo { @@ -188,7 +186,7 @@ void RegstMgr::NewBlobsInOneRegst(const std::vector<LbiBlobDescPair>& lbis, Regs regst->packed_blob_.reset( new Blob(regst->regst_desc()->mem_case(), packed_blob_desc, main_mem_ptr)); cur_header_pointer = main_mem_ptr; - if (main_mem_ptr == nullptr || packed_blob_desc->is_body_disabled()) { + if (main_mem_ptr == nullptr) { cur_body_pointer = nullptr; } else { cur_body_pointer = main_mem_ptr + packed_blob_desc->ByteSizeOfBlobHeader(); @@ -199,11 +197,9 @@ void RegstMgr::NewBlobsInOneRegst(const std::vector<LbiBlobDescPair>& lbis, Regs int64_t body_offset, int64_t header_offset) { std::unique_ptr<Blob> blob_ptr; if (cur_body_pointer == nullptr) { - CHECK(rt_regst_desc->is_body_disabled()); blob_ptr.reset(new Blob(regst->regst_desc()->mem_case(), blob_desc, cur_header_pointer + header_offset, nullptr)); } else { - CHECK(rt_regst_desc->is_body_disabled() == false); blob_ptr.reset(new Blob(regst->regst_desc()->mem_case(), blob_desc, cur_header_pointer + header_offset, cur_body_pointer + body_offset)); InitNonPODTypeBlobIfNeed(Global<MemoryAllocator>::Get(), blob_ptr.get()); diff --git a/oneflow/core/register/runtime_blob_desc.cpp b/oneflow/core/register/runtime_blob_desc.cpp index 7830ee9ec590c7b12724e38ad3f2544997871da8..07e01aaaf138538f7add94a58e5fff66c94d0f21 100644 --- a/oneflow/core/register/runtime_blob_desc.cpp +++ b/oneflow/core/register/runtime_blob_desc.cpp @@ -29,7 +29,6 @@ void RtBlobDesc::InitFromProto(const BlobDescProto& proto) { body_.InitFromProto(proto.body()); header_.InitFromProto(proto.header()); is_tensor_list_ = proto.is_tensor_list(); - is_body_disabled_ = proto.is_body_disabled(); is_dynamic_ = proto.is_dynamic(); header_is_opaque_ = proto.header_is_opaque(); } @@ -48,8 +47,8 @@ size_t RtBlobDesc::AlignedTotalByteSize() const { bool RtBlobDesc::operator==(const RtBlobDesc& rhs) const { return (body_ == rhs.body_) && (header_ == rhs.header_) - && (is_tensor_list_ == rhs.is_tensor_list_) && (is_body_disabled_ == rhs.is_body_disabled_) - && (is_dynamic_ == rhs.is_dynamic_) && (header_is_opaque_ == rhs.header_is_opaque_); + && (is_tensor_list_ == rhs.is_tensor_list_) && (is_dynamic_ == rhs.is_dynamic_) + && (header_is_opaque_ == rhs.header_is_opaque_); } } // namespace oneflow diff --git a/oneflow/core/register/runtime_blob_desc.h b/oneflow/core/register/runtime_blob_desc.h index 38f9d067b2286a78900e3c8024c4e47bceb0ac9f..fa383ba59846213f165779388565a4b308c62ecb 100644 --- a/oneflow/core/register/runtime_blob_desc.h +++ b/oneflow/core/register/runtime_blob_desc.h @@ -32,7 +32,6 @@ class RtBlobDesc final { explicit RtBlobDesc(const BlobDescProto& blob_desc_proto); const StructPodDesc& header_pod_desc() const { return header_; } - bool is_body_disabled() const { return is_body_disabled_; } bool is_tensor_list() const { return is_tensor_list_; } bool is_dynamic() const { return is_dynamic_; } bool header_is_opaque() const { return header_is_opaque_; } @@ -56,7 +55,6 @@ class RtBlobDesc final { TensorPodDesc body_; StructPodDesc header_; bool is_tensor_list_; - bool is_body_disabled_; bool is_dynamic_; bool header_is_opaque_; }; diff --git a/oneflow/core/register/runtime_register_desc.cpp b/oneflow/core/register/runtime_register_desc.cpp index 022604b5a4d9a9a982db31dec99eb9c9d202d36d..d9c838db792388d68f5f9b901f671f95086636c9 100644 --- a/oneflow/core/register/runtime_register_desc.cpp +++ b/oneflow/core/register/runtime_register_desc.cpp @@ -82,18 +82,10 @@ size_t RtRegstDesc::TotalMainByteSize4AllRegst() const { } size_t RtRegstDesc::MainByteSize4OneRegst() const { - if (packed_blob_desc_->is_body_disabled()) { - if (mem_case_.has_device_cuda_mem()) { - return 0; - } else { - return packed_blob_desc_->ByteSizeOfBlobHeader(); - } + if (mem_case_.has_device_cuda_mem()) { + return packed_blob_desc_->AlignedByteSizeOfBlobBody(); } else { - if (mem_case_.has_device_cuda_mem()) { - return packed_blob_desc_->AlignedByteSizeOfBlobBody(); - } else { - return packed_blob_desc_->AlignedTotalByteSize(); - } + return packed_blob_desc_->AlignedTotalByteSize(); } } diff --git a/oneflow/core/register/runtime_register_desc.h b/oneflow/core/register/runtime_register_desc.h index a76f2166d480fd7ff7b2f2546310adbcc589e917..31c98ed65d6ecd36b9e6420380e6c5d462effbd1 100644 --- a/oneflow/core/register/runtime_register_desc.h +++ b/oneflow/core/register/runtime_register_desc.h @@ -49,7 +49,6 @@ class RtRegstDesc { size_t SeparatedHeaderByteSize4OneRegst() const; size_t MainByteSize4OneRegst() const; const Shape& data_regst_time_shape() const; - bool is_body_disabled() const { return packed_blob_desc_->is_body_disabled(); } void ForEachBlobDescOffsetInOnRegst( const std::function<void(int64_t ordinal, const LogicalBlobId& lbi, const RtBlobDesc* desc, diff --git a/oneflow/python/framework/function_util.py b/oneflow/python/framework/function_util.py index 7efd16a672e0d1a89a419b724ba6100a07e0abbf..ad051e2825fd9a5e5de783fb7c246dec57693454 100644 --- a/oneflow/python/framework/function_util.py +++ b/oneflow/python/framework/function_util.py @@ -744,13 +744,13 @@ def set_enable_auto_mixed_precision(func_desc, value=True): @oneflow_function_config("enable_keep_header_only") def set_enable_keep_header_only(func_desc, value=True): - r"""Whether keep header only or not + r"""deprecated api. Args: func_desc ([type]): [description] value (bool, optional): [description]. Defaults to True. """ - func_desc.job_config_proto.set_enable_keep_header_only(value) + print("Sorry! enable_keep_header_only is deprecated and it doesn't work.\n") @oneflow_function_config("concurrency_width") diff --git a/oneflow/python/test/ops/test_TestReshape4KeepHeaderOnly.py b/oneflow/python/test/ops/test_TestReshape4KeepHeaderOnly.py deleted file mode 100644 index 4d56f0ca7fbc48b8fcc03ad9a03ce877b4e87efe..0000000000000000000000000000000000000000 --- a/oneflow/python/test/ops/test_TestReshape4KeepHeaderOnly.py +++ /dev/null @@ -1,102 +0,0 @@ -""" -Copyright 2020 The OneFlow Authors. All rights reserved. - -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. -""" -import unittest -import os -from collections import OrderedDict - -import numpy as np -import oneflow as flow -import tensorflow as tf -import test_global_storage -from test_util import GenArgList - -gpus = tf.config.experimental.list_physical_devices("GPU") -for gpu in gpus: - tf.config.experimental.set_memory_growth(gpu, True) - - -def TestReshape(x, shape, name): - return ( - flow.user_op_builder(name) - .Op("TestReshape4KeepHeaderOnly") - .Input("in", [x]) - .Output("out") - .Attr("shape", shape) - .Build() - .InferAndTryRun() - .RemoteBlobList()[0] - ) - - -def compare_with_tensorflow(device_type, input_shape, output_shape): - assert device_type in ["gpu", "cpu"] - flow.clear_default_session() - - func_config = flow.FunctionConfig() - func_config.default_data_type(flow.float) - - @flow.global_function(type="train", function_config=func_config) - def ReshapeJob(): - with flow.scope.placement(device_type, "0:0"): - x = flow.get_variable( - "x", - shape=input_shape, - dtype=flow.float, - initializer=flow.random_uniform_initializer(minval=-10, maxval=10), - trainable=True, - ) - loss = TestReshape(x, output_shape, "my_test_reshape") - flow.optimizer.SGD( - flow.optimizer.PiecewiseConstantScheduler([], [1e-4]), momentum=0 - ).minimize(loss) - - flow.watch(x, test_global_storage.Setter("x")) - flow.watch_diff(x, test_global_storage.Setter("x_diff")) - flow.watch(loss, test_global_storage.Setter("loss")) - flow.watch_diff(loss, test_global_storage.Setter("loss_diff")) - - return loss - - # OneFlow - check_point = flow.train.CheckPoint() - check_point.init() - of_out = ReshapeJob().get() - # TensorFlow - with tf.GradientTape(persistent=True) as tape: - x = tf.Variable(test_global_storage.Get("x")) - tf_out = tf.reshape(x, output_shape) - loss_diff = test_global_storage.Get("loss_diff") - tf_x_diff = tape.gradient(tf_out, x, loss_diff) - - assert np.allclose(of_out.numpy(), tf_out.numpy(), rtol=1e-5, atol=1e-5) - assert np.allclose( - test_global_storage.Get("x_diff"), tf_x_diff.numpy(), rtol=1e-5, atol=1e-5 - ) - - -@flow.unittest.skip_unless_1n1d() -class Test_TestReshape4KeepHeaderOnly(flow.unittest.TestCase): - def test_TestReshape_train_keep_header_only_grad(test_case): - arg_dict = OrderedDict() - arg_dict["device_type"] = ["gpu"] - arg_dict["input_shape"] = [(10, 10, 10)] - arg_dict["output_shape"] = [(100, 10), (10, 100), (5, 20, 10)] - for arg in GenArgList(arg_dict): - compare_with_tensorflow(*arg) - - -if __name__ == "__main__": - unittest.main() diff --git a/oneflow/python/test/ops/test_keep_header_only_cpu.py b/oneflow/python/test/ops/test_keep_header_only_cpu.py deleted file mode 100644 index cca1d085f4db538feed492c67266a2a860e6267f..0000000000000000000000000000000000000000 --- a/oneflow/python/test/ops/test_keep_header_only_cpu.py +++ /dev/null @@ -1,41 +0,0 @@ -""" -Copyright 2020 The OneFlow Authors. All rights reserved. - -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. -""" -import unittest -import numpy as np -import oneflow as flow -import oneflow.typing as oft - -func_config = flow.FunctionConfig() -func_config.default_data_type(flow.float) -func_config.default_logical_view(flow.scope.consistent_view()) - - -@flow.unittest.skip_unless_1n1d() -class TestKeepHeaderOnlyCpu(flow.unittest.TestCase): - def test_keep_header_only_cpu(test_case): - @flow.global_function(function_config=func_config) - def job(x: oft.Numpy.Placeholder((2, 3, 4), dtype=flow.float)): - with flow.scope.placement("cpu", "0:0"): - x = flow.identity(x) - return flow.math.reduced_shape_elem_cnt(x) - - test_case.assertTrue( - job(np.zeros((2, 3, 4), np.float32)).get().item() == 2 * 3 * 4 - ) - - -if __name__ == "__main__": - unittest.main() diff --git a/oneflow/user/kernels/test_kernels.cpp b/oneflow/user/kernels/test_kernels.cpp index 583decec11bc212a39c703417e5e49cecf52850c..14737629108e52c26d0c06b7592e71ce4f52ea77 100644 --- a/oneflow/user/kernels/test_kernels.cpp +++ b/oneflow/user/kernels/test_kernels.cpp @@ -106,14 +106,6 @@ class CopyIn2OutKernel final : public user_op::OpKernel { bool AlwaysComputeWhenAllOutputsEmpty() const override { return false; } }; -REGISTER_USER_KERNEL("TestReshape4KeepHeaderOnly") - .SetCreateFn<CopyIn2OutKernel>() - .SetIsMatchedHob(user_op::HobTrue()); - -REGISTER_USER_KERNEL("TestReshapeLike4KeepHeaderOnly") - .SetCreateFn<CopyIn2OutKernel>() - .SetIsMatchedHob(user_op::HobTrue()); - class TestSourceGpuKernel final : public user_op::OpKernel { public: TestSourceGpuKernel() = default; diff --git a/oneflow/user/ops/broadcast_like_op.cpp b/oneflow/user/ops/broadcast_like_op.cpp index 24c9d8fa587ce93dc27ea6173fdbbc0775f5cc06..873caac1b70c389c1c796f7b17d4ab64558f16e7 100644 --- a/oneflow/user/ops/broadcast_like_op.cpp +++ b/oneflow/user/ops/broadcast_like_op.cpp @@ -89,7 +89,6 @@ REGISTER_USER_OP("broadcast_like") const user_op::UserOpConfWrapper&) { user_op::InputArgModifier* like_modifier = GetInputArgModifierFn("like", 0); CHECK(like_modifier != nullptr); - like_modifier->set_use_header_only(true); like_modifier->set_requires_grad(false); }) .SetBatchAxisInferFn([](user_op::BatchAxisContext* ctx) -> Maybe<void> { diff --git a/oneflow/user/ops/cast_like_op.cpp b/oneflow/user/ops/cast_like_op.cpp index 69f668110ed4fb108469ab994491587dc76f318f..da01f4d8dd65805656ec9f9ab68fdbc016a7d430 100644 --- a/oneflow/user/ops/cast_like_op.cpp +++ b/oneflow/user/ops/cast_like_op.cpp @@ -34,7 +34,6 @@ REGISTER_USER_OP("cast_like") const user_op::UserOpConfWrapper&) { user_op::InputArgModifier* dtype_like_modifier = GetInputArgModifierFn("dtype_like", 0); CHECK_NOTNULL(dtype_like_modifier); - dtype_like_modifier->set_use_header_only(true); dtype_like_modifier->set_requires_grad(false); }) .SetBatchAxisInferFn([](user_op::BatchAxisContext* ctx) -> Maybe<void> { diff --git a/oneflow/user/ops/conv_op.cpp b/oneflow/user/ops/conv_op.cpp index 97e85f61d06e26c7ddb386abb4b68538ccfd4faf..6c8dbf92d2d48fb3033645be0ffbc31acad98674 100644 --- a/oneflow/user/ops/conv_op.cpp +++ b/oneflow/user/ops/conv_op.cpp @@ -306,12 +306,6 @@ REGISTER_USER_OP("conv_data_grad") .Attr<std::vector<int32_t>>("dilation_rate") .Attr<int32_t>("groups") .SetCheckAttrFn(CheckAttr<0>) - .SetInputArgModifyFn([](user_op::GetInputArgModifier GetInputArgModifierFn, - const user_op::UserOpConfWrapper&) { - user_op::InputArgModifier* x_like = GetInputArgModifierFn("x_like", 0); - CHECK_NOTNULL(x_like); - x_like->set_use_header_only(true); - }) .SetTensorDescInferFn([](user_op::InferContext* ctx) -> Maybe<void> { const user_op::TensorDesc* dy = ctx->TensorDesc4ArgNameAndIndex("dy", 0); const user_op::TensorDesc* x_like = ctx->TensorDesc4ArgNameAndIndex("x_like", 0); diff --git a/oneflow/user/ops/dim_gather_op.cpp b/oneflow/user/ops/dim_gather_op.cpp index 93a67ccdf95d698fe6f545a8d27b077ef4aeda33..ffcd705e482682433a10acd4bb7cbc19b724cfae 100644 --- a/oneflow/user/ops/dim_gather_op.cpp +++ b/oneflow/user/ops/dim_gather_op.cpp @@ -149,7 +149,6 @@ REGISTER_USER_OP("dim_scatter_add_like") const user_op::UserOpConfWrapper&) { user_op::InputArgModifier* like_arg_modifier = GetInputArgModifierFn("like", 0); CHECK(like_arg_modifier != nullptr); - like_arg_modifier->set_use_header_only(true); like_arg_modifier->set_requires_grad(false); }) .SetBatchAxisInferFn([](user_op::BatchAxisContext* ctx) -> Maybe<void> { diff --git a/oneflow/user/ops/dropout_op.cpp b/oneflow/user/ops/dropout_op.cpp index 4283f7943650138ed0d5ef7d2b7a71808abb1971..609527f5d6b874157b1238470a48f91a5d24b555 100644 --- a/oneflow/user/ops/dropout_op.cpp +++ b/oneflow/user/ops/dropout_op.cpp @@ -115,12 +115,6 @@ REGISTER_USER_OP("random_mask_like") *ctx->Dtype4ArgNameAndIndex("out", 0) = DataType::kInt8; return Maybe<void>::Ok(); }) - .SetInputArgModifyFn([](user_op::GetInputArgModifier GetInputArgModifierFn, - const user_op::UserOpConfWrapper&) { - user_op::InputArgModifier* like_arg_modifier = GetInputArgModifierFn("like", 0); - CHECK(like_arg_modifier != nullptr); - like_arg_modifier->set_use_header_only(true); - }) .SetBatchAxisInferFn([](user_op::BatchAxisContext* ctx) -> Maybe<void> { *ctx->BatchAxis4ArgNameAndIndex("out", 0) = *ctx->BatchAxis4ArgNameAndIndex("like", 0); return Maybe<void>::Ok(); diff --git a/oneflow/user/ops/generate_random_batch_permutation_indices_op.cpp b/oneflow/user/ops/generate_random_batch_permutation_indices_op.cpp index c6d4fa7bcc64998e982f9b0ca89cc419f00c3be2..2ea6b5b40582f137d847a5607533773e05060d00 100644 --- a/oneflow/user/ops/generate_random_batch_permutation_indices_op.cpp +++ b/oneflow/user/ops/generate_random_batch_permutation_indices_op.cpp @@ -49,10 +49,6 @@ REGISTER_USER_OP("generate_random_batch_permutation_indices") .Build(); } return Maybe<void>::Ok(); - }) - .SetInputArgModifyFn([](user_op::GetInputArgModifier GetInputArgModifierFn, - const user_op::UserOpConfWrapper&) { - GetInputArgModifierFn("x", 0)->set_use_header_only(true); }); } // namespace oneflow diff --git a/oneflow/user/ops/nd_index_slice_ops.cpp b/oneflow/user/ops/nd_index_slice_ops.cpp index 1f77d41fb5ff4979afa73a539165633d36019e22..2b18401f6b164217d213c280f93ab556b50f07aa 100644 --- a/oneflow/user/ops/nd_index_slice_ops.cpp +++ b/oneflow/user/ops/nd_index_slice_ops.cpp @@ -258,12 +258,6 @@ REGISTER_USER_OP("scatter_nd_like") .PartialSum(user_op::OpArg("out", 0)) .Build(); return Maybe<void>::Ok(); - }) - .SetInputArgModifyFn([](user_op::GetInputArgModifier GetInputArgModifierFn, - const user_op::UserOpConfWrapper&) { - user_op::InputArgModifier* like_arg_modifier = GetInputArgModifierFn("like", 0); - CHECK(like_arg_modifier != nullptr); - like_arg_modifier->set_use_header_only(true); }); REGISTER_USER_OP("tensor_scatter_nd_update") diff --git a/oneflow/user/ops/reduce_like_ops.cpp b/oneflow/user/ops/reduce_like_ops.cpp index 1f3d5cc3e61b49c104d7793332495cceb0cf08b1..7d456fe4a8dd409e496a61e5364823c8fbd643bf 100644 --- a/oneflow/user/ops/reduce_like_ops.cpp +++ b/oneflow/user/ops/reduce_like_ops.cpp @@ -74,7 +74,6 @@ REGISTER_USER_OP("reduce_sum_like") const user_op::UserOpConfWrapper&) { user_op::InputArgModifier* like_arg_modifier = GetInputArgModifierFn("like", 0); CHECK(like_arg_modifier != nullptr); - like_arg_modifier->set_use_header_only(true); like_arg_modifier->set_requires_grad(false); }); diff --git a/oneflow/user/ops/reshape_like_op.cpp b/oneflow/user/ops/reshape_like_op.cpp index 26bc02e8f45abf5739b9b6e4415d7f4fb865413f..fc5e4489fddb04ee3c73618ef14516bf018adae7 100644 --- a/oneflow/user/ops/reshape_like_op.cpp +++ b/oneflow/user/ops/reshape_like_op.cpp @@ -34,7 +34,6 @@ REGISTER_USER_OP("reshape_like") const user_op::UserOpConfWrapper&) { user_op::InputArgModifier* like_modifier = GetInputArgModifierFn("like", 0); CHECK_NOTNULL(like_modifier); - like_modifier->set_use_header_only(true); like_modifier->set_requires_grad(false); }) .SetBatchAxisInferFn([](user_op::BatchAxisContext* ctx) -> Maybe<void> { diff --git a/oneflow/user/ops/slice_op.cpp b/oneflow/user/ops/slice_op.cpp index da200729e1ef1b843ee9751887e005eb9c4816ba..47b93a1480cb517929860875f7636d674851a6e6 100644 --- a/oneflow/user/ops/slice_op.cpp +++ b/oneflow/user/ops/slice_op.cpp @@ -156,7 +156,6 @@ void InferSliceGradInputArgModifier(user_op::GetInputArgModifier GetInputArgModi dy_modifier->set_requires_grad(false); user_op::InputArgModifier* like_modifier = GetInputArgModifierFn("like", 0); CHECK_NOTNULL(like_modifier); - like_modifier->set_use_header_only(true); like_modifier->set_requires_grad(false); } diff --git a/oneflow/user/ops/split_like_op.cpp b/oneflow/user/ops/split_like_op.cpp index c1db8fe344db9d1ff683b11dd4bc6ddba48beb4a..8136ea99a7fecccbc3dfe8625784a7d85f36906b 100644 --- a/oneflow/user/ops/split_like_op.cpp +++ b/oneflow/user/ops/split_like_op.cpp @@ -64,7 +64,6 @@ void SetLikeArgModifier(user_op::GetInputArgModifier GetInputArgModifierFn, FOR_RANGE(int32_t, i, 0, user_op_conf.input_size("like")) { user_op::InputArgModifier* like_modifier = GetInputArgModifierFn("like", i); CHECK_NOTNULL(like_modifier); - like_modifier->set_use_header_only(true); like_modifier->set_requires_grad(false); } } diff --git a/oneflow/user/ops/test_ops.cpp b/oneflow/user/ops/test_ops.cpp index ba8fda57296c220775fae6efe4a3087755a7fd5b..16f962d47cf480b43f14066f91f8ce7c2c920f8b 100644 --- a/oneflow/user/ops/test_ops.cpp +++ b/oneflow/user/ops/test_ops.cpp @@ -108,54 +108,6 @@ REGISTER_USER_OP("TestReshape") return Maybe<void>::Ok(); }); -REGISTER_USER_OP("TestReshape4KeepHeaderOnly") - .Input("in") - .Output("out") - .Attr<Shape>("shape") - .SetTensorDescInferFn([](user_op::InferContext* ctx) -> Maybe<void> { - const Shape* in_shape = ctx->Shape4ArgNameAndIndex("in", 0); - Shape* out_shape = ctx->Shape4ArgNameAndIndex("out", 0); - const Shape& conf_shape = ctx->Attr<Shape>("shape"); - CHECK_EQ(in_shape->elem_cnt(), conf_shape.elem_cnt()); - *out_shape = conf_shape; - return Maybe<void>::Ok(); - }); - -REGISTER_USER_OP("TestReshapeLike4KeepHeaderOnly") - .Input("in") - .Input("like") - .Output("out") - .SetTensorDescInferFn([](user_op::InferContext* ctx) -> Maybe<void> { - const Shape* in_shape = ctx->Shape4ArgNameAndIndex("in", 0); - const Shape* like_shape = ctx->Shape4ArgNameAndIndex("like", 0); - Shape* out_shape = ctx->Shape4ArgNameAndIndex("out", 0); - CHECK_EQ(in_shape->elem_cnt(), like_shape->elem_cnt()); - *out_shape = *like_shape; - return Maybe<void>::Ok(); - }) - .SetInputArgModifyFn([](user_op::GetInputArgModifier GetInputArgModifierFn, - const user_op::UserOpConfWrapper& conf) { - CHECK_EQ(conf.input_size("like"), 1); - user_op::InputArgModifier* like_arg_modifier = GetInputArgModifierFn("like", 0); - CHECK(like_arg_modifier != nullptr); - like_arg_modifier->set_use_header_only(true); - }); - -REGISTER_USER_OP_GRAD("TestReshape4KeepHeaderOnly") - .SetGenBackwardOpConfFn([](const user_op::UserOpWrapper& op, user_op::AddOpFn AddOp) { - if (op.NeedGenGradTensor4OpInput("in", 0)) { - user_op::UserOpConfWrapperBuilder builder(op.op_name() + "_grad"); - user_op::UserOpConfWrapper test_reshape_like_op = - builder.Op("TestReshapeLike4KeepHeaderOnly") - .Input("in", op.GetGradTensorWithOpOutput("out", 0)) - .Input("like", op.input("in", 0)) - .Output("out") - .Build(); - op.BindGradTensorWithOpInput(test_reshape_like_op.output("out", 0), "in", 0); - AddOp(test_reshape_like_op); - } - }); - REGISTER_USER_OP("TestSource") .Output("out") .SetTensorDescInferFn([](user_op::InferContext* ctx) -> Maybe<void> { diff --git a/oneflow/user/ops/unsorted_segment_sum_op.cpp b/oneflow/user/ops/unsorted_segment_sum_op.cpp index 84cd636559f51e1faa1c9593dc0be4ae6aa19fb0..b569277b4bf4939947d529a997c7250fb3dd387d 100644 --- a/oneflow/user/ops/unsorted_segment_sum_op.cpp +++ b/oneflow/user/ops/unsorted_segment_sum_op.cpp @@ -154,7 +154,6 @@ REGISTER_USER_OP("unsorted_segment_sum_like") segment_ids_modifier->set_requires_grad(false); user_op::InputArgModifier* like_modifier = GetInputArgModifierFn("like", 0); CHECK_NOTNULL(like_modifier); - like_modifier->set_use_header_only(true); like_modifier->set_requires_grad(false); }) .SetGetSbpFn([](user_op::SbpContext* ctx) -> Maybe<void> { diff --git a/oneflow/user/ops/zero_like_op.cpp b/oneflow/user/ops/zero_like_op.cpp index b3e2a37640da3db86c5036b88c4aabfffadff392..1378f1adb4602e932f76d56290121bb5e738e0ce 100644 --- a/oneflow/user/ops/zero_like_op.cpp +++ b/oneflow/user/ops/zero_like_op.cpp @@ -26,12 +26,6 @@ REGISTER_USER_OP("zero_like") *ctx->Dtype4ArgNameAndIndex("out", 0) = *ctx->Dtype4ArgNameAndIndex("like", 0); return Maybe<void>::Ok(); }) - .SetInputArgModifyFn([](user_op::GetInputArgModifier GetInputArgModifierFn, - const user_op::UserOpConfWrapper&) { - user_op::InputArgModifier* like_arg_modifier = GetInputArgModifierFn("like", 0); - CHECK(like_arg_modifier != nullptr); - like_arg_modifier->set_use_header_only(true); - }) .SetGetSbpFn([](user_op::SbpContext* ctx) -> Maybe<void> { const user_op::TensorDesc& like_tensor = ctx->LogicalTensorDesc4InputArgNameAndIndex("like", 0); diff --git a/oneflow/xrt/launch_op.cpp b/oneflow/xrt/launch_op.cpp index 4511ec1bee9943122fe809a945b269c8dc5abe39..01142c5596279b3cf6c985d22164dcdfb4f5bbe1 100644 --- a/oneflow/xrt/launch_op.cpp +++ b/oneflow/xrt/launch_op.cpp @@ -50,7 +50,7 @@ Maybe<void> XrtLaunchOp::InferOutBlobDescs( const LogicalBlobId &lbi = this->BnInOp2Lbi(bn); std::string blob_name = xrt::BlobIdToName(lbi); BlobDesc blob_desc(this->job_desc().DefaultDataType()); - blob_desc.CopyMetaFrom(*GetBlobDesc4BnInOp(bn)); + blob_desc.CopyFrom(*GetBlobDesc4BnInOp(bn)); const std::string &mapping_input = io_mapping.at(blob_name); blob_descs.emplace(mapping_input, blob_desc);