MCPcopy Create free account
hub / github.com/FastFlowLM/FastFlowLM / Embedding

Class Embedding

src/include/modules/embedding.hpp:15–57  ·  view source on GitHub ↗

\brief embedding class \note This is a class for the embedding layer

Source from the content-addressed store, hash-verified

13/// \brief embedding class
14/// \note This is a class for the embedding layer
15class Embedding{
16public:
17 vdtype w;
18 vdtype y;
19 int vocab_size;
20 int d_model;
21 int buffer_id;
22
23 /// \brief Constructor
24 /// \param vocab_size the vocabulary size
25 /// \param d_model the model dimension
26 Embedding(){};
27 Embedding(int vocab_size, int d_model){
28 this->vocab_size = vocab_size;
29 this->d_model = d_model;
30 this->w.resize((size_t)vocab_size * d_model);
31 this->y.resize(d_model);
32 }
33
34 /// \brief Forward pass
35 /// \param x the input tensor
36 /// \return the output tensor
37 vdtype forward(int x){
38 this->y.copy_from(this->w.begin() + (size_t)x * this->d_model, this->d_model);
39 return this->y;
40 }
41
42 /// \brief Forward pass
43 /// \param x the input tensor
44 /// \param y the output tensor
45 /// \return the output tensor
46 vdtype forward(int x, vdtype& y){
47 y.copy_from(this->w.begin() + (size_t)x * this->d_model, this->d_model);
48 return y;
49 }
50
51 /// \brief Initialize the weights
52 /// \param safe_tensors the safe tensors
53 /// \param weight_name the weight name, which is the name of the weight file
54 void init_weights(SafeTensors* safe_tensors, std::string weight_name){
55 safe_tensors->load_weights(this->w, weight_name + ".weight");
56 }
57};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected