Case study

SwiftLM

I wanted a coding model I could tune for Swift and run on my own machine. SwiftLM took that experiment from 5,602 examples to a published model on Hugging Face.

ML Engineer2026
Industry
— AI / ML, Swift, LLM Fine-Tuning

Tools & technologies

PythonPyTorch LightningHugging Face TransformersPEFT / QLoRAbitsandbytesONNX RuntimeLM StudioGoogle Colab (L4 GPU)

The Problem

Modern Swift needed better support from a model that could run locally.

The approach

How the work took shape

Work within one GPU

I used a single L4 GPU in Colab, which made memory a practical constraint from the start. PyTorch Lightning handled training, while bitsandbytes kept the model small enough to load. I pinned the dependencies so I could repeat a run when a Colab session ended.

Give the model better examples

The dataset contained 5,602 curated Swift examples. I converted the prompt-response pairs into Qwen's chat format and tokenized them at a 512-token sequence length. Preparing those examples gave the training run a specific job: adapt an existing coding model to Swift.

Train the adapters

QLoRA let me train a small set of adapters while keeping the base model in 4-bit form. I used rank 16 adapters on the attention layers, mixed precision, and gradient accumulation to stay within memory. The run completed one epoch in about 51 minutes.

Make the run repeatable

The run covered 2,801 steps at roughly 0.91 iterations per second. I saved the adapters and tokenizer configuration rather than a new copy of the entire model, keeping the checkpoints manageable and the training setup easy to revisit.

Get beyond the notebook

I merged the adapters into the base weights and built an ONNX export path with PyTorch's Dynamo exporter. Disabling KV caching resolved a mismatch with the static graph. I then checked the output shape and numerical behavior in ONNX Runtime before moving on to local use.

Use it where I write code

I published a GGUF build and loaded it in LM Studio on Apple Silicon. Its local server gave me a route into Cursor through an OpenAI-compatible endpoint. That completed the experiment: the model could leave the training notebook and become part of a local development setup.

The hard parts

The constraint

A 7B model had to fit on a single L4 GPU during training.

The decision

4-bit quantization, about 5M trainable adapter weights, and gradient accumulation kept the run within the available memory.

The constraint

A successful training run did not guarantee a usable export.

The decision

I merged the adapters, disabled caching for export, and verified the resulting graph in ONNX Runtime.

Training to Deployment

Published on Hugging Face

Published on Hugging Face

The public model card brings the files, training setup, and local usage instructions together.

Trained on One GPU

Trained on One GPU

One L4 GPU, 5,602 Swift examples, and a training run of about 51 minutes.

Running Locally

Running Locally

The GGUF build running in LM Studio on Apple Silicon, with inference kept on the machine.

The outcome

What changed

The result

  • ✓Published a GGUF build on Hugging Face for local use in LM Studio.
  • ✓Recorded more than 1,800 downloads in a 30-day reporting window.
  • ✓Completed one epoch in about 51 minutes, with a final training loss of 0.369.
  • ✓Built and checked an ONNX export path alongside the local inference setup.

Looking back

Getting a model to train was one milestone. Packaging it, checking the export, and making it usable in an editor were separate pieces of work.

The training loss helped me follow the run, but it was not a substitute for evaluating the Swift code the model produced.

What I'd explore next

I would expand coverage of SwiftUI and concurrency, then evaluate those additions on held-out examples before extending training.

Where I contributed

Product

  • Chose a narrow Swift use case and a local setup developers could try.

Design

  • Structured the examples, model card, and usage instructions around that workflow.

Engineering

  • Built the QLoRA training, adapter merging, ONNX verification, and local inference paths.