Skip to content
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

[Python] Add Hugging Face PRs to CHANGES.md #27829

Merged
merged 1 commit into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
* Prism is a portable runner that executes each transform independantly, ensuring coders.
* At this point it supercedes the Go direct runner in functionality. The Go direct runner is now deprecated.
* See https://github.com/apache/beam/blob/master/sdks/go/pkg/beam/runners/prism/README.md for the goals and features of Prism.
* Hugging Face Model Handler for RunInference added to Python SDK. ([#26632](https://github.com/apache/beam/pull/26632))
* Hugging Face Pipelines support for RunInference added to Python SDK. ([#27399](https://github.com/apache/beam/pull/27399))

## Breaking Changes

Expand Down
12 changes: 11 additions & 1 deletion sdks/python/apache_beam/ml/inference/huggingface_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@

class PipelineTask(str, Enum):
"""
PipelineTask lists all the tasks supported by the Hugging Face Pipelines.
PipelineTask defines all the tasks supported by the Hugging Face Pipelines
listed at https://huggingface.co/docs/transformers/main_classes/pipelines.
Only these tasks can be passed to HuggingFacePipelineModelHandler.
"""
AudioClassification = 'audio-classification'
Expand Down Expand Up @@ -626,6 +627,7 @@ def __init__(
_validate_constructor_args_hf_pipeline(self._task, self._model)

def load_model(self):
"""Loads and initializes the pipeline for processing."""
return pipeline(
task=self._task, model=self._model, **self._load_pipeline_args)

Expand Down Expand Up @@ -664,6 +666,10 @@ def update_model_path(self, model_path: Optional[str] = None):
self._model = model_path if model_path else self._model

def get_num_bytes(self, batch: Sequence[str]) -> int:
"""
Returns:
The number of bytes of input batch elements.
"""
return sum(sys.getsizeof(element) for element in batch)

def batch_elements_kwargs(self):
Expand All @@ -673,4 +679,8 @@ def share_model_across_processes(self) -> bool:
return self._large_model

def get_metrics_namespace(self) -> str:
"""
Returns:
A namespace for metrics collected by the RunInference transform.
"""
return 'BeamML_HuggingFacePipelineModelHandler'