Text Generation
Transformers
Safetensors
English
querylm_nanochat
custom_code

QueryLM 400M (DCLM-Edu), base model

A 400M-parameter language model trained from scratch on DCLM-Edu web text in which search blocks were inserted during pretraining: at points where a lookup would help predict what comes next, the training text contains a search query followed by a retrieved passage. The model learned to write the queries and to use the passages; the passages themselves were never a prediction target.

This is the base model (pretraining only). The chat fine-tuned version is Kausp11/querylm-dclm-400m-sft-search. A compute-matched Standard baseline (same architecture and compute, plain text without search blocks) exists but is not published in this set yet.

Stage base model (pretraining only; no chat format)
Architecture nanochat-style decoder: 14 layers, width 1,280, 10 heads, feed-forward 5,120, head dim 128, context 4,095 tokens
Parameters 401.2M reported (842.2M 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-400m"
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)

# Base model: it continues text. Few-shot examples set the question-answer format.
shots = ("Question: Who wrote the novel Pride and Prejudice?\nAnswer: Jane Austen\n\n"
         "Question: What is the chemical symbol for gold?\nAnswer: Au\n\n")
prompt = shots + "Question: What is the capital of Australia?\n"

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 + "\nAnswer:", max_new_tokens=16, allow_search=False)           # 3) the model continues
print("query :", query)
print("answer:", answer.split("\n")[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 : capital of Australia
answer: Canberra

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.

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).

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 10,100 updates; 10.6B tokens processed, of which 6.8B document tokens; 3.09e19 FLOPs; bf16 compute

Provenance

Checkpoint run dclm_nc_v1_d14_all_chin10k, step 10,100. The run branches at step 9,000 from a longer 400M run and decays the learning rate over steps 9,000 to 10,100; the schedule is finished
Initialised from scratch
Code nanochat (upstream commit 92d63d4) with a local search-data branch
model.safetensors sha256 b887209eaac5655008c7a9d5a3ab104cb4df5b3a52ce4f14013afc4a2432ec0e

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.
  • Base model: it continues text and has no chat format. For chat-style use see the fine-tuned version.
  • 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.

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}
}
Downloads last month
100
Safetensors
Model size
0.8B params
Tensor type
BF16
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for Kausp11/querylm-dclm-400m

Finetunes
1 model

Dataset used to train Kausp11/querylm-dclm-400m

Collection including Kausp11/querylm-dclm-400m

Paper for Kausp11/querylm-dclm-400m