diff --git a/sdks/python/apache_beam/ml/inference/vertex_ai_inference_it_test.py b/sdks/python/apache_beam/ml/inference/vertex_ai_inference_it_test.py index 11643992c392..f2f0c2e8a924 100644 --- a/sdks/python/apache_beam/ml/inference/vertex_ai_inference_it_test.py +++ b/sdks/python/apache_beam/ml/inference/vertex_ai_inference_it_test.py @@ -28,6 +28,8 @@ from apache_beam.ml.inference.base import RunInference from apache_beam.testing.test_pipeline import TestPipeline +pytest.importorskip("vertexai", reason="Vertex AI dependencies not available") + # pylint: disable=ungrouped-imports try: from apache_beam.examples.inference import vertex_ai_image_classification @@ -53,8 +55,8 @@ _INVOKE_OUTPUT_DIR = "gs://apache-beam-ml/testing/outputs/vertex_invoke" +@pytest.mark.vertex_ai_postcommit class VertexAIInference(unittest.TestCase): - @pytest.mark.vertex_ai_postcommit def test_vertex_ai_run_flower_image_classification(self): output_file = '/'.join([_OUTPUT_DIR, str(uuid.uuid4()), 'output.txt']) @@ -73,7 +75,6 @@ def test_vertex_ai_run_flower_image_classification(self): test_pipeline.get_full_options_as_args(**extra_opts)) self.assertEqual(FileSystems().exists(output_file), True) - @pytest.mark.vertex_ai_postcommit @unittest.skipIf( not _INVOKE_ENDPOINT_ID, "Invoke endpoint not configured. Set _INVOKE_ENDPOINT_ID.") diff --git a/sdks/python/apache_beam/ml/rag/embeddings/vertex_ai_test.py b/sdks/python/apache_beam/ml/rag/embeddings/vertex_ai_test.py index 1a479c8e7dba..43f52d9186fc 100644 --- a/sdks/python/apache_beam/ml/rag/embeddings/vertex_ai_test.py +++ b/sdks/python/apache_beam/ml/rag/embeddings/vertex_ai_test.py @@ -23,6 +23,8 @@ import unittest import zlib +import pytest + import apache_beam as beam from apache_beam.ml.rag.types import Chunk from apache_beam.ml.rag.types import Content @@ -33,6 +35,8 @@ from apache_beam.testing.util import assert_that from apache_beam.testing.util import equal_to +pytest.importorskip("vertexai", reason="Vertex AI dependencies not available") + # pylint: disable=ungrouped-imports try: import vertexai # pylint: disable=unused-import @@ -40,9 +44,10 @@ from apache_beam.ml.rag.embeddings.vertex_ai import VertexAIImageEmbeddings from apache_beam.ml.rag.embeddings.vertex_ai import VertexAITextEmbeddings from apache_beam.ml.rag.embeddings.vertex_ai import _create_image_adapter - VERTEX_AI_AVAILABLE = True except ImportError: - VERTEX_AI_AVAILABLE = False + VertexAIImageEmbeddings = None # type: ignore + VertexAITextEmbeddings = None # type: ignore + _create_image_adapter = None # type: ignore def chunk_approximately_equals(expected, actual): @@ -58,8 +63,7 @@ def chunk_approximately_equals(expected, actual): all(isinstance(x, float) for x in actual.embedding.dense_embedding)) -@unittest.skipIf( - not VERTEX_AI_AVAILABLE, "Vertex AI dependencies not available") +@pytest.mark.vertex_ai_postcommit class VertexAITextEmbeddingsTest(unittest.TestCase): def setUp(self): self.artifact_location = tempfile.mkdtemp(prefix='vertex_ai_') @@ -113,8 +117,6 @@ def test_embedding_pipeline(self): embeddings, equal_to(expected, equals_fn=chunk_approximately_equals)) -@unittest.skipIf( - not VERTEX_AI_AVAILABLE, "Vertex AI dependencies not available") class VertexAIImageAdapterTest(unittest.TestCase): def test_image_adapter_missing_content(self): adapter = _create_image_adapter() @@ -146,8 +148,7 @@ def test_image_adapter_output(self): self.assertEqual(result[0].embedding.dense_embedding, [0.1, 0.2, 0.3]) -@unittest.skipIf( - not VERTEX_AI_AVAILABLE, "Vertex AI dependencies not available") +@pytest.mark.vertex_ai_postcommit class VertexAIImageEmbeddingsTest(unittest.TestCase): def setUp(self): self.artifact_location = tempfile.mkdtemp(prefix='vertex_ai_img_') diff --git a/sdks/python/apache_beam/ml/transforms/embeddings/vertex_ai_test.py b/sdks/python/apache_beam/ml/transforms/embeddings/vertex_ai_it_test.py similarity index 98% rename from sdks/python/apache_beam/ml/transforms/embeddings/vertex_ai_test.py rename to sdks/python/apache_beam/ml/transforms/embeddings/vertex_ai_it_test.py index 50507c54e36d..ec6bdcfbae47 100644 --- a/sdks/python/apache_beam/ml/transforms/embeddings/vertex_ai_test.py +++ b/sdks/python/apache_beam/ml/transforms/embeddings/vertex_ai_it_test.py @@ -20,11 +20,15 @@ import unittest import uuid +import pytest + import apache_beam as beam from apache_beam.ml.inference.base import RunInference from apache_beam.ml.transforms import base from apache_beam.ml.transforms.base import MLTransform +pytest.importorskip("vertexai", reason="Vertex AI dependencies not available") + # pylint: disable=ungrouped-imports # isort: off try: @@ -58,8 +62,7 @@ model_name: str = "text-embedding-005" -@unittest.skipIf( - VertexAITextEmbeddings is None, 'Vertex AI Python SDK is not installed.') +@pytest.mark.vertex_ai_postcommit class VertexAIEmbeddingsTest(unittest.TestCase): def setUp(self) -> None: self.artifact_location = tempfile.mkdtemp(prefix='_vertex_ai_test') @@ -261,8 +264,7 @@ def test_mltransform_to_ptransform_with_vertex(self): ptransform_list[i]._model_handler._underlying.model_name, model_name) -@unittest.skipIf( - VertexAIImageEmbeddings is None, 'Vertex AI Python SDK is not installed.') +@pytest.mark.vertex_ai_postcommit class VertexAIImageEmbeddingsTest(unittest.TestCase): def setUp(self) -> None: self.artifact_location = tempfile.mkdtemp(prefix='_vertex_ai_image_test') @@ -308,9 +310,7 @@ def _make_text_chunk(input: str) -> Chunk: return Chunk(content=Content(text=input)) -@unittest.skipIf( - VertexAIMultiModalEmbeddings is None, - 'Vertex AI Python SDK is not installed.') +@pytest.mark.vertex_ai_postcommit class VertexAIMultiModalEmbeddingsTest(unittest.TestCase): def setUp(self) -> None: self.artifact_location = tempfile.mkdtemp( diff --git a/sdks/python/test-suites/tox/py310/build.gradle b/sdks/python/test-suites/tox/py310/build.gradle index 751faa682ae3..8902f53a5482 100644 --- a/sdks/python/test-suites/tox/py310/build.gradle +++ b/sdks/python/test-suites/tox/py310/build.gradle @@ -49,29 +49,9 @@ project.tasks.register("postCommitPyDep") {} // For versions that we would like to prioritize for testing, // for example versions released in a timeframe of last 1-2 years. -toxTask "testPy310pyarrow-9", "py310-pyarrow-9", "${posargs}" -test.dependsOn "testPy310pyarrow-9" -postCommitPyDep.dependsOn "testPy310pyarrow-9" - -toxTask "testPy310pyarrow-10", "py310-pyarrow-10", "${posargs}" -test.dependsOn "testPy310pyarrow-10" -postCommitPyDep.dependsOn "testPy310pyarrow-10" - -toxTask "testPy310pyarrow-11", "py310-pyarrow-11", "${posargs}" -test.dependsOn "testPy310pyarrow-11" -postCommitPyDep.dependsOn "testPy310pyarrow-11" - -toxTask "testPy310pyarrow-12", "py310-pyarrow-12", "${posargs}" -test.dependsOn "testPy310pyarrow-12" -postCommitPyDep.dependsOn "testPy310pyarrow-12" - -toxTask "testPy310pyarrow-13", "py310-pyarrow-13", "${posargs}" -test.dependsOn "testPy310pyarrow-13" -postCommitPyDep.dependsOn "testPy310pyarrow-13" - -toxTask "testPy310pyarrow-14", "py310-pyarrow-14", "${posargs}" -test.dependsOn "testPy310pyarrow-14" -postCommitPyDep.dependsOn "testPy310pyarrow-14" +toxTask "testPy310pyarrow-6", "py310-pyarrow-6", "${posargs}" +test.dependsOn "testPy310pyarrow-6" +postCommitPyDep.dependsOn "testPy310pyarrow-6" toxTask "testPy310pyarrow-15", "py310-pyarrow-15", "${posargs}" test.dependsOn "testPy310pyarrow-15" @@ -89,6 +69,26 @@ toxTask "testPy310pyarrow-18", "py310-pyarrow-18", "${posargs}" test.dependsOn "testPy310pyarrow-18" postCommitPyDep.dependsOn "testPy310pyarrow-18" +toxTask "testPy310pyarrow-19", "py310-pyarrow-19", "${posargs}" +test.dependsOn "testPy310pyarrow-19" +postCommitPyDep.dependsOn "testPy310pyarrow-19" + +toxTask "testPy310pyarrow-20", "py310-pyarrow-20", "${posargs}" +test.dependsOn "testPy310pyarrow-20" +postCommitPyDep.dependsOn "testPy310pyarrow-20" + +toxTask "testPy310pyarrow-21", "py310-pyarrow-21", "${posargs}" +test.dependsOn "testPy310pyarrow-21" +postCommitPyDep.dependsOn "testPy310pyarrow-21" + +toxTask "testPy310pyarrow-22", "py310-pyarrow-22", "${posargs}" +test.dependsOn "testPy310pyarrow-22" +postCommitPyDep.dependsOn "testPy310pyarrow-22" + +toxTask "testPy310pyarrow-23", "py310-pyarrow-23", "${posargs}" +test.dependsOn "testPy310pyarrow-23" +postCommitPyDep.dependsOn "testPy310pyarrow-23" + // Create a test task for each supported minor version of pandas toxTask "testPy310pandas-14", "py310-pandas-14", "${posargs}" test.dependsOn "testPy310pandas-14" @@ -159,10 +159,6 @@ toxTask "testPy310transformers-447", "py310-transformers-447", "${posargs}" test.dependsOn "testPy310transformers-447" postCommitPyDep.dependsOn "testPy310transformers-447" -toxTask "testPy310transformers-448", "py310-transformers-448", "${posargs}" -test.dependsOn "testPy310transformers-448" -postCommitPyDep.dependsOn "testPy310transformers-448" - toxTask "testPy310transformers-latest", "py310-transformers-latest", "${posargs}" test.dependsOn "testPy310transformers-latest" postCommitPyDep.dependsOn "testPy310transformers-latest" diff --git a/sdks/python/tox.ini b/sdks/python/tox.ini index 32be7b52b034..71b9b27cfcf3 100644 --- a/sdks/python/tox.ini +++ b/sdks/python/tox.ini @@ -512,16 +512,16 @@ commands = # Allow exit code 5 (no tests run) so that we can run this command safely on arbitrary subdirectories. /bin/sh -c 'pytest -o junit_suite_name={envname} --junitxml=pytest_{envname}.xml -n 6 -m uses_xgboost {posargs}; ret=$?; [ $ret = 5 ] && exit 0 || exit $ret' -[testenv:py{310,311}-transformers-{428,447,448,latest}] +[testenv:py{310,311}-transformers-{428,447,latest}] deps = # Environment dependencies are defined in the `setenv` section and installed in the `commands` section. -extras = test,gcp,ml_test +pip_pre = False +extras = test setenv = COMMON_DEPS = tensorflow==2.12.0 protobuf==4.25.5 pip==25.0.1 # sentence-transformers 2.2.2 is the latest version that supports transformers 4.28.x 428: DEPS = sentence-transformers==2.2.2 'transformers>=4.28.0,<4.29.0' 'torch>=1.9.0,<1.14.0' 447: DEPS = 'transformers>=4.47.0,<4.48.0' 'torch>=1.9.0,<1.14.0' - 455: DEPS = 'transformers>=4.55.0,<4.56.0' 'torch>=2.0.0,<2.1.0' latest: DEPS = 'transformers>=4.55.0' 'torch>=2.0.0' 'accelerate>=1.6.0' commands = /bin/sh -c "pip install .[{extras}] {env:DEPS} {env:COMMON_DEPS}"