Lab Workspace
Doc-to-LoRA (Context Internalization)
Doc-to-LoRA (D2L) is context internalization: a hypernetwork generates LoRA adapters from documents, so context is served from the model's weights instead of the prompt. You train the hypernetwork once, then run it per document.
How it works
D2L is built around a hypernetwork — a model that takes a document as input and emits a LoRA adapter as output. Instead of stuffing a document into every prompt, you internalize it once: the hypernetwork generates an adapter that encodes the document, and the runtime serves requests through that adapter. There are two operations:
POST /v1/train/d2l— trains the hypernetwork itself (an asynchronous training job).POST /v1/d2l/internalize— runs a trained hypernetwork on one document to produce and register an adapter (a synchronous call, no training job).
This is not classical fine-tuning — there is no LoRA rank or alpha for you to tune; the hypernetwork generates the adapter. For classical parameter-efficient fine-tuning with explicit rank/alpha/target modules, see PEFT Tuning (LoRA).
Supported model families
| Family | family value |
|---|---|
| Qwen3 4B | qwen3-4b |
| Qwen3 0.6B | qwen3-0.6b |
| Mistral 7B | mistral-7b |
Train the hypernetwork
/v1/train/d2lTrains the D2L hypernetwork for a supported model family. The call returns a job id immediately (202 Accepted); training continues asynchronously with checkpoints.
| Parameter | Type | Description |
|---|---|---|
familyrequired | string | Base model family — qwen3-4b, qwen3-0.6b, or mistral-7b. |
num_examples | integer | Number of training examples to generate/use from the source documents. |
epochs | integer | Number of training epochs. |
lr | float | Learning rate. |
eval_examples | integer | Size of the held-out eval set scored automatically when the job finishes. |
seed | integer | Seed for reproducible example generation. |
device | string | Device to train on (e.g. Metal or CUDA hardware available to the runtime). |
model_dir | string | Optional base-model directory override. |
checkpoint_dir | string | Artifact destination. Default ~/hybrie-mounts/d2l-artifacts/train-<job_id>/. |
curl -X POST http://localhost:8080/v1/train/d2l \
-H "Content-Type: application/json" \
-d '{
"family": "qwen3-4b",
"num_examples": 200,
"epochs": 3,
"lr": 0.0001
}'Response (202 Accepted):
{
"job_id": "train-1718102400",
"checkpoint_dir": "~/hybrie-mounts/d2l-artifacts/train-1718102400/"
}Job ids follow the train-<timestamp> format. Poll Training Jobs for status and progress points (step, loss, reward). The artifact is a hypernet checkpoint — score it on held-out NIAH with POST /v1/eval/niah.
Internalize a document
/v1/d2l/internalizeRuns the hypernetwork on a single document: it generates an adapter encoding the document and registers it with the runtime in one call, ready to serve.
| Parameter | Type | Description |
|---|---|---|
document_textrequired | string | The source document to internalize into the adapter. |
name | string | Human-readable name for the resulting adapter. |
execution_mode | string | Where internalization runs. local. |
pin | boolean | Pin the adapter after registration so it is not evicted — see Hot-swap Inference. |
ttl_seconds | integer | Optional time-to-live. The adapter auto-expires after this many seconds. |
session_key | string | Optional session key tying the adapter to a session. |
curl -X POST http://localhost:8080/v1/d2l/internalize \
-H "Content-Type: application/json" \
-d '{
"document_text": "Our refund policy: ...",
"name": "refund-policy",
"execution_mode": "local",
"ttl_seconds": 86400
}'The response identifies the generated-and-registered artifact:
{
"adapter_id": "d2l-7f3a9c",
"version": "v1",
"artifact_dir": "~/hybrie-mounts/d2l-artifacts/d2l-7f3a9c/v1",
"source_document": "Our refund policy: ...",
"status": "registered"
}Internalizing a changed document produces a new immutable version instead of overwriting the old one. The emitted adapter artifacts are PEFT-format, so they can also be scored with POST /v1/eval/adapter and served like any registered adapter.
From the CLI
stimulir lab train d2l --family qwen3-4b --epochs 3The CLI flag is --examples; it maps to the num_examples field in the request body.
Next
- Track hypernetwork training runs in Training Jobs.
- Score hypernet checkpoints on held-out NIAH in Evaluation.
- Serve internalized adapters with Hot-swap Inference.
- For classical fine-tuning with explicit rank/alpha, see PEFT Tuning (LoRA).
