damccorm opened a new pull request, #41645:
URL: https://github.com/apache/beam/pull/41645
**Stack 2/6** — Fixes two issues blocking
`direct:py313:transformersInferenceTest`:
1. **`HuggingFacePipelineModelHandler` single-element batch regression
(`huggingface_inference.py`, `huggingface_inference_test.py`):**
- Since #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_fn`s.
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
- Verified end-to-end as part of `direct:py313:transformersInferenceTest`
(3/3 passed) locally and in [PostCommit Python (3.13) run
45406881889](https://github.com/apache/beam/actions/runs/45406881889/job/138489879460).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]