def test_layer_instance_as_activation(self):
        """Tests serialization when activation is a Layer instance."""

        # Dense layer with ReLU layer as activation
        layer_dense_relu = keras.layers.Dense(
            units=4, activation=keras.layers.ReLU(name="my_relu")
        )
        # Build the layer to ensure weights/state are initialized if needed
        layer_dense_relu.build(input_shape=(None, 8))
        _, restored_dense_relu, _ = self.roundtrip(layer_dense_relu)

        # Verify the activation is correctly deserialized as a ReLU layer
        self.assertIsInstance(restored_dense_relu.activation, keras.layers.ReLU)
        # Verify properties are preserved
        self.assertEqual(restored_dense_relu.activation.name, "my_relu")
Tests serialization when activation is a Layer instance.
keras/src/saving/serialization_lib_test.py