Add model card: architecture, training, usage, limitations

#1
Files changed (1) hide show
  1. README.md +152 -62
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
- pipeline_tag: text-generation
 
15
  ---
16
 
17
  # asd-interpreter-merged
18
 
19
- **Clinical language interpreter for ASD fMRI connectivity reports.**
20
- Fine-tuned from `Qwen/Qwen2.5-7B-Instruct` on AMD MI300X (ROCm 7.0) using QLoRA, then merged to a single fp16 checkpoint.
 
21
 
22
- Used live in the [BrainConnect-ASD Space](https://huggingface.co/spaces/lablab-ai-amd-developer-hackathon/BrainConnect-ASD) to generate patient-facing clinical summaries from gradient saliency scores produced by a 20-model LOSO GCN ensemble.
 
23
 
24
  ---
25
 
26
- ## Model Details
 
 
 
 
 
 
 
 
 
27
 
28
- | Field | Value |
 
 
 
 
29
  |---|---|
30
- | **Base model** | Qwen/Qwen2.5-7B-Instruct |
31
- | **Fine-tuning method** | QLoRA (r=16, α=32, target: q/v projections) |
32
- | **Training hardware** | AMD MI300X · ROCm 7.0 · DigitalOcean |
33
- | **Parameters** | 8B (merged, fp16) |
34
- | **Context length** | 4096 tokens |
35
- | **License** | Apache 2.0 |
 
36
 
37
  ---
38
 
39
- ## What It Does
 
 
 
 
 
 
 
 
 
 
 
40
 
41
- Given a structured prompt containing:
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
- The model outputs a **clinical connectivity summary** with:
47
- 1. Overall impression and confidence level
48
- 2. Which brain networks drove the prediction and why
49
- 3. Site-invariance assessment (20/20 model consensus signals robustness)
50
- 4. Recommended next steps for clinical review
51
 
52
  ---
53
 
54
- ## Usage
55
 
56
- ```python
57
- from transformers import AutoTokenizer, AutoModelForCausalLM
58
- import torch
59
 
60
- model_id = "Yatsuiii/asd-interpreter-merged"
61
- tokenizer = AutoTokenizer.from_pretrained(model_id)
62
- model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16, device_map="auto")
63
 
64
- prompt = """You are a clinical neuroscience AI. Write a concise clinical connectivity summary.
65
 
66
- Patient data:
67
- - p(ASD) = 0.847 (ensemble mean across 20 site-blind models)
68
- - Model consensus: 17/20 models predict ASD
69
- - Top network saliency: DMN=0.0041, Salience=0.0038, Frontoparietal=0.0029
 
70
 
71
- Write a 3-paragraph clinical summary."""
72
 
73
- inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
74
- with torch.no_grad():
75
- out = model.generate(**inputs, max_new_tokens=400, temperature=0.3, do_sample=True)
76
- print(tokenizer.decode(out[0][inputs.input_ids.shape[1]:], skip_special_tokens=True))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  ```
78
 
79
- ---
80
 
81
- ## Training Details
82
 
83
- - **Dataset**: Synthetic clinical summaries generated from ABIDE I gradient saliency outputs, manually curated for clinical tone and factual grounding
84
- - **Fine-tuning**: QLoRA via `peft` + `trl` SFTTrainer
85
- - **Hardware**: AMD MI300X (192GB HBM3), ROCm 7.0, PyTorch 2.5.1+rocm6.2
86
- - **Epochs**: 3 · Batch size: 4 · LR: 2e-4 · Warmup: 50 steps
87
- - **Merge**: LoRA adapter merged into base weights with `peft.merge_and_unload()`
88
 
89
  ---
90
 
91
- ## Integration
92
 
93
- This model runs as a vLLM endpoint (served via `rocm/vllm`) and is queried by the BrainConnect-ASD Gradio Space after every inference run. If the vLLM server is unavailable, the Space falls back to a cached demo report.
94
 
95
- ```
96
- Space → GCN ensemble inference → gradient saliency → structured prompt → this model → clinical report
97
- ```
 
 
 
 
 
98
 
99
  ---
100
 
101
  ## Limitations
102
 
103
- - Trained on synthetic data derived from ABIDE I not validated on real clinical populations
104
- - Not a medical device. Outputs are for research and demonstration purposes only.
105
- - Performance degrades on atlases other than CC200 (saliency prompt was optimized for CC200 Yeo-7 mapping)
 
 
 
106
 
107
  ---
108
 
109
- ## Citation
110
 
111
- If you use this model or the BrainConnect-ASD pipeline, please cite:
 
 
112
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  ```
114
- BrainConnect-ASD — AMD Developer Hackathon 2026
115
- Raghav Aryen · lablab.ai · AMD MI300X
116
- https://huggingface.co/spaces/lablab-ai-amd-developer-hackathon/BrainConnect-ASD
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.