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

Support Embeddings in mltransform #29564

Merged
merged 58 commits into from
Dec 11, 2023

Conversation

AnandInguva
Copy link
Contributor

@AnandInguva AnandInguva commented Nov 29, 2023

  • Support embeddings in MLTransform using config based structure.

Each config will define its own model handler so that model handler can be compatible with the inputs passed to the MLTransform.
This PR supports vertex_ai, hugging face(sentence-transformers).

Changes made:

  1. Make ProcessHandler a PTransform.
  2. Create _TextEmbeddingHandler which takes a ModelHandler but it is responsible to work on Dict[str, Any] inputs.
  3. Create a helper class that would create and saves the PTransform list required to process data processing steps or embedding configs. MLTransform would be the container that holds the list of transforms and these list of transforms are passed to the _MLTransformToPTransformMapper which maps each data processing transforms to its PTransform
    • For example, tft based transforms are mapped to TFTProcessHandler.
    • Embedding configs are mapped to RunInference
  4. Use jsonpickle to store and load the ptransforms instances. This is done to seal the gap between training and inference. jsonpickle is cross compatible across python versions and has backward compatibility with older versions of its versions.

This PR will throw if input is a Dict[str, List[str]]. Works for Dict[str, str]


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 to see a list of phrases to trigger workflows.

@AnandInguva
Copy link
Contributor Author

R: @damccorm This is ready for review.

Copy link
Contributor

Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control

Copy link
Contributor

@damccorm damccorm left a comment

Choose a reason for hiding this comment

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

Chunking the review a bit. Just reviewed base.py thus far, though I imagine that's the place I'll have the most comments

sdks/python/apache_beam/ml/transforms/base.py Show resolved Hide resolved
sdks/python/apache_beam/ml/transforms/base.py Outdated Show resolved Hide resolved
sdks/python/apache_beam/ml/transforms/base.py Outdated Show resolved Hide resolved
sdks/python/apache_beam/ml/transforms/base.py Show resolved Hide resolved
sdks/python/apache_beam/ml/transforms/base.py Outdated Show resolved Hide resolved
sdks/python/apache_beam/ml/transforms/base.py Outdated Show resolved Hide resolved
sdks/python/apache_beam/ml/transforms/base.py Outdated Show resolved Hide resolved
sdks/python/apache_beam/ml/transforms/base.py Outdated Show resolved Hide resolved
sdks/python/apache_beam/ml/transforms/base.py Outdated Show resolved Hide resolved
sdks/python/apache_beam/ml/transforms/base.py Outdated Show resolved Hide resolved
@github-actions github-actions bot added the build label Dec 5, 2023
Copy link
Contributor

@damccorm damccorm left a comment

Choose a reason for hiding this comment

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

This mostly looks good, had a few more comments though

sdks/python/apache_beam/ml/transforms/base.py Outdated Show resolved Hide resolved
sdks/python/apache_beam/ml/transforms/base.py Outdated Show resolved Hide resolved
sdks/python/apache_beam/ml/transforms/tft.py Outdated Show resolved Hide resolved
sdks/python/apache_beam/ml/transforms/base.py Show resolved Hide resolved
sdks/python/apache_beam/ml/transforms/base.py Show resolved Hide resolved
sdks/python/apache_beam/ml/transforms/utils.py Outdated Show resolved Hide resolved
sdks/python/tox.ini Outdated Show resolved Hide resolved
sdks/python/tox.ini Show resolved Hide resolved
raise FileExistsError(
"The artifact location %s already exists and contains %s. Please "
"specify a different location." %
(artifact_location, _ATTRIBUTE_FILE_NAME))
Copy link
Contributor

Choose a reason for hiding this comment

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

Good call - one possible future enhancement would be to support an overwrite argument that allows users to do this

Copy link
Contributor

@damccorm damccorm left a comment

Choose a reason for hiding this comment

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

One last nit, otherwise this LGTM. Feel free to make the change and merge once checks pass

CHANGES.md Outdated Show resolved Hide resolved
Co-authored-by: Danny McCormick <[email protected]>
@AnandInguva AnandInguva merged commit aacf1ee into apache:master Dec 11, 2023
78 of 79 checks passed
@AnandInguva AnandInguva linked an issue Jan 5, 2024 that may be closed by this pull request
16 tasks
@AnandInguva AnandInguva linked an issue Jan 5, 2024 that may be closed by this pull request
16 tasks
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.

[Task]: Support embeddings using ML models in MLTransform
2 participants