-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DLQ support in RunInference #26261
Merged
damccorm
merged 5 commits into
apache:master
from
damccorm:users/damccorm/runInferenceDLQ
Apr 14, 2023
Merged
DLQ support in RunInference #26261
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -339,6 +339,7 @@ def __init__( | |
self._metrics_namespace = metrics_namespace | ||
self._model_metadata_pcoll = model_metadata_pcoll | ||
self._enable_side_input_loading = self._model_metadata_pcoll is not None | ||
self._with_exception_handling = False | ||
|
||
# TODO(BEAM-14046): Add and link to help documentation. | ||
@classmethod | ||
|
@@ -368,20 +369,71 @@ def expand( | |
# batching DoFn APIs. | ||
| beam.BatchElements(**self._model_handler.batch_elements_kwargs())) | ||
|
||
run_inference_pardo = beam.ParDo( | ||
_RunInferenceDoFn( | ||
self._model_handler, | ||
self._clock, | ||
self._metrics_namespace, | ||
self._enable_side_input_loading), | ||
self._inference_args, | ||
beam.pvalue.AsSingleton( | ||
self._model_metadata_pcoll, | ||
) if self._enable_side_input_loading else None).with_resource_hints( | ||
**resource_hints) | ||
|
||
if self._with_exception_handling: | ||
run_inference_pardo = run_inference_pardo.with_exception_handling( | ||
exc_class=self._exc_class, | ||
use_subprocess=self._use_subprocess, | ||
threshold=self._threshold) | ||
|
||
return ( | ||
batched_elements_pcoll | ||
| 'BeamML_RunInference' >> ( | ||
beam.ParDo( | ||
_RunInferenceDoFn( | ||
self._model_handler, | ||
self._clock, | ||
self._metrics_namespace, | ||
self._enable_side_input_loading), | ||
self._inference_args, | ||
beam.pvalue.AsSingleton( | ||
self._model_metadata_pcoll, | ||
) if self._enable_side_input_loading else | ||
None).with_resource_hints(**resource_hints))) | ||
| 'BeamML_RunInference' >> run_inference_pardo) | ||
|
||
def with_exception_handling( | ||
self, *, exc_class=Exception, use_subprocess=False, threshold=1): | ||
"""Automatically provides a dead letter output for skipping bad records. | ||
This can allow a pipeline to continue successfully rather than fail or | ||
continuously throw errors on retry when bad elements are encountered. | ||
|
||
This returns a tagged output with two PCollections, the first being the | ||
results of successfully processing the input PCollection, and the second | ||
being the set of bad batches of records (those which threw exceptions | ||
during processing) along with information about the errors raised. | ||
|
||
For example, one would write:: | ||
|
||
good, bad = RunInference( | ||
maybe_error_raising_model_handler | ||
).with_exception_handling() | ||
|
||
and `good` will be a PCollection of PredictionResults and `bad` will | ||
contain a tuple of all batches that raised exceptions, along with their | ||
corresponding exception. | ||
|
||
|
||
Args: | ||
exc_class: An exception class, or tuple of exception classes, to catch. | ||
Optional, defaults to 'Exception'. | ||
use_subprocess: Whether to execute the DoFn logic in a subprocess. This | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JFYI, use_subprocess currently has some known issues / limitations, which may surface here as well. |
||
allows one to recover from errors that can crash the calling process | ||
(e.g. from an underlying library causing a segfault), but is | ||
slower as elements and results must cross a process boundary. Note | ||
that this starts up a long-running process that is used to handle | ||
all the elements (until hard failure, which should be rare) rather | ||
than a new process per element, so the overhead should be minimal | ||
(and can be amortized if there's any per-process or per-bundle | ||
initialization that needs to be done). Optional, defaults to False. | ||
threshold: An upper bound on the ratio of records that can be bad before | ||
aborting the entire pipeline. Optional, defaults to 1.0 (meaning | ||
up to 100% of records can be bad and the pipeline will still succeed). | ||
""" | ||
self._with_exception_handling = True | ||
self._exc_class = exc_class | ||
self._use_subprocess = use_subprocess | ||
self._threshold = threshold | ||
return self | ||
|
||
|
||
class _MetricsCollector: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Do we want to provide
main_tag
anddead_letter_tag
? since we already mentioned by defaultgood
tag andbad
tag so not sure how useful it will be.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I originally had it, but intentionally omitted it since those are primarily useful in the context of having >2 outputs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sg