{"record":{"id":"8a6154b2f0af0825","repo":"huggingface/transformers","slug":"batch-size-must-be-provided-either-as-an-argument","errorCode":null,"errorMessage":"batch_size must be provided, either as an argument or in cache_config.","messagePattern":"batch_size 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":531,"sourceCode":"            )\n        if not generation_config.use_cache:\n            raise AssertionError(\n                \"The model must have caching enabled to be exported with static caching. \"\n                \"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","sourceCodeStart":513,"sourceCodeEnd":549,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/integrations/executorch.py#L513-L549","documentation":"Error \"batch_size must be provided, either as an argument or in cache_config.\" thrown in huggingface/transformers.","triggerScenarios":"Raised in ExecuTorch export when batch_size is missing from both the arguments and cache_config.","commonSituations":"Static export requires a fixed batch size; none was supplied in either location.","solutions":["Pass `batch_size` 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-15T17:31:12.345Z"}