Skip to content

[Python] Fix HuggingFacePipelineModelHandler single-dict batch handling and MLM IT - #41640

Closed
damccorm wants to merge 1 commit into
apache:masterfrom
damccorm:fix/huggingface-pipeline-single-dict-and-mlm-it
Closed

damccorm wants to merge 1 commit into
apache:masterfrom
damccorm:fix/huggingface-pipeline-single-dict-and-mlm-it

Conversation

@damccorm

Copy link
Copy Markdown
Contributor

Fixes two issues blocking direct:py313:transformersInferenceTest:

  1. HuggingFacePipelineModelHandler single-element batch regression (huggingface_inference.py, huggingface_inference_test.py):

    • Since use utils._convert_to_result for huggingface_inference #36593 switched HuggingFacePipelineModelHandler.run_inference to utils._convert_to_result, Hugging Face pipelines that return a single dict (instead of a list[dict]) for batch size 1 — such as QuestionAnsweringPipeline — crashed with TypeError: 'float' object is not iterable because utils._convert_to_result treats a bare dict as a columnar dict of batch-length iterables.
    • Wraps isinstance(predictions, dict) and len(batch) == 1 into [predictions] inside _default_pipeline_inference_fn so built-in HF pipelines work for batch size 1 while custom inference_fn implementations that intentionally return columnar dicts (such as Beam YAML's runinference_huggingface.yaml) remain untouched.
    • Adds unit tests covering single-dict predictions, batched list predictions, and custom columnar-dict inference_fns.
  2. Unavailable third-party Hub model & transformers>=5 tokenizer call (huggingface_inference_it_test.py, huggingface_language_modeling.py, examples/inference/README.md):

    • Replaces the deleted/private personal Hub repo stevhliu/my_awesome_eli5_mlm_model with FacebookAI/roberta-base, inlining _EXPECTED_MASKED_LM_OUTPUTS in huggingface_inference_it_test.py so the shared GCS golden file is left unchanged for older release branches.
    • Replaces removed tokenizer.encode_plus(...) with tokenizer(...) in huggingface_language_modeling.py for transformers>=5 compatibility.

Verification

Part of the stack leading up to re-enabling Python 3.13 inferencePostCommitIT in #41595 (independent of the other prerequisite PRs; can be merged in any order).

…ng and MLM IT

- huggingface_inference.py & huggingface_inference_test.py: wrap single-dict
  predictions returned by Hugging Face pipelines (e.g. QuestionAnsweringPipeline
  on batch size 1) in a list inside _default_pipeline_inference_fn before
  utils._convert_to_result, fixing the regression from apache#36593 while preserving
  custom inference_fn implementations that return columnar dicts (e.g. Beam YAML).
- huggingface_inference_it_test.py, huggingface_language_modeling.py, README.md:
  replace the deleted/private stevhliu/my_awesome_eli5_mlm_model Hub checkpoint
  with FacebookAI/roberta-base (inlining expected outputs so the shared GCS
  golden file is unchanged) and replace removed tokenizer.encode_plus with
  tokenizer(...) for transformers 5.x compatibility.
@damccorm

Copy link
Copy Markdown
Contributor Author

Replaced by native stacked PR #41645.

@damccorm damccorm closed this Nov 24, 2026
@damccorm
damccorm deleted the fix/huggingface-pipeline-single-dict-and-mlm-it branch November 24, 2026 18:17
@github-actions github-actions Bot added python examples size/s S: 10-49 lines changed labels Nov 24, 2026
@codecov

codecov Bot commented Nov 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 58.04%. Comparing base (3e230c6) to head (f7c4314).

Additional details and impacted files
@@            Coverage Diff            @@
##             master   #41640   +/-   ##
=========================================
  Coverage     58.03%   58.04%           
  Complexity     2844     2844           
=========================================
  Files          1210     1210           
  Lines        173259   173282   +23     
  Branches       2329     2329           
=========================================
+ Hits         100554   100581   +27     
+ Misses        69995    69991    -4     
  Partials       2710     2710           
Flag Coverage Δ
python 80.67% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

examples python size/s S: 10-49 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant