ameowra commited on
Commit
44e9ee6
Β·
verified Β·
1 Parent(s): 0157d7a

Update model card: real training details, file listing, corrected usage

Browse files
Files changed (1) hide show
  1. README.md +69 -27
README.md CHANGED
@@ -11,12 +11,12 @@ tags:
11
  - fine-tuned
12
  ---
13
 
14
- # Qwen3-4B Back-Pain Coaching (LoRA fine-tune, fused)
15
 
16
- A LoRA fine-tune of `Qwen/Qwen3-4B-Instruct-2507`, fused into the base
17
- weights, specialized for back-pain coaching conversations: it asks
18
- structured intake questions, screens for red-flag symptoms, and otherwise
19
- suggests general exercises, stretches, and lifestyle/diet guidance.
20
 
21
  **This is not a diagnostic tool** and is not a substitute for professional
22
  medical advice.
@@ -45,17 +45,46 @@ repo below) that runs *before* the model is ever called and does not
45
  depend on model behavior. **Deploying this model without an equivalent
46
  independent safety layer is not the intended or recommended use.**
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  ## Training
49
 
50
  - **Base model**: `Qwen/Qwen3-4B-Instruct-2507`
51
- - **Method**: LoRA fine-tuning via `mlx_lm.lora` (MLX, Apple Silicon),
52
- fused into the base weights via `mlx_lm.fuse`
53
- - **Data**: 51 hand-authored chat-format examples across 5 categories β€”
54
- structured intake, exercise/stretch recommendation, diet/lifestyle
55
- guidance, red-flag referral, and medical-term explanation β€” grounded in
56
- real sources (Mayo Clinic, NHS Inform, Kaiser, Arthritis UK, Spine
57
- Health's glossary) collected via Firecrawl and paraphrased rather than
58
- copied verbatim
 
 
 
 
 
 
 
 
 
 
 
59
 
60
  ## System prompt
61
 
@@ -79,8 +108,15 @@ general advice.
79
 
80
  ## Limitations
81
 
82
- - Small base model (4B parameters) and a small fine-tuning set (51
83
  examples) β€” expect narrower conversational range than a frontier model
 
 
 
 
 
 
 
84
  - English only
85
  - "Call 000" guidance is Australia-specific; adapt for other regions
86
  - General lifestyle advice only, not personalized clinical guidance
@@ -97,26 +133,32 @@ uv sync --extra inference
97
  uv run inference/serve.py
98
  ```
99
 
100
- Direct usage via `transformers`:
101
 
102
  ```python
103
- from transformers import AutoModelForCausalLM, AutoTokenizer
 
104
 
105
- repo_id = "ameowra/qwen3-4b-backpain-fused"
106
- tokenizer = AutoTokenizer.from_pretrained(repo_id)
107
- model = AutoModelForCausalLM.from_pretrained(repo_id)
 
108
 
109
  messages = [
110
  {"role": "system", "content": "<see System prompt section above>"},
111
  {"role": "user", "content": "My lower back has been aching for about a week."},
112
  ]
113
- inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt")
114
- output = model.generate(inputs, max_new_tokens=512)
115
- print(tokenizer.decode(output[0][inputs.shape[-1]:], skip_special_tokens=True))
116
  ```
117
 
118
- A quantized GGUF build (for local CPU/GPU inference via `llama.cpp` /
119
- `llama-cpp-python`) is produced separately by the project pipeline β€” see
120
- the project repo for the full training-to-serving pipeline and the
121
- `ProjectScope.md` design rationale (structured intake, hardcoded safety
122
- layer, planned RAG grounding, fully local/offline deployment).
 
 
 
 
 
11
  - fine-tuned
12
  ---
13
 
14
+ # Qwen3-4B Back-Pain Coaching (LoRA fine-tune)
15
 
16
+ A LoRA fine-tune of `Qwen/Qwen3-4B-Instruct-2507`, specialized for
17
+ back-pain coaching conversations: it asks structured intake questions,
18
+ screens for red-flag symptoms, and otherwise suggests general exercises,
19
+ stretches, and lifestyle/diet guidance.
20
 
21
  **This is not a diagnostic tool** and is not a substitute for professional
22
  medical advice.
 
45
  depend on model behavior. **Deploying this model without an equivalent
46
  independent safety layer is not the intended or recommended use.**
47
 
48
+ ## Files in this repo
49
+
50
+ - `adapter_config.json` + `adapters.safetensors` β€” the trained LoRA
51
+ adapter (29MB), applied on top of the base model at load time (MLX) or
52
+ used to fuse/convert to another format
53
+ - `qwen3-4b-instruct-2507-backpain-f16.gguf` β€” full-precision GGUF (~8GB)
54
+ - `qwen3-4b-instruct-2507-backpain-q4_k_m.gguf` β€” quantized GGUF (~2.5GB),
55
+ the one this project actually serves via `llama-cpp-python`
56
+
57
+ No full fused HF-`transformers`-format safetensors checkpoint is hosted
58
+ here β€” the adapter was fused directly into an MLX checkpoint and converted
59
+ straight to GGUF, skipping an intermediate HF-format export.
60
+
61
+ ```bash
62
+ hf download ameowra/qwen3-4b-backpain-fused \
63
+ qwen3-4b-instruct-2507-backpain-q4_k_m.gguf --local-dir models/
64
+ ```
65
+
66
  ## Training
67
 
68
  - **Base model**: `Qwen/Qwen3-4B-Instruct-2507`
69
+ - **Method**: LoRA fine-tuning via `mlx_lm.lora` (MLX, Apple Silicon) β€”
70
+ rank 8, dropout 0.0, scale 20.0, 16 of 36 layers tuned (7.34M / 4022M
71
+ trainable params, 0.182%); adam optimizer, lr 1e-5 constant, batch size
72
+ 4, max sequence length 2048; fused into the base weights and converted
73
+ to GGUF via `llama.cpp`
74
+ - **Data**: 136 hand-authored chat-format examples (110 train / 26 valid,
75
+ ~27,470 tokens/epoch) across 6 categories β€” structured intake,
76
+ exercise/stretch recommendation, diet/lifestyle guidance, red-flag
77
+ referral, medical-term explanation, and back-muscle anatomy β€” grounded
78
+ in real sources (Mayo Clinic, NHS Inform, Kaiser, Arthritis UK, Spine
79
+ Health's glossary, NCBI StatPearls, TeachMeAnatomy) collected via
80
+ Firecrawl and paraphrased rather than copied verbatim
81
+ - **Checkpoint selection**: trained for 430 of a nominal 1000 iterations on
82
+ an Apple M5 Max (~1.7 it/s, ~6 minutes wall clock); validation loss
83
+ bottomed out at iteration 100 (0.441) and rose steadily after while
84
+ train loss kept falling β€” plain overfitting on a small dataset, so
85
+ iteration 100 was selected rather than the final checkpoint. At this
86
+ dataset size, ~100-150 iterations is the useful range; a longer run
87
+ needs more data, not more patience.
88
 
89
  ## System prompt
90
 
 
108
 
109
  ## Limitations
110
 
111
+ - Small base model (4B parameters) and a small fine-tuning set (136
112
  examples) β€” expect narrower conversational range than a frontier model
113
+ - Style transfer more than knowledge transfer: the adapter mainly changes
114
+ *how* the model responds (ask first, screen, defer, stay
115
+ non-prescriptive) rather than adding back-pain knowledge the base model
116
+ lacked
117
+ - Single-turn training data β€” multi-turn conversations work if prior turns
118
+ are replayed as history, but every training example was one user turn
119
+ and one reply
120
  - English only
121
  - "Call 000" guidance is Australia-specific; adapt for other regions
122
  - General lifestyle advice only, not personalized clinical guidance
 
133
  uv run inference/serve.py
134
  ```
135
 
136
+ Direct usage via MLX, applying the adapter on top of the base model:
137
 
138
  ```python
139
+ from mlx_lm import load, generate
140
+ from mlx_lm.sample_utils import make_sampler
141
 
142
+ model, tokenizer = load(
143
+ "Qwen/Qwen3-4B-Instruct-2507",
144
+ adapter_path="path/to/downloaded/adapter_config.json's directory",
145
+ )
146
 
147
  messages = [
148
  {"role": "system", "content": "<see System prompt section above>"},
149
  {"role": "user", "content": "My lower back has been aching for about a week."},
150
  ]
151
+ prompt = tokenizer.apply_chat_template(messages, add_generation_prompt=True)
152
+ print(generate(model, tokenizer, prompt=prompt, max_tokens=512,
153
+ sampler=make_sampler(temp=0.7, top_p=0.9)))
154
  ```
155
 
156
+ There is no full fused HF-`transformers`-format checkpoint hosted in this
157
+ repo (see "Files in this repo" above) β€” direct `transformers` usage would
158
+ require fusing the adapter into the base weights yourself first (e.g. via
159
+ `mlx_lm.fuse` then a HF-format export), or using one of the GGUF builds
160
+ via `llama.cpp`/`llama-cpp-python` as shown above, which is what this
161
+ project's own inference server actually does. See the project repo for
162
+ the full training-to-serving pipeline and the `ProjectScope.md` design
163
+ rationale (structured intake, hardcoded safety layer, planned RAG
164
+ grounding, fully local/offline deployment).