Hypernetworks that update LLMs to remember factual information https://arxiv.org/abs/2602.15902
Find a file
2025-10-02 06:35:33 +00:00
assets cover + readme 2025-05-29 15:20:09 +00:00
chat_templates/google iclr cleanup 2025-09-30 14:53:21 +00:00
configs python api + remove generate_multi_lora + rename config path + test eval scripts 2025-10-01 13:11:54 +00:00
data python api + remove generate_multi_lora + rename config path + test eval scripts 2025-10-01 13:11:54 +00:00
demo basic gradio app 2025-10-02 06:35:33 +00:00
examples python api + remove generate_multi_lora + rename config path + test eval scripts 2025-10-01 13:11:54 +00:00
scripts python api + remove generate_multi_lora + rename config path + test eval scripts 2025-10-01 13:11:54 +00:00
src/ctx_to_lora basic gradio app 2025-10-02 06:35:33 +00:00
trained_t2l/gemma_2b_t2l iclr cleanup 2025-09-30 14:53:21 +00:00
webui python api + remove generate_multi_lora + rename config path + test eval scripts 2025-10-01 13:11:54 +00:00
.gitignore toy ctx magic num eval upto 32k + remove configs 2025-09-01 05:57:06 +00:00
.pre-commit-config.yaml rearrange + move to uv (#1) 2025-05-27 21:18:15 +09:00
accelerate_config.yaml sakura scripts 2025-08-11 15:00:30 +09:00
install.sh python api + remove generate_multi_lora + rename config path + test eval scripts 2025-10-01 13:11:54 +00:00
pyproject.toml basic gradio app 2025-10-02 06:35:33 +00:00
README.md python api + remove generate_multi_lora + rename config path + test eval scripts 2025-10-01 13:11:54 +00:00
run_eval.py iclr cleanup 2025-09-30 14:53:21 +00:00
setup.py rearrange + move to uv (#1) 2025-05-27 21:18:15 +09:00
train.py iclr cleanup 2025-09-30 14:53:21 +00:00
uv.lock basic gradio app 2025-10-02 06:35:33 +00:00
watcher.py toy exp w/ self-gen + use double bos for eval (following vllm 0.8.4) 2025-09-07 17:16:20 +09:00

Doc-to-LoRA



🚀 Python API Usage

# caveat: this interface only supports non-batched inputs
# for batched inference please see `src/ctx_to_lora/modeling/hypernet.py`
import torch

from ctx_to_lora.model_loading import get_tokenizer
from ctx_to_lora.modeling.hypernet import ModulatedPretrainedModel

# model loading
checkpoint_path = ...
state_dict = torch.load(checkpoint_path, weights_only=False)
model = ModulatedPretrainedModel.from_state_dict(
    state_dict, train=False, use_sequence_packing=False
)
model.reset()
tokenizer = get_tokenizer(model.base_model.name_or_path)

# prepare data
doc = open("data/sakana_wiki.txt", "r").read()
chat = [{"role": "user", "content": "Summarize what Sakana AI does."}]
chat_ids = tokenizer.apply_chat_template(
    chat,
    add_special_tokens=False,
    return_attention_mask=False,
    add_generation_prompt=True,
    return_tensors="pt",
).to(model.device)


# calls after internalization will be influenced by internalized info
model.internalize(doc)

outputs = model.generate(input_ids=chat_ids, max_new_tokens=256)
print(tokenizer.decode(outputs[0]))


# remove internalized info
model.reset()

outputs = model.generate(input_ids=chat_ids, max_new_tokens=256)
print(tokenizer.decode(outputs[0]))

🎮 Interactive Demo [WIP]

uv run webui/demo.py

🧪 Experimental Scripts

Experiment Data prep Training Evaluation Notes
Main experiment uv run bash scripts/main_exp/0-download_data.sh
uv run bash scripts/main_exp/gen_data.sh (optional, rebuilds from scratch)
uv run bash scripts/main_exp/1-train.sh uv run bash scripts/main_exp/eval/<script>.sh (pick from base_model.sh, cd.sh, cd_oracle.sh, d2l.sh, llmlingua.sh, t2l.sh) Downloading data is fastest; regenerate only if you need fresh synthetic data. Evaluation scripts reproduce the main paper metrics.
NIAH uv run bash scripts/niah/0-gen_data.sh uv run bash scripts/niah/1-train.sh uv run bash scripts/niah/2-eval.sh Run the scripts in order; data generation only needs to happen once