ruiite commited on
Commit
86c2406
·
verified ·
1 Parent(s): cfa7d7d

Add README.md

Browse files
Files changed (1) hide show
  1. README.md +79 -0
README.md ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Encoder-decoder architecture lab
2
+
3
+ Implement `model.py` using plain PyTorch and the supplied anonymous checkpoint.
4
+ Do not use a pretrained-model implementation from another library.
5
+
6
+ ## Dimensions
7
+
8
+ | Quantity | Value |
9
+ |---|---:|
10
+ | Stored / usable vocabulary | 40,000 / 32,128 |
11
+ | Hidden width | 512 |
12
+ | Heads / head width | 8 / 64 |
13
+ | Feed-forward width | 2,048 |
14
+ | Encoder / decoder units | 7 / 7 |
15
+ | Relative buckets / maximum distance | 32 / 128 |
16
+
17
+ ```mermaid
18
+ flowchart LR
19
+ S[Source IDs] --> E[Shared token table]
20
+ E --> EN[7 encoder units]
21
+ EN --> EF[Encoder RMSNorm]
22
+ EF --> M[Encoder memory]
23
+ T[Shifted target IDs] --> D[Shared token table]
24
+ D --> DE[7 decoder units]
25
+ M -->|K and V| DE
26
+ DE --> DF[Decoder RMSNorm]
27
+ DF --> SC[Scale by 512^-0.5]
28
+ SC --> LM[Tied token-table projection]
29
+ LM --> V[First 32,128 logits]
30
+ ```
31
+
32
+ ### Encoder unit
33
+
34
+ ```mermaid
35
+ flowchart LR
36
+ X[x] --> N1[RMSNorm] --> SA[Bidirectional self-attention<br/>relative-position bias] --> R1((+))
37
+ X --> R1
38
+ R1 --> N2[RMSNorm] --> FF[Linear 512→2048<br/>ReLU<br/>Linear 2048→512] --> R2((+))
39
+ R1 --> R2
40
+ R2 --> Z[output]
41
+ ```
42
+
43
+ ### Decoder unit
44
+
45
+ ```mermaid
46
+ flowchart LR
47
+ X[x] --> N1[RMSNorm] --> SA[Causal self-attention<br/>relative-position bias] --> R1((+))
48
+ X --> R1
49
+ R1 --> N2[RMSNorm] --> CA[Cross-attention<br/>Q from decoder; K,V from memory] --> R2((+))
50
+ R1 --> R2
51
+ R2 --> N3[RMSNorm] --> FF[Linear 512→2048<br/>ReLU<br/>Linear 2048→512] --> R3((+))
52
+ R2 --> R3
53
+ R3 --> Z[output]
54
+ ```
55
+
56
+ ## Required behavior
57
+
58
+ - Use separate bias-free query, key, value, and output projections.
59
+ - Do not scale attention scores by `1/sqrt(head_width)`.
60
+ - Bucket relative positions logarithmically and look up a bias per head.
61
+ - RMSNorm uses no mean subtraction and no additive bias.
62
+ - Mask encoder padding in encoder self-attention and decoder cross-attention.
63
+ - Apply a causal mask in decoder self-attention.
64
+ - Begin generation with `decoder_start_id` and stop at `eos_id` or the length
65
+ limit.
66
+ - Return only the first `vocabulary_size` logits even though more token rows are
67
+ stored.
68
+
69
+ Load `safetensor_encoder_decoder.safetensors`. Module names must match its
70
+ neutral hierarchy: `tokens`, `encoder_units`, `decoder_units`, `self_mix`,
71
+ `cross_mix`, `feed_in`, `feed_out`, and the final normalization modules.
72
+
73
+ ## Completion criteria
74
+
75
+ - Implement every TODO in `model.py`.
76
+ - Verify padding, causal masking, and relative-position buckets.
77
+ - Return logits plus encoder and decoder hidden states.
78
+ - Encode the source once during greedy generation.
79
+ - Run `python inference.py . "translate English to German: The house is nice"`.