Add controlled two-layer LiSA reproduction on Qwen
This commit is contained in:
@@ -0,0 +1,151 @@
|
||||
# LiSA effect reproduction on Qwen3.5-2B
|
||||
|
||||
The earlier single-layer training verified the method but used an evaluation
|
||||
where the frozen 2B model answered only one of sixteen items. This protocol
|
||||
measures retention of an existing capability and the cost of exercising it.
|
||||
|
||||
## Comparison with the published experiment
|
||||
|
||||
The 96.44% in Table 2 is the average performance retained by LLaMA2-13B
|
||||
with 22 recipient layers across the reported benchmarks excluding LAMBADA.
|
||||
At the same 22 layers, direct score sharing retained 46.76% and the direct
|
||||
sharing plus LoRA baseline retained 65.95%. The published main uptraining
|
||||
used 4.2 billion sampled RedPajama tokens on eight A800 GPUs. This experiment
|
||||
uses a frozen Qwen3.5-2B backbone, two recipient layers, 12 synthetic fit
|
||||
prompts and a single CPU runner. The comparable effect is an improvement
|
||||
over direct sharing under a fixed layer schedule. The magnitude on a
|
||||
32-item lookup test and the timing of CPU attention should be interpreted
|
||||
within those settings. [Mu et al., Table 2 and Appendix C.1](https://aclanthology.org/2026.tacl-1.30.pdf)
|
||||
|
||||
## Task and layer screening
|
||||
|
||||
All four tasks, answer-position balances, and generators are fixed in
|
||||
`crossqkv/lisa_effect_screen.py`. The screening split is used only for
|
||||
selecting a primary task family and the schedule. Fit, validation, and test
|
||||
prompts have disjoint fixed seeds. The screen must finish before opening
|
||||
test metrics.
|
||||
|
||||
Test original attention, 19→23 direct reuse, and a chained 15→19→23
|
||||
configuration, with each donor providing its actual scores in the current
|
||||
run. Primary eligibility on the development screen requires original accuracy
|
||||
at least 5/8 and at least one original-correct item lost under shared
|
||||
attention. Compare candidate schedules by the count of native-correct items
|
||||
lost, preferring the two-receiver schedule among ties and recording net
|
||||
accuracy and four-option NLL. If none qualify, retain the screen and expand
|
||||
development coverage before choosing a new task; never pick based on test
|
||||
errors. The fixed test also reports all outcomes on the chosen task, including
|
||||
native-incorrect items.
|
||||
|
||||
## Performance comparison
|
||||
|
||||
Compare native, direct, fit-only linear calibration and trainable LiSA on
|
||||
identical prompts. Preserve Qwen recipient gates, V, and output projection.
|
||||
Compare the published 0.25 Huber and 0.75 next-token CE objective with an
|
||||
explicit answer-weighted variant. All adaptation and model selection use
|
||||
only fit/validation. Record the whole-sequence training loss. On held-out prompts, report
|
||||
answer-only loss, correctly recovered and newly lost questions, net
|
||||
accuracy, and performance at one and two recipients. A measured failure to recover is a valid outcome.
|
||||
|
||||
For speed, use a path that actually skips dense Q/K at shared sites, keeping
|
||||
gate rows. Verify against a reference first. With identical prompts,
|
||||
checkpoint and runner, report measured latency for the implemented prefill
|
||||
or decode path and its true scope. Account for both the reduced K storage
|
||||
and additional score tensors. Do not call analytical estimates measured
|
||||
speed or apply paper throughput figures to this CPU implementation.
|
||||
|
||||
The incremental recipient benchmark uses actual K/V buffers and compares the
|
||||
shared implementation with native attention at the same prefix length and FP32
|
||||
storage format. Numerical tests compare incremental scores and outputs with
|
||||
batched causal attention at every query position. Report observed allocation
|
||||
for K/V and the donor score row separately from end-to-end prefill or decode.
|
||||
It does not include upstream score generation or the rest of the decoder.
|
||||
|
||||
```sh
|
||||
python -B -m crossqkv.lisa_decode_bench --source runs/cpu-qwen35-2b \
|
||||
--capture runs/LISA_EFFECT_CAPTURE --checkpoint runs/LISA_EFFECT_RESULTS/lisa.pt \
|
||||
--out runs/LISA_EFFECT_RESULTS/decode.json
|
||||
```
|
||||
|
||||
An interrupted development screen can resume with the same fixed prompt set
|
||||
using `--resume`. Use `--reuse-prefix` to compute the frozen prefix once per
|
||||
prompt. The replay checks original-mode parity before accepting results.
|
||||
|
||||
## Recorded development selection
|
||||
|
||||
The fixed screen completed with 32 prompts. The prespecified eligibility rule
|
||||
selected the 16-entry lookup task with recipients at layers 19 and 23. Native
|
||||
and one-recipient direct sharing each scored 8/8. Two-recipient direct sharing
|
||||
scored 7/8 and lost one native-correct answer. The selected configuration,
|
||||
all screened logits, and the disjoint prompt manifest are archived under
|
||||
`results/lisa-effect-reproduction/`. This was selection evidence only.
|
||||
|
||||
The held-out analysis records rescue of native-correct errors, newly introduced
|
||||
errors, paired uncertainty and answer NLL. A second pass streams the complete
|
||||
vocabulary at the same answer positions and compares one- and two-recipient
|
||||
forward paths. In the one-recipient LiSA ablation the final adapter comes from
|
||||
the joint checkpoint. It is evaluated unchanged, with the earlier recipient
|
||||
restored to native attention.
|
||||
|
||||
Training also saves each finished epoch's adapter, AdamW state, validation
|
||||
history and selected weights atomically per variant. For interrupted training,
|
||||
re-run the same command with `--resume` and the same output directory and epoch
|
||||
budget. Resume verifies the frozen training configuration, preserves finished
|
||||
epochs and re-scores the locked test set from the validation-selected weights.
|
||||
The separate selected checkpoints retain the original weights-only schema.
|
||||
|
||||
The development error was `screen-lookup16-005`. Its correct choice was
|
||||
option 4. Across native, single-recipient direct reuse and chained direct reuse,
|
||||
the four-choice probability of option 4 was 0.706, 0.815 and 0.403,
|
||||
respectively. Its correct-versus-best-distractor logit margins were
|
||||
+1.265, +1.861 and −0.258. The chained result chose option 2. These are
|
||||
development observations that describe the selected condition, not test
|
||||
results or a basis for changing the frozen prompts.
|
||||
|
||||
## Reproduction commands
|
||||
|
||||
Run from the project code root on the confirmed remote CPU environment.
|
||||
Choose new output directories. Keep the same source checkpoint across all
|
||||
commands. The fixed manifest contains all four split definitions, and capture
|
||||
writes an independent selection record and source fingerprints.
|
||||
|
||||
```sh
|
||||
export OPENBLAS_NUM_THREADS=1 OMP_NUM_THREADS=1
|
||||
PYTHON=venv/bin/python
|
||||
SOURCE=runs/cpu-qwen35-2b
|
||||
SCREEN=runs/NEW_EFFECT_SCREEN
|
||||
CAPTURE=runs/NEW_EFFECT_CAPTURE
|
||||
RESULT=runs/NEW_EFFECT_RESULT
|
||||
|
||||
"$PYTHON" -B -m crossqkv.lisa_effect_screen --source "$SOURCE" --out "$SCREEN" --reuse-prefix
|
||||
"$PYTHON" -B -m crossqkv.lisa_effect capture --source "$SOURCE" --input "$SCREEN" --out "$CAPTURE"
|
||||
"$PYTHON" -B -m crossqkv.lisa_effect train --source "$SOURCE" --input "$CAPTURE" --out "$RESULT" --epochs 2
|
||||
"$PYTHON" -B -m crossqkv.lisa_decode_bench --source "$SOURCE" --capture "$CAPTURE" \
|
||||
--checkpoint "$RESULT/lisa.pt" --out "$RESULT/decode.json"
|
||||
"$PYTHON" -B -m crossqkv.lisa_effect_answer_audit --source "$SOURCE" --cache "$CAPTURE" \
|
||||
--trained "$RESULT" --out "$RESULT/full-vocab-answers.json"
|
||||
"$PYTHON" -B -m crossqkv.lisa_effect_audit --fixed "$SCREEN/fixed-problems.json" \
|
||||
--selection "$CAPTURE/selection.json" --items "$RESULT/test-items.json" \
|
||||
--perf "$RESULT/performance.json" --decode "$RESULT/decode.json" --out "$RESULT/paired-audit.json"
|
||||
```
|
||||
|
||||
The paired audit defines a rescue as a native-correct item made wrong by
|
||||
direct sharing and made correct again by the tested adapter. It reports
|
||||
newly lost native-and-direct-correct items separately. An improvement in
|
||||
mean four-option answer NLL, including among items already answered
|
||||
correctly, does not by itself establish a rescue.
|
||||
|
||||
Training scores *all* valid shifted tokens with exact full-vocabulary CE
|
||||
and uses the validation four-option answer loss to freeze checkpoints. The
|
||||
answer audit scores only the answer position over the whole vocabulary.
|
||||
It does not report whole-prompt CE for the held-out items or free-form
|
||||
multi-token answer accuracy. That distinction is important for interpreting
|
||||
the previous experiment, in which those two losses moved in opposite
|
||||
directions.
|
||||
|
||||
For the isolated incremental attention timing, report both streamed
|
||||
checkpoint projections and an otherwise identical timing with only that
|
||||
site's frozen projections resident in memory. Verify output and raw score
|
||||
parity before interpreting the pair of timings. The resident measurements
|
||||
exclude weight-load time, and both timings exclude upstream computation and
|
||||
other decoder blocks. K/V and upstream score-row allocation are itemized
|
||||
separately; neither timing is an end-to-end server throughput claim.
|
||||
Reference in New Issue
Block a user