{"record":{"id":"98bda666129646d4","repo":"huggingface/transformers","slug":"assisted-decoding-requires-a-cache","errorCode":null,"errorMessage":"assisted decoding requires a cache","messagePattern":"assisted decoding requires a cache","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/transformers/generation/utils.py","lineNumber":3631,"sourceCode":"            [`~generation.GenerateDecoderOnlyOutput`], [`~generation.GenerateEncoderDecoderOutput`] or\n            `torch.LongTensor`: A `torch.LongTensor` containing the generated tokens (default behaviour) or a\n            [`~generation.GenerateDecoderOnlyOutput`] if `model.config.is_encoder_decoder=False` and\n            `return_dict_in_generate=True` or a [`~generation.GenerateEncoderDecoderOutput`] if\n            `model.config.is_encoder_decoder=True`.\n        \"\"\"\n        # The cache must be dynamic for assisted generation, and the check must happen AFTER preparing cache\n        if not model_kwargs[\"use_cache\"]:\n            raise ValueError(\"assisted generate requires `use_cache=True`\")\n        if (\n            generation_config.cache_implementation in [\"static\", \"hybrid\", \"sliding_window\"]\n            or type(model_kwargs.get(\"past_key_values\")) is StaticCache\n        ):\n            raise ValueError(\"assisted generate is not supported with Static cache classes`\")\n\n        # Make sure we can record past on the cache\n        cache = model_kwargs.get(\"past_key_values\")\n        if cache is None:\n            raise RuntimeError(\"assisted decoding requires a cache\")\n        cache.activate_past_recording()\n\n        # Get the candidate generator, given the parameterization\n        candidate_generator = self._get_candidate_generator(\n            generation_config=generation_config,\n            input_ids=input_ids,\n            inputs_tensor=inputs_tensor,\n            assistant_model=assistant_model,\n            logits_processor=logits_processor,\n            target_tokenizer=tokenizer,\n            assistant_tokenizer=assistant_tokenizer,\n            model_kwargs=model_kwargs,\n        )\n        # init values\n        do_sample = generation_config.do_sample\n        output_attentions = generation_config.output_attentions\n        output_hidden_states = generation_config.output_hidden_states\n        output_scores = generation_config.output_scores","sourceCodeStart":3613,"sourceCodeEnd":3649,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/generation/utils.py#L3613-L3649","documentation":"Error \"assisted decoding requires a cache\" thrown in huggingface/transformers.","triggerScenarios":"Raised in assisted generation when no cache object is available for the candidate generator.","commonSituations":"Assisted decoding on a model whose forward pass did not return past_key_values / a usable cache.","solutions":["Enable caching (`use_cache=True`) so assisted decoding has a cache to work with."],"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"}