How sakanaai/text-to-lora works
Project Type & Purpose
• This is a research‐focused Python tool (“Text-to-LoRA”) for instantly adapting large language models via LoRA adapters.
• It provides both a CLI (scripts/) and a local Web UI (webui/app.py) to:
• Train new LoRA adapters via SFT or reconstruction
• Generate LoRA adapters from natural‐language task descriptions
• Evaluate adapters on benchmark tasks
High-Level Components
a. User Interfaces
• CLI Scripts (scripts/*.py, .sh): generate_lora.py, run_eval.py, train_* scripts, watcher.py
• Web UI (webui/app.py)
b. Core Libraries
• fishfarm (src/fishfarm/fishfarm): model abstractions (vLLM, LangChain), task loading, logging, chat_templates API
• hyper_llm_modulator (src/hyper_llm_modulator): LoRA mixing, SFT trainer, reconstruction trainer, evaluation hooks
c. Data & Config
• chat_templates/ (Jinja2 templates per base model)
• configs/*.yaml (hyperparams for reconstruction, tasks lists)
• tasks/*.yaml (metadata describing each evaluation dataset)
d. External Dependencies
• HuggingFace Hub (model and checkpoint downloads)
• vLLM & PyTorch/CUDA on GPUs
• uv for environment & task orchestration
Core Workflows & Interactions
a. LoRA Generation (CLI or Web UI)
1. UI → calls fishfarm.chat_templates to render a prompt from a natural‐language task description
2. Pass prompt to hyper_llm_modulator.hyper_modulator
3. Load base model (via model_loading), apply hyper‐network to generate LoRA weights
4. Write LoRA adapter files to local folder (trained_t2l/...)
5. Return file paths / UI response
b. SFT & Reconstruction Training
1. scripts/train_t2l_*.sh → invokes Python entrypoint (train_custom_sft.py or train_hyper_recon.py)
2. Data: loads many baseline LoRA adapters (oracle) or task descriptions + embeddings
3. Trainer uses hyper_llm_modulator.sft_trainer or recon_trainer → checkpoint LoRA models
4. watcher.py observes checkpoint directory → triggers evaluation
c. Evaluation
• scripts/run_eval.py / eval_* scripts read LoRA directories + tasks metadata → compute metrics → save results
Architectural Patterns & Design Principles
• Modular layering:
• UI layer (CLI/Web)
• Core library layer (fishfarm + hyper_llm_modulator)
• Data/config layer (YAML, templates, tasks)
• Plugin‐style tasks: tasks/*.yaml drive all evaluations uniformly
• Observer pattern in watcher.py for asynchronous validation
• Separation of concerns: model I/O, training logic, prompt rendering, and orchestration live in distinct modules