We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Torch GPU test failures
Install PyTorch via - 
```
conda install pytorch torchvision pytorch-cuda=11.8 -c pytorch -c nvidia
```

We still have to install TF (for tf.data) and JAX (for import - though this could be avoided) in the environment via - 
```
pip install tensorflow_cpu
pip install jax[cpu]
```

Test via -
```
 KERAS_BACKEND=torch pytest keras_core --ignore keras_core/applications
```
Result summary:
```
FAILED keras_core/layers/convolutional/conv_test.py::ConvCorrectnessTest::test_conv3d0 - AssertionError:
FAILED keras_core/layers/convolutional/conv_test.py::ConvCorrectnessTest::test_conv3d1 - AssertionError:
FAILED keras_core/layers/convolutional/conv_transpose_test.py::ConvTransposeCorrectnessTest::test_conv3d_transpose2 - AssertionError:
FAILED keras_core/layers/preprocessing/random_brightness_test.py::RandomBrightnessTest::test_tf_data_compatibility - TypeError: in user code:
FAILED keras_core/layers/preprocessing/random_contrast_test.py::RandomContrastTest::test_tf_data_compatibility - TypeError: in user code:
```

ConvCorrectnessTest, ConvTransposeCorrectnessTest - Failed due to mismatch in test array values.
Preprpcoessing RandomBrightnessTest, RandomContrastTest failed on `numpy()` being calld on GPU tensor.  It needs to be `cpu().numpy()` for torch.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `keras_core/layers/preprocessing/tf_data_layer.py`
Content:
```
1 from tensorflow import nest
2 
3 from keras_core import backend
4 from keras_core.layers.layer import Layer
5 from keras_core.random.seed_generator import SeedGenerator
6 from keras_core.utils import backend_utils
7 from keras_core.utils import tracking
8 
9 
10 class TFDataLayer(Layer):
11     """Layer that can safely used in a tf.data pipeline.
12 
13     The `call()` method must solely rely on `self.backend` ops.
14 
15     Only supports a single input tensor argument.
16     """
17 
18     def __init__(self, **kwargs):
19         super().__init__(**kwargs)
20         self.backend = backend_utils.DynamicBackend()
21         self._allow_non_tensor_positional_args = True
22 
23     def __call__(self, inputs, **kwargs):
24         if backend_utils.in_tf_graph() and not isinstance(
25             inputs, backend.KerasTensor
26         ):
27             # We're in a TF graph, e.g. a tf.data pipeline.
28             self.backend.set_backend("tensorflow")
29             inputs = nest.map_structure(
30                 lambda x: self.backend.convert_to_tensor(
31                     x, dtype=self.compute_dtype
32                 ),
33                 inputs,
34             )
35             switch_convert_input_args = False
36             if self._convert_input_args:
37                 self._convert_input_args = False
38                 switch_convert_input_args = True
39             try:
40                 outputs = super().__call__(inputs, **kwargs)
41             finally:
42                 self.backend.reset()
43                 if switch_convert_input_args:
44                     self._convert_input_args = True
45             return outputs
46         return super().__call__(inputs, **kwargs)
47 
48     @tracking.no_automatic_dependency_tracking
49     def _get_seed_generator(self, backend=None):
50         if backend is None or backend == self.backend._backend:
51             return self.generator
52         if not hasattr(self, "_backend_generators"):
53             self._backend_generators = {}
54         if backend in self._backend_generators:
55             return self._backend_generators[backend]
56         seed_generator = SeedGenerator(self.seed, backend=self.backend)
57         self._backend_generators[backend] = seed_generator
58         return seed_generator
59
```

Path: `keras_core/random/seed_generator.py`
Content:
```
1 import random as python_random
2 
3 import numpy as np
4 
5 from keras_core.api_export import keras_core_export
6 
7 
8 @keras_core_export("keras_core.random.SeedGenerator")
9 class SeedGenerator:
10     """Generates variable seeds upon each call to a RNG-using function.
11 
12     In Keras, all RNG-using methods (such as `keras_core.random.normal()`)
13     are stateless, meaning that if you pass an integer seed to them
14     (such as `seed=42`), they will return the same values at each call.
15     In order to get different values at each call, you must use a
16     `SeedGenerator` instead as the seed argument. The `SeedGenerator`
17     instead is stateful.
18 
19     Example:
20 
21     ```python
22     seed_gen = keras_core.random.SeedGenerator(seed=42)
23     values = keras_core.random.normal(shape=(2, 3), seed=seed_gen)
24     new_values = keras_core.random.normal(shape=(2, 3), seed=seed_gen)
25     ```
26     """
27 
28     def __init__(self, seed, **kwargs):
29         custom_backend = kwargs.pop("backend", None)
30         if kwargs:
31             raise ValueError(f"Unrecognized keyword arguments: {kwargs}")
32         if custom_backend is not None:
33             backend = custom_backend
34         else:
35             from keras_core import backend
36 
37         if seed is None:
38             seed = make_default_seed()
39         if not isinstance(seed, int):
40             raise ValueError(
41                 "Argument `seed` must be an integer. " f"Received: seed={seed}"
42             )
43 
44         def seed_initializer(*args, **kwargs):
45             dtype = kwargs.get("dtype", None)
46             return backend.convert_to_tensor([seed, 0], dtype=dtype)
47 
48         self.state = backend.Variable(
49             seed_initializer,
50             shape=(2,),
51             dtype="uint32",
52             trainable=False,
53             name="seed_generator_state",
54         )
55 
56 
57 def make_default_seed():
58     return python_random.randint(1, int(1e9))
59 
60 
61 def draw_seed(seed):
62     from keras_core.backend import convert_to_tensor
63 
64     if isinstance(seed, SeedGenerator):
65         seed_state = seed.state
66         # Use * 1 to create a copy
67         new_seed_value = seed_state.value * 1
68         increment = convert_to_tensor(np.array([0, 1]), dtype="uint32")
69         seed.state.assign(seed_state + increment)
70         return new_seed_value
71     elif isinstance(seed, int):
72         return convert_to_tensor([seed, 0], dtype="uint32")
73     elif seed is None:
74         return convert_to_tensor([make_default_seed(), 0], dtype="uint32")
75     raise ValueError(
76         "Argument `seed` must be either an integer "
77         "or an instance of `SeedGenerator`. "
78         f"Received: seed={seed} (of type {type(seed)})"
79     )
80
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/keras_core/layers/preprocessing/tf_data_layer.py b/keras_core/layers/preprocessing/tf_data_layer.py
--- a/keras_core/layers/preprocessing/tf_data_layer.py
+++ b/keras_core/layers/preprocessing/tf_data_layer.py
@@ -1,6 +1,6 @@
 from tensorflow import nest
 
-from keras_core import backend
+import keras_core.backend
 from keras_core.layers.layer import Layer
 from keras_core.random.seed_generator import SeedGenerator
 from keras_core.utils import backend_utils
@@ -22,7 +22,7 @@
 
     def __call__(self, inputs, **kwargs):
         if backend_utils.in_tf_graph() and not isinstance(
-            inputs, backend.KerasTensor
+            inputs, keras_core.backend.KerasTensor
         ):
             # We're in a TF graph, e.g. a tf.data pipeline.
             self.backend.set_backend("tensorflow")
@@ -47,7 +47,7 @@
 
     @tracking.no_automatic_dependency_tracking
     def _get_seed_generator(self, backend=None):
-        if backend is None or backend == self.backend._backend:
+        if backend is None or backend == keras_core.backend.backend():
             return self.generator
         if not hasattr(self, "_backend_generators"):
             self._backend_generators = {}
diff --git a/keras_core/random/seed_generator.py b/keras_core/random/seed_generator.py
--- a/keras_core/random/seed_generator.py
+++ b/keras_core/random/seed_generator.py
@@ -2,6 +2,7 @@
 
 import numpy as np
 
+import keras_core.backend
 from keras_core.api_export import keras_core_export
 
 
@@ -30,9 +31,9 @@
         if kwargs:
             raise ValueError(f"Unrecognized keyword arguments: {kwargs}")
         if custom_backend is not None:
-            backend = custom_backend
+            self.backend = custom_backend
         else:
-            from keras_core import backend
+            self.backend = keras_core.backend
 
         if seed is None:
             seed = make_default_seed()
@@ -43,9 +44,9 @@
 
         def seed_initializer(*args, **kwargs):
             dtype = kwargs.get("dtype", None)
-            return backend.convert_to_tensor([seed, 0], dtype=dtype)
+            return self.backend.convert_to_tensor([seed, 0], dtype=dtype)
 
-        self.state = backend.Variable(
+        self.state = self.backend.Variable(
             seed_initializer,
             shape=(2,),
             dtype="uint32",
@@ -65,7 +66,9 @@
         seed_state = seed.state
         # Use * 1 to create a copy
         new_seed_value = seed_state.value * 1
-        increment = convert_to_tensor(np.array([0, 1]), dtype="uint32")
+        increment = seed.backend.convert_to_tensor(
+            np.array([0, 1]), dtype="uint32"
+        )
         seed.state.assign(seed_state + increment)
         return new_seed_value
     elif isinstance(seed, int):

{"golden_diff": "diff --git a/keras_core/layers/preprocessing/tf_data_layer.py b/keras_core/layers/preprocessing/tf_data_layer.py\n--- a/keras_core/layers/preprocessing/tf_data_layer.py\n+++ b/keras_core/layers/preprocessing/tf_data_layer.py\n@@ -1,6 +1,6 @@\n from tensorflow import nest\n \n-from keras_core import backend\n+import keras_core.backend\n from keras_core.layers.layer import Layer\n from keras_core.random.seed_generator import SeedGenerator\n from keras_core.utils import backend_utils\n@@ -22,7 +22,7 @@\n \n     def __call__(self, inputs, **kwargs):\n         if backend_utils.in_tf_graph() and not isinstance(\n-            inputs, backend.KerasTensor\n+            inputs, keras_core.backend.KerasTensor\n         ):\n             # We're in a TF graph, e.g. a tf.data pipeline.\n             self.backend.set_backend(\"tensorflow\")\n@@ -47,7 +47,7 @@\n \n     @tracking.no_automatic_dependency_tracking\n     def _get_seed_generator(self, backend=None):\n-        if backend is None or backend == self.backend._backend:\n+        if backend is None or backend == keras_core.backend.backend():\n             return self.generator\n         if not hasattr(self, \"_backend_generators\"):\n             self._backend_generators = {}\ndiff --git a/keras_core/random/seed_generator.py b/keras_core/random/seed_generator.py\n--- a/keras_core/random/seed_generator.py\n+++ b/keras_core/random/seed_generator.py\n@@ -2,6 +2,7 @@\n \n import numpy as np\n \n+import keras_core.backend\n from keras_core.api_export import keras_core_export\n \n \n@@ -30,9 +31,9 @@\n         if kwargs:\n             raise ValueError(f\"Unrecognized keyword arguments: {kwargs}\")\n         if custom_backend is not None:\n-            backend = custom_backend\n+            self.backend = custom_backend\n         else:\n-            from keras_core import backend\n+            self.backend = keras_core.backend\n \n         if seed is None:\n             seed = make_default_seed()\n@@ -43,9 +44,9 @@\n \n         def seed_initializer(*args, **kwargs):\n             dtype = kwargs.get(\"dtype\", None)\n-            return backend.convert_to_tensor([seed, 0], dtype=dtype)\n+            return self.backend.convert_to_tensor([seed, 0], dtype=dtype)\n \n-        self.state = backend.Variable(\n+        self.state = self.backend.Variable(\n             seed_initializer,\n             shape=(2,),\n             dtype=\"uint32\",\n@@ -65,7 +66,9 @@\n         seed_state = seed.state\n         # Use * 1 to create a copy\n         new_seed_value = seed_state.value * 1\n-        increment = convert_to_tensor(np.array([0, 1]), dtype=\"uint32\")\n+        increment = seed.backend.convert_to_tensor(\n+            np.array([0, 1]), dtype=\"uint32\"\n+        )\n         seed.state.assign(seed_state + increment)\n         return new_seed_value\n     elif isinstance(seed, int):\n", "issue": "Torch GPU test failures\nInstall PyTorch via - \r\n```\r\nconda install pytorch torchvision pytorch-cuda=11.8 -c pytorch -c nvidia\r\n```\r\n\r\nWe still have to install TF (for tf.data) and JAX (for import - though this could be avoided) in the environment via - \r\n```\r\npip install tensorflow_cpu\r\npip install jax[cpu]\r\n```\r\n\r\nTest via -\r\n```\r\n KERAS_BACKEND=torch pytest keras_core --ignore keras_core/applications\r\n```\r\nResult summary:\r\n```\r\nFAILED keras_core/layers/convolutional/conv_test.py::ConvCorrectnessTest::test_conv3d0 - AssertionError:\r\nFAILED keras_core/layers/convolutional/conv_test.py::ConvCorrectnessTest::test_conv3d1 - AssertionError:\r\nFAILED keras_core/layers/convolutional/conv_transpose_test.py::ConvTransposeCorrectnessTest::test_conv3d_transpose2 - AssertionError:\r\nFAILED keras_core/layers/preprocessing/random_brightness_test.py::RandomBrightnessTest::test_tf_data_compatibility - TypeError: in user code:\r\nFAILED keras_core/layers/preprocessing/random_contrast_test.py::RandomContrastTest::test_tf_data_compatibility - TypeError: in user code:\r\n```\r\n\r\nConvCorrectnessTest, ConvTransposeCorrectnessTest - Failed due to mismatch in test array values.\r\nPreprpcoessing RandomBrightnessTest, RandomContrastTest failed on `numpy()` being calld on GPU tensor.  It needs to be `cpu().numpy()` for torch.\n", "before_files": [{"content": "from tensorflow import nest\n\nfrom keras_core import backend\nfrom keras_core.layers.layer import Layer\nfrom keras_core.random.seed_generator import SeedGenerator\nfrom keras_core.utils import backend_utils\nfrom keras_core.utils import tracking\n\n\nclass TFDataLayer(Layer):\n    \"\"\"Layer that can safely used in a tf.data pipeline.\n\n    The `call()` method must solely rely on `self.backend` ops.\n\n    Only supports a single input tensor argument.\n    \"\"\"\n\n    def __init__(self, **kwargs):\n        super().__init__(**kwargs)\n        self.backend = backend_utils.DynamicBackend()\n        self._allow_non_tensor_positional_args = True\n\n    def __call__(self, inputs, **kwargs):\n        if backend_utils.in_tf_graph() and not isinstance(\n            inputs, backend.KerasTensor\n        ):\n            # We're in a TF graph, e.g. a tf.data pipeline.\n            self.backend.set_backend(\"tensorflow\")\n            inputs = nest.map_structure(\n                lambda x: self.backend.convert_to_tensor(\n                    x, dtype=self.compute_dtype\n                ),\n                inputs,\n            )\n            switch_convert_input_args = False\n            if self._convert_input_args:\n                self._convert_input_args = False\n                switch_convert_input_args = True\n            try:\n                outputs = super().__call__(inputs, **kwargs)\n            finally:\n                self.backend.reset()\n                if switch_convert_input_args:\n                    self._convert_input_args = True\n            return outputs\n        return super().__call__(inputs, **kwargs)\n\n    @tracking.no_automatic_dependency_tracking\n    def _get_seed_generator(self, backend=None):\n        if backend is None or backend == self.backend._backend:\n            return self.generator\n        if not hasattr(self, \"_backend_generators\"):\n            self._backend_generators = {}\n        if backend in self._backend_generators:\n            return self._backend_generators[backend]\n        seed_generator = SeedGenerator(self.seed, backend=self.backend)\n        self._backend_generators[backend] = seed_generator\n        return seed_generator\n", "path": "keras_core/layers/preprocessing/tf_data_layer.py"}, {"content": "import random as python_random\n\nimport numpy as np\n\nfrom keras_core.api_export import keras_core_export\n\n\n@keras_core_export(\"keras_core.random.SeedGenerator\")\nclass SeedGenerator:\n    \"\"\"Generates variable seeds upon each call to a RNG-using function.\n\n    In Keras, all RNG-using methods (such as `keras_core.random.normal()`)\n    are stateless, meaning that if you pass an integer seed to them\n    (such as `seed=42`), they will return the same values at each call.\n    In order to get different values at each call, you must use a\n    `SeedGenerator` instead as the seed argument. The `SeedGenerator`\n    instead is stateful.\n\n    Example:\n\n    ```python\n    seed_gen = keras_core.random.SeedGenerator(seed=42)\n    values = keras_core.random.normal(shape=(2, 3), seed=seed_gen)\n    new_values = keras_core.random.normal(shape=(2, 3), seed=seed_gen)\n    ```\n    \"\"\"\n\n    def __init__(self, seed, **kwargs):\n        custom_backend = kwargs.pop(\"backend\", None)\n        if kwargs:\n            raise ValueError(f\"Unrecognized keyword arguments: {kwargs}\")\n        if custom_backend is not None:\n            backend = custom_backend\n        else:\n            from keras_core import backend\n\n        if seed is None:\n            seed = make_default_seed()\n        if not isinstance(seed, int):\n            raise ValueError(\n                \"Argument `seed` must be an integer. \" f\"Received: seed={seed}\"\n            )\n\n        def seed_initializer(*args, **kwargs):\n            dtype = kwargs.get(\"dtype\", None)\n            return backend.convert_to_tensor([seed, 0], dtype=dtype)\n\n        self.state = backend.Variable(\n            seed_initializer,\n            shape=(2,),\n            dtype=\"uint32\",\n            trainable=False,\n            name=\"seed_generator_state\",\n        )\n\n\ndef make_default_seed():\n    return python_random.randint(1, int(1e9))\n\n\ndef draw_seed(seed):\n    from keras_core.backend import convert_to_tensor\n\n    if isinstance(seed, SeedGenerator):\n        seed_state = seed.state\n        # Use * 1 to create a copy\n        new_seed_value = seed_state.value * 1\n        increment = convert_to_tensor(np.array([0, 1]), dtype=\"uint32\")\n        seed.state.assign(seed_state + increment)\n        return new_seed_value\n    elif isinstance(seed, int):\n        return convert_to_tensor([seed, 0], dtype=\"uint32\")\n    elif seed is None:\n        return convert_to_tensor([make_default_seed(), 0], dtype=\"uint32\")\n    raise ValueError(\n        \"Argument `seed` must be either an integer \"\n        \"or an instance of `SeedGenerator`. \"\n        f\"Received: seed={seed} (of type {type(seed)})\"\n    )\n", "path": "keras_core/random/seed_generator.py"}], "after_files": [{"content": "from tensorflow import nest\n\nimport keras_core.backend\nfrom keras_core.layers.layer import Layer\nfrom keras_core.random.seed_generator import SeedGenerator\nfrom keras_core.utils import backend_utils\nfrom keras_core.utils import tracking\n\n\nclass TFDataLayer(Layer):\n    \"\"\"Layer that can safely used in a tf.data pipeline.\n\n    The `call()` method must solely rely on `self.backend` ops.\n\n    Only supports a single input tensor argument.\n    \"\"\"\n\n    def __init__(self, **kwargs):\n        super().__init__(**kwargs)\n        self.backend = backend_utils.DynamicBackend()\n        self._allow_non_tensor_positional_args = True\n\n    def __call__(self, inputs, **kwargs):\n        if backend_utils.in_tf_graph() and not isinstance(\n            inputs, keras_core.backend.KerasTensor\n        ):\n            # We're in a TF graph, e.g. a tf.data pipeline.\n            self.backend.set_backend(\"tensorflow\")\n            inputs = nest.map_structure(\n                lambda x: self.backend.convert_to_tensor(\n                    x, dtype=self.compute_dtype\n                ),\n                inputs,\n            )\n            switch_convert_input_args = False\n            if self._convert_input_args:\n                self._convert_input_args = False\n                switch_convert_input_args = True\n            try:\n                outputs = super().__call__(inputs, **kwargs)\n            finally:\n                self.backend.reset()\n                if switch_convert_input_args:\n                    self._convert_input_args = True\n            return outputs\n        return super().__call__(inputs, **kwargs)\n\n    @tracking.no_automatic_dependency_tracking\n    def _get_seed_generator(self, backend=None):\n        if backend is None or backend == keras_core.backend.backend():\n            return self.generator\n        if not hasattr(self, \"_backend_generators\"):\n            self._backend_generators = {}\n        if backend in self._backend_generators:\n            return self._backend_generators[backend]\n        seed_generator = SeedGenerator(self.seed, backend=self.backend)\n        self._backend_generators[backend] = seed_generator\n        return seed_generator\n", "path": "keras_core/layers/preprocessing/tf_data_layer.py"}, {"content": "import random as python_random\n\nimport numpy as np\n\nimport keras_core.backend\nfrom keras_core.api_export import keras_core_export\n\n\n@keras_core_export(\"keras_core.random.SeedGenerator\")\nclass SeedGenerator:\n    \"\"\"Generates variable seeds upon each call to a RNG-using function.\n\n    In Keras, all RNG-using methods (such as `keras_core.random.normal()`)\n    are stateless, meaning that if you pass an integer seed to them\n    (such as `seed=42`), they will return the same values at each call.\n    In order to get different values at each call, you must use a\n    `SeedGenerator` instead as the seed argument. The `SeedGenerator`\n    instead is stateful.\n\n    Example:\n\n    ```python\n    seed_gen = keras_core.random.SeedGenerator(seed=42)\n    values = keras_core.random.normal(shape=(2, 3), seed=seed_gen)\n    new_values = keras_core.random.normal(shape=(2, 3), seed=seed_gen)\n    ```\n    \"\"\"\n\n    def __init__(self, seed, **kwargs):\n        custom_backend = kwargs.pop(\"backend\", None)\n        if kwargs:\n            raise ValueError(f\"Unrecognized keyword arguments: {kwargs}\")\n        if custom_backend is not None:\n            self.backend = custom_backend\n        else:\n            self.backend = keras_core.backend\n\n        if seed is None:\n            seed = make_default_seed()\n        if not isinstance(seed, int):\n            raise ValueError(\n                \"Argument `seed` must be an integer. \" f\"Received: seed={seed}\"\n            )\n\n        def seed_initializer(*args, **kwargs):\n            dtype = kwargs.get(\"dtype\", None)\n            return self.backend.convert_to_tensor([seed, 0], dtype=dtype)\n\n        self.state = self.backend.Variable(\n            seed_initializer,\n            shape=(2,),\n            dtype=\"uint32\",\n            trainable=False,\n            name=\"seed_generator_state\",\n        )\n\n\ndef make_default_seed():\n    return python_random.randint(1, int(1e9))\n\n\ndef draw_seed(seed):\n    from keras_core.backend import convert_to_tensor\n\n    if isinstance(seed, SeedGenerator):\n        seed_state = seed.state\n        # Use * 1 to create a copy\n        new_seed_value = seed_state.value * 1\n        increment = seed.backend.convert_to_tensor(\n            np.array([0, 1]), dtype=\"uint32\"\n        )\n        seed.state.assign(seed_state + increment)\n        return new_seed_value\n    elif isinstance(seed, int):\n        return convert_to_tensor([seed, 0], dtype=\"uint32\")\n    elif seed is None:\n        return convert_to_tensor([make_default_seed(), 0], dtype=\"uint32\")\n    raise ValueError(\n        \"Argument `seed` must be either an integer \"\n        \"or an instance of `SeedGenerator`. \"\n        f\"Received: seed={seed} (of type {type(seed)})\"\n    )\n", "path": "keras_core/random/seed_generator.py"}]}