Skip to content

[Python] Fix HuggingFacePipelineModelHandler behind keyed model handlers - #41915

Open
tvalentyn wants to merge 2 commits into
apache:masterfrom
tvalentyn:fix-hf-pipeline-handler-tuple-batch
Open

tvalentyn wants to merge 2 commits into
apache:masterfrom
tvalentyn:fix-hf-pipeline-handler-tuple-batch

Conversation

@tvalentyn

Copy link
Copy Markdown
Contributor

KeyedModelHandler (with a single model) and MaybeKeyedModelHandler pass the unkeyed batch to the wrapped handler as a tuple. Hugging Face pipelines only treat a list as a batch of examples and process any other input as a single example. A keyed batch with more than one element therefore failed, or silently returned predictions of the first example for the other examples, depending on the task. Beam YAML RunInference was affected as well, because it always wraps the model handler in a KeyedModelHandler.

Convert a tuple batch to a list in
HuggingFacePipelineModelHandler.run_inference, so that the default and custom inference functions receive the same input with and without keys.

fixes: #41913

KeyedModelHandler (with a single model) and MaybeKeyedModelHandler pass the
unkeyed batch to the wrapped handler as a tuple. Hugging Face pipelines only
treat a list as a batch of examples and process any other input as a single
example. A keyed batch with more than one element therefore failed, or
silently returned predictions of the first example for the other examples,
depending on the task. Beam YAML RunInference was affected as well, because
it always wraps the model handler in a KeyedModelHandler.

Convert a tuple batch to a list in
HuggingFacePipelineModelHandler.run_inference, so that the default and custom
inference functions receive the same input with and without keys.
Notes the fix for apache#41913 and that keyed results now match the results without keys, which changes the shape of some keyed results.
@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @chamikaramj added as fallback since no labels match configuration
Backup reviewer: damccorm (if the main reviewer is unresponsive, you can escalate to them by tagging their username)

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: HuggingFacePipelineModelHandler fails or returns wrong predictions behind KeyedModelHandler

1 participant