Skip to content

Commit 5d24fb4

Browse files
support GPT-2 & enable tests
1 parent 248c6e4 commit 5d24fb4

29 files changed

+223
-21
lines changed

.github/workflows/actions.yml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
pip install --no-deps -e "." --progress-bar off
5454
if [[ "${{ matrix.backend }}" == "openvino" ]]; then
5555
pip uninstall -y keras
56-
pip install git+https://github.com/keras-team/keras.git@master --upgrade --force-reinstall --progress-bar off
56+
pip install git+https://github.com/Mohamed-Ashraf273/keras.git@gsoc2025 --upgrade --force-reinstall --progress-bar off
5757
fi
5858
- name: Pin Keras 3.5
5959
if: ${{ matrix.version == 'keras-3.5'}}
@@ -67,20 +67,17 @@ jobs:
6767
pip install keras-nightly --progress-bar off
6868
- name: Test with pytest
6969
run: |
70-
if [[ "${{ matrix.backend }}" == "openvino" ]]; then
71-
pytest keras_hub/src/models/gemma/gemma_causal_lm_test.py
70+
if [ "${{ matrix.backend }}" == "openvino" ]; then
71+
IGNORE_FILE="openvino_excluded_tests.txt"
72+
IGNORE_ARGS=$(awk '{print "--ignore=" $0}' "$IGNORE_FILE")
7273
else
73-
pytest keras_hub/
74+
IGNORE_ARGS=""
7475
fi
76+
pytest keras_hub/ $IGNORE_ARGS
7577
- name: Run integration tests
7678
run: |
7779
python pip_build.py --install
78-
cd integration_tests
79-
if [[ "${{ matrix.backend }}" == "openvino" ]]; then
80-
pytest . --ignore=basic_usage_test.py -k "not NoTensorflow"
81-
else
82-
pytest . -k "not NoTensorflow"
83-
fi
80+
cd integration_tests && pytest . -k "not NoTensorflow"
8481
- name: Run no tensorflow integration test
8582
if: ${{ matrix.backend != 'tensorflow'}}
8683
run: |

conftest.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import keras
44
import pytest
5+
from keras.src.backend import backend
56

67

78
def pytest_addoption(parser):
@@ -70,6 +71,10 @@ def pytest_configure(config):
7071
"markers",
7172
"kaggle_key_required: mark test needing a kaggle key",
7273
)
74+
config.addinivalue_line(
75+
"markers",
76+
"requires_trainable_backend: mark test for trainable backend only",
77+
)
7378

7479

7580
def pytest_collection_modifyitems(config, items):
@@ -110,6 +115,44 @@ def pytest_collection_modifyitems(config, items):
110115
if "kaggle_key_required" in item.keywords:
111116
item.add_marker(kaggle_key_required)
112117

118+
openvino_skipped_tests = []
119+
if backend() == "openvino":
120+
from pathlib import Path
121+
122+
workspace_root = Path(__file__).resolve().parents[0]
123+
file_path = workspace_root / "openvino_excluded_concrete_tests.txt"
124+
with open(file_path, "r") as file:
125+
openvino_skipped_tests = file.readlines()
126+
# it is necessary to check if stripped line is not empty
127+
# and exclude such lines
128+
openvino_skipped_tests = [
129+
line.strip() for line in openvino_skipped_tests if line.strip()
130+
]
131+
132+
requires_trainable_backend = pytest.mark.skipif(
133+
backend() in ["openvino"],
134+
reason="Trainer not implemented for OpenVINO backend.",
135+
)
136+
137+
for item in items:
138+
if "requires_trainable_backend" in item.keywords:
139+
item.add_marker(requires_trainable_backend)
140+
# also, skip concrete tests for openvino, listed in the special file
141+
# this is more granular mechanism to exclude tests rather
142+
# than using --ignore option
143+
for skipped_test in openvino_skipped_tests:
144+
if skipped_test in item.nodeid:
145+
item.add_marker(
146+
skip_if_backend(
147+
"openvino",
148+
"Not supported operation by openvino backend",
149+
)
150+
)
151+
152+
153+
def skip_if_backend(given_backend, reason):
154+
return pytest.mark.skipif(backend() == given_backend, reason=reason)
155+
113156

114157
# Disable traceback filtering for quicker debugging of tests failures.
115158
keras.config.disable_traceback_filtering()

integration_tests/basic_usage_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import keras_hub
77

88

9+
@unittest.skip("Skip for non-trainable backends like OpenVINO")
910
class BasicUsageTest(unittest.TestCase):
1011
def test_transformer(self):
1112
# Tokenize some inputs with a binary label.

keras_hub/src/layers/modeling/alibi_bias_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import keras
2+
import pytest
23
from keras import ops
34
from keras import random
45

@@ -7,6 +8,7 @@
78

89

910
class AlibiBiasTest(TestCase):
11+
@pytest.mark.requires_trainable_backend
1012
def test_layer_behaviors(self):
1113
alibi_bias_max = 8
1214
batch_size = 4

keras_hub/src/layers/modeling/anchor_generator_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
reason="Bbox utils are not supported before keras < 3.8.0",
1515
)
1616
class AnchorGeneratorTest(TestCase):
17+
@pytest.mark.requires_trainable_backend
1718
def test_layer_behaviors(self):
1819
images_shape = (8, 128, 128, 3)
1920
self.run_layer_test(

keras_hub/src/layers/modeling/cached_multi_head_attention_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pytest
12
from keras import ops
23
from keras import random
34

@@ -8,6 +9,7 @@
89

910

1011
class CachedMultiHeadAttentionTest(TestCase):
12+
@pytest.mark.requires_trainable_backend
1113
def test_layer_behaviors(self):
1214
self.run_layer_test(
1315
cls=CachedMultiHeadAttention,
@@ -75,6 +77,7 @@ def call(outputs, cache):
7577
self.assertAllClose(output, no_loop_outputs)
7678
self.assertAllClose(output_cache, no_loop_cache)
7779

80+
@pytest.mark.requires_trainable_backend
7881
def test_training_propagation(self):
7982
batch_size = 2
8083
seq_len = 5

keras_hub/src/layers/modeling/f_net_encoder_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pytest
12
from keras import ops
23
from keras import random
34

@@ -6,6 +7,7 @@
67

78

89
class FNetEncoderTest(TestCase):
10+
@pytest.mark.requires_trainable_backend
911
def test_layer_behaviors(self):
1012
self.run_layer_test(
1113
cls=FNetEncoder,
@@ -31,6 +33,7 @@ def test_value_error_when_invalid_kernel_initializer(self):
3133
kernel_initializer="Invalid",
3234
)
3335

36+
@pytest.mark.requires_trainable_backend
3437
def test_training_propagation(self):
3538
x = random.uniform(shape=(2, 4, 6))
3639
layer = FNetEncoder(

keras_hub/src/layers/modeling/masked_lm_head_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pytest
12
from keras import random
23

34
from keras_hub.src.layers.modeling.masked_lm_head import MaskedLMHead
@@ -8,6 +9,7 @@
89

910

1011
class MaskedLMHeadTest(TestCase):
12+
@pytest.mark.requires_trainable_backend
1113
def test_layer_behaviors(self):
1214
self.run_layer_test(
1315
cls=MaskedLMHead,

keras_hub/src/layers/modeling/position_embedding.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ def call(self, inputs, start_index=0):
103103
(start_index, 0),
104104
(sequence_length, feature_length),
105105
)
106+
if keras.config.backend() == "openvino":
107+
# Reshape to ensure we have the correct 2D shape after slicing
108+
position_embeddings = ops.reshape(
109+
position_embeddings, (sequence_length, feature_length)
110+
)
106111
return ops.broadcast_to(position_embeddings, shape)
107112

108113
def compute_output_shape(self, input_shape):

keras_hub/src/layers/modeling/position_embedding_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import keras
22
import numpy as np
3+
import pytest
34
from keras import ops
45
from keras import random
56

@@ -15,6 +16,7 @@ def custom_init(shape, dtype=None):
1516

1617

1718
class PositionEmbeddingTest(TestCase):
19+
@pytest.mark.requires_trainable_backend
1820
def test_layer_behaviors(self):
1921
self.run_layer_test(
2022
cls=PositionEmbedding,
@@ -26,6 +28,7 @@ def test_layer_behaviors(self):
2628
expected_num_trainable_weights=1,
2729
)
2830

31+
@pytest.mark.requires_trainable_backend
2932
def test_layer_behaviors_4d(self):
3033
self.run_layer_test(
3134
cls=PositionEmbedding,

0 commit comments

Comments
 (0)