Views
No views yet
deepseek-ai/DeepSeek-V2-Lite (4-bit quantized)pad_token set to eos1from transformers import AutoTokenizer, BitsAndBytesConfig
2from peft import PeftModel
3import torch
4
5# 1) Load tokenizer + adapter
6tokenizer = AutoTokenizer.from_pretrained(
7 "CodCodingCode/DeepSeek-V2-medical",
8 trust_remote_code=True
9)
10tokenizer.pad_token_id = tokenizer.pad_token_id or tokenizer.eos_token_id
11
12bnb = BitsAndBytesConfig(
13 load_in_4bit=True,
14 bnb_4bit_quant_type="nf4",
15 bnb_4bit_compute_dtype=torch.float16,
16)
17
18# 2) Reload the base quantized model
19from transformers import AutoModelForCausalLM
20base = AutoModelForCausalLM.from_pretrained(
21 "deepseek-ai/DeepSeek-V2-Lite",
22 quantization_config=bnb,
23 device_map="auto",
24 trust_remote_code=True,
25)
26base.resize_token_embeddings(len(tokenizer))
27
28# 3) Attach your LoRA adapter
29model = PeftModel.from_pretrained(
30 base,
31 "CodCodingCode/DeepSeek-V2-medical",
32 device_map="auto",
33 torch_dtype=torch.float16,
34 trust_remote_code=True,
35)
36model.config.use_cache = False # match your training config
37
38# 4) Generate
39prompt = (
40 "### Instruction:\n"
41 "You are a board-certified clinician ...\n\n"
42 "### Input:\n"
43 "THINKING: ...\n\n"
44 "### Response:\n"
45)
46inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
47outputs = model.generate(
48 **inputs,
49 max_new_tokens=256,
50 do_sample=True,
51 temperature=0.2,
52 top_p=0.95,
53 pad_token_id=tokenizer.pad_token_id,
54 eos_token_id=tokenizer.eos_token_id,
55)
56print(tokenizer.decode(outputs[0], skip_special_tokens=True))
57
58This repository contains a 4-bit LoRA fine-tuned adapter on top of [deepseek-ai/DeepSeek-V2-Lite](https://huggingface.co/deepseek-ai/DeepSeek-V2-Lite) for medical treatment planning.
59
60## Model Card
61
62- **Base model:** `deepseek-ai/DeepSeek-V2-Lite` (4-bit quantized)
63- **Adapter:** LoRA, trained on clinical vignette→treatment pairs
64- **Tokenizer:** same as base, with pad_token set to eos
65
66## Usage
67
68```python
69from transformers import AutoTokenizer, BitsAndBytesConfig
70from peft import PeftModel
71import torch
72
73# 1) Load tokenizer + adapter
74tokenizer = AutoTokenizer.from_pretrained(
75 "CodCodingCode/DeepSeek-V2-medical", trust_remote_code=True
76)
77tokenizer.pad_token_id = tokenizer.pad_token_id or tokenizer.eos_token_id
78
79# 2) Reload quantized base
80bnb = BitsAndBytesConfig(
81 load_in_4bit=True,
82 bnb_4bit_quant_type="nf4",
83 bnb_4bit_compute_dtype=torch.float16,
84)
85base = AutoModelForCausalLM.from_pretrained(
86 "deepseek-ai/DeepSeek-V2-Lite",
87 quantization_config=bnb,
88 device_map="auto",
89 trust_remote_code=True,
90)
91base.resize_token_embeddings(len(tokenizer))
92
93# 3) Attach LoRA adapter
94model = PeftModel.from_pretrained(
95 base,
96 "CodCodingCode/DeepSeek-V2-medical",
97 device_map="auto",
98 trust_remote_code=True,
99)
100model.config.use_cache = False
101
102# 4) Generate text
103prompt = (
104 "### Instruction:\n"
105 "You are a board-certified clinician. Based on the following patient vignette, "
106 "suggest a concise treatment plan:\n\n"
107 "### Input:\n"
108 "A 65-year-old presents with chronic shortness of breath and persistent cough...\n\n"
109 "### Response:\n"
110)
111inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
112
113outputs = model.generate(
114 **inputs,
115 max_new_tokens=128,
116 do_sample=True,
117 top_p=0.9,
118 temperature=0.8,
119 pad_token_id=tokenizer.pad_token_id,
120 eos_token_id=tokenizer.eos_token_id,
121)
122
123print(tokenizer.decode(outputs[0], skip_special_tokens=True))
124
125# Model Card for Model ID
126
127<!-- Provide a quick summary of what the model is/does. -->
128
129
130
131
132## Model Details
133
134### Model Description
135
136<!-- Provide a longer summary of what this model is. -->
137
138
139
140- **Developed by:** [More Information Needed]
141- **Funded by [optional]:** [More Information Needed]
142- **Shared by [optional]:** [More Information Needed]
143- **Model type:** [More Information Needed]
144- **Language(s) (NLP):** [More Information Needed]
145- **License:** [More Information Needed]
146- **Finetuned from model [optional]:** [More Information Needed]
147
148### Model Sources [optional]
149
150<!-- Provide the basic links for the model. -->
151
152- **Repository:** [More Information Needed]
153- **Paper [optional]:** [More Information Needed]
154- **Demo [optional]:** [More Information Needed]
155
156## Uses
157
158<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
159
160### Direct Use
161
162<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
163
164[More Information Needed]
165
166### Downstream Use [optional]
167
168<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
169
170[More Information Needed]
171
172### Out-of-Scope Use
173
174<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
175
176[More Information Needed]
177
178## Bias, Risks, and Limitations
179
180<!-- This section is meant to convey both technical and sociotechnical limitations. -->
181
182[More Information Needed]
183
184### Recommendations
185
186<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
187
188Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
189
190## How to Get Started with the Model
191
192Use the code below to get started with the model.
193
194[More Information Needed]
195
196## Training Details
197
198### Training Data
199
200<!-- 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. -->
201
202[More Information Needed]
203
204### Training Procedure
205
206<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
207
208#### Preprocessing [optional]
209
210[More Information Needed]
211
212
213#### Training Hyperparameters
214
215- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
216
217#### Speeds, Sizes, Times [optional]
218
219<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
220
221[More Information Needed]
222
223## Evaluation
224
225<!-- This section describes the evaluation protocols and provides the results. -->
226
227### Testing Data, Factors & Metrics
228
229#### Testing Data
230
231<!-- This should link to a Dataset Card if possible. -->
232
233[More Information Needed]
234
235#### Factors
236
237<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
238
239[More Information Needed]
240
241#### Metrics
242
243<!-- These are the evaluation metrics being used, ideally with a description of why. -->
244
245[More Information Needed]
246
247### Results
248
249[More Information Needed]
250
251#### Summary
252
253
254
255## Model Examination [optional]
256
257<!-- Relevant interpretability work for the model goes here -->
258
259[More Information Needed]
260
261## Environmental Impact
262
263<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
264
265Carbon 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).
266
267- **Hardware Type:** [More Information Needed]
268- **Hours used:** [More Information Needed]
269- **Cloud Provider:** [More Information Needed]
270- **Compute Region:** [More Information Needed]
271- **Carbon Emitted:** [More Information Needed]
272
273## Technical Specifications [optional]
274
275### Model Architecture and Objective
276
277[More Information Needed]
278
279### Compute Infrastructure
280
281[More Information Needed]
282
283#### Hardware
284
285[More Information Needed]
286
287#### Software
288
289[More Information Needed]
290
291## Citation [optional]
292
293<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
294
295**BibTeX:**
296
297[More Information Needed]
298
299**APA:**
300
301[More Information Needed]
302
303## Glossary [optional]
304
305<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
306
307[More Information Needed]
308
309## More Information [optional]
310
311[More Information Needed]
312
313## Model Card Authors [optional]
314
315[More Information Needed]
316
317## Model Card Contact
318
319[More Information Needed]
320### Framework versions
321
322- PEFT 0.15.2