|
21 | 21 | from tensorflow.compiler.plugin.poplar.tests import test_utils as tu |
22 | 22 | from tensorflow.python import ipu |
23 | 23 | from tensorflow.python import keras |
24 | | -from tensorflow.python.data.ops import dataset_ops |
25 | | -from tensorflow.python.eager import backprop |
26 | | -from tensorflow.python.eager import def_function |
27 | 24 | from tensorflow.python.framework import ops |
28 | 25 | from tensorflow.python.framework import test_util |
29 | 26 | from tensorflow.python.framework import dtypes |
|
36 | 33 | from tensorflow.python.ops import init_ops |
37 | 34 | from tensorflow.python.ops import math_ops |
38 | 35 | from tensorflow.python.ops import nn |
39 | | -from tensorflow.python.ops import random_ops |
40 | 36 | from tensorflow.python.ops import variable_scope |
41 | 37 | from tensorflow.python.ops import variables |
42 | 38 | from tensorflow.python.platform import googletest |
@@ -735,68 +731,6 @@ def testPipelineFirstLargeConstant(self): |
735 | 731 | expected_value = model.predict(input_data, batch_size=1) |
736 | 732 | self.assertAllClose(expected_value, actual_value, atol=1e-05) |
737 | 733 |
|
738 | | - def testOutlinedFunctionInFunction(self): |
739 | | - @ipu.outlined_function |
740 | | - def identity(x): |
741 | | - return x |
742 | | - |
743 | | - @def_function.function(experimental_compile=True) |
744 | | - def f(x): |
745 | | - with backprop.GradientTape() as tape: |
746 | | - tape.watch(x) |
747 | | - z = identity(x) |
748 | | - return tape.gradient(z, x) |
749 | | - |
750 | | - config = ipu.config.IPUConfig() |
751 | | - config.configure_ipu_system() |
752 | | - strategy = ipu.ipu_strategy.IPUStrategy() |
753 | | - |
754 | | - with strategy.scope(): |
755 | | - x = random_ops.random_normal((1, 10)) |
756 | | - dfdx = strategy.run(f, [x]) |
757 | | - self.assertAllEqual(dfdx, np.ones((1, 10))) |
758 | | - |
759 | | - def testKerasCustomLayerWithOutlinedFunction(self): |
760 | | - class CustomLayer(keras.layers.Layer): |
761 | | - def __init__(self, **kwargs): |
762 | | - self.dense = keras.layers.Dense(units=4) |
763 | | - super().__init__(**kwargs) |
764 | | - |
765 | | - def build(self, input_shape): |
766 | | - self.dense.build(input_shape) |
767 | | - super().build(input_shape) |
768 | | - |
769 | | - def call(self, inputs): # pylint: disable=arguments-differ |
770 | | - @ipu.outlined_function |
771 | | - def inner_call(): |
772 | | - y = self.dense(inputs) |
773 | | - return y |
774 | | - |
775 | | - return inner_call() |
776 | | - |
777 | | - # Configure the IPU device. |
778 | | - config = ipu.config.IPUConfig() |
779 | | - config.auto_select_ipus = 1 |
780 | | - config.configure_ipu_system() |
781 | | - |
782 | | - micro_batch_size = 4 |
783 | | - ds = dataset_ops.Dataset.from_tensor_slices( |
784 | | - ([1.] * micro_batch_size * 4, [2.] * micro_batch_size * 4)) |
785 | | - ds = ds.batch(micro_batch_size, drop_remainder=True) |
786 | | - |
787 | | - strategy = ipu.ipu_strategy.IPUStrategy() |
788 | | - |
789 | | - with strategy.scope(): |
790 | | - # Functional model |
791 | | - input_layer = keras.Input(shape=1, batch_size=micro_batch_size) |
792 | | - x = CustomLayer()(input_layer) |
793 | | - model = keras.Model(input_layer, x) |
794 | | - |
795 | | - model.compile(optimizer="sgd", |
796 | | - loss=keras.losses.SparseCategoricalCrossentropy()) |
797 | | - |
798 | | - model.fit(ds, batch_size=micro_batch_size) |
799 | | - |
800 | 734 |
|
801 | 735 | if __name__ == "__main__": |
802 | 736 | googletest.main() |
0 commit comments