Skip to content

Commit

Permalink
Add integration tests to CI (#18513)
Browse files Browse the repository at this point in the history
* Port over changes from Keras Core PR

* Rename, remove space

* Remove Keras Core refs

* Fix formatting

* Simplify basic flow

* Remove flags

* Remove flags

* Add integration tests to CI

* Remove invalid syntax

* Fix test command with directory

* Remove visualization test from CI

* Delete obsolete test, merge into new torch workflow test

* Fix multiple if

* Fix workflow syntax

* fix formatting

* Fix imports

* Remove numpy backend from integration testing
  • Loading branch information
nkovela1 authored Sep 28, 2023
1 parent 1537470 commit fab88ec
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 125 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ jobs:
flags: keras.applications,keras.applications-${{ matrix.backend }}
files: apps-coverage.xml
fail_ci_if_error: true
- name: Test integrations
if: ${{ matrix.backend != 'numpy'}}
run: |
python integration_tests/import_test.py
- name: Test TF-specific integrations
if: ${{ matrix.backend == 'tensorflow'}}
run: |
python integration_tests/tf_distribute_training_test.py
- name: Test Torch-specific integrations
if: ${{ matrix.backend == 'torch'}}
run: |
pytest integration_tests/torch_workflow_test.py
- name: Test with pytest
run: |
pytest keras --ignore keras/applications --cov=keras
Expand Down
31 changes: 0 additions & 31 deletions integration_tests/layer_in_torch_workflow.py

This file was deleted.

94 changes: 0 additions & 94 deletions integration_tests/torch_backend_keras_workflow.py

This file was deleted.

34 changes: 34 additions & 0 deletions integration_tests/torch_workflow_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import torch

from keras import layers
from keras import testing
from keras.backend.common import KerasVariable


class Net(torch.nn.Module):
def __init__(self):
super().__init__()
self.fc1 = layers.Dense(1)

def forward(self, x):
x = self.fc1(x)
return x


class TorchWorkflowTest(testing.TestCase):
def test_keras_layer_in_nn_module(self):
net = Net()

# Test using Keras layer in a nn.Module.
# Test forward pass
self.assertAllEqual(list(net(torch.empty(100, 10)).shape), [100, 1])
# Test KerasVariables are added as nn.Parameter.
self.assertLen(list(net.parameters()), 2)

# Test using KerasVariable as a torch tensor for torch ops.
kernel = net.fc1.kernel
transposed_kernel = torch.transpose(kernel, 0, 1)
self.assertIsInstance(kernel, KerasVariable)
self.assertIsInstance(
torch.mul(kernel, transposed_kernel), torch.Tensor
)

0 comments on commit fab88ec

Please sign in to comment.