hieulum commited on
Commit
ffbbb6a
·
verified ·
1 Parent(s): 754e6fa

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +98 -225
README.md CHANGED
@@ -1,238 +1,111 @@
1
- ---
2
- library_name: transformers
3
- tags:
4
- - unsloth
5
- ---
6
-
7
- # Model Card for Model ID
8
-
9
- Base Model: unsloth/DeepSeek-R1-Distill-Llama-8B
10
- Fine-Tuning Dataset: hieulum/bacsiAI (first 200 rows)
11
- LoRA Parameters: r=16, lora_alpha=16, target modules, etc.
12
- Training Details: 1 epoch, 60 steps, batch size 8, learning rate 2e-4
13
- Usage Instructions:
14
- from unsloth import FastLanguageModel
15
- model, tokenizer = FastLanguageModel.from_pretrained(
16
- model_name="unsloth/DeepSeek-R1-Distill-Llama-8B",
17
- max_seq_length=1024,
18
- load_in_4bit=True,
19
- )
20
- model = FastLanguageModel.load_peft_model(model, "your_username/DeepSeek-R1-LoRA-medical")
21
-
22
- Programmatically Create a Model Card: Use the huggingface_hub library to generate a basic model card:
23
- from huggingface_hub import ModelCard, ModelCardData
24
-
25
- card_data = ModelCardData(
26
- language="en",
27
- license="apache-2.0",
28
- tags=["medical", "LoRA", "unsloth", "DeepSeek-R1"],
29
- datasets=["hieulum/bacsiAI"],
30
- )
31
- card = ModelCard.from_template(
32
- card_data,
33
- model_name="DeepSeek-R1-LoRA-medical",
34
- model_description="LoRA adapters for medical Q&A, fine-tuned on hieulum/bacsiAI dataset using unsloth.",
35
- base_model="unsloth/DeepSeek-R1-Distill-Llama-8B",
36
- training_details="Fine-tuned with r=16, lora_alpha=16, 1 epoch, 60 steps, batch size 8, learning rate 2e-4.",
37
- usage="Load with unsloth: `FastLanguageModel.load_peft_model(model, 'your_username/DeepSeek-R1-LoRA-medical')`",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  )
39
 
40
- # Save the model card locally
41
- card.save("model_card.md")
 
 
42
 
43
- # Upload the model card
44
- from huggingface_hub import upload_file
45
- upload_file(
46
- path_or_fileobj="model_card.md",
47
- path_in_repo="README.md",
48
- repo_id=repo_id,
49
- )
50
-
51
- ## Model Details
52
-
53
- ### Model Description
54
-
55
- <!-- Provide a longer summary of what this model is. -->
56
-
57
- This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
58
-
59
- - **Developed by:** [More Information Needed]
60
- - **Funded by [optional]:** [More Information Needed]
61
- - **Shared by [optional]:** [More Information Needed]
62
- - **Model type:** [More Information Needed]
63
- - **Language(s) (NLP):** [More Information Needed]
64
- - **License:** [More Information Needed]
65
- - **Finetuned from model [optional]:** [More Information Needed]
66
-
67
- ### Model Sources [optional]
68
-
69
- <!-- Provide the basic links for the model. -->
70
-
71
- - **Repository:** [More Information Needed]
72
- - **Paper [optional]:** [More Information Needed]
73
- - **Demo [optional]:** [More Information Needed]
74
-
75
- ## Uses
76
-
77
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
78
-
79
- ### Direct Use
80
-
81
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
82
-
83
- [More Information Needed]
84
-
85
- ### Downstream Use [optional]
86
-
87
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
88
-
89
- [More Information Needed]
90
-
91
- ### Out-of-Scope Use
92
-
93
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
94
-
95
- [More Information Needed]
96
-
97
- ## Bias, Risks, and Limitations
98
-
99
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
100
-
101
- [More Information Needed]
102
-
103
- ### Recommendations
104
-
105
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
106
-
107
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
108
-
109
- ## How to Get Started with the Model
110
-
111
- Use the code below to get started with the model.
112
-
113
- [More Information Needed]
114
-
115
- ## Training Details
116
-
117
- ### Training Data
118
-
119
- <!-- 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. -->
120
-
121
- [More Information Needed]
122
-
123
- ### Training Procedure
124
-
125
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
126
-
127
- #### Preprocessing [optional]
128
-
129
- [More Information Needed]
130
-
131
-
132
- #### Training Hyperparameters
133
-
134
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
135
-
136
- #### Speeds, Sizes, Times [optional]
137
-
138
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
139
-
140
- [More Information Needed]
141
-
142
- ## Evaluation
143
-
144
- <!-- This section describes the evaluation protocols and provides the results. -->
145
-
146
- ### Testing Data, Factors & Metrics
147
-
148
- #### Testing Data
149
-
150
- <!-- This should link to a Dataset Card if possible. -->
151
-
152
- [More Information Needed]
153
-
154
- #### Factors
155
-
156
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
157
-
158
- [More Information Needed]
159
-
160
- #### Metrics
161
-
162
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
163
-
164
- [More Information Needed]
165
-
166
- ### Results
167
-
168
- [More Information Needed]
169
-
170
- #### Summary
171
-
172
-
173
-
174
- ## Model Examination [optional]
175
-
176
- <!-- Relevant interpretability work for the model goes here -->
177
-
178
- [More Information Needed]
179
-
180
- ## Environmental Impact
181
-
182
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
183
-
184
- 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).
185
-
186
- - **Hardware Type:** [More Information Needed]
187
- - **Hours used:** [More Information Needed]
188
- - **Cloud Provider:** [More Information Needed]
189
- - **Compute Region:** [More Information Needed]
190
- - **Carbon Emitted:** [More Information Needed]
191
-
192
- ## Technical Specifications [optional]
193
-
194
- ### Model Architecture and Objective
195
-
196
- [More Information Needed]
197
-
198
- ### Compute Infrastructure
199
-
200
- [More Information Needed]
201
-
202
- #### Hardware
203
-
204
- [More Information Needed]
205
-
206
- #### Software
207
-
208
- [More Information Needed]
209
-
210
- ## Citation [optional]
211
-
212
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
213
-
214
- **BibTeX:**
215
-
216
- [More Information Needed]
217
-
218
- **APA:**
219
 
220
- [More Information Needed]
 
221
 
222
- ## Glossary [optional]
 
 
 
223
 
224
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
 
 
225
 
226
- [More Information Needed]
 
227
 
228
- ## More Information [optional]
 
 
 
229
 
230
- [More Information Needed]
 
 
 
 
 
231
 
232
- ## Model Card Authors [optional]
 
 
 
233
 
234
- [More Information Needed]
 
235
 
236
- ## Model Card Contact
 
237
 
238
- [More Information Needed]
 
 
 
1
+ # DeepSeek-R1-LoRA-medical
2
+
3
+ ## Giới thiệu
4
+
5
+ Đây là bộ LoRA adapters được fine-tune trên mô hình gốc `unsloth/DeepSeek-R1-Distill-Llama-8B` để hỗ trợ trả lời các câu hỏi y khoa. Bộ adapters này được huấn luyện trên tập dữ liệu `hieulum/bacsiAI` (200 mẫu đầu tiên) với cấu hình LoRA tối ưu, giúp cải thiện khả năng trả lời các câu hỏi về chẩn đoán, điều trị và lập kế hoạch điều trị y tế.
6
+
7
+ ### Thông tin hình
8
+ - **Mô hình gốc**: `unsloth/DeepSeek-R1-Distill-Llama-8B`
9
+ - **Dataset**: `hieulum/bacsiAI` (200 mẫu)
10
+ - **Cấu hình LoRA**:
11
+ - Rank (`r`): 16
12
+ - LoRA alpha: 16
13
+ - Các module mục tiêu: `q_proj`, `k_proj`, `v_proj`, `o_proj`, `gate_proj`, `up_proj`, `down_proj`
14
+ - **Thông tin huấn luyện**:
15
+ - Số epoch: 1
16
+ - Tổng số bước: 60
17
+ - Batch size hiệu quả: 8 (2 per device × 4 gradient accumulation steps)
18
+ - Learning rate: 2e-4
19
+ - Optimizer: AdamW 8-bit
20
+ - **Kích thước LoRA adapters**: ~168 MB
21
+ - **Giấy phép**: Apache 2.0 (hoặc thay bằng giấy phép bạn chọn)
22
+
23
+ ## Các file trong repository
24
+ - `adapter_config.json`: Cấu hình LoRA adapters.
25
+ - `adapter_model.safetensors`: Trọng số LoRA adapters (168 MB).
26
+ - `tokenizer_config.json`: Cấu hình tokenizer.
27
+ - `tokenizer.json`: Từ vựng tokenizer.
28
+ - `special_tokens_map.json`: Ánh xạ các token đặc biệt.
29
+
30
+ ## Hướng dẫn sử dụng
31
+
32
+ ### Yêu cầu
33
+ - **Thư viện**:
34
+ ```bash
35
+ pip install unsloth transformers huggingface_hub torch
36
+ ```
37
+ - **Phần cứng**: GPU với ít nhất 16GB VRAM ( dụ: NVIDIA Tesla T4).
38
+ - **Python**: 3.8 hoặc cao hơn.
39
+ - **Hugging Face token**: Để tải mô hình gốc (nếu cần).
40
+
41
+ ### Bước 1: Cài đặt môi trường
42
+ Cài đặt các thư viện cần thiết:
43
+ ```bash
44
+ pip install unsloth==2024.9 transformers huggingface_hub torch==2.4.0
45
+ ```
46
+
47
+ ### Bước 2: Tải mô hình gốc và LoRA adapters
48
+ Sử dụng đoạn code sau để tải mô hình gốc và áp dụng LoRA adapters:
49
+
50
+ ```python
51
+ from unsloth import FastLanguageModel
52
+ import torch
53
+
54
+ # Tải mô hình gốc
55
+ model, tokenizer = FastLanguageModel.from_pretrained(
56
+ model_name="unsloth/DeepSeek-R1-Distill-Llama-8B",
57
+ max_seq_length=1024, # Có thể điều chỉnh
58
+ load_in_4bit=True, # Sử dụng 4-bit quantization để tiết kiệm bộ nhớ
59
+ token="your_hugging_face_token", # Thay bằng token của bạn
60
  )
61
 
62
+ # Tải LoRA adapters
63
+ model = FastLanguageModel.load_peft_model(
64
+ model,
65
+ "hieulum/DeepSeek-R1-LoRA-BacsiAI"
66
 
67
+ # Chuẩn bị hình cho inference
68
+ model = FastLanguageModel.for_inference(model)
69
+ ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
 
71
+ ### Bước 3: Chạy inference
72
+ Ví dụ về cách chạy inference với một câu hỏi y khoa:
73
 
74
+ ```python
75
+ # Chuẩn bị input
76
+ question = "Phương pháp điều trị tăng huyết áp là gì?"
77
+ inputs = tokenizer(question, return_tensors="pt").to("cuda")
78
 
79
+ # Tạo output
80
+ outputs = model.generate(**inputs, max_new_tokens=128, temperature=0.7)
81
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
82
 
83
+ print(response)
84
+ ```
85
 
86
+ ### Lưu ý
87
+ - **Max sequence length**: Được đặt thành 1024 trong code trên để tiết kiệm bộ nhớ. Nếu bạn cần xử lý các chuỗi dài hơn, tăng `max_seq_length` (ví dụ: 2048) nhưng hãy đảm bảo GPU có đủ VRAM.
88
+ - **4-bit quantization**: Được sử dụng để giảm yêu cầu bộ nhớ. Nếu bạn có GPU mạnh hơn, có thể tắt bằng cách đặt `load_in_4bit=False`.
89
+ - **Hugging Face token**: Cần thiết để tải mô hình gốc từ `unsloth`. Đảm bảo bạn đã đăng nhập hoặc cung cấp token qua `huggingface_hub.login()`.
90
 
91
+ ### Đăng nhập Hugging Face (nếu cần)
92
+ Nếu bạn chưa đăng nhập, chạy:
93
+ ```python
94
+ from huggingface_hub import login
95
+ login(token="your_hugging_face_token")
96
+ ```
97
 
98
+ Hoặc qua terminal:
99
+ ```bash
100
+ huggingface-cli login
101
+ ```
102
 
103
+ ## Hiệu suất
104
+ Bộ LoRA adapters này được tối ưu cho các câu hỏi y khoa, đặc biệt là chẩn đoán và điều trị. Mô hình có thể tạo ra các câu trả lời logic với chuỗi suy nghĩ (chain-of-thought) rõ ràng, nhờ vào định dạng prompt đặc biệt trong quá trình fine-tune.
105
 
106
+ ## Liên hệ
107
+ Nếu bạn gặp vấn đề hoặc có câu hỏi, vui lòng mở issue trên repository này hoặc liên hệ qua Hugging Face.
108
 
109
+ ## Lời cảm ơn
110
+ - Cảm ơn `unsloth` và Hugging Face đã cung cấp các công cụ mạnh mẽ để fine-tune và chia sẻ mô hình.
111
+ - Cảm ơn tác giả dataset `hieulum/bacsiAI` đã cung cấp dữ liệu chất lượng.