Fix quantized cache (#48700)
* Do not mutate the user-provided `cache_config` in `generate`
* Fix `QuantizedLayer.reorder_cache` and stop forcing a sliding window on the shared test model
* Defer the beam reordering of the quantized states to the next update
`QuantizedLayer.reorder_cache` used to dequantize the quantized states,
reorder them and quantize them back, which costs a full extra
dequantize + quantize per layer per beam step, and recomputes the
quantization scales.
`update` already dequantizes those states on every step, so the
reordering is now simply recorded (and composed, when several of them
happen while the residual cache fills up) and applied there, on the
full-precision tensors. The pending reordering is cleared when the
residual cache is flushed, as it is then baked into the quantized
states.
* Cover the quantized beam reordering, and reset the quantized states
Add unit tests for `QuantizedLayer.reorder_cache`, which no test covered:
the beam reordering is deferred to the next `update`, including across
residual cache flushes and with duplicated beam indices.
Also drop the quantized states in `reset`, which only zeroed the residual
cache, clone the caller's `beam_idx`, and fix the `hqq` backend name in
`test_quantized_cache_generation` (`HQQ` is not a valid backend, so the
test raised instead of running).
* Address the review: deepcopy the cache config, and tighten the reordering
* Shorten the deferred reordering comment
* Drop the dynamic states on reset, instead of zeroing them in place
* Revert the base-class reset fix, split out into a dedicated PR
* Move the quantized layer tests above the offloading one
* Drop the redundant is_initialized reset, handled by DynamicLayer.reset
* Inline the quantized layer test setup, and assert the length after reset
* nit
---------
Co-authored-by: vasqu <antonprogamer@gmail.com>