From 900e435ed344399d9754f9a8ede9de619445a59e Mon Sep 17 00:00:00 2001 From: iuyu Date: Fri, 11 Dec 2020 14:41:26 +0800 Subject: [PATCH] lete embedding_lookup_sparse op --- .../lite/src/ops/embedding_lookup_sparse.cc | 89 ------------------- .../lite/src/ops/embedding_lookup_sparse.h | 48 ---------- 2 files changed, 137 deletions(-) delete mode 100644 mindspore/lite/src/ops/embedding_lookup_sparse.cc delete mode 100644 mindspore/lite/src/ops/embedding_lookup_sparse.h diff --git a/mindspore/lite/src/ops/embedding_lookup_sparse.cc b/mindspore/lite/src/ops/embedding_lookup_sparse.cc deleted file mode 100644 index 54d2cacad9..0000000000 --- a/mindspore/lite/src/ops/embedding_lookup_sparse.cc +++ /dev/null @@ -1,89 +0,0 @@ -/** - * Copyright 2019-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 "src/ops/embedding_lookup_sparse.h" - -#ifndef PRIMITIVE_WRITEABLE -#include "src/ops/ops_register.h" -#endif - -namespace mindspore { -namespace lite { -#ifdef PRIMITIVE_WRITEABLE -std::vector EmbeddingLookupSparse::GetSpIds() const { - return this->primitive_->value.AsEmbeddingLookupSparse()->spIds; -} -std::vector EmbeddingLookupSparse::GetSpWeights() const { - return this->primitive_->value.AsEmbeddingLookupSparse()->spWeights; -} -float EmbeddingLookupSparse::GetMaxNortm() const { return this->primitive_->value.AsEmbeddingLookupSparse()->maxNortm; } - -void EmbeddingLookupSparse::SetSpIds(const std::vector &sp_ids) { - this->primitive_->value.AsEmbeddingLookupSparse()->spIds = sp_ids; -} -void EmbeddingLookupSparse::SetSpWeights(const std::vector &sp_weights) { - this->primitive_->value.AsEmbeddingLookupSparse()->spWeights = sp_weights; -} -void EmbeddingLookupSparse::SetMaxNortm(float max_nortm) { - this->primitive_->value.AsEmbeddingLookupSparse()->maxNortm = max_nortm; -} - -#else -int EmbeddingLookupSparse::UnPackToFlatBuilder(const schema::Primitive *primitive, - flatbuffers::FlatBufferBuilder *fbb) { - MS_ASSERT(nullptr != primitive); - MS_ASSERT(nullptr != fbb); - auto attr = primitive->value_as_EmbeddingLookupSparse(); - if (attr == nullptr) { - MS_LOG(ERROR) << "value_as_EmbeddingLookupSparse return nullptr"; - return RET_ERROR; - } - std::vector spIds; - if (attr->spIds() != nullptr) { - for (int i = 0; i < static_cast(attr->spIds()->size()); i++) { - spIds.push_back(attr->spIds()->data()[i]); - } - } - std::vector spWeights; - if (attr->spWeights() != nullptr) { - for (int i = 0; i < static_cast(attr->spWeights()->size()); i++) { - spWeights.push_back(attr->spWeights()->data()[i]); - } - } - auto val_offset = schema::CreateEmbeddingLookupSparseDirect(*fbb, &spIds, &spWeights); - auto prim_offset = schema::CreatePrimitive(*fbb, schema::PrimitiveType_EmbeddingLookupSparse, val_offset.o); - fbb->Finish(prim_offset); - return RET_OK; -} -std::vector EmbeddingLookupSparse::GetSpIds() const { - auto fb_vector = this->primitive_->value_as_EmbeddingLookupSparse()->spIds(); - return std::vector(fb_vector->begin(), fb_vector->end()); -} -std::vector EmbeddingLookupSparse::GetSpWeights() const { - auto fb_vector = this->primitive_->value_as_EmbeddingLookupSparse()->spWeights(); - return std::vector(fb_vector->begin(), fb_vector->end()); -} -float EmbeddingLookupSparse::GetMaxNortm() const { - return this->primitive_->value_as_EmbeddingLookupSparse()->maxNortm(); -} - -PrimitiveC *EmbeddingLookupSparseCreator(const schema::Primitive *primitive) { - return PrimitiveC::NewPrimitiveC(primitive); -} -Registry EmbeddingLookupSparseRegistry(schema::PrimitiveType_EmbeddingLookupSparse, EmbeddingLookupSparseCreator); -#endif -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/src/ops/embedding_lookup_sparse.h b/mindspore/lite/src/ops/embedding_lookup_sparse.h deleted file mode 100644 index e49e08ec75..0000000000 --- a/mindspore/lite/src/ops/embedding_lookup_sparse.h +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Copyright 2019-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 LITE_MINDSPORE_LITE_C_OPS_EMBEDDING_LOOKUP_SPARSE_H_ -#define LITE_MINDSPORE_LITE_C_OPS_EMBEDDING_LOOKUP_SPARSE_H_ - -#include -#include -#include -#include -#include "src/ops/primitive_c.h" - -namespace mindspore { -namespace lite { -class EmbeddingLookupSparse : public PrimitiveC { - public: - EmbeddingLookupSparse() = default; - ~EmbeddingLookupSparse() = default; -#ifdef PRIMITIVE_WRITEABLE - MS_DECLARE_PARENT(EmbeddingLookupSparse, PrimitiveC); - explicit EmbeddingLookupSparse(schema::PrimitiveT *primitive) : PrimitiveC(primitive) {} - void SetSpIds(const std::vector &sp_ids); - void SetSpWeights(const std::vector &sp_weights); - void SetMaxNortm(float max_nortm); -#else - int UnPackToFlatBuilder(const schema::Primitive *primitive, flatbuffers::FlatBufferBuilder *fbb) override; -#endif - std::vector GetSpIds() const; - std::vector GetSpWeights() const; - float GetMaxNortm() const; -}; -} // namespace lite -} // namespace mindspore - -#endif // LITE_MINDSPORE_LITE_C_OPS_EMBEDDING_LOOKUP_SPARSE_H_