Update README.md
Browse files
README.md
CHANGED
@@ -1,16 +1,80 @@
|
|
1 |
---
|
2 |
-
library_name: transformers
|
3 |
-
pipeline_tag: text-generation
|
4 |
tags:
|
5 |
-
- text-generation
|
6 |
- medical
|
7 |
- loRA
|
8 |
- 4bit
|
9 |
-
|
|
|
10 |
---
|
11 |
|
12 |
# DeepSeek-V2-medical
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
This 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.
|
15 |
|
16 |
## Model Card
|
|
|
1 |
---
|
|
|
|
|
2 |
tags:
|
|
|
3 |
- medical
|
4 |
- loRA
|
5 |
- 4bit
|
6 |
+
- conversational
|
7 |
+
pipeline_tag: text-generation
|
8 |
---
|
9 |
|
10 |
# DeepSeek-V2-medical
|
11 |
|
12 |
+
This repository contains a 4-bit LoRA adapter fine-tuned on top of [deepseek-ai/DeepSeek-V2-Lite](https://huggingface.co/deepseek-ai/DeepSeek-V2-Lite) for **medical treatment planning**.
|
13 |
+
|
14 |
+
- **Base model**: `deepseek-ai/DeepSeek-V2-Lite` (4-bit quantized)
|
15 |
+
- **Adapter**: LoRA, trained on clinical vignette → treatment plan pairs
|
16 |
+
- **Tokenizer**: same as base, with `pad_token` set to `eos`
|
17 |
+
|
18 |
+
## Usage
|
19 |
+
|
20 |
+
```python
|
21 |
+
from transformers import AutoTokenizer, BitsAndBytesConfig
|
22 |
+
from peft import PeftModel
|
23 |
+
import torch
|
24 |
+
|
25 |
+
# 1) Load tokenizer + adapter
|
26 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
27 |
+
"CodCodingCode/DeepSeek-V2-medical",
|
28 |
+
trust_remote_code=True
|
29 |
+
)
|
30 |
+
tokenizer.pad_token_id = tokenizer.pad_token_id or tokenizer.eos_token_id
|
31 |
+
|
32 |
+
bnb = BitsAndBytesConfig(
|
33 |
+
load_in_4bit=True,
|
34 |
+
bnb_4bit_quant_type="nf4",
|
35 |
+
bnb_4bit_compute_dtype=torch.float16,
|
36 |
+
)
|
37 |
+
|
38 |
+
# 2) Reload the base quantized model
|
39 |
+
from transformers import AutoModelForCausalLM
|
40 |
+
base = AutoModelForCausalLM.from_pretrained(
|
41 |
+
"deepseek-ai/DeepSeek-V2-Lite",
|
42 |
+
quantization_config=bnb,
|
43 |
+
device_map="auto",
|
44 |
+
trust_remote_code=True,
|
45 |
+
)
|
46 |
+
base.resize_token_embeddings(len(tokenizer))
|
47 |
+
|
48 |
+
# 3) Attach your LoRA adapter
|
49 |
+
model = PeftModel.from_pretrained(
|
50 |
+
base,
|
51 |
+
"CodCodingCode/DeepSeek-V2-medical",
|
52 |
+
device_map="auto",
|
53 |
+
torch_dtype=torch.float16,
|
54 |
+
trust_remote_code=True,
|
55 |
+
)
|
56 |
+
model.config.use_cache = False # match your training config
|
57 |
+
|
58 |
+
# 4) Generate
|
59 |
+
prompt = (
|
60 |
+
"### Instruction:\n"
|
61 |
+
"You are a board-certified clinician ...\n\n"
|
62 |
+
"### Input:\n"
|
63 |
+
"THINKING: ...\n\n"
|
64 |
+
"### Response:\n"
|
65 |
+
)
|
66 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
67 |
+
outputs = model.generate(
|
68 |
+
**inputs,
|
69 |
+
max_new_tokens=256,
|
70 |
+
do_sample=True,
|
71 |
+
temperature=0.2,
|
72 |
+
top_p=0.95,
|
73 |
+
pad_token_id=tokenizer.pad_token_id,
|
74 |
+
eos_token_id=tokenizer.eos_token_id,
|
75 |
+
)
|
76 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
77 |
+
|
78 |
This 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.
|
79 |
|
80 |
## Model Card
|