Skip to content

Commit 605e0b1

Browse files
bochinskiclaude
andcommitted
Add Python 3.13 support
- pyproject.toml: requires-python ">=3.10,<3.14", add the 3.13 classifier; regenerate uv.lock accordingly. - PythonVersion enum and default image prefixes: add 3.13 in flytekit core, the sqlalchemy plugin and the openai batch plugin. Without it, DefaultImages.find_image_for() raises "(3, 13) is not a valid PythonVersion" on 3.13. - CI (pythonbuild.yml): run 3.13 on pull requests and in the nightly matrix, enable the extras (tensorflow/pytorch) tests on 3.13, exclude pandas<2 and plugins whose dependencies do not support 3.13 yet. - dev-requirements.in: tensorflow>=2.21 and torch>=2.6 on 3.13; lift the protobuf<5 dev pin on 3.13 only (tensorflow 2.21 needs protobuf>=6, and the issue behind the pin, flyteorg/flyte#5448, was fixed upstream). - Publish py3.13 images in pythonpublish.yml and build_image.yml. - pytorch extras: torch>=2.6 defaults torch.load(weights_only=True), which cannot load the whole nn.Module / checkpoint objects flytekit stores. Pass weights_only=False where the keyword exists. This is required for the extras tests on 3.13 and already fails in the nightly 3.11 run. Closes flyteorg/flyte#6993 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Signed-off-by: bochinski <30434375+bochinski@users.noreply.github.com>
1 parent d69b3fb commit 605e0b1

12 files changed

Lines changed: 302 additions & 19 deletions

File tree

.github/workflows/build_image.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
needs: get-version
2929
strategy:
3030
matrix:
31-
python-version: ["3.10", "3.11", "3.12"]
31+
python-version: ["3.10", "3.11", "3.12", "3.13"]
3232
steps:
3333
- uses: actions/checkout@v4
3434
with:

.github/workflows/pythonbuild.yml

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ jobs:
2727
- name: Set Python versions for run
2828
run: |
2929
if [[ ${{ github.event_name }} == "schedule" ]]; then
30-
echo "python_versions=[\"3.10\",\"3.11\",\"3.12\"]" >> $GITHUB_ENV
30+
echo "python_versions=[\"3.10\",\"3.11\",\"3.12\",\"3.13\"]" >> $GITHUB_ENV
3131
else
32-
echo "python_versions=[\"3.12\"]" >> $GITHUB_ENV
32+
echo "python_versions=[\"3.12\",\"3.13\"]" >> $GITHUB_ENV
3333
fi
3434
3535
build:
@@ -139,6 +139,9 @@ jobs:
139139
pandas: "pandas>=2.0.0"
140140
- pandas: "pandas<2.0.0"
141141
python-version: "3.12"
142+
# pandas 1.x has no wheels for python 3.13
143+
- pandas: "pandas<2.0.0"
144+
python-version: "3.13"
142145

143146
steps:
144147
- uses: actions/checkout@v4
@@ -389,6 +392,27 @@ jobs:
389392
# Segmentation fault on python 3.12: https://github.com/flyteorg/flyte/issues/5020
390393
- python-version: 3.12
391394
plugin-names: "flytekit-kf-pytorch"
395+
# Python 3.13: the exclusions below mirror the python 3.12 ones (same dependency limitations) and should
396+
# be revisited together with them.
397+
- python-version: 3.13
398+
plugin-names: "flytekit-airflow"
399+
- python-version: 3.13
400+
plugin-names: "flytekit-kf-pytorch"
401+
- python-version: 3.13
402+
plugin-names: "flytekit-modin"
403+
- python-version: 3.13
404+
plugin-names: "flytekit-onnx-pytorch"
405+
- python-version: 3.13
406+
plugin-names: "flytekit-ray"
407+
- python-version: 3.13
408+
plugin-names: "flytekit-vaex"
409+
# The tensorflow releases that provide python 3.13 wheels require protobuf>=6, which conflicts with the
410+
# "protobuf<5" pin used below for the plugin tests.
411+
- python-version: 3.13
412+
plugin-names: "flytekit-mlflow"
413+
# flytekitplugins-duckdb declares python_requires<3.13 (duckdb<=1.0.0 pin)
414+
- python-version: 3.13
415+
plugin-names: "flytekit-duckdb"
392416
steps:
393417
- uses: actions/checkout@v4
394418
- name: "Clear action cache"

.github/workflows/pythonpublish.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ jobs:
8282
- "3.10"
8383
- "3.11"
8484
- "3.12"
85+
- "3.13"
8586
steps:
8687
- uses: actions/checkout@v4
8788
with:

dev-requirements.in

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,17 @@ pytest-icdiff
2323

2424
# Tensorflow is not available for python 3.12 yet: https://github.com/tensorflow/tensorflow/issues/62003
2525
tensorflow<=2.15.1; python_version<'3.12'
26+
# tensorflow>=2.21 ships python 3.13 wheels (linux x86_64/aarch64, macos arm64, windows) but requires protobuf>=6,
27+
# see the protobuf constraint below.
28+
tensorflow>=2.21.0; python_version>='3.13'
2629
# Newer versions of torch bring in nvidia dependencies that are not present in windows, so
2730
# we put this constraint while we do not have per-environment requirements files
2831
torch<=1.12.1; python_version<'3.11'
2932
# pytorch 2 supports python 3.11
3033
# pytorch 2 does not support 3.12 yet: https://github.com/pytorch/pytorch/issues/110436
3134
torch; python_version<'3.12'
35+
# pytorch>=2.6 ships python 3.13 wheels
36+
torch>=2.6.0; python_version>='3.13'
3237
pydantic
3338

3439
# TODO: Currently, the python-magic library causes build errors on Windows due to its dependency on DLLs for libmagic.
@@ -40,7 +45,9 @@ python-magic; (platform_system=='Darwin' or platform_system=='Linux')
4045
# Google released a new major version of the protobuf library and once that started being used in the ecosystem at large,
4146
# including `googleapis-common-protos` we started seeing errors in CI, so let's constrain that for now.
4247
# The issue to support protobuf 5 is being tracked in https://github.com/flyteorg/flyte/issues/5448.
43-
protobuf<5
48+
# The root cause was fixed in googleapis-common-protos>=1.63.2. On python 3.13 the pin is lifted, because the
49+
# tensorflow releases that support 3.13 require protobuf>=6 (flytekit itself does not cap protobuf).
50+
protobuf<5; python_version<'3.13'
4451
types-protobuf<5
4552

4653
types-croniter

flytekit/configuration/default_images.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class PythonVersion(enum.Enum):
1313
PYTHON_3_10 = (3, 10)
1414
PYTHON_3_11 = (3, 11)
1515
PYTHON_3_12 = (3, 12)
16+
PYTHON_3_13 = (3, 13)
1617

1718

1819
class DefaultImages(object):
@@ -26,6 +27,7 @@ class DefaultImages(object):
2627
PythonVersion.PYTHON_3_10: "cr.flyte.org/flyteorg/flytekit:py3.10-",
2728
PythonVersion.PYTHON_3_11: "cr.flyte.org/flyteorg/flytekit:py3.11-",
2829
PythonVersion.PYTHON_3_12: "cr.flyte.org/flyteorg/flytekit:py3.12-",
30+
PythonVersion.PYTHON_3_13: "cr.flyte.org/flyteorg/flytekit:py3.13-",
2931
}
3032

3133
@classmethod

flytekit/extras/pytorch/checkpoint.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from flytekit.core.context_manager import FlyteContext
1111
from flytekit.core.type_engine import TypeEngine, TypeTransformer, TypeTransformerFailedError
12+
from flytekit.extras.pytorch.native import _torch_load
1213
from flytekit.models.core import types as _core_types
1314
from flytekit.models.literals import Blob, BlobMetadata, Literal, Scalar
1415
from flytekit.models.types import LiteralType
@@ -119,7 +120,7 @@ def to_python_value(
119120
map_location = torch.device("cpu")
120121

121122
# load checkpoint from a file
122-
return typing.cast(PyTorchCheckpoint, torch.load(local_path, map_location=map_location))
123+
return typing.cast(PyTorchCheckpoint, _torch_load(local_path, map_location=map_location))
123124

124125
def guess_python_type(self, literal_type: LiteralType) -> Type[PyTorchCheckpoint]:
125126
if (

flytekit/extras/pytorch/native.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import inspect
12
import pathlib
3+
import typing
24
from typing import Type, TypeVar
35

46
import torch
@@ -12,6 +14,16 @@
1214
T = TypeVar("T")
1315

1416

17+
def _torch_load(path: str, map_location: typing.Any) -> typing.Any:
18+
"""
19+
Load a full object with ``torch.load``. flytekit serializes whole tensors/modules/checkpoints, so ``weights_only``
20+
(the default since torch 2.6) must be disabled. The keyword does not exist before torch 1.13, hence the check.
21+
"""
22+
if "weights_only" in inspect.signature(torch.load).parameters:
23+
return torch.load(path, map_location=map_location, weights_only=False)
24+
return torch.load(path, map_location=map_location)
25+
26+
1527
class PyTorchTypeTransformer(TypeTransformer[T]):
1628
def get_literal_type(self, t: Type[T]) -> LiteralType:
1729
return LiteralType(
@@ -63,7 +75,7 @@ def to_python_value(self, ctx: FlyteContext, lv: Literal, expected_python_type:
6375
map_location = torch.device("cpu")
6476

6577
# load pytorch tensor/module from a file
66-
return torch.load(local_path, map_location=map_location)
78+
return _torch_load(local_path, map_location=map_location)
6779

6880

6981
class PyTorchTensorTransformer(PyTorchTypeTransformer[torch.Tensor]):

plugins/flytekit-openai/flytekitplugins/openai/batch/task.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class OpenAIFileDefaultImages(DefaultImages):
6464
PythonVersion.PYTHON_3_10: "cr.flyte.org/flyteorg/flytekit:py3.10-openai-batch-",
6565
PythonVersion.PYTHON_3_11: "cr.flyte.org/flyteorg/flytekit:py3.11-openai-batch-",
6666
PythonVersion.PYTHON_3_12: "cr.flyte.org/flyteorg/flytekit:py3.12-openai-batch-",
67+
PythonVersion.PYTHON_3_13: "cr.flyte.org/flyteorg/flytekit:py3.13-openai-batch-",
6768
}
6869

6970

plugins/flytekit-sqlalchemy/flytekitplugins/sqlalchemy/task.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class SQLAlchemyDefaultImages(DefaultImages):
2626
PythonVersion.PYTHON_3_10: "cr.flyte.org/flyteorg/flytekit:py3.10-sqlalchemy-",
2727
PythonVersion.PYTHON_3_11: "cr.flyte.org/flyteorg/flytekit:py3.11-sqlalchemy-",
2828
PythonVersion.PYTHON_3_12: "cr.flyte.org/flyteorg/flytekit:py3.12-sqlalchemy-",
29+
PythonVersion.PYTHON_3_13: "cr.flyte.org/flyteorg/flytekit:py3.13-sqlalchemy-",
2930
}
3031

3132

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ authors = [{ name = "Flyte Contributors", email = "admin@flyte.org" }]
99
description = "Flyte SDK for Python"
1010
license = { text = "Apache-2.0" }
1111
readme = { file = "README.md", content-type = "text/markdown" }
12-
requires-python = ">=3.10,<3.13"
12+
requires-python = ">=3.10,<3.14"
1313
dependencies = [
1414
# Please maintain an alphabetical order in the following list
1515
"adlfs>=2023.3.0",
@@ -62,6 +62,7 @@ classifiers = [
6262
"Programming Language :: Python :: 3.10",
6363
"Programming Language :: Python :: 3.11",
6464
"Programming Language :: Python :: 3.12",
65+
"Programming Language :: Python :: 3.13",
6566
"Topic :: Scientific/Engineering",
6667
"Topic :: Scientific/Engineering :: Artificial Intelligence",
6768
"Topic :: Software Development",

0 commit comments

Comments
 (0)