Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Task Vector Bases — Checkpoints
|
| 2 |
+
|
| 3 |
+
Pre-built task vector **bases** for
|
| 4 |
+
[Task Vector Bases: A Unified and Scalable Framework for Compressed Task Arithmetic](https://openreview.net/forum?id=zkc7u3mIaE).
|
| 5 |
+
|
| 6 |
+
**Code:** https://github.com/uiuctml/TaskVectorBasis
|
| 7 |
+
|
| 8 |
+
Each basis compresses `T` task vectors (one per dataset) into `M = T/2` basis vectors,
|
| 9 |
+
built from CLIP image encoders fine-tuned on the standard vision benchmark. Loading a
|
| 10 |
+
basis lets you do task **addition** and **negation** at a fraction of the storage of
|
| 11 |
+
keeping all `T` task vectors.
|
| 12 |
+
|
| 13 |
+
## Naming
|
| 14 |
+
|
| 15 |
+
Folders are named `{model}_{method}_M{M}_{T}task`:
|
| 16 |
+
|
| 17 |
+
- `model` ∈ {`ViT-B-16`, `ViT-B-32`, `ViT-L-14`}
|
| 18 |
+
- `method` ∈ {`AE` (Autoencoder / Gram), `PCA`}
|
| 19 |
+
- `M` = number of basis vectors (`= T/2`)
|
| 20 |
+
- `T` ∈ {8, 14, 20} tasks (seed 0)
|
| 21 |
+
|
| 22 |
+
e.g. `ViT-B-32_AE_M4_8task`, `ViT-L-14_PCA_M10_20task`.
|
| 23 |
+
|
| 24 |
+
## Contents of each folder
|
| 25 |
+
|
| 26 |
+
| file | purpose |
|
| 27 |
+
|---|---|
|
| 28 |
+
| `basis_vectors.pt` | the `M` basis vectors — used for **addition** (required) |
|
| 29 |
+
| `method_info.json` | method, hyperparameters, and the **dataset order** used at build time |
|
| 30 |
+
| `AWB.pt` / `pca_components.pt` | method-specific artifact — needed to recover per-task vectors for **negation** |
|
| 31 |
+
|
| 32 |
+
## Usage
|
| 33 |
+
|
| 34 |
+
Clone the [code repo](https://github.com/uiuctml/TaskVectorBasis), set up its environment, then:
|
| 35 |
+
|
| 36 |
+
```python
|
| 37 |
+
from huggingface_hub import snapshot_download
|
| 38 |
+
from src.basis_vectors import BasisMethod
|
| 39 |
+
from src.task_vectors import NonLinearTaskVector
|
| 40 |
+
from src.basis_pipeline import load_and_recover_from_saved_basis
|
| 41 |
+
|
| 42 |
+
name = "ViT-B-32_AE_M4_8task"
|
| 43 |
+
local = snapshot_download("cindy2000sh/TaskVectorBasis-checkpoints", allow_patterns=[f"{name}/*"])
|
| 44 |
+
basis_dir = f"{local}/{name}"
|
| 45 |
+
|
| 46 |
+
# Task addition: sum the M basis vectors into one merged task vector.
|
| 47 |
+
merged = sum(NonLinearTaskVector(vector=bv) for bv in BasisMethod.load_basis_vectors(basis_dir))
|
| 48 |
+
# image_encoder = merged.apply_to("checkpoints/ViT-B-32/zeroshot.pt", scaling_coef=0.4)
|
| 49 |
+
|
| 50 |
+
# Task negation: recover the per-task vectors from the basis, then negate.
|
| 51 |
+
recovered = load_and_recover_from_saved_basis(run_dir=basis_dir)
|
| 52 |
+
# neg = -NonLinearTaskVector(vector=recovered[0])
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
Or use the helper script:
|
| 56 |
+
|
| 57 |
+
```bash
|
| 58 |
+
python scripts/load_basis.py --hf-repo cindy2000sh/TaskVectorBasis-checkpoints --hf-subdir ViT-B-32_AE_M4_8task
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
## Citation
|
| 62 |
+
|
| 63 |
+
```bibtex
|
| 64 |
+
@article{zeng2025task,
|
| 65 |
+
title={Task Vector Bases: A Unified and Scalable Framework for Compressed Task Arithmetic},
|
| 66 |
+
author={Zeng, Siqi and He, Yifei and Liu, Meitong and You, Weiqiu and Hao, Yifan and Tsai, Yao-Hung Hubert and Yamada, Makoto and Zhao, Han},
|
| 67 |
+
journal={arXiv preprint arXiv:2502.01015},
|
| 68 |
+
year={2025}
|
| 69 |
+
}
|
| 70 |
+
```
|