Skip to content

Commit e0efbc8

Browse files
authored
Ditch Keras 2 support (#1658)
* Ditch Keras 2 * Try workaround for tf take_along_axis error * Remove dependencies
1 parent 001453d commit e0efbc8

File tree

243 files changed

+548
-831
lines changed

Some content is hidden

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

243 files changed

+548
-831
lines changed

.github/workflows/actions.yml

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,8 @@ permissions:
1111
contents: read
1212

1313
jobs:
14-
keras_2:
15-
name: Test the code with Keras 2
16-
runs-on: ubuntu-latest
17-
steps:
18-
- uses: actions/checkout@v4
19-
- name: Set up Python 3.9
20-
uses: actions/setup-python@v5
21-
with:
22-
python-version: 3.9
23-
- name: Get pip cache dir
24-
id: pip-cache
25-
run: |
26-
python -m pip install --upgrade pip setuptools
27-
echo "::set-output name=dir::$(pip cache dir)"
28-
- name: pip cache
29-
uses: actions/cache@v4
30-
with:
31-
path: ${{ steps.pip-cache.outputs.dir }}
32-
key: ${{ runner.os }}-pip-${{ hashFiles('setup.py') }}
33-
restore-keys: |
34-
${{ runner.os }}-pip-
35-
- name: Install dependencies
36-
run: |
37-
pip install -r requirements-common.txt --progress-bar off
38-
pip install tensorflow-text==2.14 tensorflow==2.14 keras-core
39-
pip install --no-deps -e "." --progress-bar off
40-
- name: Test with pytest
41-
run: |
42-
pytest --cov=keras_nlp --cov-report xml:coverage.xml keras_nlp/
43-
- name: Run integration tests
44-
run: |
45-
python pip_build.py --install && cd integration_tests && pytest .
46-
keras_3:
47-
name: Test the code with Keras 3
14+
run_tests:
15+
name: Test the code
4816
strategy:
4917
fail-fast: false
5018
matrix:

conftest.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
"The TensorFlow package is required for data preprocessing with any backend."
2525
)
2626

27-
from keras_nlp.src.backend import config as backend_config
28-
from keras_nlp.src.backend import keras
27+
import keras
2928

3029

3130
def pytest_addoption(parser):
@@ -59,7 +58,7 @@ def pytest_configure(config):
5958
# Verify that device has GPU and detected by backend
6059
if config.getoption("--check_gpu"):
6160
found_gpu = False
62-
backend = backend_config.backend()
61+
backend = keras.config.backend()
6362
if backend == "jax":
6463
import jax
6564

@@ -88,10 +87,6 @@ def pytest_configure(config):
8887
"markers",
8988
"tf_only: mark test as a tf only test",
9089
)
91-
config.addinivalue_line(
92-
"markers",
93-
"keras_3_only: mark test as a keras 3 only test",
94-
)
9590
config.addinivalue_line(
9691
"markers",
9792
"kaggle_key_required: mark test needing a kaggle key",
@@ -113,13 +108,9 @@ def pytest_collection_modifyitems(config, items):
113108
reason="need --run_extra_large option to run",
114109
)
115110
tf_only = pytest.mark.skipif(
116-
not backend_config.backend() == "tensorflow",
111+
not keras.config.backend() == "tensorflow",
117112
reason="tests only run on tf backend",
118113
)
119-
keras_3_only = pytest.mark.skipif(
120-
not backend_config.keras_3(),
121-
reason="tests only run on with multi-backend keras",
122-
)
123114
found_kaggle_key = all(
124115
[
125116
os.environ.get("KAGGLE_USERNAME", None),
@@ -137,13 +128,9 @@ def pytest_collection_modifyitems(config, items):
137128
item.add_marker(skip_extra_large)
138129
if "tf_only" in item.keywords:
139130
item.add_marker(tf_only)
140-
if "keras_3_only" in item.keywords:
141-
item.add_marker(keras_3_only)
142131
if "kaggle_key_required" in item.keywords:
143132
item.add_marker(kaggle_key_required)
144133

145134

146135
# Disable traceback filtering for quicker debugging of tests failures.
147-
tf.debugging.disable_traceback_filtering()
148-
if backend_config.keras_3():
149-
keras.config.disable_traceback_filtering()
136+
keras.config.disable_traceback_filtering()

keras_nlp/src/api_export.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import types
1616

17-
from keras_nlp.src.backend import keras
17+
import keras
1818

1919
try:
2020
import namex

keras_nlp/src/backend/__init__.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

keras_nlp/src/backend/config.py

Lines changed: 0 additions & 63 deletions
This file was deleted.

keras_nlp/src/backend/keras2.py

Lines changed: 0 additions & 42 deletions
This file was deleted.

keras_nlp/src/backend/ops.py

Lines changed: 0 additions & 43 deletions
This file was deleted.

keras_nlp/src/backend/random.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

keras_nlp/src/layers/modeling/alibi_bias.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
# limitations under the License.
1414
import math
1515

16+
import keras
17+
from keras import ops
18+
1619
from keras_nlp.src.api_export import keras_nlp_export
17-
from keras_nlp.src.backend import keras
18-
from keras_nlp.src.backend import ops
1920

2021

2122
@keras_nlp_export("keras_nlp.layers.AlibiBias")

keras_nlp/src/layers/modeling/alibi_bias_test.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from keras_nlp.src.backend import keras
16-
from keras_nlp.src.backend import ops
17-
from keras_nlp.src.backend import random
15+
import keras
16+
from keras import ops
17+
from keras import random
18+
1819
from keras_nlp.src.layers.modeling.alibi_bias import AlibiBias
1920
from keras_nlp.src.tests.test_case import TestCase
2021

keras_nlp/src/layers/modeling/cached_multi_head_attention.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import keras
16+
from keras import ops
17+
1518
from keras_nlp.src.api_export import keras_nlp_export
16-
from keras_nlp.src.backend import keras
17-
from keras_nlp.src.backend import ops
1819

1920

2021
@keras_nlp_export("keras_nlp.layers.CachedMultiHeadAttention")

keras_nlp/src/layers/modeling/cached_multi_head_attention_test.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from keras_nlp.src.backend import config
16-
from keras_nlp.src.backend import ops
17-
from keras_nlp.src.backend import random
15+
from keras import ops
16+
from keras import random
17+
1818
from keras_nlp.src.layers.modeling.cached_multi_head_attention import (
1919
CachedMultiHeadAttention,
2020
)
@@ -37,9 +37,6 @@ def test_layer_behaviors(self):
3737
expected_output_shape=(2, 4, 6),
3838
expected_num_trainable_weights=8,
3939
expected_num_non_trainable_variables=1,
40-
# Keras 2 does not handle mixed precision correctly when not set
41-
# globally.
42-
run_precision_checks=config.keras_3(),
4340
)
4441

4542
def test_cache_call_is_correct(self):

keras_nlp/src/layers/modeling/f_net_encoder.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import keras
16+
from keras import ops
17+
1518
from keras_nlp.src.api_export import keras_nlp_export
16-
from keras_nlp.src.backend import keras
17-
from keras_nlp.src.backend import ops
1819
from keras_nlp.src.utils.keras_utils import clone_initializer
1920

2021

0 commit comments

Comments
 (0)