Butanium commited on
Commit
66d2c52
·
verified ·
1 Parent(s): 39ba05d

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +26 -10
README.md CHANGED
@@ -1,10 +1,26 @@
1
- ---
2
- tags:
3
- - model_hub_mixin
4
- - pytorch_model_hub_mixin
5
- ---
6
-
7
- This model has been pushed to the Hub using the [PytorchModelHubMixin](https://huggingface.co/docs/huggingface_hub/package_reference/mixins#huggingface_hub.PyTorchModelHubMixin) integration:
8
- - Code: [More Information Needed]
9
- - Paper: [More Information Needed]
10
- - Docs: [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 0-layer transformer described in [A Mathematical Framework for Transformer Circuits](https://transformer-circuits.pub/2021/framework/index.html).Load with ```python
2
+ class ZeroLayerTransformer(nn.Module, PyTorchModelHubMixin):
3
+ def __init__(self, config):
4
+ super().__init__()
5
+ self.config = config
6
+ self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size)
7
+ self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
8
+
9
+ def forward(self, input_ids=None, attention_mask=None, labels=None, **kwargs):
10
+ hidden_states = self.embed_tokens(input_ids)
11
+ logits = self.lm_head(hidden_states)
12
+
13
+ loss = None
14
+ if labels is not None:
15
+ shift_logits = logits[..., :-1, :].contiguous()
16
+ shift_labels = labels[..., 1:].contiguous()
17
+ loss_fct = nn.CrossEntropyLoss()
18
+ loss = loss_fct(
19
+ shift_logits.view(-1, shift_logits.size(-1)), shift_labels.view(-1)
20
+ )
21
+
22
+ return {"loss": loss, "logits": logits}
23
+
24
+
25
+ ```
26
+ model = ZeroLayerTransformer.from_pretrained('Butanium/simple-stories-zero-layer-simple-transformer')