{"record":{"id":"286a6afc99cdd290","repo":"huggingface/transformers","slug":"assistant-tokenizer-is-not-required-when-the-mai","errorCode":null,"errorMessage":"`assistant_tokenizer` is not required when the main and assistant models use the same tokenizer. Please omit `assistant_tokenizer` from `generate()` {doc_reference}.","messagePattern":"`assistant_tokenizer` is not required when the main and assistant models use the same tokenizer\\. Please omit `assistant_tokenizer` from `generate\\(\\)` (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/generation/utils.py","lineNumber":1605,"sourceCode":"        ) is not None and generation_config.speculation_type != \"dflash\":\n            if self.config.is_encoder_decoder and not assistant_model.config.is_encoder_decoder:\n                attributes_to_check = [\"encoder_attention_heads\", \"encoder_ffn_dim\", \"encoder_layers\"]\n                attributes_to_check = [attr for attr in dir(assistant_model.config) if attr in attributes_to_check]\n                are_equal = all(\n                    getattr(self.config, attr) == getattr(assistant_model.config, attr) for attr in attributes_to_check\n                )\n                if not are_equal:\n                    raise ValueError(\n                        \"The main model and the assistant don't have compatible encoder-dependent input shapes. \"\n                        \"Ensure you load the assistant with the correct encoder-decoder class, e.g. `AutoModelForSpeechSeq2Seq` for Whisper.\"\n                    )\n\n            doc_reference = (\n                \"(see https://huggingface.co/docs/transformers/en/generation_strategies#universal-assisted-decoding)\"\n            )\n            if self.config.get_text_config().vocab_size == assistant_model.config.get_text_config().vocab_size:\n                if \"assistant_tokenizer\" in generation_mode_kwargs:\n                    raise ValueError(\n                        f\"`assistant_tokenizer` is not required when the main and assistant models use the same tokenizer. Please omit `assistant_tokenizer` from `generate()` {doc_reference}.\"\n                    )\n            else:\n                if \"tokenizer\" not in generation_mode_kwargs or \"assistant_tokenizer\" not in generation_mode_kwargs:\n                    raise ValueError(\n                        f\"The main and assistant models have different tokenizers. Please provide `tokenizer` and `assistant_tokenizer` to `generate()` {doc_reference}.\"\n                    )\n\n    def _validate_model_kwargs(self: \"GenerativePreTrainedModel\", model_kwargs: dict[str, Any]):\n        \"\"\"Validates model kwargs for generation. Generate argument typos will also be caught here.\"\"\"\n        # Excludes arguments that are handled before calling any model function\n        if self.config.is_encoder_decoder:\n            for key in [\"decoder_input_ids\"]:\n                model_kwargs.pop(key, None)\n\n        unused_model_args = []\n        model_args = set(inspect.signature(self.prepare_inputs_for_generation).parameters)\n        # `kwargs`/`model_kwargs` is often used to handle optional forward pass inputs like `attention_mask`. If","sourceCodeStart":1587,"sourceCodeEnd":1623,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/generation/utils.py#L1587-L1623","documentation":"In universal assisted decoding, transformers decides whether main and assistant share a tokenizer by comparing `vocab_size` of the two text configs. When the vocab sizes are EQUAL, passing `assistant_tokenizer` is contradictory and rejected — the assistant's own tokenizer is already correct and a second one invites mismatches.","triggerScenarios":"`model.generate(..., assistant_model=assistant, assistant_tokenizer=other_tok)` where `model.config.get_text_config().vocab_size == assistant.config.get_text_config().vocab_size` (same tokenizer family).","commonSituations":"Copy-pasting the universal-assisted-decoding example (written for different-tokenizer pairs) onto a same-tokenizer pair like a model plus its own distilled version; defensively passing both tokenizers 'just in case'.","solutions":["Omit `assistant_tokenizer` from the generate call — pass only `tokenizer`.","Confirm the pair truly shares a tokenizer: compare `model.config.get_text_config().vocab_size` and `assistant.config.get_text_config().vocab_size`.","If you did NOT intend a same-tokenizer pair, check that you loaded the intended assistant checkpoint."],"exampleFix":"# before\nout = model.generate(\n    **inputs, assistant_model=assistant,\n    tokenizer=tokenizer, assistant_tokenizer=assistant_tok,  # vocab sizes equal -> ValueError\n)\n\n# after\nout = model.generate(**inputs, assistant_model=assistant, tokenizer=tokenizer)","handlingStrategy":"validation","validationCode":"same_vocab = model.config.get_text_config().vocab_size == assistant.config.get_text_config().vocab_size\nif same_vocab:\n    kwargs.pop(\"assistant_tokenizer\", None)  # not required and will raise","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass assistant_tokenizer ONLY when the two vocab sizes actually differ.","Compare vocab_size before building generate kwargs in cross-model pipelines.","Follow the universal assisted decoding doc for the exact token combination rule."],"tags":["generation","assisted-decoding","tokenizer","universal-assisted-decoding"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}