Can not force TF 2.10 to use CPU only (uses GPU)
Hello, @marcusobrien :]

Instead of the `tf.config.experimental.list_physical_devices()`, do this instead early on:
```
import os

os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
```

That way, TF will not find any GPUs to allocate on. If it didn't. You are likely doing this too late in the code. You should be doing this, before you do any ops that will allocate GPU memory, like compiling your model, or similar. In some projects, I even do it before I import `tensorflow`, but that's up to you.

---
EDIT: You can check if it solved the issue, running `nvidia-smi` in a Linux terminal.

For Windows, you can use the task manager to monitor GPU utilisation. @marcusobrien,
As mentioned you can try using `os.environ["CUDA_VISIBLE_DEVICES"] = "-1"` and also I tried with the code mentioned and it was executed without any issues, Kindly find the gist of it [here](https://colab.research.google.com/gist/tilakrayal/fee822f29fe5346ccf00696d9f72c4e8/untitled1671.ipynb).

Also tensorflow v2.10 is an older version, please upgrade to latest stable v2.15 for the better performance on both GPU and CPU. Thank you! This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further. Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/62810">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/62810">No</a>

### Issue type

Bug

### Have you reproduced the bug with TensorFlow Nightly?

Yes

### Source

binary

### TensorFlow version

v2.10.0-rc3-6-g359c3cdfc5f 2.10.0

### Custom code

No

### OS platform and distribution

Windows 10

### Mobile device

_No response_

### Python version

3.10.9

### Bazel version

_No response_

### GCC/compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current behavior?

I want to use TF 2.10 with CPU only, as currently TF defaults to using my GPU. 

I tried the advice on this issue https://github.com/tensorflow/tensorflow/issues/31135

But the above can not be used in Jupyter Labs due to this error message

"RuntimeError: Visible devices cannot be modified after being initialized"

So is there any other way to force tensorflow to use CPU to perform all calculations ?

### Standalone code to reproduce the issue

```shell
import tensorflow as tf
print(tf.__version__)

# Set CPU as available physical device
my_devices = tf.config.experimental.list_physical_devices(device_type='CPU')
tf.config.experimental.set_visible_devices(devices= my_devices, device_type='CPU')

Error in msg below
```


### Relevant log output

```shell
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[42], line 6
      4 # Set CPU as available physical device
      5 my_devices = tf.config.experimental.list_physical_devices(device_type='CPU')
----> 6 tf.config.experimental.set_visible_devices(devices= my_devices, device_type='CPU')

File U:\Miniconda3\envs\MLTF_CPU_2024\lib\site-packages\tensorflow\python\framework\config.py:528, in set_visible_devices(devices, device_type)
    495 @tf_export('config.set_visible_devices',
    496            'config.experimental.set_visible_devices')
    497 @deprecation.deprecated_endpoints('config.experimental.set_visible_devices')
    498 def set_visible_devices(devices, device_type=None):
    499   """Set the list of visible devices.
    500 
    501   Specifies which `PhysicalDevice` objects are visible to the runtime.
   (...)
    526     RuntimeError: Runtime is already initialized.
    527   """
--> 528   context.context().set_visible_devices(devices, device_type)

File U:\Miniconda3\envs\MLTF_CPU_2024\lib\site-packages\tensorflow\python\eager\context.py:1621, in Context.set_visible_devices(self, devices, device_type)
   1618   return
   1620 if self._context_handle is not None:
-> 1621   raise RuntimeError(
   1622       "Visible devices cannot be modified after being initialized")
   1624 self._visible_device_list = visible_device_list

RuntimeError: Visible devices cannot be modified after being initialized
```
