Skip to content

Removes usages of the sentence-transformers package... - #40439

Merged
chamikaramj merged 2 commits into
apache:masterfrom
chamikaramj:remove_sentencetransformer_usage
Oct 9, 2026
Merged

chamikaramj merged 2 commits into
apache:masterfrom
chamikaramj:remove_sentencetransformer_usage

Conversation

@chamikaramj

@chamikaramj chamikaramj commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

... from the job submission path

This package and dependencies are extremely large. When installed via PyPI, the size is approximately:

Download size: 4 GB
Installed size: 7 GB

This change removes usage of the package for ML transforms from the job submission path so that these package do not have to be available during job submission. The packages just have to be available to workers during execution (for example, provided via a requirements file).

Example Dataflow pipeline where sentence-transformers was not installed during job submission: https://console.cloud.google.com/dataflow/jobs/us-central1/2026-10-07_21_55_30-3173716524350011720?project=apache-beam-testing


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README for a list of workflows and how to trigger them.

@chamikaramj

Copy link
Copy Markdown
Contributor Author

cc: @damccorm

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @tvalentyn for label python.
R: @derrickaw for label yaml.

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

@codecov

codecov Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.22222% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 59.04%. Comparing base (69bdf5f) to head (a2241a4).
⚠️ Report is 44 commits behind head on master.

Files with missing lines Patch % Lines
sdks/python/apache_beam/testing/test_utils.py 96.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             master   #40439    +/-   ##
==========================================
  Coverage     59.04%   59.04%            
  Complexity    15624    15624            
==========================================
  Files          2797     2798     +1     
  Lines        280750   280924   +174     
  Branches      12488    12488            
==========================================
+ Hits         165764   165877   +113     
- Misses       108540   108601    +61     
  Partials       6446     6446            
Flag Coverage Δ
python 79.63% <97.22%> (-0.04%) ⬇️

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.

@derrickaw derrickaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - yaml

super().__init__(type_adapter=create_text_adapter(), **kwargs)
self.model_name = model_name
self.max_seq_length = max_seq_length
self.model_class = SentenceTransformer

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is SentenceTransformer the only possible model class and will always be the only candidate for this codepath? It looks like we are making an assumption that if model_class is not callable, then it is SentenceTransformer. Is it safe to assume it will hold?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an assumption in existing code, right ? I'm not changing it.

It seems to me like we pushed self.model_class to a variable just to provide a better early error (not an import error). We don't support other class values for model_class within huggingface.py in existing code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And note that even if a caller (for example, a test) passes a customer model_class it will still be respected since not callable(model_class) will evaluate to false.

model_handler = huggingface.SentenceTransformerEmbeddings(
model_name=DEFAULT_MODEL_NAME,
columns=[test_query_column]).get_model_handler()
# Older Beam versions stored a reference to the SentenceTransformer class

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does older mean 2.77.0 and earlier? how does the current version store the model_class reference in the artifacts on disk when we save the artifact?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does older mean 2.77.0 and earlier?

Yes. Updated text.

how does the current version store the model_class reference in the artifacts on disk when we save the artifact?

With the current version, the artifacts will not store the model_class reference. Instead, it will be determined and imported lazily during runtime.

@chamikaramj chamikaramj left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. PTAL.

model_handler = huggingface.SentenceTransformerEmbeddings(
model_name=DEFAULT_MODEL_NAME,
columns=[test_query_column]).get_model_handler()
# Older Beam versions stored a reference to the SentenceTransformer class

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does older mean 2.77.0 and earlier?

Yes. Updated text.

how does the current version store the model_class reference in the artifacts on disk when we save the artifact?

With the current version, the artifacts will not store the model_class reference. Instead, it will be determined and imported lazily during runtime.

@chamikaramj

Copy link
Copy Markdown
Contributor Author

Thanks!

@chamikaramj
chamikaramj merged commit fadfc78 into apache:master Oct 9, 2026
98 checks passed
@chamikaramj
chamikaramj deleted the remove_sentencetransformer_usage branch October 9, 2026 02:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants