embeddingbag_packed_base.hpp
1 //*****************************************************************************
2 // Copyright 2017-2020 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //*****************************************************************************
16 
17 #pragma once
18 
19 #include "ngraph/axis_set.hpp"
20 #include "ngraph/op/util/index_reduction.hpp"
21 
22 namespace ngraph
23 {
24  namespace op
25  {
26  namespace util
27  {
28  /// \brief Returns embeddings for given indices
29  class NGRAPH_API EmbeddingBagPackedBase : public Op
30  {
31  public:
32  static constexpr NodeTypeInfo type_info{"EmbeddingBagPackedBase", 3};
33  const NodeTypeInfo& get_type_info() const override { return type_info; }
34  /// \brief Constructs a EmbeddingBagPackedBase operation.
36  /// \brief Constructs a EmbeddingBagPackedBase operation.
37  ///
38  /// EmbeddingBagPackedBase constructs an output tensor by replacing every index in a
39  /// given
40  /// input tensor with a row (from the weights matrix) at that index
41  ///
42  /// \param emb_table Tensor containing the embedding lookup table of the module of
43  /// shape [num_emb, emb_dim1, emb_dim2, ...] and of type T
44  /// \param indices Tensor of shape `[batch, indices_per_bag]` and of type *T_IND*.
45  /// Required.
46  /// \param per_sample_weigths tensor of the same shape as indices and of type T.
47  /// Each value in this tensor are multiplied with each
48  /// value pooled from embedding table for each index. Optional.
49 
50  EmbeddingBagPackedBase(const Output<Node>& emb_table,
51  const Output<Node>& indices,
52  const Output<Node>& per_sample_weights);
53 
54  EmbeddingBagPackedBase(const Output<Node>& emb_table, const Output<Node>& indices);
55 
56  void validate_and_infer_types() override;
57  bool visit_attributes(AttributeVisitor& visitor) override;
58 
59  private:
60  static constexpr int EMB_TABLE = 0;
61  static constexpr int INDICES = 1;
62  static constexpr int PER_SAMPLE_WEIGHTS = 2;
63  };
64  }
66  }
67 }
ngraph::op::util::EmbeddingBagPackedBase::EmbeddingBagPackedBase
EmbeddingBagPackedBase()=default
Constructs a EmbeddingBagPackedBase operation.
ngraph::op::util::EmbeddingBagPackedBase::get_type_info
const NodeTypeInfo & get_type_info() const override
Definition: embeddingbag_packed_base.hpp:33
ngraph::op::util::EmbeddingBagPackedBase::validate_and_infer_types
void validate_and_infer_types() override
Verifies that attributes and inputs are consistent and computes output shapes and element types....
ngraph::op::util::EmbeddingBagPackedBase
Returns embeddings for given indices.
Definition: embeddingbag_packed_base.hpp:30
ngraph
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28
ngraph::op::util::EmbeddingBagPackedBase::EmbeddingBagPackedBase
EmbeddingBagPackedBase(const Output< Node > &emb_table, const Output< Node > &indices, const Output< Node > &per_sample_weights)
Constructs a EmbeddingBagPackedBase operation.
ngraph::AttributeVisitor
Visits the attributes of a node, primarily for serialization-like tasks.
Definition: attribute_visitor.hpp:70
ngraph::op::Op
Root of all actual ops.
Definition: op.hpp:29