Instructions to use HK2184/medqa-qwen3-lora with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use HK2184/medqa-qwen3-lora with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen3-1.7B") model = PeftModel.from_pretrained(base_model, "HK2184/medqa-qwen3-lora") - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,207 +1,154 @@
|
|
| 1 |
---
|
|
|
|
|
|
|
| 2 |
base_model: Qwen/Qwen3-1.7B
|
| 3 |
-
library_name: peft
|
| 4 |
-
pipeline_tag: text-generation
|
| 5 |
tags:
|
| 6 |
-
-
|
| 7 |
-
- lora
|
| 8 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
---
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
|
| 13 |
-
<!-- Provide a quick summary of what the model is/does. -->
|
| 14 |
-
|
| 15 |
|
|
|
|
|
|
|
| 16 |
|
| 17 |
## Model Details
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
- **Developed by:** [More Information Needed]
|
| 26 |
-
- **Funded by [optional]:** [More Information Needed]
|
| 27 |
-
- **Shared by [optional]:** [More Information Needed]
|
| 28 |
-
- **Model type:** [More Information Needed]
|
| 29 |
-
- **Language(s) (NLP):** [More Information Needed]
|
| 30 |
-
- **License:** [More Information Needed]
|
| 31 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
| 32 |
-
|
| 33 |
-
### Model Sources [optional]
|
| 34 |
-
|
| 35 |
-
<!-- Provide the basic links for the model. -->
|
| 36 |
|
| 37 |
-
|
| 38 |
-
- **Paper [optional]:** [More Information Needed]
|
| 39 |
-
- **Demo [optional]:** [More Information Needed]
|
| 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 |
## Training Details
|
| 82 |
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
| 92 |
-
|
| 93 |
-
#### Preprocessing [optional]
|
| 94 |
-
|
| 95 |
-
[More Information Needed]
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
#### Training Hyperparameters
|
| 99 |
-
|
| 100 |
-
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
|
| 101 |
-
|
| 102 |
-
#### Speeds, Sizes, Times [optional]
|
| 103 |
-
|
| 104 |
-
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
| 105 |
-
|
| 106 |
-
[More Information Needed]
|
| 107 |
-
|
| 108 |
-
## Evaluation
|
| 109 |
-
|
| 110 |
-
<!-- This section describes the evaluation protocols and provides the results. -->
|
| 111 |
-
|
| 112 |
-
### Testing Data, Factors & Metrics
|
| 113 |
-
|
| 114 |
-
#### Testing Data
|
| 115 |
-
|
| 116 |
-
<!-- This should link to a Dataset Card if possible. -->
|
| 117 |
-
|
| 118 |
-
[More Information Needed]
|
| 119 |
-
|
| 120 |
-
#### Factors
|
| 121 |
-
|
| 122 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
| 123 |
-
|
| 124 |
-
[More Information Needed]
|
| 125 |
-
|
| 126 |
-
#### Metrics
|
| 127 |
-
|
| 128 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
| 129 |
-
|
| 130 |
-
[More Information Needed]
|
| 131 |
-
|
| 132 |
-
### Results
|
| 133 |
-
|
| 134 |
-
[More Information Needed]
|
| 135 |
-
|
| 136 |
-
#### Summary
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
## Model Examination [optional]
|
| 141 |
-
|
| 142 |
-
<!-- Relevant interpretability work for the model goes here -->
|
| 143 |
-
|
| 144 |
-
[More Information Needed]
|
| 145 |
-
|
| 146 |
-
## Environmental Impact
|
| 147 |
-
|
| 148 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
| 149 |
-
|
| 150 |
-
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).
|
| 151 |
-
|
| 152 |
-
- **Hardware Type:** [More Information Needed]
|
| 153 |
-
- **Hours used:** [More Information Needed]
|
| 154 |
-
- **Cloud Provider:** [More Information Needed]
|
| 155 |
-
- **Compute Region:** [More Information Needed]
|
| 156 |
-
- **Carbon Emitted:** [More Information Needed]
|
| 157 |
-
|
| 158 |
-
## Technical Specifications [optional]
|
| 159 |
-
|
| 160 |
-
### Model Architecture and Objective
|
| 161 |
-
|
| 162 |
-
[More Information Needed]
|
| 163 |
-
|
| 164 |
-
### Compute Infrastructure
|
| 165 |
-
|
| 166 |
-
[More Information Needed]
|
| 167 |
-
|
| 168 |
-
#### Hardware
|
| 169 |
-
|
| 170 |
-
[More Information Needed]
|
| 171 |
-
|
| 172 |
-
#### Software
|
| 173 |
-
|
| 174 |
-
[More Information Needed]
|
| 175 |
-
|
| 176 |
-
## Citation [optional]
|
| 177 |
-
|
| 178 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
| 179 |
-
|
| 180 |
-
**BibTeX:**
|
| 181 |
|
| 182 |
-
|
| 183 |
|
| 184 |
-
|
|
|
|
|
|
|
| 185 |
|
| 186 |
-
|
|
|
|
|
|
|
|
|
|
| 187 |
|
| 188 |
-
##
|
| 189 |
|
| 190 |
-
|
|
|
|
| 191 |
|
| 192 |
-
|
| 193 |
|
| 194 |
-
|
|
|
|
| 195 |
|
| 196 |
-
|
| 197 |
|
| 198 |
-
|
|
|
|
|
|
|
| 199 |
|
| 200 |
-
|
| 201 |
|
| 202 |
-
|
|
|
|
| 203 |
|
| 204 |
-
|
| 205 |
-
### Framework versions
|
| 206 |
|
| 207 |
-
|
|
|
|
| 1 |
---
|
| 2 |
+
language: en
|
| 3 |
+
license: mit
|
| 4 |
base_model: Qwen/Qwen3-1.7B
|
|
|
|
|
|
|
| 5 |
tags:
|
| 6 |
+
- medical
|
| 7 |
+
- lora
|
| 8 |
+
- peft
|
| 9 |
+
- rocm
|
| 10 |
+
- amd
|
| 11 |
+
- question-answering
|
| 12 |
+
- fine-tuned
|
| 13 |
+
datasets:
|
| 14 |
+
- openlifescienceai/medmcqa
|
| 15 |
---
|
| 16 |
|
| 17 |
+
# MedQA — Qwen3-1.7B LoRA Fine-tuned on MedMCQA
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
Clinical question-answering AI fine-tuned on MedMCQA.
|
| 20 |
+
Built on AMD Instinct MI300X via ROCm — no CUDA required.
|
| 21 |
|
| 22 |
## Model Details
|
| 23 |
|
| 24 |
+
- Base Model : Qwen/Qwen3-1.7B
|
| 25 |
+
- Fine-tuning : LoRA (r=4, target: q_proj + v_proj)
|
| 26 |
+
- Dataset : openlifescienceai/medmcqa (193k clinical MCQs)
|
| 27 |
+
- Hardware : AMD Instinct MI300X (192GB HBM3)
|
| 28 |
+
- Precision : bfloat16 (ROCm native)
|
| 29 |
+
- Trainable : ~2.2M of 1.7B parameters (0.15%)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
+
## What It Does
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
Given a clinical multiple-choice question with 4 options,
|
| 34 |
+
the model selects the correct answer and explains its reasoning.
|
| 35 |
|
| 36 |
+
Example input:
|
| 37 |
|
| 38 |
+
### Question:
|
| 39 |
+
First-line treatment for hypertensive emergency?
|
| 40 |
|
| 41 |
+
### Options:
|
| 42 |
+
A) Oral amlodipine
|
| 43 |
+
B) IV labetalol or IV nitroprusside
|
| 44 |
+
C) Sublingual nifedipine
|
| 45 |
+
D) IM hydralazine
|
| 46 |
|
| 47 |
+
### Answer:
|
| 48 |
|
| 49 |
+
Example output:
|
| 50 |
|
| 51 |
+
B) IV labetalol or IV nitroprusside
|
| 52 |
|
| 53 |
+
Explanation:
|
| 54 |
+
Hypertensive emergencies require immediate IV therapy.
|
| 55 |
+
Labetalol is a combined alpha and beta blocker that rapidly
|
| 56 |
+
reduces blood pressure safely. Nitroprusside is a vasodilator
|
| 57 |
+
used when faster or more precise control is needed.
|
| 58 |
|
| 59 |
+
## How to Use
|
| 60 |
|
| 61 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 62 |
+
from peft import PeftModel
|
| 63 |
+
import torch
|
| 64 |
|
| 65 |
+
BASE_MODEL = "Qwen/Qwen3-1.7B"
|
| 66 |
+
ADAPTER_REPO = "HK2184/medqa-qwen3-lora"
|
| 67 |
|
| 68 |
+
tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL, trust_remote_code=True)
|
| 69 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 70 |
+
tokenizer.padding_side = "left"
|
| 71 |
|
| 72 |
+
base = AutoModelForCausalLM.from_pretrained(
|
| 73 |
+
BASE_MODEL,
|
| 74 |
+
dtype=torch.bfloat16,
|
| 75 |
+
device_map="auto",
|
| 76 |
+
trust_remote_code=True,
|
| 77 |
+
)
|
| 78 |
|
| 79 |
+
model = PeftModel.from_pretrained(base, ADAPTER_REPO)
|
| 80 |
+
model = model.merge_and_unload()
|
| 81 |
+
model.eval()
|
| 82 |
|
| 83 |
+
prompt = """### Question:
|
| 84 |
+
First-line treatment for hypertensive emergency?
|
| 85 |
|
| 86 |
+
### Options:
|
| 87 |
+
A) Oral amlodipine
|
| 88 |
+
B) IV labetalol or IV nitroprusside
|
| 89 |
+
C) Sublingual nifedipine
|
| 90 |
+
D) IM hydralazine
|
| 91 |
|
| 92 |
+
### Answer:
|
| 93 |
+
"""
|
| 94 |
|
| 95 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 96 |
+
with torch.no_grad():
|
| 97 |
+
out = model.generate(
|
| 98 |
+
**inputs,
|
| 99 |
+
max_new_tokens=200,
|
| 100 |
+
do_sample=True,
|
| 101 |
+
temperature=0.7,
|
| 102 |
+
top_p=0.9,
|
| 103 |
+
repetition_penalty=1.3,
|
| 104 |
+
pad_token_id=tokenizer.eos_token_id,
|
| 105 |
+
)
|
| 106 |
+
new = out[0][inputs["input_ids"].shape[-1]:]
|
| 107 |
+
print(tokenizer.decode(new, skip_special_tokens=True))
|
| 108 |
|
| 109 |
## Training Details
|
| 110 |
|
| 111 |
+
- Framework : PyTorch + HuggingFace Transformers + PEFT + TRL
|
| 112 |
+
- LoRA rank : r=4, alpha=16
|
| 113 |
+
- Batch size : 4
|
| 114 |
+
- Learning rate: 1e-4
|
| 115 |
+
- Epochs : 1
|
| 116 |
+
- Max length : 128 tokens
|
| 117 |
+
- Samples : 500 from MedMCQA train split
|
| 118 |
+
- Training time: ~5 minutes on AMD MI300X
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
+
## AMD ROCm Notes
|
| 121 |
|
| 122 |
+
Trained entirely on AMD hardware using ROCm 7.2.
|
| 123 |
+
Key insight: bfloat16 is stable on MI300X — fp16 caused
|
| 124 |
+
gradient norm explosion (nan) during LoRA training.
|
| 125 |
|
| 126 |
+
Environment variables used:
|
| 127 |
+
ROCR_VISIBLE_DEVICES=0
|
| 128 |
+
HIP_VISIBLE_DEVICES=0
|
| 129 |
+
HSA_OVERRIDE_GFX_VERSION=9.4.2
|
| 130 |
|
| 131 |
+
## Live Demo
|
| 132 |
|
| 133 |
+
Try it without any setup:
|
| 134 |
+
https://huggingface.co/spaces/lablab-ai-amd-developer-hackathon/MedQA-Medical-AI-on-AMD-ROCm
|
| 135 |
|
| 136 |
+
## Repository
|
| 137 |
|
| 138 |
+
Full training code, eval script, and Gradio app:
|
| 139 |
+
https://github.com/HK2184/MedQA-Medical-AI-on-AMD-ROCm
|
| 140 |
|
| 141 |
+
## Dataset
|
| 142 |
|
| 143 |
+
MedMCQA — 193,000 medical multiple choice questions
|
| 144 |
+
from Indian medical entrance exams (AIIMS, USMLE-style).
|
| 145 |
+
https://huggingface.co/datasets/openlifescienceai/medmcqa
|
| 146 |
|
| 147 |
+
## Authors
|
| 148 |
|
| 149 |
+
Harikrishna Sivanand Iyer and Srijan Sivaram A
|
| 150 |
+
Built for the AMD Hackathon on lablab.ai
|
| 151 |
|
| 152 |
+
## License
|
|
|
|
| 153 |
|
| 154 |
+
MIT — free to use, modify, and build on.
|