Skip to content

Commit 65f75bb

Browse files
authored
Merging master with mlx (#21152)
1 parent d630199 commit 65f75bb

File tree

191 files changed

+8846
-1095
lines changed

Some content is hidden

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

191 files changed

+8846
-1095
lines changed

.github/workflows/actions.yml

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
strategy:
1616
fail-fast: false
1717
matrix:
18-
python-version: [3.9]
18+
python-version: [3.10]
1919
backend: [tensorflow, jax, torch, numpy, openvino, mlx]
2020
name: Run tests
2121
runs-on: ubuntu-latest
@@ -116,10 +116,10 @@ jobs:
116116
runs-on: ubuntu-latest
117117
steps:
118118
- uses: actions/checkout@v4
119-
- name: Set up Python 3.9
119+
- name: Set up Python 3.10
120120
uses: actions/setup-python@v5
121121
with:
122-
python-version: '3.9'
122+
python-version: '3.10'
123123
- name: Get pip cache dir
124124
id: pip-cache
125125
run: |
@@ -136,23 +136,7 @@ jobs:
136136
pip install -r requirements-openvino.txt --progress-bar off --upgrade
137137
pip uninstall -y keras keras-nightly
138138
pip install -e "." --progress-bar off --upgrade
139-
- name: Check for API changes
140-
run: |
141-
bash shell/api_gen.sh
142-
git status
143-
clean=$(git status | grep "nothing to commit")
144-
if [ -z "$clean" ]; then
145-
echo "Please run shell/api_gen.sh to generate API."
146-
exit 1
147-
fi
148-
- name: Lint
149-
run: bash shell/lint.sh
150-
- name: Check for API changes
151-
run: |
152-
bash shell/api_gen.sh
153-
git status
154-
clean=$(git status | grep "nothing to commit")
155-
if [ -z "$clean" ]; then
156-
echo "Please run shell/api_gen.sh to generate API."
157-
exit 1
158-
fi
139+
- name: Install pre-commit
140+
run: pip install pre-commit && pre-commit install
141+
- name: Run pre-commit
142+
run: pre-commit run --all-files --hook-stage manual

.github/workflows/nightly.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
python-version: [3.9]
16+
python-version: ['3.10']
1717
backend: [tensorflow, jax, torch, numpy]
1818
name: Run tests
1919
runs-on: ubuntu-latest
@@ -62,10 +62,10 @@ jobs:
6262
runs-on: ubuntu-latest
6363
steps:
6464
- uses: actions/checkout@v4
65-
- name: Set up Python 3.9
65+
- name: Set up Python 3.10
6666
uses: actions/setup-python@v5
6767
with:
68-
python-version: '3.9'
68+
python-version: '3.10'
6969
- name: Get pip cache dir
7070
id: pip-cache
7171
run: |
@@ -113,7 +113,7 @@ jobs:
113113
- name: Set up Python
114114
uses: actions/setup-python@v5
115115
with:
116-
python-version: 3.9
116+
python-version: '3.10'
117117
- name: Install dependencies
118118
run: |
119119
python -m pip install --upgrade pip setuptools

.github/workflows/scorecard.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
persist-credentials: false
3131

3232
- name: "Run analysis"
33-
uses: ossf/scorecard-action@62b2cac7ed8198b15735ed49ab1e5cf35480ba46 # v2.4.0
33+
uses: ossf/scorecard-action@f49aabe0b5af0936a0987cfb85d86b75731b0186 # v2.4.1
3434
with:
3535
results_file: results.sarif
3636
results_format: sarif
@@ -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@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
51+
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1
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@48ab28a6f5dbc2a99bf1e0131198dd8f1df78169 # v3.28.0
59+
uses: github/codeql-action/upload-sarif@b56ba49b26e50535fa1e7f7db0f4f7b4bf65d80d # v3.28.10
6060
with:
6161
sarif_file: results.sarif

.kokoro/github/ubuntu/gpu/build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ set -x
33

44
cd "${KOKORO_ROOT}/"
55

6-
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 1
6+
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1
77

8-
PYTHON_BINARY="/usr/bin/python3.9"
8+
PYTHON_BINARY="/usr/bin/python3.10"
99

1010
"${PYTHON_BINARY}" -m venv venv
1111
source venv/bin/activate

.pre-commit-config.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
repos:
2+
- repo: local
3+
hooks:
4+
- id: api-gen
5+
name: api_gen
6+
entry: |
7+
bash shell/api_gen.sh
8+
git status
9+
clean=$(git status | grep "nothing to commit")
10+
if [ -z "$clean" ]; then
11+
echo "Please run shell/api_gen.sh to generate API."
12+
exit 1
13+
fi
14+
language: system
15+
stages: [pre-commit, manual]
16+
require_serial: true
17+
- repo: https://github.com/astral-sh/ruff-pre-commit
18+
rev: v0.9.2
19+
hooks:
20+
- id: ruff
21+
args: [--config, pyproject.toml, --fix, .]
22+
stages: [pre-commit]
23+
- id: ruff-format
24+
args: [--config, pyproject.toml, .]
25+
stages: [pre-commit]
26+
- id: ruff
27+
args: [--config, pyproject.toml, .]
28+
stages: [manual]
29+
- id: ruff-format
30+
args: ["--check", --config, pyproject.toml, .]
31+
stages: [manual]

CONTRIBUTING.md

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,22 +107,35 @@ You can also add GPU support to your environment, see the
107107
[Adding GPU support](https://github.com/keras-team/keras/blob/master/README.md#adding-gpu-support)
108108
section of the README.
109109

110-
## Code style
110+
## Generating public API and formatting the code
111111

112-
Keras uses [Ruff](https://docs.astral.sh/ruff/) to format the code. Please refer to
113-
[requirements-common.txt](https://github.com/keras-team/keras/blob/master/requirements-common.txt)
114-
for the required versions. Run the following command **at the root directory of
115-
the repo** to format your code.
112+
For the first time you are setting up the repo, please run `pre-commit install`.
113+
Note that this needs to be done only once at the beginning.
114+
115+
Now, whenever you run `git commit -m "<message>"`, three things are
116+
automatically done:
117+
118+
- Public API generation
119+
- Code formatting
120+
- Code linting
121+
122+
If there's any error, the commit will not go through. Please fix the error (
123+
most of the times, the error is fixed automatically by the formatter/linter) and
124+
re-run the following:
116125

117126
```
118-
sh shell/format.sh
127+
git add .
128+
git commit -m "<message>" # This will not get logged as a duplicate commit.
119129
```
120130

121-
It will also display the errors that cannot be resolved by autoformatting. You
122-
need to follow the output of the command to resolve them manually.
131+
In case you want to run the above manually on all files, you can do the
132+
following:
133+
134+
```
135+
pre-commit run --all-files
136+
```
123137

124-
If you do not want to auto format the code but only show the lint errors, you
125-
can run `sh shell/lint.sh` **at the root directory of the repo**.
138+
KerasHub uses [Ruff](https://docs.astral.sh/ruff/) to format the code.
126139

127140
### Docstrings
128141

conftest.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,36 @@ def pytest_configure(config):
2525

2626

2727
def pytest_collection_modifyitems(config, items):
28+
openvino_skipped_tests = []
29+
if backend() == "openvino":
30+
with open(
31+
"keras/src/backend/openvino/excluded_concrete_tests.txt", "r"
32+
) as file:
33+
openvino_skipped_tests = file.readlines()
34+
# it is necessary to check if stripped line is not empty
35+
# and exclude such lines
36+
openvino_skipped_tests = [
37+
line.strip() for line in openvino_skipped_tests if line.strip()
38+
]
39+
2840
requires_trainable_backend = pytest.mark.skipif(
2941
backend() == "numpy" or backend() == "openvino",
3042
reason="Trainer not implemented for NumPy and OpenVINO backend.",
3143
)
3244
for item in items:
3345
if "requires_trainable_backend" in item.keywords:
3446
item.add_marker(requires_trainable_backend)
47+
# also, skip concrete tests for openvino, listed in the special file
48+
# this is more granular mechanism to exclude tests rather
49+
# than using --ignore option
50+
for skipped_test in openvino_skipped_tests:
51+
if skipped_test in item.nodeid:
52+
item.add_marker(
53+
skip_if_backend(
54+
"openvino",
55+
"Not supported operation by openvino backend",
56+
)
57+
)
3558

3659

3760
def skip_if_backend(given_backend, reason):

integration_tests/import_test.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
BACKEND_REQ = {
99
"tensorflow": ("tensorflow-cpu", ""),
1010
"torch": (
11-
"torch torchvision",
11+
"torch",
1212
"--extra-index-url https://download.pytorch.org/whl/cpu ",
1313
),
1414
"jax": ("jax[cpu]", ""),
@@ -29,11 +29,12 @@ def setup_package():
2929
whl_path = re.findall(
3030
r"[^\s]*\.whl",
3131
build_process.stdout,
32-
)[-1]
32+
)
3333
if not whl_path:
34+
print(build_process.stdout)
3435
print(build_process.stderr)
3536
raise ValueError("Installing Keras package unsuccessful. ")
36-
return whl_path
37+
return whl_path[-1]
3738

3839

3940
def create_virtualenv():

keras/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from keras.api import Optimizer
1515
from keras.api import Quantizer
1616
from keras.api import Regularizer
17+
from keras.api import RematScope
1718
from keras.api import Sequential
1819
from keras.api import StatelessScope
1920
from keras.api import SymbolicScope
@@ -44,6 +45,7 @@
4445
from keras.api import quantizers
4546
from keras.api import random
4647
from keras.api import regularizers
48+
from keras.api import remat
4749
from keras.api import saving
4850
from keras.api import tree
4951
from keras.api import utils

keras/api/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
from keras.src.backend import device
3838
from keras.src.backend import name_scope
3939
from keras.src.backend.common.keras_tensor import KerasTensor
40+
from keras.src.backend.common.remat import RematScope
41+
from keras.src.backend.common.remat import remat
4042
from keras.src.backend.common.stateless_scope import StatelessScope
4143
from keras.src.backend.common.symbolic_scope import SymbolicScope
4244
from keras.src.dtype_policies.dtype_policy import DTypePolicy

0 commit comments

Comments
 (0)