-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathembedding.h
More file actions
53 lines (41 loc) · 1.29 KB
/
embedding.h
File metadata and controls
53 lines (41 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// embedding.h
// Embedding layer module
#ifndef TINYTENSOR_NN_EMBEDDING_H_
#define TINYTENSOR_NN_EMBEDDING_H_
#include <tt/device.h>
#include <tt/export.h>
#include <tt/nn/module.h>
#include <tt/scalar.h>
#include <tt/tensor.h>
#include <memory>
#include <ostream>
#include <string>
namespace tinytensor::nn {
// An embedding layer
class TINYTENSOR_EXPORT Embedding : public Module {
public:
/**
* Construct a linear layer
* @param num_embeddings Number of embeddings
* @param embedding_dim Dimension for each embedding vector
* @param dtype The dtype of the weights
* @param device The device the weights should be initialized on
*/
Embedding(int num_embeddings, int embedding_dim, ScalarType dtype = kDefaultFloat, Device device = kCPU);
/**
* Forward pass for Embedding layer
* @param input The input tensor, of integral type
* @return Output tensor
*/
[[nodiscard]] auto forward(const Tensor &input) const -> Tensor;
void pretty_print(std::ostream &os) const override;
[[nodiscard]] auto name() const -> std::string override {
return "Embedding";
}
std::shared_ptr<Tensor> weight;
private:
int num_embeddings_;
int embedding_dim_;
};
} // namespace tinytensor::nn
#endif // TINYTENSOR_NN_EMBEDDING_H_