embeddingbag_packed_base.hpp
1 // Copyright (C) 2018-2021 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 #pragma once
6 
7 #include "ngraph/axis_set.hpp"
8 #include "ngraph/op/util/index_reduction.hpp"
9 
10 namespace ngraph
11 {
12  namespace op
13  {
14  namespace util
15  {
16  /// \brief Returns embeddings for given indices
17  class NGRAPH_API EmbeddingBagPackedBase : public Op
18  {
19  public:
20  static constexpr NodeTypeInfo type_info{"EmbeddingBagPackedBase", 3};
21  const NodeTypeInfo& get_type_info() const override { return type_info; }
22  /// \brief Constructs a EmbeddingBagPackedBase operation.
24  /// \brief Constructs a EmbeddingBagPackedBase operation.
25  ///
26  /// EmbeddingBagPackedBase constructs an output tensor by replacing every index in a
27  /// given
28  /// input tensor with a row (from the weights matrix) at that index
29  ///
30  /// \param emb_table Tensor containing the embedding lookup table of the module of
31  /// shape [num_emb, emb_dim1, emb_dim2, ...] and of type T
32  /// \param indices Tensor of shape `[batch, indices_per_bag]` and of type *T_IND*.
33  /// Required.
34  /// \param per_sample_weigths tensor of the same shape as indices and of type T.
35  /// Each value in this tensor are multiplied with each
36  /// value pooled from embedding table for each index. Optional.
37 
39  const Output<Node>& indices,
40  const Output<Node>& per_sample_weights);
41 
42  EmbeddingBagPackedBase(const Output<Node>& emb_table, const Output<Node>& indices);
43 
44  void validate_and_infer_types() override;
45  bool visit_attributes(AttributeVisitor& visitor) override;
46 
47  private:
48  static constexpr int EMB_TABLE = 0;
49  static constexpr int INDICES = 1;
50  static constexpr int PER_SAMPLE_WEIGHTS = 2;
51  };
52  } // namespace util
54  } // namespace op
55 } // namespace ngraph
Visits the attributes of a node, primarily for serialization-like tasks.
Definition: attribute_visitor.hpp:59
A handle for one of a node's outputs.
Definition: node_output.hpp:33
Root of all actual ops.
Definition: op.hpp:17
Returns embeddings for given indices.
Definition: embeddingbag_packed_base.hpp:18
void validate_and_infer_types() override
Verifies that attributes and inputs are consistent and computes output shapes and element types....
EmbeddingBagPackedBase(const Output< Node > &emb_table, const Output< Node > &indices, const Output< Node > &per_sample_weights)
Constructs a EmbeddingBagPackedBase operation.
EmbeddingBagPackedBase()=default
Constructs a EmbeddingBagPackedBase operation.
const NodeTypeInfo & get_type_info() const override
Definition: embeddingbag_packed_base.hpp:21
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:16
Definition: type.hpp:27