HenryHHHH commited on
Commit
e2ad4c8
·
verified ·
1 Parent(s): fdb368b

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +150 -0
README.md CHANGED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ tags:
4
+ - text-generation
5
+ - knowledge-distillation
6
+ - llama
7
+ - causal-lm
8
+ - openwebtext
9
+ - wikitext
10
+ - transfer-learning
11
+ model_name: DistilLLaMA
12
+ license: apache-2.0
13
+ datasets:
14
+ - openwebtext
15
+ - wikitext
16
+ parameter_count: 80M
17
+ metrics:
18
+ - cosine-similarity
19
+ - exact-match
20
+ - rouge
21
+ library_name: transformers
22
+ base_model: meta-llama/LLaMA-2-7B
23
+ ---
24
+
25
+
26
+ ### Overview
27
+
28
+ This model is a distilled version of LLaMA 2, containing approximately 80 million parameters. It was trained using a mix of OpenWebText and WikiText Raw V1 datasets. Knowledge distillation was employed to transfer knowledge from a larger "teacher" model—Meta’s 7B LLaMA 2—to help this smaller model mimic the behavior of the teacher.
29
+
30
+ ### Model Architecture
31
+
32
+ The architecture is based on LLaMA 2, with the following parameters:
33
+ | Parameter | Value |
34
+ |-------------------------|-------|
35
+ | Hidden Dimension | 512 |
36
+ | Intermediate Dimension | 1536 |
37
+ | Max Positional Embeddings | 128 |
38
+ | Attention Heads | 8 |
39
+ | Transformer Layers | 16 |
40
+
41
+
42
+ ### Training Process
43
+
44
+ During each training step, the input data \( X \) is fed to both the teacher and student models. The student model calculates output logits and loss with the true labels, while the teacher model only generates logits. The total loss combines task-specific loss and distillation loss:
45
+
46
+ ```python
47
+ def distillation_loss(student_logits, teacher_logits, temperature=2.0):
48
+ return F.kl_div(
49
+ F.log_softmax(student_logits / temperature, dim=-1),
50
+ F.softmax(teacher_logits / temperature, dim=-1),
51
+ reduction='batchmean'
52
+ ) * (temperature ** 2)
53
+
54
+ # Loss Calculation
55
+ loss = (alpha * distill_loss) + ((1 - alpha) * task_loss)
56
+ ```
57
+
58
+ ### Training Configuration
59
+
60
+ - **Batch Size**: 64
61
+ - **Max Sequence Length**: 128
62
+ - **Epochs**: 2
63
+ - **Log Interval**: 3000
64
+ - **Learning Rate**: 3e-4
65
+ - **Warmup Steps**: 4000
66
+ - **Accumulation Steps**: 8
67
+ - **Load Model**: True
68
+ - **Temperature**: 2.0
69
+ - **Alpha**: 0.3
70
+
71
+ ### Performance Comparison
72
+
73
+ The model’s performance is evaluated on 200 queries created in-house. For more details, visit the [GitHub repository](https://github.com/svarnim1805/Knowledge-Distillation/tree/main).
74
+
75
+ #### Example Queries
76
+
77
+ | **Query** | **Keyword** |
78
+ |----------------------------------------------|-------------------|
79
+ | The capital of France is | Paris |
80
+ | The author of *To Kill a Mockingbird* is | Harper Lee |
81
+ | The planet known as the Red Planet is | Mars |
82
+ | The smallest country in the world is | Vatican City |
83
+ | The *Mona Lisa* was painted by | Leonardo da Vinci |
84
+ | The tallest mountain in the world is | Mount Everest |
85
+ | The host country of the 2016 Summer Olympics | Brazil |
86
+ | The currency of Japan is | Yen |
87
+ | The "Father of Computers" is | Charles Babbage |
88
+ | The largest ocean on Earth is | Pacific Ocean |
89
+
90
+ ### Text Generation Examples
91
+
92
+ 1. **Input**: *The capital of France is*
93
+ - **Output**: "The capital of France is located in the southern province of Lyon, France. The capital is the main hub of the French capital, La Caillion, and the main hub of the French capital. A major part of the French capital is in the southern city of Paris."
94
+
95
+ 2. **Input**: *The tallest mountain in the world is*
96
+ - **Output**: "The tallest mountain in the world is Mount Everest, which is located in the northwest corner of the village of Kahuna. The mountain is about 1,000 feet (3,000 m) above sea level."
97
+
98
+ ### Evaluation Metrics
99
+
100
+ 1. **Cosine Similarity using Word Embeddings**
101
+ - **Description**: Measures semantic similarity by mapping words/phrases to vectors.
102
+ - **Equation**: Cosine Similarity = ( A • B ) / ( ||A|| ||B|| )
103
+ - **Example**: "The dog chased the cat." vs. "A canine pursued a feline." (High similarity)
104
+
105
+ 2. **Exact Match (EM)**
106
+ - **Description**: Checks if critical keywords are present.
107
+ - **Example**:
108
+ - Expected: "Paris"
109
+ - Response: "The capital of France is Paris." (EM = 1)
110
+
111
+ 3. **ROUGE Score**
112
+ - **Description**: Measures the overlap of the longest common subsequences between reference and response texts.
113
+ - **Equation**:
114
+ - Precision = Precision = LCS(R, C) / Length of C
115
+ - Recall = Recall = LCS(R, C) / Length of R
116
+
117
+ ### Model Evaluation Summary
118
+
119
+ | Model Name | Duration (s) | Emissions (kgCO₂e) | Avg. EM | Avg. Cosine Similarity | Avg. ROUGE Score |
120
+ |-----------------|--------------|--------------------|---------|------------------------|------------------|
121
+ | LLaMA-2-7B-HF | 18215.61 | 1.84e-01 | 0.715 | 0.7257 | 0.0821 |
122
+ | baby-llama-58m | 57.20 | 2.73e-06 | 0.025 | 0.6556 | 0.0097 |
123
+ | DistilLlama | 77.12 | 7.79e-04 | 0.02 | 0.6623 | 0.0115 |
124
+
125
+ *Note: CodeCarbon was used to track carbon emission. Allocated 80GB memory, 32 cores, Intel(R) Xeon(R) Gold 6448H for the evaluation*
126
+
127
+ ### Acknowledgments
128
+
129
+ - **University of Melbourne**
130
+ - **AGL Energy**
131
+ - **My teammates**: Svarnim and Mohit
132
+
133
+ ### GitHub Repositories
134
+
135
+ - **Training Repo**: [DistilLlama Training Repository](https://github.com/HenryHuang2/DistilLlama)
136
+ - **Evaluation Repo**: [Knowledge Distillation Evaluation Repository](https://github.com/svarnim1805/Knowledge-Distillation)
137
+
138
+ ### Reference
139
+
140
+ @misc{timiryasov2023babyllamaknowledgedistillation,
141
+ title={Baby Llama: knowledge distillation from an ensemble of teachers trained on a small dataset with no performance penalty},
142
+ author={Inar Timiryasov and Jean-Loup Tastet},
143
+ year={2023},
144
+ eprint={2308.02019},
145
+ archivePrefix={arXiv},
146
+ primaryClass={cs.CL},
147
+ url={https://arxiv.org/abs/2308.02019},
148
+ }
149
+
150
+ *Note: The repository will be updated as training progresses. Last update 2024-10-23*