agentleFS
MacroTechTitanMacroTechTitan/MaximusAI/skills/maximus-slm-local-finetune/SKILL.md

maximus-slm-local-finetune

Skill1 starsChanged 4 months agoMITView on GitHub

Fine-tune a small model on hardware you own and ship it to Ollama: decide whether to fine-tune at all, build the dataset, run LoRA/QLoRA with Unsloth (NVIDIA/AMD/Intel/Mac) or MLX-LM (Apple Silicon), evaluate against the base model, then merge, export GGUF, quantize, and create an Ollama model with the training chat template. Use for 'fine-tune locally', 'LoRA on my GPU', 'QLoRA', 'Unsloth', 'MLX fine-tune', 'export to GGUF', 'put my fine-tune in Ollama'.

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    If any are false, stop and say which one.

    line 42

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Maximus — SLM Local Fine-Tune

Fine-tuning is the most expensive way to discover that you needed a better prompt. When it is the right tool, doing it locally is now practical: a 7B QLoRA fits in single-digit gigabytes. This skill makes you earn the fine-tune, then carries it all the way into ollama run without losing the chat template on the way.

Purpose

Produce a local fine-tune that measurably beats the base model on the user's task, packaged as an Ollama model, with the evaluation that proves it and a record of every setting needed to reproduce it.

Scope boundary

NeedSkill
LoRA/QLoRA on your own box → GGUF → Ollamathis skill
Fine-tune vs RAG vs prompt decision in general; hosted FT APIs; DPOmaximus-fine-tuning
Dataset curation, labeling, leakagemaximus-ai-data-pipeline
Proving the tune is bettermaximus-slm-eval
Serving the resultmaximus-ollama-ops

Earn it first

Fine-tune locally only if all three are true:

  1. A prompt plus retrieval has been tried and measured, and it falls short on format, style, or a narrow skill. Fine-tuning teaches behavior. It is a poor way to teach facts that change, which is what RAG is for.
  2. There are at least a few hundred clean examples of the target behavior, or a plan to make them.
  3. There is a held-out eval set (maximus-slm-eval) and a baseline score.

If any are false, stop and say which one.

Core workflow

  1. Baseline. Score the base model on the held-out set with the exact prompt format you will train on.
  2. Pick the toolchain by hardware. Unsloth covers NVIDIA (CUDA capability 7.0+), AMD, Intel, and Mac. MLX-LM is native on Apple Silicon. Check VRAM against the dated table in references/ (for example, Unsloth lists about 5 GB for 7B QLoRA and 19 GB for 7B 16-bit LoRA).
  3. Build the dataset in the chat format of the target model. JSONL with messages (system/user/assistant), or MLX's chat / tools / completions / text formats. Deduplicate, strip PII, split train/valid/test before looking at the results, and never let test prompts leak into train.
  4. Train small first. QLoRA on a 3-8B model with a short run. Watch validation loss. If it rises while training loss falls, you are overfitting. On OOM, reduce batch size before anything else.
  5. Evaluate adapter vs base on the held-out set, same prompt, same decoding. No gain means no ship. Also re-run a few general prompts to catch collapse elsewhere.
  6. Merge and export. Unsloth: save_pretrained_gguf with a quantization method, which also writes a Modelfile carrying the training chat template. MLX: mlx_lm.fuse --export-gguf exports fp16 only, and only for Mistral, Mixtral, and Llama-style models. For other architectures, fuse to safetensors and convert with llama.cpp.
  7. Quantize and import. Ollama does not quantize GGUF on import, so quantize first (llama-quantize ... Q4_K_M). Then ollama create from a Modelfile whose TEMPLATE matches the one used in training.
  8. Re-evaluate the quantized Ollama build. Quantization can erase a thin fine-tune gain. The number that counts is the one from the model you will actually serve.
  9. Record it. Base model and revision, dataset hash, hyperparameters, toolchain versions, quant method, and all eval scores, in a TRAINING.md next to the Modelfile.

Anti-patterns

  • Fine-tuning facts in. They go stale and hallucinate at the edges. Use RAG.
  • Mismatched chat template at inference. Unsloth names this "the most common cause" of broken exports.
  • Evaluating the fp16 adapter, shipping the Q4 GGUF.
  • No held-out set. Then the claimed improvement is a hope.
  • Training on the eval set by accident via near-duplicates. Deduplicate across splits.
  • Assuming MLX exports any architecture to GGUF. It does not.

Output

Dataset splits with hashes, the training config, an eval table (base, adapter, quantized Ollama build), the Modelfile, and TRAINING.md. If the tune did not beat the base, the output is that finding.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.