This project trains a hypernetwork to generate LoRA adapters for teaching new facts to language models.
Instead of manually training a LoRA for each new fact, the hypernetwork learns to predict what LoRA weights are needed. You give it a fact, and it outputs the adapter weights.
train_lora_adapters.py- Creates individual LoRA adapters for each fact in the datasettrain_hypernetwork.py- Trains the hypernetwork to predict LoRA weightstest_hypernetwork.py- Tests the trained hypernetworkevaluate_real_loras.py- Evaluates the individually trained LoRAscheck_base_knowledge.py- Checks if the base model already knows certain facts
Uses wikifactdiff_converted.csv which contains questions and updated answers for fact changes.
First, generate the training data (individual LoRAs):
python train_lora_adapters.py --num_facts 100Then train the hypernetwork:
python train_hypernetwork.pyTest it:
python test_hypernetwork.pyBase model: Qwen2-7B-Instruct LoRA config: rank=2, alpha=4, targets=q_proj,v_proj