--- base_model: meta-llama/Llama-3.2-3B library_name: peft license: llama3.2 tags: - lora - qlora - ties-merging - model-routing - llama-3.2 - math - code pipeline_tag: text-generation --- # Dynamic Multi-Adapter Routing: LoRA Weights & Meta-Router Artifacts This repository hosts the domain adapters, the TIES hybrid adapter, and routers All adapters are trained on top of the **`meta-llama/Llama-3.2-3B`** base model. --- ## Repository Contents | Path / Filename | Type | Description | |---|---|---| | `math_adapter_3b/` | PEFT LoRA Adapter | Trained on 7,500 samples from `openai/gsm8k` for mathematical reasoning. | | `code_adapter_3b/` | PEFT LoRA Adapter | Trained on 15,000 length-filtered Python samples from `m-a-p/CodeFeedback-Filtered-Instruction`. | | `hybrid_ties_code_math_3b/` | PEFT LoRA Adapter | Offline TIES-Merged adapter combining `math_adapter_3b` and `code_adapter_3b` (`density=0.8`, weights `0.5 / 0.5`). | | `syntax_router.joblib` | Joblib Artifact | Pre-trained TF-IDF vectorizer (1–3 n-grams, 10k features) + Logistic Regression classifier. | | `semantic_centroids.npy` | NumPy Artifact | Pre-calculated 768D domain centroids using `sentence-transformers/all-mpnet-base-v2`. | | `meta_router.joblib` | Joblib Artifact | 6-dimensional Random Forest Meta-Classifier (`n_estimators=100`, `max_depth=4`). | --- ## Training Hyperparameters The single-domain adapters (`math_adapter_3b` and `code_adapter_3b`) were trained on a Google Colab NVIDIA T4 GPU using 4-bit NormalFloat (NF4) QLoRA via `bitsandbytes` with `-100` loss masking applied to prompt tokens: - **Base Model:** `meta-llama/Llama-3.2-3B` - **Rank ($r$):** 32 - **LoRA Alpha ($\alpha$):** 64 - **LoRA Dropout:** 0.0 - **Target Modules:** `q_proj`, `k_proj`, `v_proj`, `o_proj`, `gate_proj`, `up_proj`, `down_proj` - **Optimizer:** `adamw_torch` - **Learning Rate:** $3 \times 10^{-4}$ (Cosine scheduler, 50 warmup steps) - **Batch Size:** 8 (Gradient Accumulation: 2, Effective Batch Size: 16) - **Max Sequence Length:** 512 - **Epochs:** 1 - **Precision:** FP16 (`torch.float16`) --- ## Usage: Loading Multi-Adapters with PEFT You can mount all three adapters simultaneously into VRAM and dynamically switch between them in ~2.44 ms using `set_adapter()`: ```python import torch from transformers import AutoModelForCausalLM, AutoTokenizer from peft import PeftModel from huggingface_hub import snapshot_download # Download repository artifacts repo_dir = snapshot_download(repo_id="mutli-adapter-routing/multi-adapter") base_model_id = "meta-llama/Llama-3.2-3B" tokenizer = AutoTokenizer.from_pretrained(base_model_id) base_model = AutoModelForCausalLM.from_pretrained( base_model_id, torch_dtype=torch.float16, device_map="auto" ) # Load Math adapter first, then mount Code and Hybrid adapters model = PeftModel.from_pretrained( base_model, f"{repo_dir}/math_adapter_3b", adapter_name="math" ) model.load_adapter(f"{repo_dir}/code_adapter_3b", adapter_name="code") model.load_adapter(f"{repo_dir}/hybrid_ties_code_math_3b", adapter_name="hybrid") # Switch active adapter dynamically per query model.set_adapter("math") inputs = tokenizer( "Question: Natalia sold clips to 48 of her friends in April, and then she sold half as many clips in May. How many clips did Natalia sell altogether in April and May?\nAnswer:\n", return_tensors="pt" ).to("cuda") outputs = model.generate(**inputs, max_new_tokens=256, do_sample=False) print(tokenizer.decode(outputs[0], skip_special_tokens=True)) # Or disable adapters to use the raw base model for general queries with model.disable_adapter(): outputs = model.generate(**inputs, max_new_tokens=256) ```