social-story-gemma4-e2b-v3

LoRA fine-tune of mlx-community/Gemma4-E2B-IT-Text-int4 (text-only Gemma 4 E2B Instruct, 4-bit) trained to generate Carol-Gray-style social stories for autistic children. Fused, then quantized for both Python (mlx-lm) and Swift (mlx-swift-lm) on-device deployment.

Use case

Drop-in on-device text generation backend for the Mystoria iOS/iPadOS app (formerly Social Story Studio). Pairs with the v2-era prompt template — same system message and 8-rule user prompt — and emits valid JSON {title, pages: [{text, order}]}.

Training

  • Base: mlx-community/Gemma4-E2B-IT-Text-int4 (Gemma 4 E2B Instruct, text-only, 4-bit)
  • Method: LoRA via mlx_lm.lora
  • Hyperparameters: rank 8, scale 16, num_layers 26, lr 1e-5, batch 1 + grad-accum 4, max_seq 1024
  • Iters: 2500
  • Dataset: ~1,720 train / 152 valid / 153 test social stories generated and filtered to first-person, qualifier-rich, tentative-directive Carol Gray voice (10.2 / 10.4 methodology)

Eval (20-prompt grid: 5 ages × 4 topics)

Metric Rate
JSON valid 100%
Schema correct (text/order) 100%
Tier-1 Carol Gray pass 70%
Descriptive:coaching ≥ 2:1 80%
Test loss 0.447 (ppl 1.563)

The 30% Tier-1 misses are all driven by the descriptive:coaching ratio on coaching-heavy topics (e.g. "making a new friend"). Every other sub-check (first-person, forbidden phrases, qualifiers, no-figurative-language, structure, positive framing, reading level, no-page-dupes) passes 100%.

Quantization (mixed precision for Swift compatibility)

Most weights are 4-bit (group_size=64, ~4.5 bits/weight). The per_layer_model_projection layer is kept in float16 because mlx-swift-lm 3.31.3's Gemma4Text.ScaledLinear is a plain Module and cannot dequantize at load time (the loader sees the packed (8960, 192) uint32 shape and rejects). Keeping that one layer in fp16 adds ~25 MB but lets the model load on iOS without a Swift-side patch.

Deployment

  • Final size: ~2.5 GB on disk
  • Loads via standard mlx_lm.load (Python) and mlx-swift-lm ≥ 3.31.3 (Swift) — both work without the sanitize patch the original mlx-community/Gemma4-*-Text-int4 checkpoints needed
  • iOS users: clear any prior cache from a broken v3 download before loading this revision

Limitations

  • The descriptive:coaching ratio fails on topics where every "I can try to..." sentence reads as coaching. Future work: more descriptive-first training data for action-oriented topics.
  • On-device generation is text-only. Image generation in the app continues to run cloud-only.
Downloads last month
22
Safetensors
Model size
5B params
Tensor type
U32
·
F16
·
MLX
Hardware compatibility
Log In to add your hardware

4-bit

Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for Kris0404/social-story-gemma4-e2b-v3

Adapter
(183)
this model