Prerequisites
- A Spectra account with a configured teacher model API key
- Ollama installed on your target machine
- Python 3.10+ with
transformersandggufpackages (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.- Tool 1: name_topic_cluster
- Tool 2: classify_message
- Tool 3: expand_search_query
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:Step 4: Add a vector in Optimization
Prepare Contrastive Data
JSONL file withprompt, positive (desired output), and negative (unwanted output):
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 withextra_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
- Hosted (Spectra API)
- Local (Ollama)
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 pswhile 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)