Hypernetworks that update LLMs to remember factual information https://arxiv.org/abs/2602.15902
Find a file
2025-05-30 08:11:31 +00:00
assets cover + readme 2025-05-29 15:20:09 +00:00
chat_templates webui working (not yet two loras) 2025-05-13 10:49:31 +00:00
configs medium fw qa 3 + fallback to manual cache dataset 2025-05-10 15:31:08 +00:00
data data gen scripts 2025-05-30 03:11:03 +00:00
eval_results/google/gemma-2-2b-it everything :) 2025-01-22 12:59:22 +00:00
icae_v2 rearrange + move to uv (#1) 2025-05-27 21:18:15 +09:00
scripts webui chat + result display + eval datasets + preprocessing eval + refactoring data_utils.py to data_definition.py 2025-05-20 06:06:20 +00:00
src/ctx_to_lora autocast bfloat16 2025-05-30 08:11:31 +00:00
webui rearrange + move to uv (#1) 2025-05-27 21:18:15 +09:00
.gitignore versioning + cli commands 2025-05-30 08:11:00 +00:00
.pre-commit-config.yaml rearrange + move to uv (#1) 2025-05-27 21:18:15 +09:00
eval.py rearrange + move to uv (#1) 2025-05-27 21:18:15 +09:00
install.sh versioning + cli commands 2025-05-30 08:11:00 +00:00
intx_sft.py rearrange + move to uv (#1) 2025-05-27 21:18:15 +09:00
pyproject.toml versioning + cli commands 2025-05-30 08:11:00 +00:00
README.md versioning + cli commands 2025-05-30 08:11:00 +00:00
run_lm_eval.py rearrange + move to uv (#1) 2025-05-27 21:18:15 +09:00
setup.py rearrange + move to uv (#1) 2025-05-27 21:18:15 +09:00
uv.lock rearrange + move to uv (#1) 2025-05-27 21:18:15 +09:00
watcher.py rearrange + move to uv (#1) 2025-05-27 21:18:15 +09:00

Ctx-to-LoRA



Project doc

🚀 API Usage [WIP]

from ctx_to_lora.modeling import ModulatedPretrainedModel
model = ModulatedPretrainedModel.from_state_dict(...)

ctx_info = "..."
query = "..."

ctx_ids = model.ctx_encoder.tokenize(ctx_info)
input_ids = model.tokenize(query)
outputs = model.generate(ctx_ids, input_ids)
print(model.decode(outputs))

🏋️ Training

🔢 HyperLoRA w/ context_numbers_10

WANDB_MODE=disabled uv run python intx_sft.py configs/context_numbers_10.yaml --model_name_or_path=meta-llama/Llama-3.2-1B-Instruct --num_train_epochs=100 --per_device_train_batch_size=64 --per_device_eval_batch_size=64 --exp_setup=hyper_lora --aggregator_type=perceiver --target_modules=down_proj --per_rank_gen=True --per_layer_processing=True --decoder_depth=2 --seed=1 --gen_lora_l1_reg_coef=0 --use_token_mixing=False --lora_r=8 --bf16=True --tf32=True --dataloader_num_workers=8 --dataloader_prefetch_factor=8

Favourite numbers data generation

uv run python data/generate_fav_num.py
# or
uv run python data/generate_fav_num_big.py

Data Generation

# this might take several days...
# python process_fineweb.py
# python generate_fw_qa.py
# python post_process_fw_qa.py
conda activate vllm;
# [WIP] download fineweb-edu
vllm_model=mistralai/Mistral-Small-3.1-24B-Instruct-2503 uv run python generate_fw_edu_qa_vllm.py "0*_*" 3
# [WIP] there are other datasets where we used openAI to gen QA pairs

# self-generate SFT data
# gemma-2-2b-it
vllm_model=google/gemma-2-2b-it uv run python data/self_generate_qa.py "0*_*"
# each context has 3 chat instances as training data
# the responses are not the same as the ones in the pretraining though


# pre-training data
# better to include QAs at the end of pretrain docs
# # https://arxiv.org/pdf/2406.14491
uv run python data/generate_pretrain_from_fw_qa.py
# we could do this online but
# will have duplicate contexts (each context is used to generate 3 QA pairs)
# better if we do this offline bc dedup the contexts


Continue from a checkpoint

run python intx_sft.py configs/...yaml ... --from_pretrained_checkpoint=train_outputs/runs/May09_16-25-35_slurm0-a3nodeset-4_59459_ea85a571/checkpoint-10000/pytorch_model.bin --resume_from_checkpoint=train_outputs/runs/May09_16-25-35_slurm0-a3nodeset-4_59459_ea85a571/checkpoint-10000

Evaluation

LongBench

# generative
run python src/ctx_to_lora/eval.py --checkpoint_path train_outputs/runs/.../pytorch_model.bin --datasets negative_nq triviaqa_retrieved squad longbench_e --split test

# hypernet checkpoint
uv run python eval.py --checkpoint_path train_outputs/runs/May08_13-56-31_slurm0-a3nodeset-5_59383_906acb28/checkpoint-105000/pytorch_model.bin --datasets negative_nq triviaqa_retrieved squad longbench_e --split test

# base model
uv run python eval.py --model_name_or_path google/gemma-2-2b-it --datasets longbench_e --split test

# base model w/o context
run uv run python eval.py --model_name_or_path google/gemma-2-2b-it --datasets longbench_e --split test --remove_context

# run python src/ctx_to_lora/eval.py --checkpoint_path train_outputs/runs/May08_13-56-31_slurm0-a3nodeset-5_59383_906acb28/checkpoint-105000/pytorch_model.bin

# # benchmark
# cd LongBench/LongBench

# run python pred_ctx_to_lora.py  --checkpoint_path ../../train_outputs/runs/Mar16_12-38-01_slurm0-a3nodeset-12_54818_32426662/checkpoint-136782/pytorch_model.bin

# run python eval_ctx_to_lora.py --model_name Mar16_12-38-01_slurm0-a3nodeset-12_54818_32426662/checkpoint-136782 --checkpoint_path ../../train_outputs/runs/Mar16_12-38-01_slurm0-a3nodeset-12_54818_32426662/checkpoint-136782/pytorch_model.bin