huggingface/transformers · error · AssertionError
The model must have caching enabled to be exported with stat
Error message
The model must have caching enabled to be exported with static caching. Please set `generation_config.use_cache=True`.
What it means
Error "The model must have caching enabled to be exported with static caching. Please set `generation_config.use_cache=True`." thrown in huggingface/transformers.
Source
Thrown at src/transformers/integrations/executorch.py:515
Raises:
AssertionError: If the pretrained model does not have caching enabled or if it does
not use a 'static' caching implementation in `model.generation_config`.
ValueError: If `batch_size` or `max_cache_len` is not provided, either as an argument or in `cache_config`.
"""
super().__init__()
config = model.config.get_text_config()
generation_config = model.generation_config
# Sanity checks
if generation_config is None:
raise AssertionError(
"The model must have a generation config to be exported with static caching. "
"Please set `generation_config` in `model`."
)
if not generation_config.use_cache:
raise AssertionError(
"The model must have caching enabled to be exported with static caching. "
"Please set `generation_config.use_cache=True`."
)
if generation_config.cache_implementation != "static":
raise AssertionError(
"The model must use a 'static' caching implementation to be exported with static caching. "
"Please set `generation_config.cache_implementation='static'`."
)
cache_config = {} if generation_config.cache_config is None else generation_config.cache_config
# Ensure batch_size and max_cache_len are set
if batch_size is None:
batch_size = cache_config.get("batch_size", None)
if batch_size is None:
raise ValueError("batch_size must be provided, either as an argument or in cache_config.")
if max_cache_len is None:
max_cache_len = cache_config.get("max_cache_len", None)View on GitHub (pinned to a597f97485)
Solutions
- Set `generation_config.use_cache=True` before export.
When it happens
Trigger: Raised in ExecuTorch static-cache export when generation_config.use_cache is not True.
Common situations: Export with generation_config.use_cache=False; static cache export requires caching enabled.
AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14).
Data as JSON: /api/errors/85ef6ada1193722e.
Report an issue: GitHub.