Repository: AUTOMATIC1111/stable-diffusion-webui

Issue:
[Bug]: Torch deepdanbooru refuses to run on CPU
### Is there an existing issue for this?

- [X] I have searched the existing issues and checked the recent builds/commits

### What happened?

When trying to launch deepdanbooru with `--use-cpu all` it fails with `RuntimeError: No CUDA GPUs are available`.

### Steps to reproduce the problem

1. Launch webui in CPU only mode.
2. Press "Interrogate Deepdanbooru"
3. Exception occurs


### What should have happened?

Should work in CPU like the older implementation.

### Commit where the problem happens

c81d440d876dfd2ab3560410f37442ef56fc6632

### What platforms do you use to access UI ?

Linux

### What browsers do you use to access the UI ?

Mozilla Firefox

### Command Line Arguments

```Shell
ACCELERATE="True" CUDA_VISIBLE_DEVICES="-1" bash webui.sh --use-cpu all --precision=full --no-half --no-half-vae --skip-torch-cuda-test --deepdanbooru --opt-channelslast --always-batch-cond-uncond
```


### Additional information, context and logs

_No response_
[Bug]: DeepDanBooru Interrogate fails if using --device-id 1 on startup
### Is there an existing issue for this?

- [X] I have searched the existing issues and checked the recent builds/commits

### What happened?

I use 2 GPUs in my system. device 0 is for training and 1 is what I use for the webui.

Using the webui on default or device-id 0, works as I expect. However if I use 1, I can not interrogate anymore.

### Steps to reproduce the problem

Add --device-id 1 to your startup commands.

add or send an image to img2img

press Interrogate DeepBooru

### What should have happened?

The prompt should have been populated, instead this error is generated:

Traceback (most recent call last):
  File "C:\sd\forks\auto1111\venv\lib\site-packages\gradio\routes.py", line 284, in run_predict
    output = await app.blocks.process_api(
  File "C:\sd\forks\auto1111\venv\lib\site-packages\gradio\blocks.py", line 982, in process_api
    result = await self.call_function(fn_index, inputs, iterator)
  File "C:\sd\forks\auto1111\venv\lib\site-packages\gradio\blocks.py", line 824, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "C:\sd\forks\auto1111\venv\lib\site-packages\anyio\to_thread.py", line 31, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "C:\sd\forks\auto1111\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 937, in run_sync_in_worker_thread
    return await future
  File "C:\sd\forks\auto1111\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 867, in run
    result = context.run(func, *args)
  File "C:\sd\forks\auto1111\modules\ui.py", line 352, in interrogate_deepbooru
    prompt = deepbooru.model.tag(image)
  File "C:\sd\forks\auto1111\modules\deepbooru.py", line 45, in tag
    res = self.tag_multi(pil_image)
  File "C:\sd\forks\auto1111\modules\deepbooru.py", line 62, in tag_multi
    y = self.model(x)[0].detach().cpu().numpy()
  File "C:\sd\forks\auto1111\venv\lib\site-packages\torch\nn\modules\module.py", line 1130, in _call_impl
    return forward_call(*input, **kwargs)
  File "C:\sd\forks\auto1111\modules\deepbooru_model.py", line 199, in forward
    t_360 = self.n_Conv_0(t_359_padded)
  File "C:\sd\forks\auto1111\venv\lib\site-packages\torch\nn\modules\module.py", line 1130, in _call_impl
    return forward_call(*input, **kwargs)
  File "C:\sd\forks\auto1111\venv\lib\site-packages\torch\nn\modules\conv.py", line 457, in forward
    return self._conv_forward(input, self.weight, self.bias)
  File "C:\sd\forks\auto1111\venv\lib\site-packages\torch\nn\modules\conv.py", line 453, in _conv_forward
    return F.conv2d(input, weight, bias, self.stride,
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cuda:1! (when checking argument for argument weight in method wrapper__cudnn_convolution)

### Commit where the problem happens

Commit hash: 828438b4a190759807f9054932cae3a8b880ddf1

### What platforms do you use to access UI ?

Windows

### What browsers do you use to access the UI ?

Google Chrome, Microsoft Edge

### Command Line Arguments

```Shell
--api --force-enable-xformers --ckpt-dir "C:\sd\models" --embeddings-dir "C:\sd\embeddings" --hypernetwork-dir "C:\sd\hypernetworks" --vae-path "C:\sd\models\VAE" --device-id 1
```


### Additional information, context and logs

_No response_


Discussion:

Resolving patch:
diff --git a/modules/deepbooru.py b/modules/deepbooru.py
--- a/modules/deepbooru.py
+++ b/modules/deepbooru.py
@@ -58,7 +58,7 @@ def tag_multi(self, pil_image, force_disable_ranks=False):
         a = np.expand_dims(np.array(pic, dtype=np.float32), 0) / 255
 
         with torch.no_grad(), devices.autocast():
-            x = torch.from_numpy(a).cuda()
+            x = torch.from_numpy(a).to(devices.device)
             y = self.model(x)[0].detach().cpu().numpy()
 
         probability_dict = {}


Test patch: