Skip to content

Commit 3321224

Browse files
authored
Add python ml extras (#33825)
* Add python ml extras * Create clear bounds on transformers suite and add latest test * Add docs
1 parent 6e3cf2b commit 3321224

File tree

6 files changed

+85
-3
lines changed

6 files changed

+85
-3
lines changed

sdks/python/setup.py

+34-1
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,40 @@ def get_portability_package_data():
541541
'virtualenv-clone>=0.5,<1.0',
542542
# https://github.com/PiotrDabkowski/Js2Py/issues/317
543543
'js2py>=0.74,<1; python_version<"3.12"',
544-
] + dataframe_dependency
544+
] + dataframe_dependency,
545+
# Keep the following dependencies in line with what we test against
546+
# in https://github.com/apache/beam/blob/master/sdks/python/tox.ini
547+
# For more info, see
548+
# https://docs.google.com/document/d/1c84Gc-cZRCfrU8f7kWGsNR2o8oSRjCM-dGHO9KvPWPw/edit?usp=sharing
549+
'torch': [
550+
'torch<=1.13.0,<=2.0.0'
551+
],
552+
'tensorflow': [
553+
'tensorflow>=2.12rc1,<2.13'
554+
],
555+
'transformers': [
556+
'transformers>=4.28.0,<4.49.0',
557+
'tensorflow==2.12.0',
558+
'torch>=1.9.0,<2.1.0'
559+
],
560+
'tft': [
561+
'tensorflow_transform>=1.14.0,<1.15.0'
562+
],
563+
'onnx': [
564+
'onnxruntime==1.13.1',
565+
'torch==1.13.1',
566+
'tensorflow==2.11.0',
567+
'tf2onnx==1.13.0',
568+
'skl2onnx==1.13',
569+
'transformers==4.25.1'
570+
],
571+
'xgboost': [
572+
'xgboost>=1.6.0,<2.1.3',
573+
'datatable==1.0.0'
574+
],
575+
'tensorflow-hub': [
576+
'tensorflow-hub>=0.14.0,<0.16.0'
577+
]
545578
},
546579
zip_safe=False,
547580
# PyPI package information.

sdks/python/test-suites/tox/py39/build.gradle

+4
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ toxTask "testPy39transformers-448", "py39-transformers-448", "${posargs}"
166166
test.dependsOn "testPy39transformers-448"
167167
postCommitPyDep.dependsOn "testPy39transformers-448"
168168

169+
toxTask "testPy39transformers-latest", "py39-transformers-latest", "${posargs}"
170+
test.dependsOn "testPy39transformers-latest"
171+
postCommitPyDep.dependsOn "testPy39transformers-latest"
172+
169173
toxTask "testPy39embeddingsMLTransform", "py39-embeddings", "${posargs}"
170174
test.dependsOn "testPy39embeddingsMLTransform"
171175
postCommitPyDep.dependsOn "testPy39embeddingsMLTransform"

sdks/python/tox.ini

+4-2
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ commands =
454454
# Allow exit code 5 (no tests run) so that we can run this command safely on arbitrary subdirectories.
455455
/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'
456456

457-
[testenv:py{39,310}-transformers-{428,447,448}]
457+
[testenv:py{39,310}-transformers-{428,447,448,latest}]
458458
deps =
459459
# sentence-transformers 2.2.2 is the latest version that supports transformers 4.28.x
460460
428: sentence-transformers==2.2.2
@@ -463,7 +463,9 @@ deps =
463463
447: transformers>=4.47.0,<4.48.0
464464
447: torch>=1.9.0,<1.14.0
465465
448: transformers>=4.48.0,<4.49.0
466-
448: torch>=2.0.0
466+
448: torch>=2.0.0,torch<2.1.0
467+
latest: transformers>=4.48.0
468+
latest: torch>=2.0.0
467469
tensorflow==2.12.0
468470
protobuf==4.25.5
469471
extras = test,gcp,ml_test
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
title: "ML Dependency Extras"
3+
---
4+
<!--
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
18+
# ML Dependency Extras
19+
20+
In order to make it easy to make sure you are using dependencies which have
21+
been well tested with Beam ML, Beam provides a set of ML extras which can
22+
be installed alongside of Beam. For example, if you want to use a version
23+
of PyTorch which has been tested with Beam, you can install it with:
24+
25+
```
26+
pip install beam[torch]
27+
```
28+
29+
A full set of extras can be found in
30+
[setup.py](https://github.com/apache/beam/blob/6e3cf2b113026e27db7833a1f0fd08977b7c71e1/sdks/python/setup.py#L397).
31+
32+
**Note:** You can also pin to dependencies outside of the extra range with
33+
a normal install - for example:
34+
35+
```
36+
pip install beam==2.XX.0
37+
pip install torch==<version released after Beam 2.XX.0>
38+
```
39+
40+
this will usually work, but can break if the dependency releases a breaking
41+
change between the version Beam tests with and the version you pin to.

website/www/site/content/en/documentation/ml/overview.md

+1
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,4 @@ When you use Apache Beam as one of the building blocks in your project, these or
131131
* [ML model evaluation](/documentation/ml/model-evaluation/)
132132
* [RunInference public codelab](https://colab.sandbox.google.com/github/apache/beam/blob/master/examples/notebooks/beam-ml/run_inference_basic.ipynb)
133133
* [RunInference notebooks](https://github.com/apache/beam/tree/master/examples/notebooks/beam-ml)
134+
* [Beam ML dependency management](/documentation/ml/ml-dependency-extras)

website/www/site/layouts/partials/section-menu/en/documentation.html

+1
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@
253253
<li><a href="/documentation/ml/model-evaluation/">ML model evaluation</a></li>
254254
</ul>
255255
</li>
256+
<li><a href="/documentation/ml/ml-dependency-extras/">ML Dependency Extras</a></li>
256257
<li class="section-nav-item--collapsible">
257258
<span class="section-nav-list-title">Use cases</span>
258259
<ul class="section-nav-list">

0 commit comments

Comments
 (0)