LLM#

class BatchMultiHeadAttention(n_heads, d_model, d_value, d_key, masked=True, dropout_p=0.2, device='cpu')[source]#

Bases: Module

This is more truthful to the paper

forward(X: Tensor)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class BatchMultiHeadAttentionV2(n_heads, d_model, d_value, d_key, masked=True, dropout_p=0.2, device='cpu')[source]#

Bases: Module

This is modern implementation for more efficient processing

forward(X: Tensor)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class FFN(in_units, out_units, dropout_p=0.2, device='cpu')[source]#

Bases: Module

forward(X)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class LLM(n_heads, d_model, d_key, d_value, n_x, vocab_size, dropout_p, device='cpu')[source]#

Bases: Module

forward(X: Tensor)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

property total_params: int#
class PositionalEmbedding(*args, **kwargs)[source]#

Bases: Module

class PositionalEncoding(d_model, context_len=10000, scale=10000, device='cpu')[source]#

Bases: Module

forward(X)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class RepeatBlock(n_heads, d_model, d_key, d_value, device, dropout_p)[source]#

Bases: Module

forward(X)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class Word2Vec(vocab_size, embedding_dims, device='cpu')[source]#

Bases: Module

forward(X: Tensor)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

generate(llm_model: LLM, emb_model: Word2Vec, tokenizer: PyBytePairTokenizer, context, max_tokens, top_k, temperature, device='cpu')[source]#
train(data_loader, llm_model: LLM, emb_model, loss_fn, optimizer, epochs, device)[source]#