
gemma-tuner-multimodal
Fine-tune Gemma 4 and 3n models with audio, images, and text on Apple Silicon using PyTorch and Metal Performance Shaders.
- Installs
- 582
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/reason-machines/trending-skills --skill gemma-tuner-multimodal- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads gemma-tuner-multimodal automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
Gemma Multimodal Fine-Tuner
Skill by ara.so — Daily 2026 Skills collection.
Fine-tune Gemma 4 and Gemma 3n models on text, images, and audio data entirely on Apple Silicon (MPS), with support for streaming large datasets from GCS/BigQuery without filling local storage.
What It Does
- Text LoRA: instruction-tuning or completion fine-tuning from local CSV
- Image + Text LoRA: captioning and VQA from local CSV
- Audio + Text LoRA: the only Apple-Silicon-native path for this modality
- Cloud streaming: train on terabytes from GCS/BigQuery without local copy
- MPS-native: no NVIDIA GPU required — runs on MacBook Pro/Air/Mac Studio
Installation
Prerequisites
- macOS 12.3+ with Apple Silicon (arm64)
- Python 3.10+ (native arm64, not Rosetta)
- Hugging Face account with Gemma access
# Install Python 3.12 if needed
brew install python@3.12
# Create venv
python3.12 -m venv .venv
source .venv/bin/activate
# Verify arm64 (must show arm64, not x86_64)
python -c "import platform; print(platform.machine())"
# Install PyTorch
pip install torch torchaudio
# Clone and install
git clone https://github.com/mattmireles/gemma-tuner-multimodal
cd gemma-tuner-multimodal
pip install -e .
# For Gemma 4 support (separate venv recommended)
pip install -r requirements/requirements-gemma4.txt
Authenticate with Hugging Face
huggingface-cli login
# Or set environment variable:
export HF_TOKEN=your_token_here
CLI Commands
# Check system is ready
gemma-macos-tuner system-check
# Guided setup wizard (recommended for first run)
gemma-macos-tuner wizard
# Prepare dataset
gemma-macos-tuner prepare <dataset-profile>
# Fine-tune a model
gemma-macos-tuner finetune <profile> --json-logging
# Evaluate a run
gemma-macos-tuner evaluate <profile-or-run>
# Export merged HF/SafeTensors (merges LoRA when adapter_config.json present)
gemma-macos-tuner export <run-dir-or-profile>
# Blacklist bad samples from errors
gemma-macos-tuner blacklist <profile>
# List training runs
gemma-macos-tuner runs list
Configuration (config/config.ini)
The config is hierarchical INI: defaults → groups → models → datasets → profiles.
[defaults]
output_dir = output
batch_size = 2
gradient_accumulation_steps = 8
learning_rate = 2e-4
num_train_epochs = 3
[model:gemma-3n-e2b-it]
group = gemma
base_model = google/gemma-3n-E2B-it
[model:gemma-4-e2b-it]
group = gemma
base_model = google/gemma-4-E2B-it
[dataset:my-audio-dataset]
data_dir = data/datasets/my-audio-dataset
audio_column = audio_path
text_column = transcript
[profile:my-audio-profile]
model = gemma-3n-e2b-it
dataset = my-audio-dataset
modality = audio
lora_r = 16
lora_alpha = 32
lora_dropout = 0.05
max_seq_length = 512
Use GEMMA_TUNER_CONFIG env var to point to config outside repo root:
export GEMMA_TUNER_CONFIG=/path/to/my/config.ini
Modality Configuration
Text-Only Fine-Tuning
Instruction tuning (user/assistant pairs):
[profile:text-instruction]
model = gemma-3n-e2b-it
dataset = my-text-dataset
modality = text
text_sub_mode = instruction
prompt_column = prompt
text_column = response
max_seq_length = 2048
lora_r = 16
lora_alpha = 32
Completion tuning (full sequence trained):
[profile:text-completion]
model = gemma-3n-e2b-it
dataset = my-text-dataset
modality = text
text_sub_mode = completion
text_column = text
max_seq_length = 2048
CSV format for instruction tuning (data/datasets/my-text-dataset/train.csv):
prompt,response
"What is photosynthesis?","Photosynthesis is the process by which plants..."
"Explain LoRA fine-tuning","LoRA (Low-Rank Adaptation) is a parameter-efficient..."
Image Fine-Tuning
[profile:image-caption]
model = gemma-3n-e2b-it
dataset = my-image-dataset
modality = image
image_sub_mode = captioning
image_token_budget = 256
prompt_column = prompt
text_column = caption
max_seq_length = 512
CSV format (data/datasets/my-image-dataset/train.csv):
image_path,prompt,caption
/data/images/img1.jpg,Describe this image,A dog sitting on a green lawn...
/data/images/img2.jpg,What is shown here,A bar chart showing quarterly revenue...
Audio Fine-Tuning
[profile:audio-asr]
model = gemma-3n-e2b-it
dataset = my-audio-dataset
modality = audio
audio_column = audio_path
text_column = transcript
max_seq_length = 512
lora_r = 16
lora_alpha = 32
lora_dropout = 0.05
CSV format (data/datasets/my-audio-dataset/train.csv):
audio_path,transcript
/data/audio/recording1.wav,The patient presents with acute respiratory symptoms
/data/audio/recording2.wav,Counsel objects to the characterization of the evidence
Supported Models
| Model Key | Hugging Face ID | Notes |
|---|---|---|
gemma-3n-e2b-it | google/gemma-3n-E2B-it | Default, ~2B instruct |
gemma-3n-e4b-it | google/gemma-3n-E4B-it | ~4B instruct |
gemma-4-e2b-it | google/gemma-4-E2B-it | Needs requirements-gemma4.txt |
gemma-4-e4b-it | google/gemma-4-E4B-it | Needs requirements-gemma4.txt |
gemma-4-e2b | google/gemma-4-E2B | Base, needs Gemma 4 stack |
gemma-4-e4b | google/gemma-4-E4B | Base, needs Gemma 4 stack |
Add custom models with a [model:your-name] section using group = gemma.
Dataset Directory Layout
data/
└── datasets/
└── <dataset-name>/
├── train.csv # required
├── validation.csv # optional
└── test.csv # optional
Output Layout
output/
└── {run-id}-{profile}/
├── metadata.json
├── metrics.json
├── checkpoint-*/
└── adapter_model/ # LoRA artifacts
Python API Examples
Running Fine-Tuning Programmatically
from gemma_tuner.core.config import load_config
from gemma_tuner.core.ops import run_finetune
# Load config
config = load_config("config/config.ini")
# Run fine-tuning for a profile
run_finetune(profile="my-audio-profile", config=config, json_logging=True)
Using Device Utilities
from gemma_tuner.utils.device import get_device, memory_hint
device = get_device() # Returns "mps", "cuda", or "cpu"
print(f"Training on: {device}")
hint = memory_hint(model_key="gemma-3n-e2b-it")
print(hint)
Loading and Inspecting Datasets
from gemma_tuner.utils.dataset_utils import load_csv_dataset
train_df, val_df = load_csv_dataset(
data_dir="data/datasets/my-text-dataset",
text_column="response",
prompt_column="prompt"
)
print(f"Train samples: {len(train_df)}, Val samples: {len(val_df)}")
Custom LoRA Config
from peft import LoraConfig, get_peft_model
from transformers import AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained(
"google/gemma-3n-E2B-it",
torch_dtype="auto",
device_map="mps"
)
lora_config = LoraConfig(
r=16,
lora_alpha=32,
lora_dropout=0.05,
target_modules=["q_proj", "v_proj", "k_proj", "o_proj"],
task_type="CAUSAL_LM"
)
model = get_peft_model(model, lora_config)
model.print_trainable_parameters()
Common Patterns
Full Workflow: Text Instruction Tuning
# 1. Prepare your data
mkdir -p data/datasets/my-dataset
cp train.csv data/datasets/my-dataset/
cp validation.csv data/datasets/my-dataset/
# 2. Add profile to config/config.ini
cat >> config/config.ini << 'EOF'
[dataset:my-dataset]
data_dir = data/datasets/my-dataset
[profile:my-text-run]
model = gemma-3n-e2b-it
dataset = my-dataset
modality = text
text_sub_mode = instruction
prompt_column = prompt
text_column = response
max_seq_length = 2048
lora_r = 16
lora_alpha = 32
EOF
# 3. Prepare dataset
gemma-macos-tuner prepare my-dataset
# 4. Fine-tune
gemma-macos-tuner finetune my-text-run --json-logging
# 5. Export merged weights
gemma-macos-tuner export my-text-run
GCS Streaming for Large Datasets
[dataset:large-audio-gcs]
source = gcs
gcs_bucket = my-bucket
gcs_prefix = audio-training-data/
audio_column = audio_path
text_column = transcript
[profile:large-audio-run]
model = gemma-3n-e4b-it
dataset = large-audio-gcs
modality = audio
lora_r = 32
lora_alpha = 64
Set credentials:
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json
gemma-macos-tuner finetune large-audio-run
Add a Custom Gemma Checkpoint
[model:my-custom-gemma]
group = gemma
base_model = my-org/my-gemma-checkpoint
[profile:custom-run]
model = my-custom-gemma
dataset = my-dataset
modality = text
text_sub_mode = instruction
Troubleshooting
Wrong architecture (x86_64 instead of arm64)
python -c "import platform; print(platform.machine())"
# Must be arm64 — if x86_64, reinstall Python natively:
brew install python@3.12
python3.12 -m venv .venv && source .venv/bin/activate
MPS out of memory
- Reduce
batch_size(try 1) - Increase
gradient_accumulation_stepsto compensate - Use a smaller model (
e2binstead ofe4b) - Reduce
max_seq_length
Gemma 4 model not loading
# Gemma 4 requires the updated Transformers stack
pip install -r requirements/requirements-gemma4.txt
# Use a separate venv if you also need Gemma 3n
Config not found outside repo root
export GEMMA_TUNER_CONFIG=/absolute/path/to/config/config.ini
gemma-macos-tuner finetune my-profile
Hugging Face auth errors
huggingface-cli login
# Or:
export HF_TOKEN=your_hf_token
# Accept Gemma license at: https://huggingface.co/google/gemma-3n-E2B-it
System check before debugging anything else
gemma-macos-tuner system-check
Audio tower loaded even for text-only runs
This is a known v1 issue — USM audio tower weights stay in memory even for modality = text. See README/KNOWN_ISSUES.md. Workaround: use a smaller model variant to stay within RAM budget.
Architecture Reference
| File | Role |
|---|---|
gemma_tuner/cli_typer.py | Main CLI entrypoint (gemma-macos-tuner) |
gemma_tuner/core/ops.py | Dispatches prepare/finetune/evaluate/export |
gemma_tuner/scripts/finetune.py | Router: Gemma models → models/gemma/finetune.py |
gemma_tuner/models/gemma/finetune.py | Core training loop with LoRA |
gemma_tuner/scripts/export.py | Merges LoRA → HF/SafeTensors tree |
gemma_tuner/utils/device.py | MPS/CUDA/CPU selection and memory hints |
gemma_tuner/utils/dataset_utils.py | CSV loading, blacklist/protection semantics |
gemma_tuner/wizard/ | Interactive CLI wizard (questionary + Rich) |
config/config.ini | Hierarchical INI configuration |
FAQ
What does the gemma-tuner-multimodal skill do?
Fine-tune Gemma 4 and 3n models with audio, images, and text on Apple Silicon using PyTorch and Metal Performance Shaders.
How do I install gemma-tuner-multimodal?
Run npx skills add https://github.com/reason-machines/trending-skills --skill gemma-tuner-multimodal in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/gemma-tuner-multimodal/ (personal) or .claude/skills/gemma-tuner-multimodal/ (project).
Which AI agents can use gemma-tuner-multimodal?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is gemma-tuner-multimodal safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains gemma-tuner-multimodal?
It is published by reason-machines in reason-machines/trending-skills. It has 582 recorded installs.
More from reason-machines/trending-skills
openclaw-control-center
reason-machines/trending-skills
Local-first, security-first control center for OpenClaw agents — visibility dashboard with readonly defaults, token attribution, collaboration tracing, and safe write operations.
inkos-multi-agent-novel-writing
reason-machines/trending-skills
Multi-agent CLI system for autonomous novel writing, auditing, and revision with human review gates
claude-hud-statusline
reason-machines/trending-skills
A Claude Code plugin that displays a real-time HUD showing context usage, active tools, running agents, and todo progress in your terminal statusline.
understand-anything-knowledge-graph
reason-machines/trending-skills
Turn any codebase into an interactive knowledge graph using Claude Code skills — explore, search, and ask questions about any project visually.
agency-agents-ai-specialists
reason-machines/trending-skills
A collection of specialized AI agent personalities for Claude Code, Cursor, Aider, Windsurf, and other AI coding tools — covering engineering, design, marketing, sales, and more.
agent-browser-automation
reason-machines/trending-skills
Headless browser automation CLI for AI agents using native Rust binary with Chrome DevTools Protocol
Popular media & creative skills
hyperframes
heygen-com/hyperframes
Read first to make, edit, animate or render any video with HyperFrames (HTML rendered to video), including launch films, explainers, music videos, charts, maps, vertical clips, title cards, captions and overlays. Holds the render contract, the work loop and what each kind of video needs.
media-use
heygen-com/hyperframes
Get or make any media for a HyperFrames video - music, sound effects, images, icons, logos, voiceover, avatar and generated video, transcripts, cutouts, colour grades and looks - with HeyGen or free local tools, and mix placed audio. Also for footage that looks dark, flat or dull, or should be stylized or hidden.
hyperframes-registry
heygen-com/hyperframes
About 450 ready-made HyperFrames blocks and components installed as editable source - transitions, overlays, titles, kinetic type, captions, charts, map overlays, 3D, camera moves. Use it before hand-building any named visual (CRT scanlines, glitch, film grain, a chart); also for hyperframes add and catalog.
hyperframes-creative
heygen-com/hyperframes
Non-animation creative direction for HyperFrames videos. Use for design spec (frame.md / design.md) handling, palettes, typography, narration, beat planning, audio-reactive visuals, composition patterns, and brand / style decisions. For atomic motion patterns and scene blueprints, use hyperframes-animation.
ai-video-generation
101-skills/superpowers
Generate AI videos with Google Veo, Seedance 2.0, HappyHorse, Wan, Grok and 40+ models via inference.sh CLI. Models: Veo 3.1, Veo 3, Seedance 2.0, HappyHorse 1.0, Wan 2.5, Grok Imagine Video, OmniHuman, Fabric, HunyuanVideo. Capabilities: text-to-video, image-to-video, reference-to-video, video editing, lipsync, avatar animation, video upscaling, foley sound. Use for: social media videos, marketing content, explainer videos, product demos, AI avatars. Triggers: video generation, ai video, text to video, image to video, veo, animate image, video from image, ai animation, video generator, generate video, t2v, i2v, ai video maker, create video with ai, runway alternative, pika alternative, sora alternative, kling alternative, seedance, happyhorse
ai-image-generation
101-skills/superpowers
Generate AI images with GPT-Image-2, FLUX, Gemini, Grok, Seedream, Reve and 50+ models via inference.sh CLI. Models: GPT-Image-2, FLUX Dev LoRA, FLUX.2 Klein LoRA, Gemini 3 Pro Image, Grok Imagine, Seedream 4.5, Reve, ImagineArt. Capabilities: text-to-image, image-to-image, inpainting, LoRA, image editing, upscaling, text rendering. Use for: AI art, product mockups, concept art, social media graphics, marketing visuals, illustrations. Triggers: flux, image generation, ai image, text to image, stable diffusion, generate image, ai art, midjourney alternative, dall-e alternative, text2img, t2i, image generator, ai picture, create image with ai, generative ai, ai illustration, grok image, gemini image, gpt image, openai image, chatgpt image