Update README.md
Browse files
README.md
CHANGED
|
@@ -1,80 +1,160 @@
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
datasets:
|
| 4 |
-
-
|
| 5 |
language:
|
| 6 |
- en
|
| 7 |
tags:
|
| 8 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
---
|
| 10 |
-
# MedAssist-GPT
|
| 11 |
|
| 12 |
-
|
| 13 |
-
**NOT for clinical use.**
|
| 14 |
|
| 15 |
-
|
|
|
|
| 16 |
|
| 17 |
-
|
| 18 |
-
* **Tokenizer:** `tiktoken` **p50k_base** (vocab โ 50,281).
|
| 19 |
-
* **Context:** 1,024 tokens (default).
|
| 20 |
-
* **Size (default config):** ~125M params (d_model=512, n_heads=16, layers=16, d_ff=2048).
|
| 21 |
-
* **Trained on** about 2.2B tokens of pure medical data.
|
| 22 |
|
| 23 |
-
##
|
| 24 |
|
| 25 |
-
*
|
| 26 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
|
| 29 |
|
| 30 |
-
|
| 31 |
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
|
|
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
```python
|
| 41 |
# pip install torch tiktoken huggingface_hub safetensors
|
| 42 |
import torch, tiktoken
|
| 43 |
from safetensors.torch import load_file
|
| 44 |
from huggingface_hub import hf_hub_download
|
|
|
|
| 45 |
|
| 46 |
-
REPO_ID = "kunjcr2/
|
| 47 |
-
|
| 48 |
-
state = load_file(
|
| 49 |
-
|
| 50 |
-
# Import your MedAssistGPT class from the script/notebook
|
| 51 |
-
from MedAssistGPT import MedAssistGPT, MODEL_CONFIG # ensure paths match your repo
|
| 52 |
|
| 53 |
model = MedAssistGPT(MODEL_CONFIG)
|
| 54 |
model.load_state_dict(state, strict=True).eval()
|
| 55 |
|
| 56 |
enc = tiktoken.get_encoding("p50k_base")
|
| 57 |
-
ids = torch.tensor([enc.encode(
|
| 58 |
-
with
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
print(enc.decode(ids[0].tolist()))
|
| 66 |
```
|
| 67 |
|
| 68 |
-
|
| 69 |
|
| 70 |
-
|
| 71 |
-
Do **NOT** use for medical decisions.
|
| 72 |
|
| 73 |
-
|
|
|
|
| 74 |
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
* `config.json`, `tokenizer_config.json`
|
| 77 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
-
|
| 80 |
-
Apache-2.0
|
|
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
datasets:
|
| 4 |
+
- japhba/pubmed_simple
|
| 5 |
language:
|
| 6 |
- en
|
| 7 |
tags:
|
| 8 |
+
- v2_pretrain_medassist
|
| 9 |
+
- gqa
|
| 10 |
+
- rope
|
| 11 |
+
- swiglu
|
| 12 |
+
- rmsnorm
|
| 13 |
+
- medical
|
| 14 |
---
|
|
|
|
| 15 |
|
| 16 |
+
# ๐ง MedAssist-GPT-401M
|
|
|
|
| 17 |
|
| 18 |
+
**Mid-sized medical-domain LLM pretraining project.**
|
| 19 |
+
โ ๏ธ *Strictly for research. Not for clinical or diagnostic use.*
|
| 20 |
|
| 21 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
## ๐งฉ TL;DR
|
| 24 |
|
| 25 |
+
* **Architecture:** Transformer with **RoPE**, **GQA**, **SwiGLU** MLP, and **RMSNorm**
|
| 26 |
+
* **Tokenizer:** `tiktoken` `p50k_base` (vocab โ **50,281**)
|
| 27 |
+
* **Context length:** 1,024 tokens
|
| 28 |
+
* **Parameters:** โ **401 M** (`d_model=1024`, `n_heads=32`, `blocks=24`, `d_ff=2048`)
|
| 29 |
+
* **GQA groups:** 8 โ 4 KV heads per 32 query heads
|
| 30 |
+
* **Dropout:** 0.0 (pretraining)
|
| 31 |
+
* **Precision:** **bf16** mixed precision
|
| 32 |
+
* **Training objective:** Next-token prediction
|
| 33 |
+
* **Effective batch:** 32 ร 4 = 128
|
| 34 |
|
| 35 |
+
---
|
| 36 |
|
| 37 |
+
## ๐ Data
|
| 38 |
|
| 39 |
+
| Field | Value |
|
| 40 |
+
| ----------------------- | --------------------------------- |
|
| 41 |
+
| **Dataset** | `japhba/pubmed_simple` |
|
| 42 |
+
| **Text column** | `abstract` |
|
| 43 |
+
| **Train/Val split** | 95 / 5 |
|
| 44 |
+
| **Samples used** | 100 k abstracts |
|
| 45 |
+
| **Seq length / stride** | 1,024 / 1,024 |
|
| 46 |
+
| **Cleaning** | `use_clean=False` (raw abstracts) |
|
| 47 |
|
| 48 |
+
---
|
| 49 |
|
| 50 |
+
## โ๏ธ Training
|
| 51 |
+
|
| 52 |
+
| Item | Value |
|
| 53 |
+
| -------------------------- | --------------------------------------------------------------------- |
|
| 54 |
+
| **Framework** | PyTorch |
|
| 55 |
+
| **Precision** | bf16 |
|
| 56 |
+
| **Objective** | Causal LM (next-token prediction) |
|
| 57 |
+
| **Optimizer** | AdamW (`ฮฒโ = 0.9`, `ฮฒโ = 0.95`, `eps = 1e-8`) |
|
| 58 |
+
| **Learning rate** | 3 ร 10โปโด (linear + 100-step warmup) |
|
| 59 |
+
| **Weight decay** | 0.1 |
|
| 60 |
+
| **Batch size** | 32 (ร 4 grad acc โ 128 effective) |
|
| 61 |
+
| **Grad clip** | 1.0 |
|
| 62 |
+
| **Total steps** | 100 k |
|
| 63 |
+
| **Eval** | every 500 steps ร 100 iters |
|
| 64 |
+
| **Checkpoint save** | every 1 k steps |
|
| 65 |
+
| **Seed** | 7 979 797 |
|
| 66 |
+
| **Gradient checkpointing** | โ
Enabled |
|
| 67 |
+
| **WandB** | `kunjcr2-dreamable/MedAssist-GPT-Pretraining` (`medassist-401M-test`) |
|
| 68 |
+
| **HF repo** | `kunjcr2/MedAssist-GPT-401M` |
|
| 69 |
+
|
| 70 |
+
---
|
| 71 |
+
|
| 72 |
+
## ๐งฎ Training Environment
|
| 73 |
+
|
| 74 |
+
| Item | Value |
|
| 75 |
+
| ------------------- | ---------------------- |
|
| 76 |
+
| **Hardware** | 1ร NVIDIA A100 (80 GB) |
|
| 77 |
+
| **Precision dtype** | bf16 |
|
| 78 |
+
| **Runtime** | ~15 hours |
|
| 79 |
+
| **Scheduler** | Linear LR decay |
|
| 80 |
+
| **Mixed precision** | Native AMP (bf16) |
|
| 81 |
+
|
| 82 |
+
---
|
| 83 |
|
| 84 |
+
## ๐ Loss Curves
|
| 85 |
+
|
| 86 |
+
*(Placeholder โ will update post-training)*
|
| 87 |
+

|
| 88 |
+

|
| 89 |
+
|
| 90 |
+
---
|
| 91 |
+
|
| 92 |
+
## ๐ Minimal Inference
|
| 93 |
|
| 94 |
```python
|
| 95 |
# pip install torch tiktoken huggingface_hub safetensors
|
| 96 |
import torch, tiktoken
|
| 97 |
from safetensors.torch import load_file
|
| 98 |
from huggingface_hub import hf_hub_download
|
| 99 |
+
from MedAssistGPT import MedAssistGPT, MODEL_CONFIG
|
| 100 |
|
| 101 |
+
REPO_ID = "kunjcr2/MedAssist-GPT-401M"
|
| 102 |
+
weights = hf_hub_download(REPO_ID, "model.safetensors")
|
| 103 |
+
state = load_file(weights, device="cpu")
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
model = MedAssistGPT(MODEL_CONFIG)
|
| 106 |
model.load_state_dict(state, strict=True).eval()
|
| 107 |
|
| 108 |
enc = tiktoken.get_encoding("p50k_base")
|
| 109 |
+
ids = torch.tensor([enc.encode(
|
| 110 |
+
"A patient was admitted with severe headache. Initial assessment revealed"
|
| 111 |
+
)], dtype=torch.long)
|
| 112 |
+
|
| 113 |
+
for _ in range(100):
|
| 114 |
+
logits = model(ids)[:, -1, :]
|
| 115 |
+
next_id = torch.multinomial(torch.softmax(logits / 0.6, dim=-1), 1)
|
| 116 |
+
ids = torch.cat([ids, next_id], dim=1)
|
| 117 |
print(enc.decode(ids[0].tolist()))
|
| 118 |
```
|
| 119 |
|
| 120 |
+
---
|
| 121 |
|
| 122 |
+
## ๐พ Checkpoints
|
|
|
|
| 123 |
|
| 124 |
+
* Main run: `medassist-401M-test`
|
| 125 |
+
* Checkpoint: `/checkpoints/checkpoint_step_44500.pt`
|
| 126 |
|
| 127 |
+
---
|
| 128 |
+
|
| 129 |
+
## ๐งช Intended Use
|
| 130 |
+
|
| 131 |
+
For research and experimentation only โ e.g.,
|
| 132 |
+
|
| 133 |
+
* domain-adapted pretraining,
|
| 134 |
+
* architecture exploration,
|
| 135 |
+
* fine-tuning for medical text understanding.
|
| 136 |
+
|
| 137 |
+
๐ซ **Not intended for clinical or production medical use.**
|
| 138 |
+
|
| 139 |
+
---
|
| 140 |
+
|
| 141 |
+
## ๐ฎ Future Work
|
| 142 |
+
|
| 143 |
+
Next update includes:
|
| 144 |
+
|
| 145 |
+
* **Supervised fine-tuning (SFT)**
|
| 146 |
+
* **Reinforcement Learning (PPO) for alignment**
|
| 147 |
+
|
| 148 |
+
---
|
| 149 |
+
|
| 150 |
+
## ๐ Files
|
| 151 |
+
|
| 152 |
+
* 'checkpoints/'
|
| 153 |
* `config.json`, `tokenizer_config.json`
|
| 154 |
+
* Training script / notebook defining `MedAssistGPT`
|
| 155 |
+
|
| 156 |
+
---
|
| 157 |
+
|
| 158 |
+
## ๐ชช License
|
| 159 |
|
| 160 |
+
Apache 2.0
|
|
|