Skip to main content
Train an open-weight model against a reward you define, then publish and serve its weights with the MKA1 API. This example uses a small invoice-extraction task, TRL’s GRPO trainer, and a finite Compute job. Compute allocates hardware, records logs, and enforces spending limits. The container generates answers, scores them, updates the model, and uploads checkpoints. The examples assume an initialized sdk client and an authenticated MKA1 CLI.

What the example does

  1. Generates 128 invoice prompts for training and eight separate prompts for evaluation.
  2. Loads a pinned revision of Qwen2.5-0.5B-Instruct from the public Hugging Face Hub.
  3. Scores JSON validity, currency, and the extracted total.
  4. Runs 20 GRPO steps with LoRA adapters on one GPU.
  5. Publishes intermediate checkpoints, merged weights, tokenizer files, and before/after evaluation results to MKA1 repositories.
The model downloads use the public Hub. Artifact uploads use an explicitly configured MKA1 endpoint, so setting up output storage does not redirect the base-model download.

Step 1 - Prepare the complete training image

Save the following two files together, or use the files in examples/compute/rl. The training script includes dataset generation, the reward function, training, evaluation, and checkpoint publishing; no additional entry script or reward plugin is required.
Dockerfile
train.py
Build and publish the image. Replace the registry path with a repository you own:
Build image
Use that exact image reference in the quote and job examples below. Pin the pushed image by digest when repeating an experiment.

Step 2 - Create the output repository

Use a new output repository so that the run does not overwrite your base model. The response includes your organization slug; substitute it for <org-from-create> in the job request.

Step 3 - Store the artifact credential

Create a Compute secret containing your MKA1 API key under ARTIFACT_TOKEN. Replace the credential placeholder before running this step, and use the returned secret ID in Step 5. The image and job command contain no credentials.

Step 4 - Quote the GPU job

Replace <your-pushed-image> with the image you built. A quote does not reserve capacity. If available is false, choose another catalog configuration before proceeding.

Step 5 - Start training

Replace the image, output repository, and secret ID with the values from the earlier steps. Set MKA1_REQUEST_ID to a unique value for this experiment. Reuse it only when retrying the identical request.
ARTIFACT_TOKEN is resolved from the stored secret at launch. OUTPUT_MODEL_REPO and ARTIFACT_ENDPOINT are read by the provided script. The script verifies repository access before downloading the base model or starting training.
Billing starts at allocation. Runtime limits, spending limits, and exhausted budgets can terminate a job without a final upload. The script publishes every five training steps and at completion; only completed uploads survive loss of the job’s ephemeral disk.

Step 6 - Monitor and inspect the result

Use the job status, logs, and events examples with the returned job ID. Training metrics appear in user logs. The script emits checkpoint_published and model_published messages after successful uploads. A failed upload makes the workload fail instead of reporting success with missing weights. Download the output using the repository artifact tools:
Download results
The repository contains: Compare the same held-out prompts before and after training. Higher training reward alone does not establish better extraction; inspect errors and the exact-match score. Twenty steps and eight validation prompts are a workflow check, not a benchmark.

Step 7 - Serve or continue experimenting

Follow Deploy a model server with your output repository as the model identifier. The output already contains merged weights, so no separate LoRA merge is needed. Creating a training job does not automatically deploy the model or register it for the Responses API. Terminate any serving service when finished. Keep output artifacts until you have inspected them. To train on your own task, replace records() and score() while keeping a separate evaluation set and the checkpoint export path. The provided script starts a new run; it does not implement automatic resume.

Validation boundary

  • TypeScript and C# snippets are compiled against the pinned SDK releases.
  • SDK requests are checked offline for their URL, headers, and serialized body.
  • The workload’s local test uses a tiny random model and a local artifact client; it exercises execution and does not measure learning quality or provider compatibility.
  • A real GPU training run, image pull, and MKA1 artifact upload still need an end-to-end pilot.

See also