Reproduce trainable LiSA attention on Qwen3.5-2B

This commit is contained in:
2026-11-23 16:47:19 +08:00
parent 0df3b0bfe6
commit 67327d62d8
9 changed files with 1031 additions and 0 deletions
+40
View File
@@ -104,3 +104,43 @@ without repeatedly forwarding the whole backbone. For interrupted captures,
`--resume` checks source and code fingerprints and keeps finished batches.
This is a single-site
comparison, not an evaluation of full-model fine-tuning or measured speedup.
## LiSA with the published trainable modules and loss
`lisa_train.py` implements the two-layer 256-unit ReLU head fusion and
learned low-rank grouped Q/K branch. The objective is the published
0.25 Huber (delta 1) attention-score distillation plus 0.75 next-token
full-vocabulary cross-entropy. The loss and gradient stream the frozen
vocabulary head in chunks. This avoids allocating the whole embedding
matrix or retaining dense vocabulary logits across backward.
The Qwen-specific run shares scores from layer 19 at layer 23, using
zero-based numbering. The recipient's V, output gate, projection, MLP
and final norm are preserved and frozen. The low-rank branch uses
40 coordinates per head and Qwen text-mode partial RoPE. Earlier layers
are frozen, and only the final layer is replaced, so training on cached
recipient inputs evaluates the same next-token objective as rerunning
the frozen prefix. The teacher path computes native scores and checks
final hidden states against the original model. The comparison includes
native, direct sharing, and the previous joint linear mapping.
The dataset is the fixed 36-prompt retrieval study with each gold digit
appended as a next-token target. Training uses every valid shifted token
of the fit sequences, and early model selection uses the validation
objective before the test set. The evaluation also measures exact greedy
digit at the answer position. This is a single-recipient port of the method.
The paper's LLaMA configurations, RedPajama training budget, and 13-task
results are separate experimental conditions.
```sh
OPENBLAS_NUM_THREADS=1 OMP_NUM_THREADS=1 venv/bin/python -B -m crossqkv.lisa_reproduction capture \
--source runs/cpu-qwen35-2b --out runs/NEW_LISA_FULL_CACHE
OPENBLAS_NUM_THREADS=1 OMP_NUM_THREADS=1 venv/bin/python -B -m crossqkv.lisa_reproduction train \
--source runs/cpu-qwen35-2b --cache runs/NEW_LISA_FULL_CACHE --out runs/NEW_LISA_FULL_RESULT \
--linear-control results/lisa-forward-search/frozen.json
```
References: [paper §5 and Appendix C](https://arxiv.org/html/2408.01890v2) and
[authors' implementation](https://github.com/takagi97/lisa). The official
code names its distillation weight `mse_loss_weight` but computes Huber,
consistent with the paper.