Post-Training & RL

Fine-Tuning Inkling 2 Mini with Kimi K3.1 Pro for Bug Fixes

Train Inkling 2 Mini on CSS patches written by Kimi K3.1 Pro and verified in a browser. Compare original, base and tuned pages at three phone widths and two desktop widths.

Build it with an agent

Paste into Claude Code, Cursor, or any coding agent — it builds the recipe for you.

Fine-tune Inkling 2 Mini to repair mobile landing-page CSS on an H100. Generate patches with Kimi K3.1 Pro on Nebius Token Factory, verify all training targets in a browser, freeze disjoint primary and transfer tests, compare base and tuned repairs under matched decoding, save both private Hugging Face artifacts and report costs, screenshots, desktop regressions and all paired outcomes.

Recipe

Inkling 2 Mini is a model you can run locally and fine-tune for bugs your team sees often. Take the Fieldnote page below. On a phone, its chart sits beside the headline and pushes a button out of reach. Both versions of Mini tried to stack the columns. Only the fine-tuned model wrote a CSS rule specific enough to override the desktop layout.

You’ll use Kimi K3.1 Pro on Nebius Token Factory to write example patches, check them in a browser, and train a low-rank adapter (LoRA) for Mini in JupyterLab. On the 32 pages held out of training, the base model fixed 21 and the fine-tuned model fixed all 32. Each repair had to pass at three phone widths and preserve the layout at two desktop widths. The results below come from the November 25, 2026 UTC run.

One landing page rendered at 375 pixels before repair, with base Mini CSS, and with the trained adapter CSS

Fieldnote (test-005) is the first ticket in test order that only the adapter fixed. Base Mini targeted .fieldnote-zone, but the existing rule targeted .fieldnote-signal .fieldnote-zone. Adding the parent selector gave the adapter’s rule enough specificity. The chart moved below the buttons, and both buttons fit.

Fine-tuning parameters

Only the adapters in the language model’s attention and feed-forward layers received weight updates. The 4-bit base weights stayed frozen. The trainer counted 202,555,392 trainable parameters out of 26,588,967,936 (0.76%).

Training parameter Value used on one H100
Base checkpoint unsloth/Inkling-2-Mini-unsloth-bnb-4bit, revision 22035f8bf3fd71a588d78591f8b3ec45c0994524
Adapter Rank 8, alpha 8, dropout 0, bias disabled
Targets Language attention and MLP, including expert projections. Vision layers frozen
Batch and duration 1 example per device, 4 gradient accumulation steps, effective batch size 4, 2 epochs, 114 optimizer steps
Optimizer 8-bit AdamW, peak learning rate 0.0001, weight decay 0.001
Schedule 4 warmup steps, then linear decay. Seed 3407
Memory and context Unsloth gradient checkpointing, 4,096-token context. Longest training example 1,875 tokens
Training split 225 verified patches for training, 12 reserved for validation. The fixed two-epoch run used no validation-based checkpoint selection

Each training example contains a bug report, the page markup, the broken stylesheet and a verified CSS patch. Mini sees the whole conversation, but only its reply contributes to the training loss. The trainer uses Mini’s native chat template with reasoning_effort="none" so the reply contains the patch.

The two message markers below tell the trainer which tokens belong to the reply. Before training starts, the script decodes one masked example to check that the target CSS survived, then checks that every example has tokens to learn from.

trainer = train_on_responses_only(
    trainer,
    instruction_part="<|message_user|>",
    response_part="<|message_model|>",
)

The recipe uses Unsloth’s Mini fine-tuning procedure with browser-verified CSS as the supervised target. Unsloth fine-tuning guide

Set up JupyterLab with Serverless AI on Nebius AI Cloud

To inspect the published repairs on a laptop, skip to Replay the comparison. To train a new adapter, you’ll need Git, Bash, Python 3.12 or newer, a Token Factory API key for the teacher calls, and a CUDA GPU. The recorded run used an existing JupyterLab with one 80 GB H100. If you already have a GPU-backed JupyterLab, go straight to step 5. To start a new Devlab, open the Nebius AI Cloud console.

  1. Select your project. In the left sidebar, open Serverless AI → Devlabs and click Create Devlab.

  2. Under Configuration, choose Template, select JupyterLab, and click Use template. Keep the generated Jupyter token available for sign-in.

    Template catalog with JupyterLab selected and Use template enabled

  3. Choose With GPUs → NVIDIA H100 NVLink and the 1 GPU — 16 CPUs — 200 GiB RAM preset shown here. Review availability and the price in your project. Size the container disk for the model cache, environment and adapter. Nebius requires at least 50 GiB for GPU workloads. Submit the form and wait until the Devlab is running.

    H100 NVLink with 80 GB of GPU memory selected above the one-GPU preset

  4. Open the Devlab details. Under Network → Public endpoints, open the managed HTTPS URL. Enter the generated Jupyter token at Password or token. The Token Factory API key is used later for teacher requests. Nebius Devlab setup and connection guide

    Jupyter Server sign-in with a blank Password or token field

  5. In JupyterLab, click + to open the Launcher and choose Other → Terminal. Use your template’s persistent workspace for the checkout. The training output shown below comes from the JupyterLab used for the measured run.

In the terminal, change to your persistent workspace (usually /workspace) and check that nvidia-smi lists the GPU. The setup below uses Python 3.12+ and a PyTorch build for CUDA 12.8. Use a compatible driver. Companion code

python --version
nvidia-smi --query-gpu=name,memory.total --format=csv
git clone https://github.com/nebius/token-factory-cookbook.git
cd token-factory-cookbook
git switch --detach 3ed56761759a66e58e05889bee47f271502ee1bf
cd post-training/inkling-mini-mobile-repair
bash setup.sh
source .venv/bin/activate
python -m pip install -r requirements-replay.txt
export PLAYWRIGHT_BROWSERS_PATH="$PWD/.browsers"
python -m playwright install chromium
python pages.py
python independent.py

Look for Environment ready after setup. If Chromium reports missing Linux libraries, install its system dependencies for the Devlab image with python -m playwright install-deps chromium and the necessary OS permissions. The final two Python commands build the page fixtures. pages.py creates the training and validation candidates and the first 24 test cases. independent.py creates eight more test cases from a separate template. Keep using this terminal so the virtual environment and browser path stay active.

Generate and verify the teacher patches

Each synthetic example starts with a broken page and a bug report. The earlier pages.py command creates both. One of its tickets asks the model to “Keep the full headline readable” when the text runs past the edge of the screen. The page’s markup and current stylesheet give the model the selectors it needs to fix the bug. Page and ticket generator

Copy the key template in the recipe directory, open the new .env file in JupyterLab, and set NEBIUS_API_KEY to your Token Factory key. Open Nebius Token Factory

cp -n env.example .env

After saving the file, load the key and check that your account can see the teacher model. Continue when the check prints Kimi K3.1 Pro is available. Model availability check

set -a
. ./.env
set +a
curl -fsS https://api.tokenfactory.nebius.com/v1/models -H "Authorization: Bearer $NEBIUS_API_KEY" |
  python -c '
import json, sys
models = json.load(sys.stdin)["data"]
if not any(model["id"] == "moonshotai/Kimi-K3.1-Pro" for model in models):
    sys.exit("Teacher model unavailable")
print("Kimi K3.1 Pro is available")
'

teacher.py supplies the answer side of each example. It sends the ticket, markup and stylesheet to Kimi K3.1 Pro and asks for the smallest CSS patch that fixes the bug. The request uses temperature 0.4, disables thinking and allows up to 950 output tokens. The script saves the reply and token usage in work/teacher/<id>.json. Only training and validation tickets go to Kimi. Kimi synthetic-data generator

python teacher.py

If the teacher run is interrupted, rerun python teacher.py from the same directory. It skips tickets that already have a saved reply.

A proposed patch still has to work in a browser. For the headline ticket, the text must fit at all three phone widths and the desktop layout must stay intact. The next two commands check each patch and write the accepted prompt–patch pairs to data/train.jsonl and data/validation.jsonl. The recorded run used headless Brave. The setup above installs Playwright’s Chromium. Browser verification · Dataset split and export

python browser_check.py teacher
python freeze.py

All 237 patches passed the browser checks in the recorded run. Of those, 225 went into training and 12 were reserved for validation. A fresh Kimi run can produce a different number of accepted patches. Before training, inspect one of yours. The ticket field describes the visible bug, prompt includes the stylesheet and markup, and response holds Kimi’s accepted fix.

python - <<'PYTHON'
import json
from pathlib import Path

data = Path("data")
counts = json.loads((data / "manifest.json").read_text())["counts"]
print("Accepted training pairs:", counts["train"])
print("Reserved validation pairs:", counts["validation"])
if not counts["train"]:
    raise SystemExit("No accepted patches. Inspect work/checks/teacher before training.")
with (data / "train.jsonl").open() as rows:
    example = json.loads(next(rows))
print(example["ticket"])
print(example["response"])
PYTHON

The test pages were set aside before either version of Mini saw them. The first set has 24 pages built with the training generator, but uses six new brands, new CSS selectors and four new combinations of three bugs. Training pages had only one or two bugs each. The other eight pages come from a separately written template with different markup and layout rules. Every test page starts with at least one failing browser check.

Train the adapter and read the loss curve

Use a fresh recipe directory for each new experiment. The trainer protects an existing adapter from being overwritten. Start training from the same JupyterLab terminal. Read the checksum from your manifest so the trainer verifies the exact file that passed the browser checks.

train_sha=$(python -c 'import json; print(json.load(open("data/manifest.json"))["sha256"]["train.jsonl"])')
python runner/train.py "$train_sha"

When training finishes, the terminal prints RESPONSIVE_REPAIR_TRAINING_COMPLETE. The adapter weights are in adapter/adapter_model.safetensors. In results/, mask.json shows one example of the tokens used for training, loss.json records the loss over time, and metrics.json holds the run totals. Training script

JupyterLab terminal reporting the H100, two completed epochs and the saved adapter weight file

Training ran for 114 optimizer steps. Loss averaged 0.4845 over the first five steps and 0.0392 over the five ending at step 110. The average for the whole run was 0.0901. That downward trend tells you how well Mini learned the training responses. To see whether a patch actually fixes a page, render it. Recorded loss history

Training loss logged every five optimizer steps. It falls steeply through step 25 and fluctuates around 0.04 to 0.06 later in training.

Reload the adapter and evaluate

Run the evaluation from the recipe directory. The script loads the base model and the saved adapter in separate processes. Each gets the same system instruction, ticket, HTML and stylesheet. Both generate CSS directly, using greedy decoding in batches of eight with a 500-token output limit. The longest accepted training patch was 160 tokens.

bash evaluate.sh

The evaluation runs the base model and adapter on each test set, then applies their saved CSS in the browser. Open results/scores.json for page and defect counts, results/costs.json for the time and cost breakdown, and results/showcase.html to see the actual pages. From JupyterLab, download the gallery file and open it in a local browser to use its interactive controls.

Score the repairs in the browser

At 320, 375 and 430 CSS pixels, the browser checks the things a phone user would notice. Can a reader see the full headline? Are the buttons tall enough to tap? Do the cards stack in order, the form controls stay within reach and the graphic fit its panel? At 1024 and 1280 pixels, the grader compares selected elements’ positions, sizes, content and computed styles with the original page. A page counts as repaired only if it passes every check at all five widths.

Test set Checkpoint Full repairs Reported defects passing Desktop preserved At token cap
24 component-system cases Base Mini 18/24 55/72 24/24 0
24 component-system cases Kimi-trained Mini 24/24 72/72 24/24 0
8 independent-template cases Base Mini 3/8 9/24 8/8 0
8 independent-template cases Kimi-trained Mini 8/8 24/24 8/8 0

Each ticket reports three defects. A patch can fix one and still leave the page broken, which is why the table gives both defect and full-page counts. The adapter fixed six additional pages on the first template and five on the second. It retained every fix the base model got right. These checks cover layout and reading order on two templates. A broader accessibility audit or a judgment about visual design would require other tests.

Before and after on held-out pages

Each comparison below shows the original page, the base model’s repair and the fine-tuned model’s repair at the same width. Use the ticket ID to find the saved CSS in the replay gallery.

Switchyard (test-009). At 375 px, the original page cuts off the headline “Make every connection” and part of the chart. The base patch leaves both clipped. The adapter includes the parent selector .switchyard-deck, giving its font and width rules enough specificity to fix both.

Switchyard at 375 px. The headline and chart are clipped in the original and base columns and fit in the fine-tuned column.

Bracken (external-01). The ticket asks for three cards stacked in reading order. The base model makes the first card fill the row, but the next one still starts off to its right. The adapter stacks all three. The crop begins at the feature section so you can see where the second card lands.

Bracken at 375 px. The original and base layouts extend cards horizontally. The adapter stacks A pressed fern, A coast walk and Last light.

Loomline (external-02). At 320 px, the email field is visible, but the button sits offscreen even after the base model’s patch. The adapter’s main .loomline__signup rule puts the form in one column. “Sign me up” now sits directly below the field.

Loomline at 320 px. Only the fine-tuned footer shows the Sign me up button directly below the email field.

Hearth (test-001). Both models fixed this one. They stacked the two buttons and moved the preview underneath. The button padding differs, and both layouts pass at all five widths.

Hearth at 375 px. The original actions share a row. Both model repairs stack Reserve a seat and Explore the menu above the chart.

Time and cost

On the existing GPU workspace, about 30 minutes elapsed from the first Kimi request to the final held-out prediction. This interval excludes Devlab provisioning and the subsequent browser scoring. Training took 9 minutes 20 seconds on one H100 and peaked at 24.65 GiB of allocated GPU memory. At the November 25 list price of USD 4.50 per H100-hour, the training loop cost about USD 0.70. Including model loading, saving and inference, the GPU portions of the run took 18.50 minutes and cost an estimated USD 1.39.

The 237 Kimi requests ran in parallel and finished in 24.5 seconds. The calls used 317,474 input tokens and 15,438 output tokens and cost USD 0.79, bringing the estimate for teacher calls and measured GPU time to USD 2.18. That estimate excludes setup, idle time, storage, transfers and earlier experiments. Nebius GPU prices · Token Factory model prices

The cost report uses the recipe’s stored token prices and USD 4.50 per H100-hour. For a run at different rates, use its token counts and elapsed GPU time with your project’s prices.

Save the adapter, dataset and results

Copy the entire adapter/ directory, the accepted dataset and results/ out of the lab. Loading the adapter requires its configuration and the base checkpoint named in the parameter table. The recorded run’s adapter and dataset are private. The public replay uses the saved predictions.

To archive a new run on Hugging Face, sign in with a write-enabled token and choose two unused repository names under your own account. Run the commands from the recipe directory with its training environment active. Each upload below runs only after its private repository has been created. Hugging Face CLI guide

hf auth login
owner="YOUR_HF_USERNAME"
hf repos create "$owner/inkling-css-adapter" --private &&
  hf upload "$owner/inkling-css-adapter" adapter .
hf repos create "$owner/inkling-css-data" --repo-type dataset --private &&
  hf upload "$owner/inkling-css-data" data . --repo-type dataset \
    --include train.jsonl --include validation.jsonl --include manifest.json --include system.txt

Keep the two Hub commit links with your run notes. To take the loss history, scores, costs and interactive gallery with you, run tar -czf repair-results.tar.gz results/ and download the archive from JupyterLab’s file browser.

After saving the files, stop the Devlab from its details page to release compute. Its persistent disk continues to incur storage charges while stopped. Stop or start a Devlab

Replay the comparison

To inspect the recorded outputs on a laptop, start in an empty working directory with Git, Bash and Python 3.12+ available. This path rebuilds the test pages and applies the saved CSS. It needs neither an API key nor a GPU.

git clone https://github.com/nebius/token-factory-cookbook.git
cd token-factory-cookbook
git switch --detach 3ed56761759a66e58e05889bee47f271502ee1bf
cd post-training/inkling-mini-mobile-repair
python3 -m venv .venv-replay
source .venv-replay/bin/activate
python -m pip install -r requirements-replay.txt
export PLAYWRIGHT_BROWSERS_PATH="$PWD/.browsers"
python -m playwright install chromium
bash replay.sh

Open replay-results/showcase.html in a browser, select a ticket and switch between the five viewport widths. replay-results/scores.json contains your replay scores and recorded/scores.json contains the reference scores. Fonts and browser versions can affect layout. If you prefer a notebook, open repairs.ipynb from this directory in a Python kernel with the replay dependencies installed. Replay setup

Summary

On Loomline, success meant a visitor could reach “Sign me up” on a 320 px screen. The same browser check that caught the original bug could tell whether a proposed fix worked. That gave Kimi’s patches a clear acceptance test before they became training examples for Mini.

To try this with a bug your team sees often, start with a failing page. Write down what a reader should be able to do after the fix and turn that into a browser check. Use it to screen candidate training patches. Keep a separate set of broken pages to see whether the model can fix the same kind of bug on a page it hasn’t seen.