mattmireles/gemma-tuner-multimodal

Fine-tune Gemma 4 and 3n with audio, images and text on Apple Silicon, using PyTorch and Metal Performance Shaders.

Gemma Multimodal Fine‑Tuner (macOS‑only)

What it is – A Python package that lets you fine‑tune Google’s Gemma language models (both the 3‑nano and 4‑series) with LoRA adapters on text, images, and audio data, all from a Mac with Apple‑Silicon (MPS) – no NVIDIA GPU required. The tool includes a small CLI wizard, a real‑time web visualiser, and built‑in support for streaming huge datasets from Google Cloud Storage or BigQuery.


Core capabilities (as described in the README)

Feature Details
Modality support • Text‑only (instruction or completion)\n• Image + text (captioning or VQA)\n• Audio + text (ASR‑style)
Hardware Runs natively on Apple Silicon via PyTorch MPS; optional CUDA support if you have an NVIDIA GPU.
Data ingestion CSV files (train/validation) are the only required format. CSV rows can reference local files, HTTP URLs, GCS paths, or BigQuery tables; the prepare command streams data so you never need to copy terabytes locally.
Training UI A browser‑based visualiser (loss curve, attention heat‑map, gradient signal, memory usage, token predictions) starts automatically when visualize = true in a profile.
Model targets Gemma‑3n (2 B & 4 B) and Gemma‑4 (2 B & 4 B) checkpoints from Hugging Face. LoRA adapters are merged into a single SafeTensors/HF tree for export.
Export gemma-macos-tuner export produces a merged model ready for Core ML conversion or GGUF inference.
CLI wizard Guided setup (gemma-macos-tuner wizard) creates a config file, picks a model, selects a dataset profile, and launches training with a single click.
Streaming & big data prepare can stream audio shards from GCS/BigQuery; the same pipeline works for image/audio modalities, letting you train on multi‑TB corpora without filling your SSD.
Package layout gemma_tuner/cli_typer.py – entry‑point CLI (gemma-macos-tuner).\n• gemma_tuner/scripts/finetune.py – dispatches to the Gemma‑specific trainer.\n• gemma_tuner/models/gemma/finetune.py – PEFT LoRA fine‑tuning logic.\n• gemma_tuner/wizard/ – Rich/Questionary UI for the wizard.

Typical use‑cases (from the README)

  • Domain‑specific speech recognition – adapt Gemma + audio LoRA to medical dictation, legal transcripts, call‑center recordings, etc.
  • Specialised vision tasks – fine‑tune on receipts, charts, manufacturing defects, or medical images for captioning or VQA.
  • Document & UI understanding – train on screenshot → structured‑output pairs for on‑device assistants.
  • Low‑resource language or accent adaptation – improve transcription or translation for under‑represented dialects.
  • Private on‑device pipelines – all training and inference stay on the Mac; no data leaves the machine.

Getting started (summarised from the README)

  1. Create a native arm64 Python 3.10+ venv (Homebrew python@3.12 works).
  2. Install PyTorch (pip install torch torchaudio).
  3. Install the package (pip install -e .).
  4. Log in to Hugging Face and accept the Gemma model license.
  5. (Optional) Install Gemma‑4 extras (pip install -r requirements/requirements-gemma4.txt).
  6. Run the wizardgemma-macos-tuner wizard. It will generate config/config.ini and walk you through model, dataset, and hyper‑parameter selection.
  7. Train – either via the wizard or directly: gemma-macos-tuner finetune <profile>. Use --json-logging for machine‑readable logs.
  8. Exportgemma-macos-tuner export <run‑dir-or‑profile> produces a merged checkpoint ready for Core ML or GGUF.

Limitations & known issues (as documented)

  • Image & audio streaming – only audio pipelines currently support GCS/BigQuery streaming; image fine‑tuning still requires local CSV files.
  • Gemma 4 large checkpoints (26 B/31 B) are not supported because the trainer’s AutoModelForCausalLM audio path expects a different architecture.
  • Audio‑only LoRA works on Apple Silicon; CUDA‑only paths are marked “⚠️” and may require an NVIDIA GPU.
  • Memory – Minimum 16 GB RAM; 32 GB+ recommended for the 4 B models. OOM can be mitigated by smaller batch sizes or gradient checkpointing.
  • MPS stability – The trainer forces eager attention and prefers bf16; fallback to CPU (PYTORCH_ENABLE_MPS_FALLBACK=1) is for debugging only and slows training.
  • Export for Gemma 4 – Some inference utilities still reject Gemma 4 IDs until those code paths are upgraded.

Quick reference cheat‑sheet (from the README)

# Prepare data (CSV → optional streaming)
 gemma-macos-tuner prepare <dataset‑profile>

# Train
 gemma-macos-tuner finetune <profile> --json-logging

# Evaluate
 gemma-macos-tuner evaluate <profile-or‑run>

# Export merged checkpoint
 gemma-macos-tuner export <run‑dir-or‑profile>

# Launch the wizard UI
 gemma-macos-tuner wizard

Bottom lineGemma‑tuner‑multimodal is a purpose‑built, Apple‑Silicon‑first trainer that adds LoRA‑based multimodal fine‑tuning (text, image, audio) to the Gemma family, with a friendly CLI wizard and live visualisation, while allowing massive cloud‑resident datasets to be streamed directly to a Mac.

Related

  • Dispatch
  • Dispatch
  • Dispatch
  • Project
  • Dispatch