Add model card: architecture, training, usage, limitations
#1
by Yatsuiii - opened
README.md
CHANGED
|
@@ -1,117 +1,207 @@
|
|
| 1 |
---
|
| 2 |
-
language: en
|
| 3 |
license: apache-2.0
|
| 4 |
base_model: Qwen/Qwen2.5-7B-Instruct
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
tags:
|
| 6 |
-
- qwen2
|
| 7 |
- neuroscience
|
| 8 |
- ASD
|
|
|
|
| 9 |
- fMRI
|
| 10 |
- clinical-nlp
|
| 11 |
- fine-tuned
|
|
|
|
|
|
|
|
|
|
| 12 |
- amd-mi300x
|
| 13 |
- rocm
|
| 14 |
-
|
|
|
|
| 15 |
---
|
| 16 |
|
| 17 |
# asd-interpreter-merged
|
| 18 |
|
| 19 |
-
**
|
| 20 |
-
|
|
|
|
| 21 |
|
| 22 |
-
|
|
|
|
| 23 |
|
| 24 |
---
|
| 25 |
|
| 26 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|---|---|
|
| 30 |
-
| **Base model** | Qwen/Qwen2.5-7B-Instruct |
|
| 31 |
-
| **
|
| 32 |
-
| **
|
| 33 |
-
| **
|
| 34 |
-
| **
|
| 35 |
-
| **
|
|
|
|
| 36 |
|
| 37 |
---
|
| 38 |
|
| 39 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
-
|
| 42 |
-
- Ensemble ASD probability `p(ASD)`
|
| 43 |
-
- Per-model predictions from 20 LOSO site-blind GCN models
|
| 44 |
-
- Network-level gradient saliency scores (7 Yeo networks: DMN, Salience, Frontoparietal, etc.)
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
3. Site-invariance assessment (20/20 model consensus signals robustness)
|
| 50 |
-
4. Recommended next steps for clinical review
|
| 51 |
|
| 52 |
---
|
| 53 |
|
| 54 |
-
##
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
import torch
|
| 59 |
|
| 60 |
-
|
| 61 |
-
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 62 |
-
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16, device_map="auto")
|
| 63 |
|
| 64 |
-
|
| 65 |
|
| 66 |
-
|
| 67 |
-
-
|
| 68 |
-
-
|
| 69 |
-
|
|
|
|
| 70 |
|
| 71 |
-
|
| 72 |
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
```
|
| 78 |
|
| 79 |
-
|
| 80 |
|
| 81 |
-
|
| 82 |
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
-
|
| 86 |
-
-
|
| 87 |
-
|
| 88 |
|
| 89 |
---
|
| 90 |
|
| 91 |
-
##
|
| 92 |
|
| 93 |
-
|
| 94 |
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
|
| 99 |
---
|
| 100 |
|
| 101 |
## Limitations
|
| 102 |
|
| 103 |
-
-
|
| 104 |
-
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
---
|
| 108 |
|
| 109 |
-
##
|
| 110 |
|
| 111 |
-
|
|
|
|
|
|
|
| 112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
```
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
|
|
|
| 1 |
---
|
|
|
|
| 2 |
license: apache-2.0
|
| 3 |
base_model: Qwen/Qwen2.5-7B-Instruct
|
| 4 |
+
library_name: transformers
|
| 5 |
+
pipeline_tag: text-generation
|
| 6 |
+
language:
|
| 7 |
+
- en
|
| 8 |
tags:
|
|
|
|
| 9 |
- neuroscience
|
| 10 |
- ASD
|
| 11 |
+
- autism
|
| 12 |
- fMRI
|
| 13 |
- clinical-nlp
|
| 14 |
- fine-tuned
|
| 15 |
+
- qwen2
|
| 16 |
+
- lora
|
| 17 |
+
- merged
|
| 18 |
- amd-mi300x
|
| 19 |
- rocm
|
| 20 |
+
datasets:
|
| 21 |
+
- custom-synthetic-clinical
|
| 22 |
---
|
| 23 |
|
| 24 |
# asd-interpreter-merged
|
| 25 |
|
| 26 |
+
**Qwen2.5-7B fine-tuned to translate brain-connectivity GCN outputs into structured clinical reports.**
|
| 27 |
+
|
| 28 |
+
Companion language model to [`Yatsuiii/brain-connect-gcn`](https://huggingface.co/Yatsuiii/brain-connect-gcn) — takes the GCN's per-network gradient saliency and ensemble probability and produces a neurologist-readable interpretation grounded only in the input values.
|
| 29 |
|
| 30 |
+
Live demo: [BrainConnect-ASD Space](https://huggingface.co/spaces/lablab-ai-amd-developer-hackathon/BrainConnect-ASD)
|
| 31 |
+
Built for the **AMD Developer Hackathon 2026**.
|
| 32 |
|
| 33 |
---
|
| 34 |
|
| 35 |
+
## What this model does
|
| 36 |
+
|
| 37 |
+
The GCN ensemble outputs a number (`p(ASD)`) and a saliency map over 7 brain networks. Those numbers are useless to a clinician without context. This model writes the clinical interpretation:
|
| 38 |
+
|
| 39 |
+
```
|
| 40 |
+
Input → ICD-10 code · ensemble confidence · per-network findings
|
| 41 |
+
· cross-site agreement · supporting literature · disclaimer
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
It is **constrained to ground every finding** in the per-network saliency scores it receives — it must not invent networks, statistics, or citations not present in the input. The system prompt enforces this; the LoRA was trained on 600 examples where this constraint was modelled.
|
| 45 |
|
| 46 |
+
---
|
| 47 |
+
|
| 48 |
+
## Architecture
|
| 49 |
+
|
| 50 |
+
| Component | Detail |
|
| 51 |
|---|---|
|
| 52 |
+
| **Base model** | `Qwen/Qwen2.5-7B-Instruct` |
|
| 53 |
+
| **Adaptation** | LoRA, then merged back into the base for single-file inference |
|
| 54 |
+
| **LoRA rank (r)** | 16 |
|
| 55 |
+
| **LoRA alpha** | 32 |
|
| 56 |
+
| **Target modules** | `q_proj`, `k_proj`, `v_proj`, `o_proj`, `gate_proj`, `up_proj`, `down_proj` |
|
| 57 |
+
| **Precision** | bf16 (no quantization needed on MI300X) |
|
| 58 |
+
| **Context window** | inherited from base (32k) |
|
| 59 |
|
| 60 |
---
|
| 61 |
|
| 62 |
+
## Training
|
| 63 |
+
|
| 64 |
+
| Detail | Value |
|
| 65 |
+
|---|---|
|
| 66 |
+
| **Examples** | 600 (synthetic clinical-report dialogues) |
|
| 67 |
+
| **Epochs** | 3 |
|
| 68 |
+
| **Batch size** | 4 |
|
| 69 |
+
| **Learning rate** | 2e-4 |
|
| 70 |
+
| **Optimizer** | AdamW (default Hugging Face Trainer) |
|
| 71 |
+
| **Hardware** | AMD Instinct MI300X (single GPU) |
|
| 72 |
+
| **Software** | PyTorch 2.5.1 · ROCm 7.0 · PEFT 0.14 · Transformers 4.46 |
|
| 73 |
+
| **Training time** | ~25 minutes on a single MI300X |
|
| 74 |
|
| 75 |
+
Training data was generated programmatically by sampling realistic GCN outputs (`p(ASD)`, per-network saliency, per-model votes) across the three diagnostic regions (clear ASD, clear TC, borderline) and pairing each with a structured clinical report grounded in those exact values. The system prompt enforces grounding; the LoRA learns the report format and the conventions for ICD-10 coding, ensemble-consensus phrasing, and supporting-literature citation.
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
+
### Why MI300X
|
| 78 |
+
|
| 79 |
+
The 192 GB HBM3 unified memory on a single MI300X fit the full Qwen2.5-7B in bf16 with PEFT optimizer state — no quantization, no sharding, no gradient checkpointing tricks. ROCm 7.0's PyTorch backend ran the existing training script with zero code changes from a CUDA setup.
|
|
|
|
|
|
|
| 80 |
|
| 81 |
---
|
| 82 |
|
| 83 |
+
## Intended use
|
| 84 |
|
| 85 |
+
- **Demo / educational**: live in the [BrainConnect-ASD Space](https://huggingface.co/spaces/lablab-ai-amd-developer-hackathon/BrainConnect-ASD), where every clinical report is generated from real GCN outputs.
|
| 86 |
+
- **Research**: as a downstream interpreter for connectivity-based classifiers that need readable outputs for review.
|
|
|
|
| 87 |
|
| 88 |
+
**This is not a medical device.** Outputs are AI-assisted screening text only. Any clinical decision must be made by a licensed clinician using ADOS-2, ADI-R, and full developmental history.
|
|
|
|
|
|
|
| 89 |
|
| 90 |
+
## Out-of-scope use
|
| 91 |
|
| 92 |
+
- Direct diagnosis or treatment decisions.
|
| 93 |
+
- General medical question-answering (the model was tuned on a narrow report-writing task; behavior outside that distribution is undefined).
|
| 94 |
+
- Inputs that are not formatted as `Brain Connectivity GCN Analysis Report` (the system prompt assumes that specific structured input).
|
| 95 |
+
|
| 96 |
+
---
|
| 97 |
|
| 98 |
+
## How to use
|
| 99 |
|
| 100 |
+
### Via the Space
|
| 101 |
+
|
| 102 |
+
The simplest path is the live [BrainConnect-ASD Space](https://huggingface.co/spaces/lablab-ai-amd-developer-hackathon/BrainConnect-ASD) — upload an fMRI ROI time-series or click a demo subject and the Space wires this model into the pipeline automatically.
|
| 103 |
+
|
| 104 |
+
### Direct inference
|
| 105 |
+
|
| 106 |
+
```python
|
| 107 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 108 |
+
|
| 109 |
+
model_id = "lablab-ai-amd-developer-hackathon/asd-interpreter-merged"
|
| 110 |
+
tok = AutoTokenizer.from_pretrained(model_id)
|
| 111 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype="bfloat16", device_map="auto")
|
| 112 |
+
|
| 113 |
+
SYSTEM = (
|
| 114 |
+
"You are a clinical AI assistant specializing in functional MRI brain "
|
| 115 |
+
"connectivity analysis for autism spectrum disorder (ASD) diagnosis support. "
|
| 116 |
+
"You interpret outputs from a validated graph neural network (GCN) trained on "
|
| 117 |
+
"the ABIDE I dataset (1,102 subjects, 20 acquisition sites). Only reference "
|
| 118 |
+
"brain networks and values explicitly provided in the input. Do not hallucinate."
|
| 119 |
+
)
|
| 120 |
+
|
| 121 |
+
USER = """Brain Connectivity GCN Analysis Report
|
| 122 |
+
========================================
|
| 123 |
+
Dataset : ABIDE I · 1,102 subjects · 20 acquisition sites
|
| 124 |
+
p(ASD) : 0.841
|
| 125 |
+
Confidence Level : HIGH
|
| 126 |
+
Model Consensus : 19/20 site-blind models predict ASD
|
| 127 |
+
|
| 128 |
+
Per-Network Gradient Saliency (ranked high→low):
|
| 129 |
+
DMN: 0.00821
|
| 130 |
+
Frontoparietal: 0.00674
|
| 131 |
+
Subcortical: 0.00591
|
| 132 |
+
|
| 133 |
+
Provide a structured clinical interpretation referencing ONLY the networks
|
| 134 |
+
and values listed above."""
|
| 135 |
+
|
| 136 |
+
prompt = tok.apply_chat_template(
|
| 137 |
+
[{"role": "system", "content": SYSTEM},
|
| 138 |
+
{"role": "user", "content": USER}],
|
| 139 |
+
tokenize=False, add_generation_prompt=True,
|
| 140 |
+
)
|
| 141 |
+
out = model.generate(**tok(prompt, return_tensors="pt").to(model.device),
|
| 142 |
+
max_new_tokens=512, temperature=0.1, do_sample=False)
|
| 143 |
+
print(tok.decode(out[0][len(tok(prompt).input_ids[0]):], skip_special_tokens=True))
|
| 144 |
```
|
| 145 |
|
| 146 |
+
### Serving via vLLM
|
| 147 |
|
| 148 |
+
The Space uses vLLM with this model on an AMD MI300X for live inference. The merged checkpoint loads directly without LoRA adapters:
|
| 149 |
|
| 150 |
+
```bash
|
| 151 |
+
vllm serve lablab-ai-amd-developer-hackathon/asd-interpreter-merged \
|
| 152 |
+
--dtype bfloat16 \
|
| 153 |
+
--max-model-len 8192
|
| 154 |
+
```
|
| 155 |
|
| 156 |
---
|
| 157 |
|
| 158 |
+
## Evaluation
|
| 159 |
|
| 160 |
+
Evaluation is qualitative — the goal of the fine-tune was to enforce report structure and grounding, not to maximize a numeric metric. Manual inspection over the validation cohort of the [BrainConnect-ASD Space](https://huggingface.co/spaces/lablab-ai-amd-developer-hackathon/BrainConnect-ASD):
|
| 161 |
|
| 162 |
+
| Property | Behavior |
|
| 163 |
+
|---|---|
|
| 164 |
+
| **Grounding** | All reports reference only networks present in the input saliency block |
|
| 165 |
+
| **ICD-10 coding** | Correctly maps `p(ASD)` regions to F84.0 / Z03.89 / F84.5 |
|
| 166 |
+
| **Borderline handling** | Recommends ADOS-2 / ADI-R follow-up when 0.4 < p < 0.6 |
|
| 167 |
+
| **Disclaimer** | Always appended; never omitted across the validation cohort |
|
| 168 |
+
|
| 169 |
+
The base Qwen2.5-7B-Instruct produces qualitatively similar text but does not consistently obey the grounding constraint without explicit few-shot demonstrations. The LoRA bakes the format in.
|
| 170 |
|
| 171 |
---
|
| 172 |
|
| 173 |
## Limitations
|
| 174 |
|
| 175 |
+
1. **Small fine-tune corpus** — 600 synthetic examples. The model learned the report format but did not see real-world clinical variation.
|
| 176 |
+
2. **Synthetic training data** — all examples were programmatically generated. The structure is realistic but the underlying connectivity patterns were sampled, not measured.
|
| 177 |
+
3. **Tight prompt assumption** — outside the `Brain Connectivity GCN Analysis Report` input format, behavior is unconstrained and may regress to base Qwen2.5-7B-Instruct behavior.
|
| 178 |
+
4. **English only** — base Qwen2.5-7B-Instruct is multilingual but the fine-tune was English-only.
|
| 179 |
+
5. **No real ABIDE patient cases were used** for training — the GCN ensemble itself was trained on ABIDE I (1,102 subjects), but this language model was trained only on synthetic interpretations of GCN outputs.
|
| 180 |
+
6. **Not a medical device.** Treat all outputs as illustrative.
|
| 181 |
|
| 182 |
---
|
| 183 |
|
| 184 |
+
## Companion artifacts
|
| 185 |
|
| 186 |
+
- 🧠 GCN ensemble: [`Yatsuiii/brain-connect-gcn`](https://huggingface.co/Yatsuiii/brain-connect-gcn)
|
| 187 |
+
- 🚀 Live Space: [`lablab-ai-amd-developer-hackathon/BrainConnect-ASD`](https://huggingface.co/spaces/lablab-ai-amd-developer-hackathon/BrainConnect-ASD)
|
| 188 |
+
- 📖 Source: [`Yatsuiii/Brain-Connectivity-GCN`](https://github.com/Yatsuiii/Brain-Connectivity-GCN)
|
| 189 |
|
| 190 |
+
---
|
| 191 |
+
|
| 192 |
+
## Citation
|
| 193 |
+
|
| 194 |
+
```bibtex
|
| 195 |
+
@misc{brainconnect_asd_2026,
|
| 196 |
+
title = {BrainConnect-ASD: Site-Invariant Autism Detection from Resting-State fMRI
|
| 197 |
+
with a Clinical Language Interpreter},
|
| 198 |
+
author = {Sharma, Raghav},
|
| 199 |
+
year = {2026},
|
| 200 |
+
note = {AMD Developer Hackathon 2026 submission},
|
| 201 |
+
url = {https://huggingface.co/spaces/lablab-ai-amd-developer-hackathon/BrainConnect-ASD}
|
| 202 |
+
}
|
| 203 |
```
|
| 204 |
+
|
| 205 |
+
## License
|
| 206 |
+
|
| 207 |
+
Apache 2.0, inherited from the Qwen2.5-7B-Instruct base model.
|