add KV cache dtype as explicit argument [PRI-347]#1120
Conversation
There was a problem hiding this comment.
Code Review
This pull request replaces the boolean flags quantize_kv_cache and maybe_quantize_kv_cache with a new kv_cache_dtype parameter (accepting 'auto' or 'int8') across the TabPFN classifier, regressor, inference engines, and architecture configurations. The code reviewer recommends using getattr(self, "kv_cache_dtype", "int8") when accessing this attribute on estimators to ensure backward compatibility with older unpickled models. Additionally, the reviewer suggests adding validation to ensure kv_cache_dtype is restricted to valid values.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request replaces the boolean quantize_kv_cache parameter with a more explicit kv_cache_dtype argument (accepting 'auto' or 'int8') across the TabPFN classifier, regressor, inference engines, and cache size calculations. It also introduces a warning when a forced inference precision is overridden by the int8 KV cache. The review feedback highlights a lack of runtime validation for this new parameter in public APIs, specifically in warn_if_kv_cache_dtype_overrides_inference_precision and get_cache_size, which could lead to silent fallbacks on invalid inputs.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
bejaeger
left a comment
There was a problem hiding this comment.
Looks great thanks a lot!
I forgot to mention that not all our models currently supported kv cache quantization. So not only is the new kv_cache_dtype argument only relevant when fit_mode is fit_with_cache but also only if the model is v3 (which is the only one that currently supports int8). This is not ideal and might be confusing if we have "int8" as the default. Should we have another "magic" option like "auto" that is "smallest" or "optimized" which will always pick the smallest supported kv cache dtype?
oscarkey
left a comment
There was a problem hiding this comment.
Just a few thoughts! I'm on holiday tomorrow and monday, so happy with whatever's decided if you want to merge :)
bejaeger
left a comment
There was a problem hiding this comment.
Very nice! thanks for all the changes, looks very clean now.
Approving to avoid blocking you but please consider my other comments before merging.
| self.maybe_quantize_kv_cache = maybe_quantize_kv_cache | ||
| self.kv_cache_precision = resolve_kv_cache_precision( | ||
| kv_cache_precision, architecture=models[0] | ||
| ) |
There was a problem hiding this comment.
Can we make this a list instead for each model in models and below in build_cache use the model_index? Could otherwise bite us in the future. I'd say we then want to adjust the warning in the resolve function to only be thrown once?
There was a problem hiding this comment.
I moved the resolution now within each cache build, so it is per estimator.
Issue
Fixes #1119 and #631.
Also this is an alternative to #1099
Motivation and Context
kv_cache_dtypeis a tradeoff decision and should be possible to control explicitlyPublic API Changes
How Has This Been Tested?
I fixed the unit tests to not rely on Monkeypatching anymore.
I also ran the script shared in #631
Using
kv_cache_dtype="auto"fixes the issue. Ifint8is used we now throw a warning, when someone forces the inference dtype to sth else.Checklist
changelog/README.md), or "no changelog needed" label requested.