From ab9689c034ace6fef573ce017bbb30908826b114 Mon Sep 17 00:00:00 2001 From: Prathamesh Jadhav <55660103+lollinng@users.noreply.github.com> Date: Thu, 11 Jun 2026 18:00:54 +0530 Subject: [PATCH] Handle canonical inputs_embeds kwarg in unsloth_base_fast_generate (#3082) (#6015) The kwarg-dispatch in unsloth_base_fast_generate recognized input_ids, input, input_features and the misspelled input_embeds, but not HF's canonical inputs_embeds. So generate(inputs_embeds=...) fell through to the 'first kwarg' fallback, which picks whatever kwarg happens to come first (e.g. attention_mask) and uses it as input_ids -- giving the wrong tensor / batch size, or the KeyError reported in #3082 on older versions. Add an explicit inputs_embeds branch so embedding inputs (e.g. multimodal audio+text) are routed correctly regardless of kwarg order. Co-authored-by: Claude Opus 4.8 (1M context) Co-authored-by: Etherll <61019402+Etherll@users.noreply.github.com> --- unsloth/models/vision.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/unsloth/models/vision.py b/unsloth/models/vision.py index 58814699b3..a52ab359bd 100644 --- a/unsloth/models/vision.py +++ b/unsloth/models/vision.py @@ -283,6 +283,9 @@ def unsloth_base_fast_generate(self, *args, **kwargs): input_ids = kwargs["input"] elif "input_features" in kwargs: input_ids = kwargs["input_features"] + elif "inputs_embeds" in kwargs: + # canonical HF name for embedding inputs (e.g. multimodal generate) + input_ids = kwargs["inputs_embeds"] elif "input_embeds" in kwargs: input_ids = kwargs["input_embeds"] elif "inputs" in kwargs: