Commit d250b46
gemma4: full feature mirror resync after prefix cache restore
After restoring KV from a snapshot, do_prefill only syncs the feature mirror
for the delta tokens [snap_pos..committed). The positions [0..snap_pos) in
the mirror retain stale data from the previous request's decode phase (which
may have diverged from the current prompt context after the ring buffer
wraps).
Fix: call draft_feature_mirror_sync_tail after restore to resync the entire
[0..committed) feature range from cache_.target_feat to the mirror. This
ensures the draft model sees consistent features and maintains high
acceptance rate (AL) during speculative decoding.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
gemma4: save/restore target_feat in prefix cache snapshot
Matching Qwen35's approach: save target_feat (BF16 feature ring buffer) and
last_tok as part of the KV snapshot. On restore, target_feat is copied back
to GPU before the delta prefill + feature mirror resync.
Previously, only K/V tensors were snapshotted. After restore, the feature
mirror contained stale data from the previous request's decode phase, causing
the draft model to make poor predictions and halving speculative decode
acceptance rate (52% → 24%).
With this fix, the full feature state is correctly restored, and the
subsequent draft_feature_mirror_sync_tail ensures the mirror matches.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 1090d51 commit d250b46
3 files changed
Lines changed: 63 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
511 | 511 | | |
512 | 512 | | |
513 | 513 | | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
514 | 524 | | |
515 | 525 | | |
516 | 526 | | |
| |||
623 | 633 | | |
624 | 634 | | |
625 | 635 | | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
626 | 642 | | |
627 | 643 | | |
| 644 | + | |
628 | 645 | | |
629 | 646 | | |
630 | 647 | | |
| |||
651 | 668 | | |
652 | 669 | | |
653 | 670 | | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
654 | 689 | | |
655 | 690 | | |
656 | 691 | | |
| |||
738 | 773 | | |
739 | 774 | | |
740 | 775 | | |
| 776 | + | |
741 | 777 | | |
742 | | - | |
| 778 | + | |
743 | 779 | | |
744 | 780 | | |
745 | 781 | | |
| |||
759 | 795 | | |
760 | 796 | | |
761 | 797 | | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
762 | 808 | | |
763 | 809 | | |
764 | 810 | | |
765 | 811 | | |
| 812 | + | |
766 | 813 | | |
767 | 814 | | |
768 | 815 | | |
| |||
792 | 839 | | |
793 | 840 | | |
794 | 841 | | |
| 842 | + | |
795 | 843 | | |
796 | | - | |
797 | | - | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
798 | 851 | | |
799 | 852 | | |
800 | 853 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
193 | 193 | | |
194 | 194 | | |
195 | 195 | | |
| 196 | + | |
196 | 197 | | |
197 | 198 | | |
| 199 | + | |
| 200 | + | |
198 | 201 | | |
199 | 202 | | |
200 | 203 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
478 | 478 | | |
479 | 479 | | |
480 | 480 | | |
481 | | - | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
482 | 485 | | |
483 | 486 | | |
484 | 487 | | |
0 commit comments