Skip to content

Conversation

@liferoad
Copy link
Contributor

@liferoad liferoad commented Oct 3, 2025

Versions 4.55.0+ use Python 3.10+ union syntax which causes TypeError on Python 3.9


apache_beam/ml/transforms/embeddings/huggingface.py:37: in <module> |  
-- | --
from sentence_transformers import SentenceTransformer |  
../../build/gradleenv/1922375555/lib/python3.9/site-packages/sentence_transformers/__init__.py:15: in <module> |  
from sentence_transformers.cross_encoder import ( |  
../../build/gradleenv/1922375555/lib/python3.9/site-packages/sentence_transformers/cross_encoder/__init__.py:5: in <module> |  
from .trainer import CrossEncoderTrainer |  
../../build/gradleenv/1922375555/lib/python3.9/site-packages/sentence_transformers/cross_encoder/trainer.py:22: in <module> |  
from sentence_transformers.trainer import SentenceTransformerTrainer |  
../../build/gradleenv/1922375555/lib/python3.9/site-packages/sentence_transformers/trainer.py:16: in <module> |  
from transformers import EvalPrediction, PreTrainedTokenizerBase, Trainer, TrainerCallback |  
<frozen importlib._bootstrap>:1055: in _handle_fromlist |  
??? |  
../../build/gradleenv/1922375555/lib/python3.9/site-packages/transformers/utils/import_utils.py:2317: in __getattr__ |  
module = self._get_module(self._class_to_module[name]) |  
../../build/gradleenv/1922375555/lib/python3.9/site-packages/transformers/utils/import_utils.py:2347: in _get_module |  
raise e |  
../../build/gradleenv/1922375555/lib/python3.9/site-packages/transformers/utils/import_utils.py:2345: in _get_module |  
return importlib.import_module("." + module_name, self.__name__) |  
/opt/hostedtoolcache/Python/3.9.22/x64/lib/python3.9/importlib/__init__.py:127: in import_module |  
return _bootstrap._gcd_import(name[level:], package, level) |  
../../build/gradleenv/1922375555/lib/python3.9/site-packages/transformers/trainer.py:311: in <module> |  
class Trainer: |  
../../build/gradleenv/1922375555/lib/python3.9/site-packages/transformers/trainer.py:5593: in Trainer |  
def _get_num_items_in_batch(self, batch_samples: list, device: torch.device) -> int \| None: |  
E   TypeError: unsupported operand type(s) for \|: 'type' and 'NoneType' |  
 

<br class="Apple-interchange-newline">

Tested: https://github.com/apache/beam/actions/runs/18237181501/job/51934437687?pr=36385 is green now.


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.

…bility

Versions 4.55.0+ use Python 3.10+ union syntax which causes TypeError on Python 3.9
@github-actions github-actions bot added the python label Oct 3, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @liferoad, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical compatibility issue within the Python SDK related to the transformers library. It implements a conditional version restriction for transformers to ensure that users running Python 3.9 do not encounter TypeError exceptions caused by newer union type syntax introduced in transformers versions 4.55.0 and later, which are only compatible with Python 3.10 and above. This change maintains broader Python version support for the SDK while allowing newer Python environments to utilize the latest compatible transformers versions.

Highlights

  • Python 3.9 Compatibility: The transformers library version is now conditionally restricted for Python 3.9 environments. Specifically, transformers versions 4.55.0 and above utilize Python 3.10+ union syntax (int | None), which leads to TypeError on Python 3.9. To prevent this, Python 3.9 users will now install transformers versions less than 4.55.0.
  • Conditional Dependency: A conditional dependency has been introduced in setup.py for the transformers package. For Python versions less than 3.10, the dependency is set to transformers>=4.28.0,<4.55.0. For Python 3.10 and above, the dependency remains transformers>=4.28.0,<4.56.0.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

…tibility

Use sentence-transformers 2.x for Python 3.9 to maintain compatibility with transformers <4.55.0, while allowing newer versions for Python 3.10+
Add required license header to comply with Apache Software Foundation requirements
@liferoad liferoad requested review from Amar3tto and hjtran October 4, 2025 00:54
@github-actions
Copy link
Contributor

github-actions bot commented Oct 4, 2025

Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment assign set of reviewers

@liferoad liferoad requested a review from damccorm October 5, 2025 00:10
@liferoad liferoad merged commit 7174991 into apache:master Oct 5, 2025
114 of 126 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants