We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN 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_

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `modules/deepbooru.py`
Content:
```
1 import os
2 import re
3 
4 import torch
5 from PIL import Image
6 import numpy as np
7 
8 from modules import modelloader, paths, deepbooru_model, devices, images, shared
9 
10 re_special = re.compile(r'([\\()])')
11 
12 
13 class DeepDanbooru:
14     def __init__(self):
15         self.model = None
16 
17     def load(self):
18         if self.model is not None:
19             return
20 
21         files = modelloader.load_models(
22             model_path=os.path.join(paths.models_path, "torch_deepdanbooru"),
23             model_url='https://github.com/AUTOMATIC1111/TorchDeepDanbooru/releases/download/v1/model-resnet_custom_v3.pt',
24             ext_filter=".pt",
25             download_name='model-resnet_custom_v3.pt',
26         )
27 
28         self.model = deepbooru_model.DeepDanbooruModel()
29         self.model.load_state_dict(torch.load(files[0], map_location="cpu"))
30 
31         self.model.eval()
32         self.model.to(devices.cpu, devices.dtype)
33 
34     def start(self):
35         self.load()
36         self.model.to(devices.device)
37 
38     def stop(self):
39         if not shared.opts.interrogate_keep_models_in_memory:
40             self.model.to(devices.cpu)
41             devices.torch_gc()
42 
43     def tag(self, pil_image):
44         self.start()
45         res = self.tag_multi(pil_image)
46         self.stop()
47 
48         return res
49 
50     def tag_multi(self, pil_image, force_disable_ranks=False):
51         threshold = shared.opts.interrogate_deepbooru_score_threshold
52         use_spaces = shared.opts.deepbooru_use_spaces
53         use_escape = shared.opts.deepbooru_escape
54         alpha_sort = shared.opts.deepbooru_sort_alpha
55         include_ranks = shared.opts.interrogate_return_ranks and not force_disable_ranks
56 
57         pic = images.resize_image(2, pil_image.convert("RGB"), 512, 512)
58         a = np.expand_dims(np.array(pic, dtype=np.float32), 0) / 255
59 
60         with torch.no_grad(), devices.autocast():
61             x = torch.from_numpy(a).cuda()
62             y = self.model(x)[0].detach().cpu().numpy()
63 
64         probability_dict = {}
65 
66         for tag, probability in zip(self.model.tags, y):
67             if probability < threshold:
68                 continue
69 
70             if tag.startswith("rating:"):
71                 continue
72 
73             probability_dict[tag] = probability
74 
75         if alpha_sort:
76             tags = sorted(probability_dict)
77         else:
78             tags = [tag for tag, _ in sorted(probability_dict.items(), key=lambda x: -x[1])]
79 
80         res = []
81 
82         for tag in tags:
83             probability = probability_dict[tag]
84             tag_outformat = tag
85             if use_spaces:
86                 tag_outformat = tag_outformat.replace('_', ' ')
87             if use_escape:
88                 tag_outformat = re.sub(re_special, r'\\\1', tag_outformat)
89             if include_ranks:
90                 tag_outformat = f"({tag_outformat}:{probability:.3f})"
91 
92             res.append(tag_outformat)
93 
94         return ", ".join(res)
95 
96 
97 model = DeepDanbooru()
98
```
--- 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/modules/deepbooru.py b/modules/deepbooru.py
--- a/modules/deepbooru.py
+++ b/modules/deepbooru.py
@@ -58,7 +58,7 @@
         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 = {}

{"golden_diff": "diff --git a/modules/deepbooru.py b/modules/deepbooru.py\n--- a/modules/deepbooru.py\n+++ b/modules/deepbooru.py\n@@ -58,7 +58,7 @@\n         a = np.expand_dims(np.array(pic, dtype=np.float32), 0) / 255\n \n         with torch.no_grad(), devices.autocast():\n-            x = torch.from_numpy(a).cuda()\n+            x = torch.from_numpy(a).to(devices.device)\n             y = self.model(x)[0].detach().cpu().numpy()\n \n         probability_dict = {}\n", "issue": "[Bug]: Torch deepdanbooru refuses to run on CPU\n### Is there an existing issue for this?\n\n- [X] I have searched the existing issues and checked the recent builds/commits\n\n### What happened?\n\nWhen trying to launch deepdanbooru with `--use-cpu all` it fails with `RuntimeError: No CUDA GPUs are available`.\n\n### Steps to reproduce the problem\n\n1. Launch webui in CPU only mode.\r\n2. Press \"Interrogate Deepdanbooru\"\r\n3. Exception occurs\r\n\n\n### What should have happened?\n\nShould work in CPU like the older implementation.\n\n### Commit where the problem happens\n\nc81d440d876dfd2ab3560410f37442ef56fc6632\n\n### What platforms do you use to access UI ?\n\nLinux\n\n### What browsers do you use to access the UI ?\n\nMozilla Firefox\n\n### Command Line Arguments\n\n```Shell\nACCELERATE=\"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\n```\n\n\n### Additional information, context and logs\n\n_No response_\n[Bug]: DeepDanBooru Interrogate fails if using --device-id 1 on startup\n### Is there an existing issue for this?\n\n- [X] I have searched the existing issues and checked the recent builds/commits\n\n### What happened?\n\nI use 2 GPUs in my system. device 0 is for training and 1 is what I use for the webui.\r\n\r\nUsing the webui on default or device-id 0, works as I expect. However if I use 1, I can not interrogate anymore.\n\n### Steps to reproduce the problem\n\nAdd --device-id 1 to your startup commands.\r\n\r\nadd or send an image to img2img\r\n\r\npress Interrogate DeepBooru\n\n### What should have happened?\n\nThe prompt should have been populated, instead this error is generated:\r\n\r\nTraceback (most recent call last):\r\n  File \"C:\\sd\\forks\\auto1111\\venv\\lib\\site-packages\\gradio\\routes.py\", line 284, in run_predict\r\n    output = await app.blocks.process_api(\r\n  File \"C:\\sd\\forks\\auto1111\\venv\\lib\\site-packages\\gradio\\blocks.py\", line 982, in process_api\r\n    result = await self.call_function(fn_index, inputs, iterator)\r\n  File \"C:\\sd\\forks\\auto1111\\venv\\lib\\site-packages\\gradio\\blocks.py\", line 824, in call_function\r\n    prediction = await anyio.to_thread.run_sync(\r\n  File \"C:\\sd\\forks\\auto1111\\venv\\lib\\site-packages\\anyio\\to_thread.py\", line 31, in run_sync\r\n    return await get_asynclib().run_sync_in_worker_thread(\r\n  File \"C:\\sd\\forks\\auto1111\\venv\\lib\\site-packages\\anyio\\_backends\\_asyncio.py\", line 937, in run_sync_in_worker_thread\r\n    return await future\r\n  File \"C:\\sd\\forks\\auto1111\\venv\\lib\\site-packages\\anyio\\_backends\\_asyncio.py\", line 867, in run\r\n    result = context.run(func, *args)\r\n  File \"C:\\sd\\forks\\auto1111\\modules\\ui.py\", line 352, in interrogate_deepbooru\r\n    prompt = deepbooru.model.tag(image)\r\n  File \"C:\\sd\\forks\\auto1111\\modules\\deepbooru.py\", line 45, in tag\r\n    res = self.tag_multi(pil_image)\r\n  File \"C:\\sd\\forks\\auto1111\\modules\\deepbooru.py\", line 62, in tag_multi\r\n    y = self.model(x)[0].detach().cpu().numpy()\r\n  File \"C:\\sd\\forks\\auto1111\\venv\\lib\\site-packages\\torch\\nn\\modules\\module.py\", line 1130, in _call_impl\r\n    return forward_call(*input, **kwargs)\r\n  File \"C:\\sd\\forks\\auto1111\\modules\\deepbooru_model.py\", line 199, in forward\r\n    t_360 = self.n_Conv_0(t_359_padded)\r\n  File \"C:\\sd\\forks\\auto1111\\venv\\lib\\site-packages\\torch\\nn\\modules\\module.py\", line 1130, in _call_impl\r\n    return forward_call(*input, **kwargs)\r\n  File \"C:\\sd\\forks\\auto1111\\venv\\lib\\site-packages\\torch\\nn\\modules\\conv.py\", line 457, in forward\r\n    return self._conv_forward(input, self.weight, self.bias)\r\n  File \"C:\\sd\\forks\\auto1111\\venv\\lib\\site-packages\\torch\\nn\\modules\\conv.py\", line 453, in _conv_forward\r\n    return F.conv2d(input, weight, bias, self.stride,\r\nRuntimeError: 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)\n\n### Commit where the problem happens\n\nCommit hash: 828438b4a190759807f9054932cae3a8b880ddf1\n\n### What platforms do you use to access UI ?\n\nWindows\n\n### What browsers do you use to access the UI ?\n\nGoogle Chrome, Microsoft Edge\n\n### Command Line Arguments\n\n```Shell\n--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\n```\n\n\n### Additional information, context and logs\n\n_No response_\n", "before_files": [{"content": "import os\nimport re\n\nimport torch\nfrom PIL import Image\nimport numpy as np\n\nfrom modules import modelloader, paths, deepbooru_model, devices, images, shared\n\nre_special = re.compile(r'([\\\\()])')\n\n\nclass DeepDanbooru:\n    def __init__(self):\n        self.model = None\n\n    def load(self):\n        if self.model is not None:\n            return\n\n        files = modelloader.load_models(\n            model_path=os.path.join(paths.models_path, \"torch_deepdanbooru\"),\n            model_url='https://github.com/AUTOMATIC1111/TorchDeepDanbooru/releases/download/v1/model-resnet_custom_v3.pt',\n            ext_filter=\".pt\",\n            download_name='model-resnet_custom_v3.pt',\n        )\n\n        self.model = deepbooru_model.DeepDanbooruModel()\n        self.model.load_state_dict(torch.load(files[0], map_location=\"cpu\"))\n\n        self.model.eval()\n        self.model.to(devices.cpu, devices.dtype)\n\n    def start(self):\n        self.load()\n        self.model.to(devices.device)\n\n    def stop(self):\n        if not shared.opts.interrogate_keep_models_in_memory:\n            self.model.to(devices.cpu)\n            devices.torch_gc()\n\n    def tag(self, pil_image):\n        self.start()\n        res = self.tag_multi(pil_image)\n        self.stop()\n\n        return res\n\n    def tag_multi(self, pil_image, force_disable_ranks=False):\n        threshold = shared.opts.interrogate_deepbooru_score_threshold\n        use_spaces = shared.opts.deepbooru_use_spaces\n        use_escape = shared.opts.deepbooru_escape\n        alpha_sort = shared.opts.deepbooru_sort_alpha\n        include_ranks = shared.opts.interrogate_return_ranks and not force_disable_ranks\n\n        pic = images.resize_image(2, pil_image.convert(\"RGB\"), 512, 512)\n        a = np.expand_dims(np.array(pic, dtype=np.float32), 0) / 255\n\n        with torch.no_grad(), devices.autocast():\n            x = torch.from_numpy(a).cuda()\n            y = self.model(x)[0].detach().cpu().numpy()\n\n        probability_dict = {}\n\n        for tag, probability in zip(self.model.tags, y):\n            if probability < threshold:\n                continue\n\n            if tag.startswith(\"rating:\"):\n                continue\n\n            probability_dict[tag] = probability\n\n        if alpha_sort:\n            tags = sorted(probability_dict)\n        else:\n            tags = [tag for tag, _ in sorted(probability_dict.items(), key=lambda x: -x[1])]\n\n        res = []\n\n        for tag in tags:\n            probability = probability_dict[tag]\n            tag_outformat = tag\n            if use_spaces:\n                tag_outformat = tag_outformat.replace('_', ' ')\n            if use_escape:\n                tag_outformat = re.sub(re_special, r'\\\\\\1', tag_outformat)\n            if include_ranks:\n                tag_outformat = f\"({tag_outformat}:{probability:.3f})\"\n\n            res.append(tag_outformat)\n\n        return \", \".join(res)\n\n\nmodel = DeepDanbooru()\n", "path": "modules/deepbooru.py"}], "after_files": [{"content": "import os\nimport re\n\nimport torch\nfrom PIL import Image\nimport numpy as np\n\nfrom modules import modelloader, paths, deepbooru_model, devices, images, shared\n\nre_special = re.compile(r'([\\\\()])')\n\n\nclass DeepDanbooru:\n    def __init__(self):\n        self.model = None\n\n    def load(self):\n        if self.model is not None:\n            return\n\n        files = modelloader.load_models(\n            model_path=os.path.join(paths.models_path, \"torch_deepdanbooru\"),\n            model_url='https://github.com/AUTOMATIC1111/TorchDeepDanbooru/releases/download/v1/model-resnet_custom_v3.pt',\n            ext_filter=\".pt\",\n            download_name='model-resnet_custom_v3.pt',\n        )\n\n        self.model = deepbooru_model.DeepDanbooruModel()\n        self.model.load_state_dict(torch.load(files[0], map_location=\"cpu\"))\n\n        self.model.eval()\n        self.model.to(devices.cpu, devices.dtype)\n\n    def start(self):\n        self.load()\n        self.model.to(devices.device)\n\n    def stop(self):\n        if not shared.opts.interrogate_keep_models_in_memory:\n            self.model.to(devices.cpu)\n            devices.torch_gc()\n\n    def tag(self, pil_image):\n        self.start()\n        res = self.tag_multi(pil_image)\n        self.stop()\n\n        return res\n\n    def tag_multi(self, pil_image, force_disable_ranks=False):\n        threshold = shared.opts.interrogate_deepbooru_score_threshold\n        use_spaces = shared.opts.deepbooru_use_spaces\n        use_escape = shared.opts.deepbooru_escape\n        alpha_sort = shared.opts.deepbooru_sort_alpha\n        include_ranks = shared.opts.interrogate_return_ranks and not force_disable_ranks\n\n        pic = images.resize_image(2, pil_image.convert(\"RGB\"), 512, 512)\n        a = np.expand_dims(np.array(pic, dtype=np.float32), 0) / 255\n\n        with torch.no_grad(), devices.autocast():\n            x = torch.from_numpy(a).to(devices.device)\n            y = self.model(x)[0].detach().cpu().numpy()\n\n        probability_dict = {}\n\n        for tag, probability in zip(self.model.tags, y):\n            if probability < threshold:\n                continue\n\n            if tag.startswith(\"rating:\"):\n                continue\n\n            probability_dict[tag] = probability\n\n        if alpha_sort:\n            tags = sorted(probability_dict)\n        else:\n            tags = [tag for tag, _ in sorted(probability_dict.items(), key=lambda x: -x[1])]\n\n        res = []\n\n        for tag in tags:\n            probability = probability_dict[tag]\n            tag_outformat = tag\n            if use_spaces:\n                tag_outformat = tag_outformat.replace('_', ' ')\n            if use_escape:\n                tag_outformat = re.sub(re_special, r'\\\\\\1', tag_outformat)\n            if include_ranks:\n                tag_outformat = f\"({tag_outformat}:{probability:.3f})\"\n\n            res.append(tag_outformat)\n\n        return \", \".join(res)\n\n\nmodel = DeepDanbooru()\n", "path": "modules/deepbooru.py"}]}