A bug in Hugging Face's `generate()` function causes incorrect outputs when `past_key_values` is an externally-built `DynamicCache`. This issue affects KV cache compression methods like SnapKV, H2O, and KIVI that reconstruct caches from prefill data. The root cause is the failure to propagate positional context, leading to a 10.7pp accuracy loss on Qwen3-VL-8B.
- Add `DynamicCache.from_kv_tensors()` classmethod to safely reconstruct caches with proper internal state.
- Require explicit `attention_mask` and `position_ids` during generation to restore baseline quality.
- The new method pre-allocates internal lists via an optional `num_hidden_layers` parameter for backward compatibility.
This fix ensures that KV compression workflows produce reliable outputs by correctly handling sequence length and attention masks.