Skip to content

[BUG] Looper: cross-layer KV reuse (Hymba) keeps only batch 0's KV; checkpoint/drain and batch-alignment edge cases #4182

Closed

Description

@Qubitium

Severity: medium (Hymba), low (others)
Version: 7.11.0 @ 6c3421c

1. reuse_kv / write_shared_kv_cache keeps the first batch's KV for all batches

  • In looper/forward_executor.py:447 (run_single) and :749 (run_parallel), shared_kv_cache_dict[layer_index] is written only when it is None.
  • Every batch of the consuming layer (:324 / :624) then gets batch 0's K/V as kv_last_layer, and Hymba's attention uses that tensor directly.
  • Effect: wrong attention for batches 1..N-1 (silent Hessian corruption), or a shape-mismatch crash when batch shapes differ.
  • The KV is also captured by the pre-quant (FP) forward and never refreshed during the post-quant replay. So layer L+1 pairs quantized hidden states with FP K/V.

Driving ForwardExecutor.run_single with batch inputs 0, 1, 2, 3 gives kv_last_layer values: [0.0, 0.0, 0.0, 0.0].

Fix: key the cache by (layer_index, batch_idx) and overwrite it during replay.

2. Smaller issues

  • stage_layer.py:1542: the return value of _drain_finalize_futures is ignored. Its docstring says False means the layer must not be a durable resume point, but a custom quantization_layer_boundary_checkpoint.commit_layer() still runs.
  • forward_executor.py:~791 (and run_single): with subset_early_stop plus need_outputs=True, a None output is dropped instead of keeping its slot. Later batches then pair with the wrong layer_input_kwargs / masks / position_ids.
  • stage_subset.py:1423: the uncovered-MoE prune path (fallback=None) inserts into processor.qcfg.dynamic without _dynamic_lock_for(...). Under GIL=0 that races with the previous layer's async finalizers iterating the dict (suspected, not reproduced).
  • run_parallel (forward_executor.py:~736) and weight_only_looper.py:638,685 propagate the first worker failure without draining the remaining futures. stage_subset._collect_worker_results does this correctly.
  • utils/p2p.py:~2044: type(item)(generator) breaks namedtuples, and the walk skips tensors inside Cache objects and dataclasses.
  • utils/logger.py:256: layers = len(result) counts processors, so a 28-layer run logs "Quantize summary: 1 layer(s), 196 module(s)".

Verified fine: 1 GPU vs 2 GPU and GIL=0 vs GIL=1 runs are bit-identical (same arch). Checkpoint stop/resume is bit-identical, and fault injection raises promptly without hangs.


Found during an AI-assisted review (Claude Code) of 6c3421c; repros were run on RTX 4090/5090 (CUDA 13) and Radeon AI PRO R9700 (ROCm) unless marked static/suspected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions