-
Notifications
You must be signed in to change notification settings - Fork 19.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration tests to CI (#18513)
* 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
Showing
5 changed files
with
46 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |