Repository navigation
Attach RunInference model_identifier only to the inference ParDo with exception handling - #40922
Brijesh-Thakkar wants to merge 1 commit into
Conversation
… exception handling (apache#40715)
There was a problem hiding this comment.
📋 Review Summary
This PR resolves #40715 by attaching the model_identifier annotation directly to the run_inference_pardo instance and forwarding ParDo.annotations() to the inner ParDo inside _ExceptionHandlingWrapper._build_pardo. The changes are clean, well-scoped, and properly covered by unit tests.
🔍 General Feedback
- Forwarding
ParDo.annotations()to the innerParDoinParDo.with_exception_handling/_ExceptionHandlingWrapper._build_pardohas clean semantics consistent with howresource_hintsandtype_hintsare already forwarded, while avoiding leakingParDo-specific annotations onto the auxiliary threshold-checking transforms or outer composite wrappers. - Replacing the
pipeline.transform_annotations(...)context manager inRunInference.expand()with an instance-levelannotationsoverride follows the established pattern used elsewhere in the SDK (e.g.,annotate_yaml).
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
|
Assigning reviewers: R: @claudevdm for label python. This pull request likely touches a core component ("core" label). Please review with scrutiny. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
Fixes #40715.
RunInference.expand()scoped themodel_identifierannotation withpipeline.transform_annotations(...)(added in #40671). That context applies to everything applied inside it, so withwith_exception_handling(threshold<1)the annotation landed on all 25 annotated transforms:CountTotal,CountBad, theCombineGloballysub-steps,Map(check_threshold)and the wrapper composites, none of which run_RunInferenceDoFn. Even withthreshold=1the outer composites were annotated.Now exactly one transform, the inner inference ParDo (
RunInference/BeamML_RunInference/ParDo(_RunInferenceDoFn)/ParDo(_RunInferenceDoFn)), carriesmodel_identifier.Changes
ml/inference/base.py: drop thetransform_annotationscontext manager and setmodel_identifieronrun_inference_pardo.annotationsinstead (same instance-override pattern asannotate_yaml). Most of the line count is the dedent from removing thewithblock;git diff -wis ~16 lines.transforms/core.py:ParDo.with_exception_handlingnow forwardsself.annotations()to a new_ExceptionHandlingWrapper(pardo_annotations=...)argument, and_build_pardoapplies them to the inner ParDo only (not to the threshold-checking transforms).Please weigh in
The
core.pychange is not RunInference-specific: any annotations set on aParDoare now carried onto the inner ParDo built bywith_exception_handling. Previously they were silently dropped, since the wrapper built a fresh ParDo. I think that is the right semantics and avoids a RunInference-only hook, but it touches a core path (transforms/), so I'd appreciate reviewers' opinions. The alternative is an explicit RunInference-only hook on the wrapper.Testing
base_test.py::test_run_inference_with_exception_handling_only_annotates_inference_step(new):RunInference(...).with_exception_handling(threshold=0.5)annotates exactly the inference ParDo, and theCountBadsteps exist but are unannotated.core_test.py::ExceptionHandlingTest::test_pardo_annotations_only_on_inner_pardo_with_threshold(new): annotations set on aParDoland on exactly one transform underwith_exception_handling(threshold=0.5).test_run_inference_only_attaches_model_identifier_to_inference_step(no exception handling) is unchanged and still passes.pytest apache_beam/ml/inference/base_test.py apache_beam/transforms/core_test.py apache_beam/transforms/error_handling_test.py apache_beam/transforms/ptransform_test.py: 365 passed, 11 skipped.yapf --diffclean on the changed files;ruffreports the same 5 pre-existing diagnostics as master, none in changed lines.Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
addresses #123orfixes #456).CHANGES.mdwith noteworthy changes.See CONTRIBUTING.md for more details.