new features

This commit is contained in:
Mark Gregory
2026-11-17 15:35:04 +00:00
parent 71972cd843
commit d1a1b454f6
18 changed files with 2598 additions and 112 deletions
+49 -14
View File
@@ -1,8 +1,20 @@
# Fine-tune a model for use in AI Studio
AI Studio can download and run MLX checkpoints from Hugging Face and register
local MLX model folders. Training is currently an external MLX LM workflow.
The app does not yet provide a Clone or Train button.
local MLX model folders. Training and conversion run locally using the MLX LM tools.
Use the repository's `Scripts/train-mlx.py` to validate a local chat dataset, train and evaluate an adapter, and fuse a new checkpoint from Terminal.
## Use the tools in AI Studio
1. Open **Settings → Model Library → MLX → MLX Tools…**. For an installed model, use **Clone & Train…** to preselect its weights.
2. Use **Install MLX Tools** once. It uses a native Apple Silicon Python 3.11 or newer to install MLX LM with its training dependencies into a dedicated AI Studio environment. If automatic selection picks the wrong interpreter, use **Choose Python…**.
3. Use **Clone Base…** to write a separate copy to a new folder and add it to the library. Training can also use the original checkpoint while writing adapter weights to a separate run folder.
4. Choose a dataset folder and a run folder. Use **Validate Dataset**, **Train Adapter**, and **Evaluate**. Use **Fuse and Register** to create and register the final checkpoint. The run folder contains the adapter at `adapter` and the fused output at `trained-model`. Pick a fresh run folder for a new experiment.
5. Read errors and training output in the workshop. **Stop** ends the current operation. If stopping a run leaves partial output in its folder, choose a new destination before retrying.
The workshop also has **Convert to MLX**. Choose a compatible original checkpoint folder, or enter a Hugging Face repo ID and optionally pin its revision. Choose a new destination. The 4-bit option reduces weight size. A successful result appears in the MLX library and can be used as a training base.
In the Ollama library, an installed model's **Tools → Clone…** creates a new tag on the configured server. **Tools → Convert to MLX…** opens the same conversion workflow using the original Hugging Face checkpoint. The MLX LM converter accepts compatible model checkpoints. A packaged Ollama GGUF blob requires a separate conversion approach.
## 1. Choose the base model
@@ -21,6 +33,19 @@ an explicit revision. For a gated repository, request access and authenticate
using the Hub CLI before downloading. AI Studio's built-in catalog currently
downloads public MLX Community checkpoints.
To download a separate copy, run this from your training project after
installing the Hugging Face Hub CLI. Take the repository and full commit
from the model preview in AI Studio and choose a new local folder.
```sh
hf download OWNER/REPO --revision FULL_COMMIT_SHA --local-dir ./base-model
```
To copy an Ollama model tag on the server configured for the Ollama CLI, use
`ollama cp SOURCE:TAG MY-MODEL:TAG`. This copies the inference model under a
new name with the same weights. To fine-tune it, obtain the matching training
checkpoint from the publisher and record its revision.
## 2. Prepare your local dataset
Create a dataset folder with `train.jsonl`, `valid.jsonl`, and `test.jsonl`.
@@ -50,7 +75,7 @@ Record the installed version with the experiment so you can reproduce it.
```sh
python3 -m venv .venv
source .venv/bin/activate
python -m pip install mlx-lm
python -m pip install "mlx-lm[train]"
python -m pip show mlx-lm
```
@@ -67,6 +92,25 @@ mlx_lm.generate --model "$BASE" --adapter-path ./adapter \
--prompt "Review this change for missing validation."
```
The repository runner offers the same local workflow with dataset validation
and checks for new output folders. Run these from your training project with
the MLX environment activated.
```sh
RUNNER="$HOME/Developer/Applications/AIStudio/Scripts/train-mlx.py"
python "$RUNNER" validate --data ./dataset
python "$RUNNER" train --base "$BASE" --data ./dataset --adapter ./adapter-smoke
python "$RUNNER" evaluate --base "$BASE" --data ./dataset --adapter ./adapter-smoke
python "$RUNNER" fuse --base "$BASE" --adapter ./adapter-smoke --out ./trained-model
```
The runner expects text chat examples and rejects the same prompt history
across splits. It starts with 50 iterations, batch size 1, and four adapted
layers. Use `--iters` and `--layers` to change the smoke run and choose a new
adapter folder for each experiment. Prompt masking trains against the final
assistant response. On a quantized base, MLX LM uses QLoRA. A smoke run checks
the pipeline. Use a held-out evaluation to judge whether to keep the adapter.
Compare base and adapter answers on the same held-out examples. Check
grounding, task accuracy, style, and regressions outside the target task.
Use a small first run to check memory and verify the checkpoint supports
@@ -95,15 +139,6 @@ training configuration, evaluation and limitations in the model card. A Hub
repository can store the adapter or fused checkpoint separately from the base.
Keep it private unless you intend to publish it.
## Proposed AI Studio integration
A **Create Training Variant** action should create a new local record tied to
the pinned base revision. A dataset picker should validate JSONL and preview
the splits. A training screen should show settings, progress, loss, cancellation
and checkpoints. Once a run completes, present a side-by-side evaluation and
a **Register Trained Model** action. Start with the MLX LM worker in a dedicated
environment and record the runtime version and exact inputs. Set no automatic
upload destination.
Sources: [MLX LM LoRA guide](https://github.com/ml-explore/mlx-lm/blob/main/mlx_lm/LORA.md) ·
[Hugging Face Hub download guide](https://huggingface.co/docs/huggingface_hub/guides/download)
[Hugging Face Hub download guide](https://huggingface.co/docs/huggingface_hub/guides/download) ·
[Ollama import guide](https://docs.ollama.com/import)