Text Generation
PEFT
Safetensors
Transformers
English
lora
qlora
medical
research-artifact
conversational
Instructions to use Babblu2821/tinyllama-medqa-qlora with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use Babblu2821/tinyllama-medqa-qlora with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("TinyLlama/TinyLlama-1.1B-Chat-v1.0") model = PeftModel.from_pretrained(base_model, "Babblu2821/tinyllama-medqa-qlora") - Transformers
How to use Babblu2821/tinyllama-medqa-qlora with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Babblu2821/tinyllama-medqa-qlora") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("Babblu2821/tinyllama-medqa-qlora", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Babblu2821/tinyllama-medqa-qlora with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Babblu2821/tinyllama-medqa-qlora" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Babblu2821/tinyllama-medqa-qlora", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Babblu2821/tinyllama-medqa-qlora
- SGLang
How to use Babblu2821/tinyllama-medqa-qlora with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Babblu2821/tinyllama-medqa-qlora" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Babblu2821/tinyllama-medqa-qlora", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Babblu2821/tinyllama-medqa-qlora" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Babblu2821/tinyllama-medqa-qlora", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Babblu2821/tinyllama-medqa-qlora with Docker Model Runner:
docker model run hf.co/Babblu2821/tinyllama-medqa-qlora
docs: real model card — measured results, provenance, and safety limits
Browse files
README.md
CHANGED
|
@@ -1,62 +1,163 @@
|
|
| 1 |
---
|
| 2 |
base_model: TinyLlama/TinyLlama-1.1B-Chat-v1.0
|
| 3 |
library_name: peft
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
tags:
|
| 6 |
- base_model:adapter:TinyLlama/TinyLlama-1.1B-Chat-v1.0
|
| 7 |
- lora
|
| 8 |
-
-
|
|
|
|
| 9 |
- transformers
|
| 10 |
-
-
|
| 11 |
-
|
| 12 |
-
pipeline_tag: text-generation
|
| 13 |
---
|
| 14 |
|
| 15 |
-
#
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
```python
|
| 23 |
-
from
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
```
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
This model was trained with SFT.
|
| 38 |
-
|
| 39 |
-
### Framework versions
|
| 40 |
-
|
| 41 |
-
- PEFT 0.19.1
|
| 42 |
-
- TRL: 1.9.2
|
| 43 |
-
- Transformers: 5.13.1
|
| 44 |
-
- Pytorch: 2.11.0+cu128
|
| 45 |
-
- Datasets: 5.0.1
|
| 46 |
-
- Tokenizers: 0.22.2
|
| 47 |
|
| 48 |
-
##
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
|
|
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
```bibtex
|
| 55 |
-
@software{vonwerra2020trl,
|
| 56 |
-
title = {{TRL: Transformers Reinforcement Learning}},
|
| 57 |
-
author = {von Werra, Leandro and Belkada, Younes and Tunstall, Lewis and Beeching, Edward and Thrush, Tristan and Lambert, Nathan and Huang, Shengyi and Rasul, Kashif and Gallouédec, Quentin},
|
| 58 |
-
license = {Apache-2.0},
|
| 59 |
-
url = {https://github.com/huggingface/trl},
|
| 60 |
-
year = {2020}
|
| 61 |
-
}
|
| 62 |
-
```
|
|
|
|
| 1 |
---
|
| 2 |
base_model: TinyLlama/TinyLlama-1.1B-Chat-v1.0
|
| 3 |
library_name: peft
|
| 4 |
+
pipeline_tag: text-generation
|
| 5 |
+
license: apache-2.0
|
| 6 |
+
language:
|
| 7 |
+
- en
|
| 8 |
+
datasets:
|
| 9 |
+
- keivalya/MedQuad-MedicalQnADataset
|
| 10 |
tags:
|
| 11 |
- base_model:adapter:TinyLlama/TinyLlama-1.1B-Chat-v1.0
|
| 12 |
- lora
|
| 13 |
+
- qlora
|
| 14 |
+
- peft
|
| 15 |
- transformers
|
| 16 |
+
- medical
|
| 17 |
+
- research-artifact
|
|
|
|
| 18 |
---
|
| 19 |
|
| 20 |
+
# tinyllama-medqa-qlora
|
| 21 |
+
|
| 22 |
+
A QLoRA adapter (4-bit NF4, double-quantised) for **TinyLlama-1.1B-Chat**, fine-tuned
|
| 23 |
+
for one epoch on [MedQuAD](https://huggingface.co/datasets/keivalya/MedQuad-MedicalQnADataset)
|
| 24 |
+
medical Q&A. It is the **treatment arm** of a controlled comparison against LoRA on a
|
| 25 |
+
smaller model — the other arm is
|
| 26 |
+
[`Babblu2821/gpt2-medqa-lora`](https://huggingface.co/Babblu2821/gpt2-medqa-lora).
|
| 27 |
+
|
| 28 |
+
Code, method and full results: **https://github.com/fayazhussain2821/llm-finetuning-medqa**
|
| 29 |
+
|
| 30 |
+
> ## ⚠️ Do not use this for medical information
|
| 31 |
+
>
|
| 32 |
+
> This is a **methodology demonstration**, not a medical tool. Its factual reliability
|
| 33 |
+
> has been measured, and while it is the best arm in this project, it is still poor: on
|
| 34 |
+
> a blinded review of 20 held-out questions it **contradicted the reference answer or
|
| 35 |
+
> invented an entity in 40% of them**, scoring **2.70 out of 5** for factual soundness.
|
| 36 |
+
>
|
| 37 |
+
> It produces fluent, confident, well-formed text that is frequently wrong. Fluency is
|
| 38 |
+
> exactly what makes this dangerous.
|
| 39 |
+
>
|
| 40 |
+
> Do not use it for diagnosis, treatment, triage, patient-facing text, or to answer any
|
| 41 |
+
> real health question.
|
| 42 |
+
|
| 43 |
+
## What it is for
|
| 44 |
+
|
| 45 |
+
Reproducing and studying a parameter-efficient fine-tuning comparison. Note that the
|
| 46 |
+
project's own conclusion is a caution against over-reading this adapter: most of its
|
| 47 |
+
advantage over the LoRA arm comes from the base model being ~9× larger and already
|
| 48 |
+
instruction-tuned, not from QLoRA. See "Evaluation".
|
| 49 |
+
|
| 50 |
+
## Training
|
| 51 |
+
|
| 52 |
+
| | |
|
| 53 |
+
|---|---|
|
| 54 |
+
| Base model | `TinyLlama/TinyLlama-1.1B-Chat-v1.0` (1.1B) |
|
| 55 |
+
| Method | QLoRA — 4-bit NF4, double quantisation, fp16 compute |
|
| 56 |
+
| LoRA | r=16, α=32, dropout=0.05 |
|
| 57 |
+
| Target modules | `q_proj`, `k_proj`, `v_proj`, `o_proj` |
|
| 58 |
+
| Data | MedQuAD, 16,407 pairs, 90/10 split, seed 42 → 14,766 train |
|
| 59 |
+
| Epochs | 1 |
|
| 60 |
+
| Learning rate | 2e-4, cosine schedule, 30 warmup steps |
|
| 61 |
+
| Effective batch | 16 (4 × 4 accumulation) — matched to the LoRA arm |
|
| 62 |
+
| Optimiser | `paged_adamw_8bit` |
|
| 63 |
+
| Mixed precision | Off — QLoRA trains fp32 adapters with no grad scaler |
|
| 64 |
+
| Max length | 1024 tokens |
|
| 65 |
+
| Prompt format | TinyLlama's native chat template |
|
| 66 |
+
| Hardware | Colab T4 |
|
| 67 |
+
|
| 68 |
+
**Provenance.** These weights were trained on 2026-08-03 with the project's original
|
| 69 |
+
notebook pipeline, using TRL's `SFTTrainer`. The current repository trains both arms
|
| 70 |
+
under `transformers.Trainer` — a deliberate change, so the two arms of the comparison
|
| 71 |
+
no longer run different training machinery. **Re-running the current code will not
|
| 72 |
+
reproduce these exact weights.** Every published number below was measured on *these*
|
| 73 |
+
files.
|
| 74 |
+
|
| 75 |
+
## Evaluation
|
| 76 |
+
|
| 77 |
+
Scored on 1,641 held-out rows, identical rows for every arm, **answer span only** —
|
| 78 |
+
the prompt template differs between arms and scoring it would let boilerplate move the
|
| 79 |
+
metric.
|
| 80 |
+
|
| 81 |
+
**Bits per byte** is the headline metric, not perplexity. Perplexity is per *token*,
|
| 82 |
+
and TinyLlama's SentencePiece tokenizer differs from GPT-2's byte-level BPE, so the two
|
| 83 |
+
perplexities are not on one scale.
|
| 84 |
+
|
| 85 |
+
| run | bits/byte ↓ | perplexity |
|
| 86 |
+
|---|---|---|
|
| 87 |
+
| `gpt2` (untrained control) | 0.8049 | 11.51 |
|
| 88 |
+
| `gpt2-medqa-lora` | 0.5970 | 6.12 |
|
| 89 |
+
| `TinyLlama-1.1B-Chat` (untrained control) | 0.6120 | 5.39 |
|
| 90 |
+
| **`tinyllama-medqa-qlora` (this model)** | **0.3954** | **2.97** |
|
| 91 |
+
|
| 92 |
+
Fine-tuning cut bits per byte by **35.4%** against its own base model.
|
| 93 |
+
|
| 94 |
+
**Read the control row carefully.** Untouched TinyLlama (0.6120) is already within a
|
| 95 |
+
few percent of *fully fine-tuned* GPT-2 (0.5970), having seen no MedQuAD at all. Most
|
| 96 |
+
of the cross-model gap is model scale and prior instruction tuning, **not** QLoRA. An
|
| 97 |
+
earlier version of this project reported a "53% improvement" by comparing the two
|
| 98 |
+
fine-tuned arms' perplexities directly; that number was wrong twice over — different
|
| 99 |
+
tokenizers, and no control.
|
| 100 |
+
|
| 101 |
+
### Generated-answer quality
|
| 102 |
+
|
| 103 |
+
Greedy decoding, ≤200 new tokens, 200 held-out questions:
|
| 104 |
+
|
| 105 |
+
| | ROUGE-L F1 ↑ | token F1 ↑ | repeated 4-grams ↓ |
|
| 106 |
+
|---|---|---|---|
|
| 107 |
+
| base (control) | 0.1548 | 0.2718 | 0.0101 |
|
| 108 |
+
| **this model** | **0.2337** | **0.3435** | **0.0146** |
|
| 109 |
+
|
| 110 |
+
No degeneration — the model does not loop.
|
| 111 |
+
|
| 112 |
+
### Factual soundness (blinded, 1–5)
|
| 113 |
+
|
| 114 |
+
| | mean ↑ | contradicts reference ↓ |
|
| 115 |
+
|---|---|---|
|
| 116 |
+
| base (control) | 2.30 | 50% |
|
| 117 |
+
| **this model** | **2.70** | **40%** |
|
| 118 |
+
|
| 119 |
+
Fine-tuning produced **no detectable improvement in factual accuracy** (paired 95% CI
|
| 120 |
+
−0.10 to +0.90, spanning zero), despite the automatic metrics reporting large gains.
|
| 121 |
+
What *is* detectable is that the untouched base model already beats the fully
|
| 122 |
+
fine-tuned GPT-2 arm by +1.10 (95% CI +0.55 to +1.65).
|
| 123 |
+
|
| 124 |
+
These ratings were produced by an LLM judge, not a clinician, and are labelled as such
|
| 125 |
+
in the source repository. They are a strong prior, not a clinical assessment.
|
| 126 |
+
|
| 127 |
+
## Usage
|
| 128 |
|
| 129 |
```python
|
| 130 |
+
from peft import PeftModel
|
| 131 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 132 |
+
|
| 133 |
+
base_id = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
|
| 134 |
+
base = AutoModelForCausalLM.from_pretrained(base_id)
|
| 135 |
+
model = PeftModel.from_pretrained(base, "Babblu2821/tinyllama-medqa-qlora")
|
| 136 |
+
tokenizer = AutoTokenizer.from_pretrained("Babblu2821/tinyllama-medqa-qlora")
|
| 137 |
+
|
| 138 |
+
prompt = tokenizer.apply_chat_template(
|
| 139 |
+
[{"role": "user", "content": "What is anemia?"}],
|
| 140 |
+
tokenize=False,
|
| 141 |
+
add_generation_prompt=True,
|
| 142 |
+
)
|
| 143 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
| 144 |
+
out = model.generate(**inputs, max_new_tokens=160, repetition_penalty=1.15)
|
| 145 |
+
print(tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
|
| 146 |
```
|
| 147 |
|
| 148 |
+
4-bit loading requires CUDA (`bitsandbytes`). On CPU or Apple Silicon, load in fp16 or
|
| 149 |
+
fp32 as above — the published evaluation was run that way, in fp16 on MPS, so the
|
| 150 |
+
figures are not bit-identical to a 4-bit run.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
|
| 152 |
+
## Limitations
|
| 153 |
|
| 154 |
+
- **Not factually reliable.** See the measured numbers above.
|
| 155 |
+
- One epoch, one seed, one run — no variance estimate across training runs.
|
| 156 |
+
- The comparison against the GPT-2 arm confounds model size, prior instruction tuning
|
| 157 |
+
and adaptation method. Only the within-model comparison is attributable.
|
| 158 |
+
- MedQuAD is NIH-sourced, US-centric, and frozen at collection time.
|
| 159 |
+
- Evaluation compares against a single reference answer.
|
| 160 |
|
| 161 |
+
## License
|
| 162 |
|
| 163 |
+
Apache 2.0, following the base model. The dataset carries its own license.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|