text-to-lora

SakanaAIApache-2.0长期未更新

用超网络仅凭任务文本描述就为 LLM 生成 LoRA 权重,免去标注数据和反向传播,让模型快速适配特定基准任务。

Hypernetworks that adapt LLMs for specific benchmark tasks using only textual task description as the input

暂无版本1,329star93fork同步于 2026-11-07 07:29 UTC

怎么上手

由 README 提炼,执行前请确认
git clone https://github.com/SakanaAI/text-to-lora.git
cd text-to-lora
uv venv --python 3.10 --seed
uv sync
uv pip install src/fishfarm
硬件要求按 README 说明

README 说明同时加载两个模型需大于 16GB 显存;gemma-2-2b-it 可在更小显存上运行;训练单个模型约需单张 H100 跑 5 天。

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

用任务文本描述直接生成 LoRA 超网络,免去为每个基准任务单独微调

用超网络仅凭任务文本描述就为 LLM 生成 LoRA 权重,免去标注数据和反向传播,让模型快速适配特定基准任务。

核心能力

  • 以任务描述文本为输入,由超网络直接生成 LoRA 权重
  • 提供 SFT 与重建两种训练流程,含异步 watcher 评估
  • 附带 Web UI 与 CLI 脚本,可生成并评测 LoRA
  • 支持 Mistral-7B、Llama-3.1-8B、Gemma-2-2b 等基座

容易踩的坑

运行任何 demo 前必须先下载 trained_t2l 检查点并登录 Hugging Face;flash-attention 需按自身硬件替换对应 wheel;首次运行会下载并缓存基座模型,耗时较长;vLLM 应用 LoRA 存在非确定性,同种子评测结果也会有波动。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

0 个版本

暂无 release 数据(可能没有发版,或尚未同步)。

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    Text-to-LoRA (T2L): Instant Transformer Adaption


    Install uv if you don't have uv (see https://docs.astral.sh/uv/getting-started/installation/)

    With uv installed, run the following to install the dependencies.

    git clone https://github.com/SakanaAI/text-to-lora.git
    cd text-to-lora
    # make sure you have `uv` installed
    # (see https://docs.astral.sh/uv/getting-started/installation/)
    uv self update
    uv venv --python 3.10 --seed
    uv sync
    # we use the following wheel for installation
    # you might have to change the wheel to be compatible with your hardware
    uv pip install https://github.com/Dao-AILab/flash-attention/releases/download/v2.6.3/flash_attn-2.6.3+cu123torch2.3cxx11abiFALSE-cp310-cp310-linux_x86_64.whl
    uv pip install src/fishfarm
    

    Downloading trained T2L

    :warning: You need to download the checkpoints before running any of the demos. :warning:

    :warning: You need a >16GB GPU to handle both models simultaneously to run any of these demos. :warning:

    uv run huggingface-cli login
    uv run huggingface-cli download SakanaAI/text-to-lora --local-dir . --include "trained_t2l/*"
    

    Web UI

    This demo runs Mistral-7B-Instruct-v0.2 locally alongside a T2L model.

    # start webui locally
    uv run python webui/app.py
    

    LoRA generation from CLI

    This script allows us to generate a LoRA based on a task description. Running for the first time would take longer as the base model will be downloaded and cached.

    # uv run generate_lora.py {T2l_DIRECTORY} {TASK_DESCRIPTION}
    # e.g.,
    uv run python scripts/generate_lora.py \
    trained_t2l/llama_8b_t2l \
    "This task challenges your problem-solving abilities through mathematical reasoning. You must carefully read each scenario and systematically work through the data to compute the final outcome."
    
    # You might be able to run T2L w/ `gemma-2-2b-it` with a smaller GPU.
    uv run python scripts/generate_lora.py \
    trained_t2l/gemma_2b_t2l \
    "This task challenges your problem-solving abilities through mathematical reasoning. You must carefully read each scenario and systematically work through the data to compute the final outcome."
    

    Evaluating generated LoRA

    We can evaluate the generated LoRA by using the path printed at the end of the above script.

    # uv run python scripts/run_eval.py --model-dir {base_model_dir} \
    # --lora-dirs {lora_dirs} --save-results --tasks {tasks}
    # e.g.,
    uv run python scripts/run_eval.py \
    --model-dir meta-llama/Llama-3.1-8B-Instruct \
    --lora-dirs {PATH_TO_GENERATED_LORA} \
    --save-results --tasks gsm8k
    
    # You might be able to run T2L w/ `gemma-2-2b-it` with a smaller GPU.
    uv run python scripts/run_eval.py \
    --model-dir google/gemma-2-2b-it \
    --lora-dirs {PATH_TO_GENERATED_LORA} \
    --save-results --tasks gsm8k
    

    Disclaimer :grey_exclamation:

    Even with random descriptions, SFT-trained T2L still generates reasonable LoRAs. This result with SFT-trained T2L differs from Table 5 in the paper that uses reconstruction-trained T2L. Nonetheless, comparing the results obtained between aligned and unaligned descriptions, aligned LoRAs perform noticeably better overall. The training descriptions can be found in tasks/ folder, while the unseen ones used for evaluation can be found in configs/hyper_lora_decontam_lol_tasks.yaml


    # start a watcher process for async eval
    uv run watcher.py
    

    Then run one of the following scripts for each GPU you have. Each takes around 5 days on a single H100 GPU.

    # T2L training
    ./scripts/train_t2l_mistral.sh
    ./scripts/train_t2l_llama.sh
    ./scripts/train_t2l_gemma.sh
    

    ./scripts/train_lora_baselines.sh
    

    Then, we train T2L to reconstruct the oracle adapters.

    # train T2L via reconstruction training
    WANDB_MODE=disabled uv run python scripts/train_hyper_recon.py configs/hyper_lora_decontam_lol_tasks.yaml \
    --model_dir=mistralai/Mistral-7B-Instruct-v0.2/ \
    --emb_model=Alibaba-NLP/gte-large-en-v1.5 \
    --warmup_frac=0.1 --lr=1e-3 --epochs=10000 \
    --n_train_ds=479 --exp_setup=hyper_lora --encoder_type=linear \
    --pred_z_score=True --n_descs_per_ds=128 --n_embs_per_sampled_task=1 \
    --n_tasks_per_batch=4 --factorized=False --delta_w_scaling=10000 --shared_AB_head=True
    

    Base model

    ./scripts/eval_base_models.sh
    

    T2L

    # example for T2L trained for gemma-2-2b-it
    WANDB_MODE=disabled uv run python scripts/eval_hypermod_checkpoint.py --checkpoint_path trained_t2l/gemma_2b_t2l/hypermod.pt --full_eval --use-icl
    

    --use-icl includes 3-shot in-context examples into evaluation queries.


    :test_tube: Reproducibility

    Disclaimer :grey_exclamation:

    We have re-trained a new set of baselines and T2L models due to a small mismatch between the specific package version combinations used in the original submission.

    Furthermore, vLLM is inherently non-deterministic when applying LoRA (in the version-configuration combinations we tested). Thus, we have observed some small variance between evaluation runs even with a fixed initial seed.

    However, after re-retraining and collecting new results, T2L still consistently outperforms baselines across model families, confirming the validity of our original empirical analysis. We present this new set of results with the updated package versions in the following tables. (eval #1 and eval #2 indicate that the results are gathered from two different evaluation calls with the same random seed.)

    Mistral-7B-Instruct-v0.2

    ModelArcC (acc)ArcE (acc)BoolQ (acc)GSM8K (acc)HS (acc)OQA (acc)PIQA (acc)WG (acc)HE (pass@1)MBPP (pass@1)AVG
    Mistral-7B65.7977.7471.5641.0249.6454.2072.9645.0739.0242.6155.96
    Mistral-7B w/ ICL72.0186.0371.8041.0259.1565.6076.3358.0939.0241.3561.04
    Mistral-7B w/ task desc61.8677.5371.5041.0245.0856.2069.7547.5938.4139.6054.85
    MT LoRA (eval #1)76.5489.2785.2346.4767.1172.4082.8162.5139.0245.3666.67
    MT LoRA (eval #2)76.5489.2785.2345.6467.1072.4082.8162.5139.6346.1266.73
    Hyperdecoders (eval #1)76.6288.3884.3446.1067.2572.6082.4862.8335.3752.8866.89
    Hyperdecoders (eval #2)77.0588.3884.4645.4966.7373.2081.9462.3535.9852.3866.80
    T2L (eval #1)77.4289.2084.6244.0267.0875.0782.3263.1438.6248.7167.02
    T2L (eval #2)77.4289.2084.6244.2067.0775.0782.3263.1438.6248.8767.05

    Llama-3.1-8B-Instruct

    ModelArcC (acc)ArcE (acc)BoolQ (acc)GSM8K (acc)HS (acc)OQA (acc)PIQA (acc)WG (acc)HE (pass@1)MBPP (pass@1)AVG
    Llama-8B73.2990.5380.4075.3666.5375.4079.6055.0165.2468.9273.03
    Llama-8B w/ ICL80.8091.9679.8875.3659.1978.0080.6361.6465.2469.1774.19
    Llama-8B w/ task desc72.7890.9576.5775.3663.2173.0080.5256.2067.0770.9372.66
    MT LoRA (eval #1)82.4293.1884.4076.3573.8881.8081.9460.3862.2069.4276.60
    MT LoRA (eval #2)82.4293.1884.4376.8873.8981.8081.9460.3062.2069.6776.67
    T2L (eval #1)82.8293.0484.2377.0573.8482.0782.1261.1964.6370.9377.19
    T2L (eval #2)82.6593.1584.3476.9873.8882.1382.0661.3864.2370.0977.09

    Gemma-2-2b-it

    ModelArcC (acc)ArcE (acc)BoolQ (acc)GSM8K (acc)HS (acc)OQA (acc)PIQA (acc)WG (acc)HE (pass@1)MBPP (pass@1)AVG
    gemma-2-2b-it73.6389.8680.9855.2754.9970.8070.8453.8343.9013.5360.76
    gemma + ICL72.1088.8082.2955.2755.5972.2067.6853.3543.9043.3663.45
    gemma + ICL + task desc72.1088.8082.2955.2755.5972.2067.6853.3543.9043.3663.45
    mt lora + ICL (#eval1)74.0688.8081.0156.4160.0974.4068.1758.0139.6350.1365.07
    mt lora + ICL (#eval2)74.0688.8081.0456.5660.1074.4068.1758.0139.6349.8765.06
    T2L + ICL (#eval1)74.1290.0382.2756.6162.8774.3373.6157.5139.0250.5466.09
    T2L + ICL (#eval2)74.1290.0382.2756.8962.8674.3373.6157.5139.0250.5466.12

    📡 Huggingface datasets connection

    Huggingface datasets server might reject connections sometimes, which can be problematic if you haven't locally cached the relevant datasets. The cause could be that we're downloading a lot of datasets (~500 datasets). If this happens, keep retrying the SFT training script until all datasets are cached locally. Once the datasets are cached, you should be able to run the SFT training script.


    📖 BibTex

    @inproceedings{
        charakorn2025texttolora,
        title={Text-to-Lo{RA}: Instant Transformer Adaption},
        author={Rujikorn Charakorn and Edoardo Cetin and Yujin Tang and Robert Tjarko Lange},
        booktitle={Forty-second International Conference on Machine Learning},
        year={2025},
        url={https://openreview.net/forum?id=zWskCdu3QA}
    }