{"record":{"id":"7235abe690180d0b","repo":"huggingface/transformers","slug":"max-cache-len-must-be-provided-either-as-an-argum","errorCode":null,"errorMessage":"max_cache_len must be provided, either as an argument or in cache_config.","messagePattern":"max_cache_len must be provided, either as an argument or in cache_config\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/integrations/executorch.py","lineNumber":535,"sourceCode":"                \"Please set `generation_config.use_cache=True`.\"\n            )\n        if generation_config.cache_implementation != \"static\":\n            raise AssertionError(\n                \"The model must use a 'static' caching implementation to be exported with static caching. \"\n                \"Please set `generation_config.cache_implementation='static'`.\"\n            )\n\n        cache_config = {} if generation_config.cache_config is None else generation_config.cache_config\n\n        # Ensure batch_size and max_cache_len are set\n        if batch_size is None:\n            batch_size = cache_config.get(\"batch_size\", None)\n            if batch_size is None:\n                raise ValueError(\"batch_size must be provided, either as an argument or in cache_config.\")\n        if max_cache_len is None:\n            max_cache_len = cache_config.get(\"max_cache_len\", None)\n            if max_cache_len is None:\n                raise ValueError(\"max_cache_len must be provided, either as an argument or in cache_config.\")\n        # Infer device if not provided\n        if device is None:\n            device = cache_config.get(\"device\", model.device)\n\n        # Initialize the static cache\n        self.model = model\n        self.static_cache = StaticCache(max_cache_len=max_cache_len, config=config)\n        # Since StaticSlidingWindow have dynamic control flow that cannot be avoided, we have to replace them here by\n        # simple StaticLayer... It means that any generation beyond the window is unfortunately unsupported\n        for i, layer in enumerate(self.static_cache.layers):\n            if isinstance(layer, StaticSlidingWindowLayer):\n                self.static_cache.layers[i] = StaticLayer(max_cache_len)\n        num_heads, head_dim = get_head_shapes(config)\n        dtype = self.model.dtype\n        # We need this call to initialize all the layers (otherwise it's done lazily, which is not exportable)\n        self.static_cache.early_initialization(batch_size, num_heads, head_dim, dtype, device)\n\n        # Register cache buffers to make them exportable","sourceCodeStart":517,"sourceCodeEnd":553,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/integrations/executorch.py#L517-L553","documentation":"Error \"max_cache_len must be provided, either as an argument or in cache_config.\" thrown in huggingface/transformers.","triggerScenarios":"Raised in ExecuTorch export when max_cache_len is missing from both the arguments and cache_config.","commonSituations":"Static export requires a fixed cache length; none was supplied in either location.","solutions":["Pass `max_cache_len` explicitly or include it in `cache_config`."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}