File size: 6,404 Bytes
86b9e77
 
9261167
 
 
 
 
 
 
 
 
 
 
 
86b9e77
9261167
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
916eca2
 
 
 
 
 
 
 
 
 
9261167
 
 
 
 
 
916eca2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
---
license: mit
datasets:
- karpathy/tiny_shakespeare
language:
- en
metrics:
- accuracy
base_model:
- Bigram-Language-Model
tags:
- Transformer
- GPT
- Decoder-only
---
# Model Card for Model ID

<!-- Provide a quick summary of what the model is/does. -->

This modelcard aims to be a base template for new models. It has been generated using [this raw template](https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/templates/modelcard_template.md?plain=1).

## Model Details

This model recreates the GPT architecture scaled down just to 10.8M parameters. This Model is build entirely from Scratch.

### Model Description

<!-- Provide a longer summary of what this model is. -->



- **Developed by:** [Deepmalya Koley]
- **Funded by [optional]:** [More Information Needed]
- **Inspired by [optional]:** [Andrej Karpathy]
- **Model type:** [Transformer]
- **Language(s) (NLP):** [Decoder only]
- **License:** [MIT]
- **Evolved from model [optional]:** [BigramLanguageModel]

### Model Sources [optional]

<!-- Provide the basic links for the model. -->

- **Repository:** [(https://github.com/Deepmalya2506/From-Kernel-to-Silicon---Transformers)]

## Uses

<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
The Model replicates the exact same Decoder only Transformer architecture used in GPT. However this model is trained over 5000 epochs with Parallely processed batches of 328 vectors to predict the next token in the subsequent timestep

## Bias, Risks, and Limitations

<!-- This section is meant to convey both technical and sociotechnical limitations. -->

[The Model is a scaled down version of actual GPT architecture build entirely from scratch. It has only 10.8M params unlike GPT with Billions. The model doesnot incorporate autoregressive processings ]

### Recommendations

<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->

Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.

## How to Get Started with the Model

Use the code below to get started with the model.

[More Information Needed]

## Training Details

### Training Data

<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->

[More Information Needed]

### Training Procedure

<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->

#### Preprocessing [optional]

[More Information Needed]


#### Training Hyperparameters

- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
- batch_size = 64 # how many independent sequences will we process in parallel?
- block_size = 256 # what is the maximum context length for predictions?
- max_iters = 5000
- eval_interval = 500
- learning_rate = 3e-4
- device = 'cuda' if torch.cuda.is_available() else 'cpu' 
- eval_iters = 200
- n_embed=384
- n_head=6    # therefore every head (head_size)= 384//6 = 64 dim
- dropout=0.2


## Evaluation

<!-- This section describes the evaluation protocols and provides the results. -->

* step 0: train loss 4.3585, val loss 4.3557
* step 500: train loss 2.0170, val loss 2.0917
* step 1000: train loss 1.6125, val loss 1.7842
* step 1500: train loss 1.4475, val loss 1.6449
* step 2000: train loss 1.3575, val loss 1.5784
* step 2500: train loss 1.2872, val loss 1.5347
* step 3000: train loss 1.2367, val loss 1.5039
* step 3500: train loss 1.1909, val loss 1.4929
* step 4000: train loss 1.1529, val loss 1.4847
* step 4500: train loss 1.1201, val loss 1.4798


#### Overview & Purpose
To prevent overfitting on the 1.1M character TinyShakespeare dataset, **Dropout (0.2)** is injected into:
1. Attention softmax weights (dropping attention edges).
2. Multi-Head projection layer outputs.
3. FeedForward Network layer outputs.

#### Complete System Architecture Summary

```
====================================================================================================
Layer / Submodule               Input Shape             Output Shape            Parameters
====================================================================================================
Token Embedding Table           (B, T)                  (B, T, 384)             65 x 384 = 24,960
Positional Embedding Table      (T,)                    (T, 384)                256 x 384 = 98,304
----------------------------------------------------------------------------------------------------
Block 1..6 (x6 Stacked):
  β”œβ”€β”€ LayerNorm 1               (B, T, 384)             (B, T, 384)             2 x 384 = 768
  β”œβ”€β”€ Multi-Head Attention:
  β”‚   β”œβ”€β”€ Key Linear            (B, T, 384)             (B, T, 384)             384 x 384 = 147,456
  β”‚   β”œβ”€β”€ Query Linear          (B, T, 384)             (B, T, 384)             384 x 384 = 147,456
  β”‚   β”œβ”€β”€ Value Linear          (B, T, 384)             (B, T, 384)             384 x 384 = 147,456
  β”‚   └── Out Projection        (B, T, 384)             (B, T, 384)             384 x 384 + 384 = 147,840
  β”œβ”€β”€ LayerNorm 2               (B, T, 384)             (B, T, 384)             2 x 384 = 768
  └── FeedForward Net:
      β”œβ”€β”€ FC 1 (Expand)         (B, T, 384)             (B, T, 1536)            384 x 1536 + 1536 = 591,360
      └── FC 2 (Contract)       (B, T, 1536)            (B, T, 384)             1536 x 384 + 384 = 590,208
----------------------------------------------------------------------------------------------------
Final LayerNorm                 (B, T, 384)             (B, T, 384)             2 x 384 = 768
Language Model Head             (B, T, 384)             (B, T, 65)              384 x 65 + 65 = 25,025
====================================================================================================
Total Parameters: ~10,788,929 (~10.8 Million)
====================================================================================================
```