QueryLM 3.3B (DCLM-Edu), search fine-tuned
The chat version of QueryLM 3.3B: fine-tuned for one epoch from the base model Kausp11/querylm-dclm-3.3b on user-assistant conversations, part of which contain search blocks. QueryLM is a language model pretrained from scratch on text with inline search blocks (a search query followed by a retrieved passage), so it writes queries and reads passages as part of ordinary text generation.
| Stage | base model + search fine-tuning; fine-tuned from Kausp11/querylm-dclm-3.3b |
| Architecture | nanochat-style decoder: 32 layers, width 2,816, 22 heads, feed-forward 11,264, head dim 128, context 4,095 tokens |
| Parameters | 3,322.3M reported (5,539.7M stored, including value embeddings) |
| Loads with | transformers + trust_remote_code=True (the repo ships modeling_nanochat.py) |
How to use
The model can be used without search like any causal language model. To let it search: open a search block, let it write the query, run your own retriever, insert the result, and let it continue.
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
repo = "Kausp11/querylm-dclm-3.3b-sft-search"
tok = AutoTokenizer.from_pretrained(repo)
# trust_remote_code runs modeling_nanochat.py from this repo; pin `revision=` to a commit you have read.
model = AutoModelForCausalLM.from_pretrained(repo, trust_remote_code=True, torch_dtype=torch.bfloat16).eval()
Q_OPEN, Q_CLOSE = tok.convert_tokens_to_ids("<WEB_QUERY>"), tok.convert_tokens_to_ids("</WEB_QUERY>")
def my_search(query: str) -> str:
"""Replace with your retriever (BM25 index, web search API, ...). Return one short passage."""
return "Canberra is the capital city of Australia. It was founded in 1913 and is the country's largest inland city."
@torch.no_grad()
def generate(text, max_new_tokens, stop_id=None, allow_search=True):
x = tok(text, add_special_tokens=False, return_tensors="pt")
kw = {} if allow_search else {"bad_words_ids": [[Q_OPEN]]}
out = model.generate(**x, max_new_tokens=max_new_tokens, do_sample=False,
eos_token_id=stop_id, pad_token_id=tok.eos_token_id, **kw)
return tok.decode(out[0, x.input_ids.shape[1]:], skip_special_tokens=True)
# Chat format is plain text: "User: ...\n\nAssistant: ". There is no chat template.
prompt = "User: What is the capital of Australia?\n\nAssistant: "
query = generate(prompt + "<WEB_QUERY>", max_new_tokens=24, stop_id=Q_CLOSE).strip() # 1) the model writes the query
block = f"<WEB_QUERY>{query}</WEB_QUERY> <WEB_RESPONSE>{my_search(query)}</WEB_RESPONSE>" # 2) you retrieve and insert the block
answer = generate(prompt + block, max_new_tokens=64, allow_search=False) # 3) the model answers
print("query :", query)
print("answer:", answer.split("\n\nUser:")[0].strip())
Output of this exact script (CPU, bfloat16, torch 2.8.0, transformers 4.56.0, run 2026-11-19 on the files in this repo):
query : Australia capital city name
answer: The capital of Australia is Canberra. It is a city located in the Australian Capital Territory, which is a self-governing entity within the Commonwealth of Australia. Canberra is the political, economic, and administrative center of Australia, and it serves as the country's capital.
The passage here is a fixed example string; the output shows the mechanics, not the model's accuracy.
Search-block format
| Token | id |
|---|---|
<WEB_QUERY> | 49152 |
</WEB_QUERY> | 49153 |
<WEB_RESPONSE> | 49154 |
</WEB_RESPONSE> | 49155 |
Layout in the training text: …text<WEB_QUERY>query</WEB_QUERY> <WEB_RESPONSE>passage</WEB_RESPONSE> text continues…. The tokenizer is the SmolLM2 tokenizer plus these four tokens (vocabulary 49,156). The loss covered the text, the query and the query tags; the response tags and the passage carried no loss, so the model does not generate passages. The caller supplies them.
Chat format: plain text with System:, User: and Assistant: prefixes, turns separated by a blank line. There is no chat template, so apply_chat_template does not apply. A search goes at the start of the assistant turn or at the start of a sentence.
Training data
Pretraining: DCLM-Edu, annotated with search blocks by a fine-tuned annotator model (Gemma 4 E4B-it with a LoRA adapter). The annotator marks positions where a search would help (insertion probability at least 0.05, at least 40 characters apart) and writes a query of at most 24 tokens for each. Passages come from BM25 retrieval over the public Sphere web corpus and are shortened by extractive cleaning. An insertion is kept only if the passage overlaps the text that follows it in the document (ROUGE-1 F1 of at least 0.1 against the next 260 characters).
Fine-tuning: about 53,000 user-assistant conversations. About 64% teach general chat skills (SmolTalk subsets) and 15% tool calling (SmolTalk2 subsets), without search. The remaining 21% are SmolTalk conversations whose assistant turns were annotated with search blocks by the same pipeline as the pretraining text, each block moved to the start of the sentence it was placed in (38,436 blocks in 9,713 conversations). 35.2M tokens, packed into 4,096-token sequences; loss on assistant text, queries and end of turn.
Training procedure
| Pretraining optimizer | Muon for matrix weights (peak LR 0.02828), AdamW for embeddings and output head |
| Batch | 256 sequences x 4,095 tokens = 1,048,320 tokens per update |
| Schedule | 40 warmup steps, constant, then linear decay to 5% of peak at the end |
| Pretraining budget | 95,172 updates; 99.8B tokens processed, of which 64.0B document tokens; 2.35e21 FLOPs; bf16 compute |
| Fine-tuning | resumes from the pretraining checkpoint with its optimizer state; 33 updates of 256 sequences (one epoch); learning rates 0.8x the pretraining peaks, constant for the first half, then linear to zero |
Provenance
| Checkpoint | run sftnc_v4cannsent_v1_d32_64Bdoc, update 33 of 33 (finished) |
| Initialised from | Kausp11/querylm-dclm-3.3b (weights and optimizer state) |
| Code | nanochat (upstream commit 92d63d4) with a local search-data branch |
model-00001-of-00003.safetensors sha256 | 99269bf9f98de575606990c65acd200c32523fdd15d775a571e750262e3d5e7c |
model-00002-of-00003.safetensors sha256 | 73b645a6a66be48d34ff39a53f9d8004769220585c319f1d6a8b19a114df35aa |
model-00003-of-00003.safetensors sha256 | b6f359cd1e0298d6290cdb2fbbaf4f13d5065ea09a7d5152e117fe719c53bcdc |
| Also published as | Kausp11/searchlm-dclm_nc-sftnc_v4cannsent_v1_d32_64Bdoc (identical weights, earlier name) |
Evaluation
Evaluation results will be added later.
Intended use and limitations
- A research artifact for studying models that learn to search during pretraining. Not a product.
- Fine-tuned for one epoch on a small chat mixture. It follows the plain-text chat format above and is not a general-purpose assistant.
- English web text only; no safety or refusal training of any kind. It will state false things fluently.
- It searches usefully only when the caller runs the loop above. Passages are inserted verbatim into the context: whatever the retriever returns, the model conditions on, including wrong or adversarial text. The retrieval source is the caller's choice and responsibility.
- Loading executes Python from this repository (
modeling_nanochat.py). Read it or pin a revision.
Built with Llama
Built with Llama. The fine-tuning data was selected with the help of Llama 3.1 8B (base), used as a yes/no classifier that decides which candidate conversations are kept for search annotation (none of its text enters the data), and it contains SmolTalk conversations generated with Llama 3.1 models (5,452 from smol-magpie-ultra, generated with Llama-3.1-405B-Instruct, and 907 from everyday-conversations, generated with Llama-3.1-70B-Instruct). Llama 3.1 is licensed under the Llama 3.1 Community License, Copyright © Meta Platforms, Inc. All Rights Reserved. License: https://www.llama.com/llama3_1/license/ ; Acceptable Use Policy: https://www.llama.com/llama3_1/use-policy/
License
Apache-2.0 (licence text in LICENSE). modeling_nanochat.py is adapted from nanochat, MIT License, Copyright (c) 2025 Andrej Karpathy (text in LICENSE-nanochat). Training text: DCLM-Edu (CC-BY-4.0). Retrieved passages used as masked context during pretraining come from Sphere (CC BY-NC 4.0); they are not part of this repo.
Citation
Paper: Search From the Start: Search-Native Pretraining for Language Models · Project page: https://kaustubhp11.github.io/querylm/
@article{ponkshe2026searchfromthestart,
title = {Search From the Start: Search-Native Pretraining for Language Models},
author = {Ponkshe, Kaustubh and Je, Gyung Hyun and Taga, Stefan and Raffel, Colin and Jaggi, Martin},
journal = {arXiv preprint arXiv:2611.26809},
year = {2026}
}