SakanaAI
doc-to-lora
Python

Hypernetworks that update LLMs to remember factual information

Last updated Aug 2, 2026
794
Stars
103
Forks
0
Issues
0
Stars/day
Attention Score
90
Language breakdown
Python 93.9%
Shell 3.1%
HTML 2.5%
Jinja 0.6%
โ–ธ Files click to expand
README

Doc-to-LoRA (D2L): Learning to Instantly Internalize Contexts

:sparkles:Interactive Web | :newspaper:X | :scroll:Paper | :hugs:Hugging Face | :octocat:GitHub
A reference implementation of Doc-to-LoRA (D2L).


๐Ÿ› ๏ธ Installation

curl -LsSf https://astral.sh/uv/install.sh | sh
./install.sh

๐Ÿค— Pre-Trained Models

uv run huggingface-cli login
uv run huggingface-cli download SakanaAI/doc-to-lora --local-dir trained_d2l --include "*/"

๐Ÿš€ Python API Usage

# caveat: this interface only supports non-batched inputs

for batched inference please see src/ctxtolora/modeling/hypernet.py

import torch

from ctxtolora.modelloading import gettokenizer from ctxtolora.modeling.hypernet import ModulatedPretrainedModel

model loading

checkpointpath = "trainedd2l/gemmademo/checkpoint-80000/pytorchmodel.bin" statedict = torch.load(checkpointpath, weights_only=False) model = ModulatedPretrainedModel.fromstatedict( statedict, train=False, usesequence_packing=False ) model.reset() tokenizer = gettokenizer(model.basemodel.nameorpath)

prepare data

doc = open("data/sakana_wiki.txt", "r").read() chat = [{"role": "user", "content": "Tell me about Sakana AI."}] chatids = tokenizer.applychat_template( chat, addspecialtokens=False, returnattentionmask=False, addgenerationprompt=True, return_tensors="pt", ).to(model.device)

calls after internalization will be influenced by internalized info

model.internalize(doc)

outputs = model.generate(inputids=chatids, maxnewtokens=512) print(tokenizer.decode(outputs[0]))

remove internalized info

model.reset()

without internalized info, the model will halucinate

outputs = model.generate(inputids=chatids, maxnewtokens=512)

print(tokenizer.decode(outputs[0]))

๐ŸŽฎ Interactive Demo

uv run demo/app.py

Video Demo

๐Ÿงช Experimental Scripts

To run any of the following scripts, use uv run $PATHTOSCRIPT from the root of this project.

| Experiment | Data prep | Training | Evaluation | Notes | | ------------------------------------ | ------------------------------------- | ----------------------------- | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | | Main experiment | scripts/mainexp/0-downloaddata.sh | scripts/mainexp/1-train.sh | scripts/mainexp/eval/*.sh | Downloading data is fastest; regenerate only if you need fresh synthetic data. Evaluation scripts reproduce the main paper metrics. | | NIAH | scripts/niah/0-gendata.sh | scripts/niah/1-train.sh | scripts/niah/2-eval.sh | Run the scripts in order; data generation only needs to happen once |

๐Ÿ”ฌ Self-Generated Data Viewer

After downloading/generating the data, we can see samples of the data using this script.
uv run webui/selfgenviewer.py
See more info at webui/SELFGEN_VIEWER.md.

๐Ÿ“š Citation

@inproceedings{charakorn2026doctolora,
  title       ={Doc-to-Lo{RA}: Learning to Instantly Internalize Contexts},
  author      ={Rujikorn Charakorn and Edoardo Cetin and Shinnosuke Uesaka and Robert Tjarko Lange},
  booktitle   ={Forty-third International Conference on Machine Learning},
  year        ={2026},
  url         ={https://openreview.net/forum?id=iW1oBBO72S}
}
๐Ÿ”— More in this category

ยฉ 2026 GitRepoTrend ยท SakanaAI/doc-to-lora ยท Updated daily from GitHub