Models Module¶
- class visualize_training.model.Attention(d_model, num_heads, d_head, n_ctx, model)¶
- forward(x)¶
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 visualize_training.model.Embed(d_vocab, d_model)¶
Define network architecture I defined my own transformer from scratch so I’d fully understand each component - I expect this wasn’t necessary or particularly important, and a bunch of this replicates existing Pyt functionality
- forward(x)¶
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 visualize_training.model.FF(d_model, d_mlp, act_type, model)¶
- forward(x)¶
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 visualize_training.model.HookPoint¶
A helper class to get access to intermediate activations (inspired by Garcon) It’s a dummy module that is the identity function by default I can wrap any intermediate activation in a HookPoint and get a convenient way to add PyTorch hooks
- forward(x)¶
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 visualize_training.model.LeNet5(num_classes=10)¶
- forward(x)¶
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 visualize_training.model.MLP(input_dim, hidden_dims, output_dim, init_scaling: float = 2.0, kaiming_uniform: bool = True, use_batch_norm: bool = False, use_layer_norm: bool = False)¶
- forward(x)¶
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 visualize_training.model.MyBasicBlock(use_batch_norm, use_residual, **kwargs)¶
- forward(x)¶
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 visualize_training.model.MyResNet(use_batch_norm, use_residual, **kwargs)¶
- class visualize_training.model.PosEmbed(max_ctx, d_model)¶
- forward(x)¶
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 visualize_training.model.ToyModel(digit_rep_dim, internal_rep_dim, encoder_width=50, encoder_depth=3, decoder_width=50, decoder_depth=3, activation=<class 'torch.nn.modules.activation.Tanh'>, device='cpu')¶
- forward(x1, x2)¶
Runs the toy model on input x.
x must contain vectors of dimension 2 * digit_rep_dim, since it represents a pair of symbols that we want to compute our binary operation between.
- class visualize_training.model.Transformer(d_model, d_head, d_vocab, num_heads, num_layers, n_ctx, act_type='ReLU', use_ln=False)¶
- forward(x)¶
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 visualize_training.model.TransformerBlock(d_model, d_mlp, d_head, num_heads, n_ctx, act_type, model, use_ln=False)¶
- forward(x)¶
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 visualize_training.model.Unembed(d_vocab, d_model)¶
- forward(x)¶
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.