Skip to content

Commit 38a714c

Browse files
Fix GPU CI (#20637)
* Fix GPU CI * Fix dtype issue * Remove duplicate tests
1 parent 90d36dc commit 38a714c

File tree

4 files changed

+17
-62
lines changed

4 files changed

+17
-62
lines changed

keras/src/layers/preprocessing/image_preprocessing/bounding_boxes/bounding_box.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -419,11 +419,11 @@ def _compute_inverse_affine_matrix(
419419
shear_x = -shear_x
420420
shear_y = -shear_y
421421

422-
cx = center_x * (width - 1)
423-
cy = center_y * (height - 1)
422+
cx = ops.numpy.multiply(center_x, (width - 1))
423+
cy = ops.numpy.multiply(center_y, (height - 1))
424424
rot = ops.numpy.multiply(angle, 1.0 / 180.0 * math.pi)
425-
tx = -translate_x * (width - 1)
426-
ty = -translate_y * (height - 1)
425+
tx = ops.numpy.multiply(-translate_x, (width - 1))
426+
ty = ops.numpy.multiply(-translate_y, (height - 1))
427427
sx = ops.numpy.multiply(shear_x, 1.0 / 180.0 * math.pi)
428428
sy = ops.numpy.multiply(shear_y, 1.0 / 180.0 * math.pi)
429429

@@ -442,10 +442,10 @@ def _compute_inverse_affine_matrix(
442442

443443
# Inverted rotation matrix with scale and shear
444444
# det([[a, b], [c, d]]) == 1, since det(rotation) = 1 and det(shear) = 1
445-
a0 = d * scale
446-
a1 = -b * scale
447-
b0 = -c * scale
448-
b1 = a * scale
445+
a0 = ops.numpy.multiply(d, scale)
446+
a1 = ops.numpy.multiply(-b, scale)
447+
b0 = ops.numpy.multiply(-c, scale)
448+
b1 = ops.numpy.multiply(a, scale)
449449
a2 = cx - a0 * cx_plus_tx - a1 * cy_plus_ty
450450
b2 = cy - b0 * cx_plus_tx - b1 * cy_plus_ty
451451

keras/src/layers/preprocessing/image_preprocessing/bounding_boxes/converters_test.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def setUp(self):
4545
[[[0.01, 0.02, 0.1, 0.1], [0.02, 0.03, 0.1, 0.1]]], dtype="float32"
4646
)
4747

48-
self.images = np.ones([2, 1000, 1000, 3])
48+
self.images = np.ones([2, 1000, 1000, 3], dtype="float32")
4949
self.height = 1000
5050
self.width = 1000
5151

@@ -131,12 +131,12 @@ def test_affine_identity(self):
131131
batch_size = self.boxes["xyxy"].shape[0]
132132
transformed_boxes = affine_transform(
133133
boxes=self.boxes["xyxy"],
134-
angle=np.zeros([batch_size]),
135-
translate_x=np.zeros([batch_size]),
136-
translate_y=np.zeros([batch_size]),
137-
scale=np.ones([batch_size]),
138-
shear_x=np.zeros([batch_size]),
139-
shear_y=np.zeros([batch_size]),
134+
angle=np.zeros([batch_size], dtype="float32"),
135+
translate_x=np.zeros([batch_size], dtype="float32"),
136+
translate_y=np.zeros([batch_size], dtype="float32"),
137+
scale=np.ones([batch_size], dtype="float32"),
138+
shear_x=np.zeros([batch_size], dtype="float32"),
139+
shear_y=np.zeros([batch_size], dtype="float32"),
140140
height=self.height,
141141
width=self.width,
142142
)

keras/src/layers/preprocessing/image_preprocessing/mix_up_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ def test_layer(self):
1717
input_shape=(8, 3, 4, 3),
1818
supports_masking=False,
1919
expected_output_shape=(8, 3, 4, 3),
20+
# StatelessRandomGammaV3 is not supported on XLA_GPU_JIT
21+
run_training_check=not testing.tensorflow_uses_gpu(),
2022
)
2123

2224
def test_mix_up_basic_functionality(self):

keras/src/trainers/trainer_test.py

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2745,50 +2745,3 @@ def predict_step(self, *args):
27452745
verbose=0,
27462746
)
27472747
self.assertLessEqual(tracing_count[0], 2)
2748-
2749-
2750-
class TrainerDistributeTest(testing.TestCase):
2751-
@pytest.mark.skipif(
2752-
backend.backend() != "tensorflow", reason="Requires tf.distribute"
2753-
)
2754-
def test_end_to_end_tf_distribute(self):
2755-
import tensorflow as tf
2756-
from tensorflow.python.eager import context
2757-
2758-
context._reset_context()
2759-
cpus = tf.config.list_physical_devices("CPU")
2760-
tf.config.set_logical_device_configuration(
2761-
cpus[0],
2762-
[
2763-
tf.config.LogicalDeviceConfiguration(),
2764-
tf.config.LogicalDeviceConfiguration(),
2765-
],
2766-
)
2767-
strategy = tf.distribute.MirroredStrategy(["CPU:0", "CPU:1"])
2768-
with strategy.scope():
2769-
model = keras.Sequential(
2770-
[
2771-
keras.Input((2,)),
2772-
keras.layers.Dense(
2773-
2,
2774-
activation="softmax",
2775-
use_bias=False,
2776-
kernel_initializer="ones",
2777-
),
2778-
]
2779-
)
2780-
model.compile(
2781-
optimizer="sgd",
2782-
loss="sparse_categorical_crossentropy",
2783-
metrics=["sparse_categorical_accuracy"],
2784-
)
2785-
x = (np.arange(512) / 128).reshape((256, 2))
2786-
y = (np.arange(256) % 2).reshape((256, 1))
2787-
out_fit = model.fit(x, y)
2788-
self.assertLess(out_fit.history["sparse_categorical_accuracy"][0], 0.6)
2789-
out_eval = model.evaluate(x, y)
2790-
self.assertLess(out_eval[1], 0.6)
2791-
out_predict = model.predict(x)
2792-
self.assertEqual(out_predict.shape, (256, 2))
2793-
2794-
context._reset_context()

0 commit comments

Comments
 (0)