Skip to content

Commit 736d581

Browse files
committed
Merge branch 'master' of https://github.com/pass-lin/keras
2 parents e6dd99f + 2730d52 commit 736d581

File tree

100 files changed

+5542
-1083
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+5542
-1083
lines changed

.github/workflows/actions.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ jobs:
5959
if [ "${{ matrix.nnx_enabled }}" == "true" ]; then
6060
pip install --upgrade flax>=0.11.1
6161
fi
62+
pip install --no-deps tf_keras==2.18.0
6263
pip uninstall -y keras keras-nightly
6364
pip install -e "." --progress-bar off --upgrade
6465
- name: Test applications with pytest
@@ -147,4 +148,4 @@ jobs:
147148
pip uninstall -y keras keras-nightly
148149
pip install -e "." --progress-bar off --upgrade
149150
- name: Run pre-commit
150-
run: pre-commit run --all-files --hook-stage manual
151+
run: pre-commit run --all-files --hook-stage manual

.github/workflows/nightly.yml

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Nightly
33
on:
44
workflow_dispatch: # To Generate wheels on demand outside of schedule.
55
schedule:
6-
- cron: '0 3 * * *' # run at 3 AM UTC / 8 PM PDT
6+
- cron: "0 3 * * *" # run at 3 AM UTC / 8 PM PDT
77

88
permissions:
99
contents: read
@@ -13,9 +13,9 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
python-version: ['3.10']
16+
python-version: ["3.10"]
1717
backend: [tensorflow, jax, torch, numpy]
18-
name: Run tests
18+
name: Run tests (Python ${{ matrix.python-version }})
1919
runs-on: ubuntu-latest
2020
env:
2121
PYTHON: ${{ matrix.python-version }}
@@ -57,6 +57,54 @@ jobs:
5757
run: |
5858
pytest keras --ignore keras/src/applications --cov=keras --cov-config=pyproject.toml
5959
60+
build-python-latest:
61+
strategy:
62+
fail-fast: false
63+
matrix:
64+
python-version: ["3.13"]
65+
backend: [tensorflow, jax, torch, numpy]
66+
name: Run tests (Python ${{ matrix.python-version }})
67+
runs-on: ubuntu-latest
68+
env:
69+
PYTHON: ${{ matrix.python-version }}
70+
KERAS_BACKEND: ${{ matrix.backend }}
71+
steps:
72+
- uses: actions/checkout@v5
73+
- name: Set up Python
74+
uses: actions/setup-python@v6
75+
with:
76+
python-version: ${{ matrix.python-version }}
77+
- name: Get pip cache dir
78+
id: pip-cache
79+
run: |
80+
python -m pip install --upgrade pip setuptools
81+
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
82+
- name: pip cache
83+
uses: actions/cache@v4
84+
with:
85+
path: ${{ steps.pip-cache.outputs.dir }}
86+
key: ${{ runner.os }}-pip-latest-${{ hashFiles('pyproject.toml') }}-${{ hashFiles('requirements.txt') }}
87+
- name: Install dependencies
88+
run: |
89+
pip install -r requirements.txt --progress-bar off --upgrade
90+
pip uninstall -y keras keras-nightly
91+
pip install -e "." --progress-bar off --upgrade
92+
- name: Test integrations
93+
if: ${{ matrix.backend != 'numpy'}}
94+
run: |
95+
python integration_tests/import_test.py
96+
- name: Test TF-specific integrations
97+
if: ${{ matrix.backend == 'tensorflow'}}
98+
run: |
99+
python integration_tests/tf_distribute_training_test.py
100+
- name: Test Torch-specific integrations
101+
if: ${{ matrix.backend == 'torch'}}
102+
run: |
103+
pytest integration_tests/torch_workflow_test.py
104+
- name: Test with pytest
105+
run: |
106+
pytest keras --ignore keras/src/applications --cov=keras --cov-config=pyproject.toml
107+
60108
format:
61109
name: Check the code format
62110
runs-on: ubuntu-latest
@@ -65,7 +113,7 @@ jobs:
65113
- name: Set up Python 3.10
66114
uses: actions/setup-python@v6
67115
with:
68-
python-version: '3.10'
116+
python-version: "3.10"
69117
- name: Get pip cache dir
70118
id: pip-cache
71119
run: |
@@ -84,17 +132,16 @@ jobs:
84132
- name: Run pre-commit
85133
run: pre-commit run --all-files --hook-stage manual
86134

87-
88135
nightly:
89136
name: Build Wheel file and upload
90-
needs: [build, format]
137+
needs: [build, build-python-latest, format]
91138
runs-on: ubuntu-latest
92139
steps:
93140
- uses: actions/checkout@v5
94141
- name: Set up Python
95142
uses: actions/setup-python@v6
96143
with:
97-
python-version: '3.10'
144+
python-version: "3.10"
98145
- name: Install dependencies
99146
run: |
100147
python -m pip install --upgrade pip setuptools

.github/workflows/scorecard.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ jobs:
4848
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
4949
# format to the repository Actions tab.
5050
- name: "Upload artifact"
51-
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
51+
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
5252
with:
5353
name: SARIF file
5454
path: results.sarif
5555
retention-days: 5
5656

5757
# Upload the results to GitHub's code scanning dashboard.
5858
- name: "Upload to code-scanning"
59-
uses: github/codeql-action/upload-sarif@3599b3baa15b485a2e49ef411a7a4bb2452e7f93 # v3.29.5
59+
uses: github/codeql-action/upload-sarif@0499de31b99561a6d14a36a5f662c2a54f91beee # v3.29.5
6060
with:
6161
sarif_file: results.sarif

.github/workflows/tpu_tests.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Keras Tests
2+
3+
# TODO: Consider enabling all tests (pytest, applications, etc.) with NNX in the future
4+
# Currently only basic flow tests run with NNX enabled
5+
6+
on:
7+
push:
8+
branches: [ master ]
9+
pull_request_review:
10+
types: [submitted]
11+
release:
12+
types: [created]
13+
14+
permissions:
15+
contents: read
16+
17+
jobs:
18+
19+
test-in-container:
20+
name: Run tests on TPU
21+
runs-on: linux-x86-ct6e-44-1tpu
22+
# Only run on approved PRs, pushes to master, or releases
23+
if: |
24+
github.event_name == 'push' ||
25+
github.event_name == 'release' ||
26+
(github.event_name == 'pull_request_review' && github.event.review.state == 'approved')
27+
28+
strategy:
29+
fail-fast: false
30+
matrix:
31+
backend: [jax]
32+
33+
container:
34+
image: python:3.10-slim
35+
options: --privileged --network host
36+
37+
steps:
38+
- name: Checkout Repository
39+
uses: actions/checkout@v4
40+
41+
- name: Install Dependencies
42+
run: |
43+
pip install --no-cache-dir -r requirements-${{ matrix.backend }}-tpu.txt \
44+
45+
- name: Set Keras Backend
46+
run: echo "KERAS_BACKEND=jax" >> $GITHUB_ENV
47+
48+
- name: Run Verification and Tests
49+
run: |
50+
echo "Successfully running inside the public python container!"
51+
echo "Verifying JAX installation..."
52+
python3 -c "import jax; print(f'JAX backend: {jax.default_backend()}'); print(f'JAX devices : {jax.devices()}')"
53+
54+
pytest keras --ignore keras/src/applications \
55+
--cov=keras \
56+
--cov-config=pyproject.toml

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ __pycache__
66
**/.vscode test/**
77
**/.vscode-smoke/**
88
**/.venv*/
9+
venv
910
bin/**
1011
build/**
1112
obj/**

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Contributions can be made in a variety of ways, including coding, enriching docu
44

55

66
## Current items open for contributions
7-
At [this link](https://github.com/keras-team/keras/issues/18442), you'll find a list of items where you help is needed!
7+
At [this link](https://github.com/keras-team/keras/issues/18442), you'll find a list of items where your help is needed!
88

99

1010
## How to contribute code

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ pip install keras --upgrade
2727

2828
2. Install backend package(s).
2929

30-
To use `keras`, you should also install the backend of choice: `tensorflow`, `jax`, or `torch`.
31-
Note that `tensorflow` is required for using certain Keras 3 features: certain preprocessing layers
32-
as well as `tf.data` pipelines.
30+
To use `keras`, you should also install the backend of choice: `tensorflow`, `jax`, or `torch`. Additionally,
31+
The `openvino` backend is available with support for model inference only.
3332

3433
### Local installation
3534

@@ -56,6 +55,17 @@ python pip_build.py --install
5655
./shell/api_gen.sh
5756
```
5857

58+
## Backend Compatibility Table
59+
60+
The following table lists the minimum supported versions of each backend for the latest stable release of Keras (v3.x):
61+
62+
| Backend | Minimum Supported Version |
63+
|------------|---------------------------|
64+
| TensorFlow | 2.16.1 |
65+
| JAX | 0.4.20 |
66+
| PyTorch | 2.1.0 |
67+
| OpenVINO | 2025.3.0 |
68+
5969
#### Adding GPU support
6070

6171
The `requirements.txt` file will install a CPU-only version of TensorFlow, JAX, and PyTorch. For GPU support, we also

conftest.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,21 @@ def pytest_collection_modifyitems(config, items):
3131
line.strip() for line in openvino_skipped_tests if line.strip()
3232
]
3333

34+
tpu_skipped_tests = []
35+
if backend() == "jax":
36+
try:
37+
with open(
38+
"keras/src/backend/jax/excluded_tpu_tests.txt", "r"
39+
) as file:
40+
tpu_skipped_tests = file.readlines()
41+
# it is necessary to check if stripped line is not empty
42+
# and exclude such lines
43+
tpu_skipped_tests = [
44+
line.strip() for line in tpu_skipped_tests if line.strip()
45+
]
46+
except FileNotFoundError:
47+
pass # File doesn't exist, no tests to skip
48+
3449
requires_trainable_backend = pytest.mark.skipif(
3550
backend() in ["numpy", "openvino"],
3651
reason="Trainer not implemented for NumPy and OpenVINO backend.",
@@ -49,6 +64,14 @@ def pytest_collection_modifyitems(config, items):
4964
"Not supported operation by openvino backend",
5065
)
5166
)
67+
# also, skip concrete tests for TPU when using JAX backend
68+
for skipped_test in tpu_skipped_tests:
69+
if skipped_test in item.nodeid:
70+
item.add_marker(
71+
pytest.mark.skip(
72+
reason="Known TPU test failure",
73+
)
74+
)
5275

5376

5477
def skip_if_backend(given_backend, reason):

keras/api/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from keras import config as config
1313
from keras import constraints as constraints
1414
from keras import datasets as datasets
15+
from keras import distillation as distillation
1516
from keras import distribution as distribution
1617
from keras import dtype_policies as dtype_policies
1718
from keras import export as export

keras/api/_tf_keras/keras/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from keras import config as config
1111
from keras import constraints as constraints
1212
from keras import datasets as datasets
13+
from keras import distillation as distillation
1314
from keras import distribution as distribution
1415
from keras import dtype_policies as dtype_policies
1516
from keras import export as export

0 commit comments

Comments
 (0)