Skip to main content
Replaces a general-purpose 1.7B model with a fine-tuned 0.5B model for structured data extraction. The resulting model runs on a 2GB GPU, classifies chat messages into topics, names semantic clusters, and expands search queries with domain synonyms.

Prerequisites

  • A Spectra account with a configured teacher model API key
  • Ollama installed on your target machine
  • Python 3.10+ with transformers and gguf packages (for local conversion)
  • An application that currently calls an LLM for structured output

Step 1: Audit Your Existing LLM Usage

Before training, identify exactly what your application asks the LLM to do. In this project, the application had three LLM-powered workflows: The first workflow was the only one using an LLM. The second two were opportunities to add LLM-powered functionality that the 1.7B model’s VRAM footprint had previously precluded.

Step 2: Design Tool Schemas

Each distinct LLM task becomes a tool. If your application already prompts for JSON with a specific schema, use that as the starting point.
Upload all three as a JSON array via the Paste JSON tab. See Tool Schemas for format details.
Avoid naming parameters "name" or "description" — these collide with tool-level fields in some parsers. Use topic_name, topic_description, etc.

Step 3: Configure Training

Model Selection

Training Parameters

Training Objectives

Keep the three defaults and add domain-specific objectives:
Click Start Training. Training typically completes in 5-15 minutes for a 0.5B student model.

Step 4: Add a vector in Optimization

Prepare Contrastive Data

JSONL file with prompt, positive (desired output), and negative (unwanted output):
10-15 pairs covering all tools. Mix clear-cut examples with ambiguous edge cases.

Create the Vector

1

Open Vector Library

Open the Optimization workspace for your model and click + Create Vector.
2

Configure

3

Upload data

Select Upload as the dataset source and upload your JSONL file. Verify the pair count matches your expectations.
4

Set refinement parameters

Use defaults: Refinement Steps = 100, Learning Rate = 0.01.
5

Create and attach

Click Create Vector. Once generated, attach it in Optimization and set strength to 60%. Increase to 80% if prose still leaks through during testing.

Step 5: Test via API

Step 6: Deploy Locally with Ollama

Convert to GGUF for local inference via Ollama.

Download from HuggingFace

Fix Tokenizer Compatibility (Qwen2)

Qwen2-based models may ship with extra_special_tokens as a list instead of a dict, which breaks conversion:

Convert to GGUF

Spectra exports safetensors in BF16. GPUs without BF16 support (Pascal-generation and older) will crash at inference. GGUF conversion to F16 or Q8_0 is required for these cards.

Quantization Options

For sub-1B models, Q8_0 is the default choice.

Create an Ollama Model

Modelfile with the Qwen2 chat template (required for tool-calling support):
If you skip the TEMPLATE directive, Ollama assigns a minimal {{ .Prompt }} template that breaks chat-format inference and tool calling.

Verify

Step 7: Integrate into Your Application

Both the Spectra API and Ollama’s /v1 endpoint implement the OpenAI chat completions spec. Write once, switch with env vars.

Environment Configuration

Use during development or when you want Spectra’s steering vectors and SAE monitoring applied at inference time.

Parse the Response

Small models occasionally wrap JSON in markdown fences:

Step 8: Production Checklist

  • Test all three tools with representative inputs from your actual dataset
  • Verify GPU memory with ollama ps while the model is loaded
  • Set up fallback if using the hosted API (local Ollama for resilience)
  • Monitor output quality for the first week
  • Remove the previous model (ollama rm old-model)

Results