File size: 2,757 Bytes
b3862b1
fd01421
cb3c818
 
 
 
 
b3862b1
fd01421
 
 
 
cb3c818
 
 
b3862b1
 
fd01421
 
cb3c818
 
 
fd01421
cb3c818
 
 
 
 
fd01421
cb3c818
 
 
 
 
 
 
 
 
 
ca2c12e
 
cb3c818
ca2c12e
 
 
 
 
 
 
 
 
 
 
cb3c818
 
 
ca2c12e
cb3c818
ca2c12e
cb3c818
ca2c12e
 
 
 
 
cb3c818
 
ca2c12e
 
cb3c818
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
---
license: apache-2.0
base_model: unsloth/Meta-Llama-3.1-8B-Instruct-bnb-4bit
datasets:
- lingshu-medical-mllm/ReasonMed
library_name: transformers
pipeline_tag: text-generation
tags:
- medical
- reasoning
- llama-3.1
- reasonmed
- chain-of-thought
language:
- en
---

# LlamaMed-3.1-8B-Reasoner

<p align="center">
  <img src="https://cdn-uploads.huggingface.co/production/uploads/66e00ba55e4fd4bfead4a97c/SpwOsRpS_Bd9pmC4k_I98.png" alt="LlamaMed-3.1-8B-Reasoner" width="100%">
</p>

LlamaMed-3.1-8B-Reasoner is a fine-tune of **Llama-3.1-8B-Instruct** trained
on **ReasonMed**, a dataset of chain-of-thought medical reasoning over
multiple-choice clinical questions. The model works through a question
step by step — considering each answer option in turn — before giving a
final answer, in the same structured reasoning style as its training data.

## Model Details

- **Base model:** [unsloth/Meta-Llama-3.1-8B-Instruct-bnb-4bit](https://huggingface.co/unsloth/Meta-Llama-3.1-8B-Instruct-bnb-4bit)
- **Dataset:** [lingshu-medical-mllm/ReasonMed](https://huggingface.co/datasets/lingshu-medical-mllm/ReasonMed) — 10,000 samples used for training
- **Method:** QLoRA (4-bit), rank 16, via [Unsloth](https://github.com/unslothai/unsloth)
- **License:** Apache 2.0

## Usage

```python
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
import torch

bnb_config = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_quant_type="nf4",
    bnb_4bit_compute_dtype=torch.float16,
)

tokenizer = AutoTokenizer.from_pretrained("Rumiii/LlamaMed-3.1-8B-Reasoner")
model = AutoModelForCausalLM.from_pretrained(
    "Rumiii/LlamaMed-3.1-8B-Reasoner",
    device_map={"": 0},
    quantization_config=bnb_config,
)

messages = [
    {"role": "user", "content": "A 45-year-old man presents with polyuria, polydipsia, and weight loss. Fasting blood glucose is 210 mg/dL. What is the most likely diagnosis?\nA. Type 1 Diabetes Mellitus\nB. Type 2 Diabetes Mellitus\nC. Diabetes Insipidus\nD. Cushing's Syndrome"},
]

inputs = tokenizer.apply_chat_template(
    messages,
    add_generation_prompt=True,
    tokenize=True,
    return_dict=True,
    return_tensors="pt",
).to(model.device)

outputs = model.generate(**inputs, max_new_tokens=1500, temperature=0.6, top_p=0.95)
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True))
```

## Training

Trained on a single Tesla T4 GPU using Unsloth for memory-efficient QLoRA
fine-tuning, with periodic adapter checkpoints saved during training.

## Intended Use

This model is a research checkpoint intended for exploring medical
reasoning fine-tunes. It is not validated for clinical use and should
not be used to inform real medical decisions.