vynr1504 commited on
Commit
ded2baf
·
verified ·
1 Parent(s): 03fbb69

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +161 -174
README.md CHANGED
@@ -2,209 +2,196 @@
2
  base_model: unsloth/Llama-3.1-8B-Instruct-bnb-4bit
3
  library_name: peft
4
  pipeline_tag: text-generation
 
5
  tags:
6
- - base_model:adapter:unsloth/Llama-3.1-8B-Instruct-bnb-4bit
7
- - lora
8
- - sft
9
- - transformers
10
- - trl
11
- - unsloth
12
  ---
13
 
14
- # Model Card for Model ID
15
-
16
- <!-- Provide a quick summary of what the model is/does. -->
17
-
18
 
 
19
 
20
  ## Model Details
21
 
22
- ### Model Description
23
-
24
- <!-- Provide a longer summary of what this model is. -->
25
-
26
-
27
-
28
- - **Developed by:** [More Information Needed]
29
- - **Funded by [optional]:** [More Information Needed]
30
- - **Shared by [optional]:** [More Information Needed]
31
- - **Model type:** [More Information Needed]
32
- - **Language(s) (NLP):** [More Information Needed]
33
- - **License:** [More Information Needed]
34
- - **Finetuned from model [optional]:** [More Information Needed]
35
-
36
- ### Model Sources [optional]
37
-
38
- <!-- Provide the basic links for the model. -->
39
-
40
- - **Repository:** [More Information Needed]
41
- - **Paper [optional]:** [More Information Needed]
42
- - **Demo [optional]:** [More Information Needed]
43
-
44
- ## Uses
45
-
46
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
47
-
48
- ### Direct Use
49
-
50
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
51
-
52
- [More Information Needed]
53
-
54
- ### Downstream Use [optional]
55
-
56
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
57
-
58
- [More Information Needed]
59
-
60
- ### Out-of-Scope Use
61
-
62
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
63
-
64
- [More Information Needed]
65
-
66
- ## Bias, Risks, and Limitations
67
-
68
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
69
-
70
- [More Information Needed]
71
-
72
- ### Recommendations
73
-
74
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
75
-
76
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
77
-
78
- ## How to Get Started with the Model
79
-
80
- Use the code below to get started with the model.
81
-
82
- [More Information Needed]
83
-
84
- ## Training Details
85
-
86
- ### Training Data
87
-
88
- <!-- 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. -->
89
-
90
- [More Information Needed]
91
-
92
- ### Training Procedure
93
-
94
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
95
-
96
- #### Preprocessing [optional]
97
-
98
- [More Information Needed]
99
-
100
-
101
- #### Training Hyperparameters
102
-
103
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
104
-
105
- #### Speeds, Sizes, Times [optional]
106
-
107
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
108
-
109
- [More Information Needed]
110
-
111
- ## Evaluation
112
-
113
- <!-- This section describes the evaluation protocols and provides the results. -->
114
-
115
- ### Testing Data, Factors & Metrics
116
-
117
- #### Testing Data
118
-
119
- <!-- This should link to a Dataset Card if possible. -->
120
-
121
- [More Information Needed]
122
-
123
- #### Factors
124
-
125
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
126
-
127
- [More Information Needed]
128
-
129
- #### Metrics
130
-
131
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
132
-
133
- [More Information Needed]
134
-
135
- ### Results
136
-
137
- [More Information Needed]
138
-
139
- #### Summary
140
-
141
-
142
-
143
- ## Model Examination [optional]
144
-
145
- <!-- Relevant interpretability work for the model goes here -->
146
-
147
- [More Information Needed]
148
-
149
- ## Environmental Impact
150
-
151
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
152
-
153
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
154
-
155
- - **Hardware Type:** [More Information Needed]
156
- - **Hours used:** [More Information Needed]
157
- - **Cloud Provider:** [More Information Needed]
158
- - **Compute Region:** [More Information Needed]
159
- - **Carbon Emitted:** [More Information Needed]
160
 
161
- ## Technical Specifications [optional]
162
 
163
- ### Model Architecture and Objective
 
 
164
 
165
- [More Information Needed]
 
 
 
 
 
166
 
167
- ### Compute Infrastructure
168
 
169
- [More Information Needed]
170
 
171
- #### Hardware
 
 
172
 
173
- [More Information Needed]
 
 
 
 
 
 
174
 
175
- #### Software
176
 
177
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
178
 
179
- ## Citation [optional]
 
 
 
 
 
 
180
 
181
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
182
 
183
- **BibTeX:**
 
 
 
 
 
 
 
184
 
185
- [More Information Needed]
186
 
187
- **APA:**
188
 
189
- [More Information Needed]
190
 
191
- ## Glossary [optional]
 
 
 
 
 
192
 
193
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
194
 
195
- [More Information Needed]
 
 
 
 
196
 
197
- ## More Information [optional]
198
 
199
- [More Information Needed]
200
 
201
- ## Model Card Authors [optional]
 
 
202
 
203
- [More Information Needed]
204
 
205
- ## Model Card Contact
206
 
207
- [More Information Needed]
208
- ### Framework versions
209
 
210
- - PEFT 0.19.1
 
2
  base_model: unsloth/Llama-3.1-8B-Instruct-bnb-4bit
3
  library_name: peft
4
  pipeline_tag: text-generation
5
+ license: llama3.1
6
  tags:
7
+ - base_model:adapter:unsloth/Llama-3.1-8B-Instruct-bnb-4bit
8
+ - lora
9
+ - sft
10
+ - transformers
11
+ - trl
12
+ - unsloth
13
  ---
14
 
15
+ # Magnus LoRA Adapter
 
 
 
16
 
17
+ A Low-Rank Adaptation (LoRA) fine-tuned adapter for the Llama-3.1-8B-Instruct model, optimized for chess move prediction using Magnus Carlsen's game dataset. This adapter enables the model to understand and predict chess positions and strategies using 4-bit quantization via BNB (Bits and Bytes).
18
 
19
  ## Model Details
20
 
21
+ - **Base Model:** [unsloth/Llama-3.1-8B-Instruct-bnb-4bit](https://huggingface.co/unsloth/Llama-3.1-8B-Instruct-bnb-4bit)
22
+ - **Adapter Type:** LoRA (Low-Rank Adaptation)
23
+ - **Library:** [PEFT](https://github.com/huggingface/peft)
24
+ - **Training Framework:** [TRL](https://github.com/huggingface/trl) + [Unsloth](https://github.com/unslothai/unsloth)
25
+ - **License:** Llama 3.1
26
+
27
+ ## Dataset
28
+
29
+ This adapter was trained on a specialized dataset compiled from **Magnus Carlsen chess matches**. The dataset contains:
30
+
31
+ #### First Training Attempt
32
+ - **Total Moves:** 1,123 moves from Magnus Carlsen's games
33
+
34
+ #### Second Training Attempt
35
+ - **Total Moves:** 2,145 moves from Magnus Carlsen's games
36
+
37
+ ### Dataset Features
38
+ - **Instruction-based chess analysis tasks** - Predicting moves from FEN (Forsyth-Edwards Notation) positions
39
+ - **Real match positions** - Game states from actual matches played by Magnus Carlsen
40
+ - **Training examples** - Position-move pairs representing Magnus's playing style and strategies
41
+
42
+ The dataset format follows the supervised fine-tuning (SFT) structure:
43
+ ```json
44
+ {
45
+ "instruction": "Predict Magnus Carlsen's next move from the given chess position.",
46
+ "input": "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
47
+ "output": "e2e3"
48
+ }
49
+ ```
50
+
51
+ This approach allows the model to learn Magnus Carlsen's distinctive playing patterns, move preferences, and strategic insights from his games.
52
+
53
+ ## Why LoRA? - Benefits of This Approach
54
+
55
+ LoRA (Low-Rank Adaptation) offers significant advantages for fine-tuning large language models:
56
+
57
+ ### Efficiency
58
+ - **Reduced Parameters:** Only ~0.5-2% of the base model parameters need to be trained, dramatically reducing memory requirements
59
+ - **Faster Training:** Significantly faster training times compared to full fine-tuning
60
+ - **Lower Cost:** Enables fine-tuning on consumer-grade hardware (4-bit quantization compatible)
61
+
62
+ ### Flexibility & Modularity
63
+ - **Composable Adapters:** Multiple LoRA adapters can be applied or switched easily without retraining
64
+ - **Storage Efficient:** Adapter files are typically 10-50MB vs. GB-sized full model checkpoints
65
+ - **Easy Distribution:** Lightweight adapters can be easily shared and deployed
66
+
67
+ ### Performance
68
+ - **Quality Retention:** Maintains the base model's general capabilities while specializing for specific tasks
69
+ - **Domain Adaptation:** Effectively transfers knowledge from chess game data to instruction-following context
70
+ - **Minimal Degradation:** Low rank matrices ensure efficient learning without catastrophic forgetting
71
+
72
+ ### Practical Advantages
73
+ - **Multi-GPU Friendly:** Works seamlessly with distributed training and inference
74
+ - **Inference Speed:** Negligible overhead during inference compared to full models
75
+ - **Compatibility:** Works with existing PEFT infrastructure and Hugging Face ecosystem
76
+
77
+ ## Training Hyperparameters
78
+
79
+ ### Precision & Optimization
80
+ - **Training Regime:** bf16/fp16 mixed precision
81
+ - **Optimizer:** AdamW with scheduler
82
+
83
+ ### Training Schedule
84
+ - **Steps:** 269
85
+ - **Epochs:** 1
86
+ - **Train Batch Size:** 2 (per device)
87
+ - **Learning Rate:** Dynamic scheduler peaking at 2e-4
88
+
89
+ ### LoRA Configuration
90
+ - **LoRA Rank (r):** 16
91
+ - **LoRA Alpha:** 16
92
+ - **LoRA Dropout:** 0.0
93
+ - **Target Modules:**
94
+ - q_proj (Query projection)
95
+ - k_proj (Key projection)
96
+ - v_proj (Value projection)
97
+ - o_proj (Output projection)
98
+ - gate_proj (Gate projection)
99
+ - up_proj (Up projection)
100
+ - down_proj (Down projection)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
 
102
+ ### Training Results
103
 
104
+ #### First Training Attempt (Initial)
105
+ - **Total Moves:** 1,123
106
+ - **Loss Progression:** Started at 0.673 (step 1) → 0.782 (step 2) → 0.697 (step 3) through convergence
107
 
108
+ #### Second Training Attempt (Reused Weights)
109
+ - **Total Moves:** 2,145
110
+ - **Trainable Parameters:** 41,943,040 of 8,072,204,288 (0.52% trained)
111
+ - **Steps:** 269 total steps completed (1 epoch)
112
+ - **Loss Progression:** Step 266 (0.495) → Step 267 (0.462) → Step 268 (0.565) → Step 269 (0.795)
113
+ - **Training Convergence:** Successfully completed training across 269 steps with reused adapter weights
114
 
115
+ ## Usage
116
 
117
+ ### Loading the Adapter
118
 
119
+ ```python
120
+ from peft import AutoPeftModelForCausalLM
121
+ from transformers import AutoTokenizer
122
 
123
+ model = AutoPeftModelForCausalLM.from_pretrained(
124
+ "path/to/magnus_lora_adapter",
125
+ device_map="auto",
126
+ torch_dtype="auto"
127
+ )
128
+ tokenizer = AutoTokenizer.from_pretrained("unsloth/Llama-3.1-8B-Instruct-bnb-4bit")
129
+ ```
130
 
131
+ ### Inference
132
 
133
+ ```python
134
+ def generate_response(prompt):
135
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
136
+ outputs = model.generate(**inputs, max_new_tokens=256)
137
+ return tokenizer.decode(outputs[0], skip_special_tokens=True)
138
+
139
+ response = generate_response("Your prompt here")
140
+ print(response)
141
+ ```
142
+
143
+ ## Files in This Repository
144
 
145
+ - `adapter_config.json` - LoRA adapter configuration
146
+ - `adapter_model.safetensors` - Adapter weights in safetensors format
147
+ - `tokenizer.json` - Tokenizer vocabulary
148
+ - `tokenizer_config.json` - Tokenizer configuration
149
+ - `special_tokens_map.json` - Special tokens mapping
150
+ - `training_args.bin` - Training arguments
151
+ - `chat_template.jinja` - Chat template for inference
152
 
153
+ ## Requirements
154
 
155
+ ```
156
+ torch>=2.0.0
157
+ transformers>=4.36.0
158
+ peft>=0.7.0
159
+ bitsandbytes>=0.41.0
160
+ unsloth
161
+ trl
162
+ ```
163
 
164
+ ## Future Improvements & Optimization Potential
165
 
166
+ The adapter has been successfully trained on Magnus Carlsen's chess game dataset. Future enhancements could include:
167
 
168
+ ### Potential Enhancement Areas
169
 
170
+ - **Extended Training:** Training with multiple epochs or additional datasets could improve move prediction accuracy
171
+ - **Larger Datasets:** Incorporating additional Magnus Carlsen games or broader chess datasets could enhance pattern recognition
172
+ - **Hyperparameter Tuning:** Experimenting with different LoRA ranks (r), alpha values, and learning rates may yield better results
173
+ - **Increased Batch Size:** Training with larger batch sizes could improve convergence and model stability
174
+ - **Multi-Phase Training:** Implementing curriculum learning or progressive fine-tuning strategies
175
+ - **Domain-Specific Evaluation:** Using chess-specific metrics to validate and iteratively improve move prediction accuracy
176
 
177
+ ### Recommendations for Further Development
178
 
179
+ 1. Train for multiple epochs with validation monitoring to assess convergence improvements
180
+ 2. Implement early stopping based on move prediction accuracy metrics
181
+ 3. Experiment with different learning rate schedules and warmup strategies
182
+ 4. Fine-tune on a curated dataset of high-rated games for better strategic learning
183
+ 5. Evaluate performance gains from retraining with different random seeds or augmented chess positions
184
 
185
+ Users interested in further improving these weights are encouraged to continue training with your own datasets and hyperparameters.
186
 
187
+ ## Inference Tips
188
 
189
+ - Use `device_map="auto"` for automatic device placement with quantized models
190
+ - The adapter is optimized for chess move prediction tasks
191
+ - Supports both CPU and GPU inference (GPU recommended for performance)
192
 
 
193
 
 
194
 
195
+ ## License
 
196
 
197
+ This adapter is licensed under the Llama 3.1 License. See the base model's license for details.