bbc-mc / sdweb-merge-block-weighted-gui

Merge models with separate rate for each 25 U-Net block (input, middle, output). Extension for Stable Diffusion UI by AUTOMATIC1111
318 stars 33 forks source link

RuntimeError: Expected all tensors to be on the same device: even when explicitly requesting cpu #21

Closed AI-Casanova closed 1 year ago

AI-Casanova commented 1 year ago

I'm really confused by this as I'm not invoking cuda anywhere, even modified merge_block_weighted.py to read device="cpu"


Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/gradio/routes.py", line 337, in run_predict
    output = await app.get_blocks().process_api(
  File "/usr/local/lib/python3.8/dist-packages/gradio/blocks.py", line 1015, in process_api
    result = await self.call_function(
  File "/usr/local/lib/python3.8/dist-packages/gradio/blocks.py", line 833, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "/usr/local/lib/python3.8/dist-packages/anyio/to_thread.py", line 31, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "/usr/local/lib/python3.8/dist-packages/anyio/_backends/_asyncio.py", line 937, in run_sync_in_worker_thread
    return await future
  File "/usr/local/lib/python3.8/dist-packages/anyio/_backends/_asyncio.py", line 867, in run
    result = context.run(func, *args)
  File "/content/gdrive/.shortcut-targets-by-id/1IH8QoWPSgvNIHn0c282S_XijTCsku8yS/sd/stable-diffusion-webui/extensions/sdweb-merge-block-weighted-gui/scripts/mbw/ui_mbw.py", line 172, in onclick_btn_do_merge_block_weighted
    result, ret_message = merge(weights=_weights, model_0=model_A, model_1=model_B, allow_overwrite=chk_allow_overwrite,
  File "/content/gdrive/.shortcut-targets-by-id/1IH8QoWPSgvNIHn0c282S_XijTCsku8yS/sd/stable-diffusion-webui/extensions/sdweb-merge-block-weighted-gui/scripts/mbw/merge_block_weighted.py", line 133, in merge
    theta_0[key] = (1 - current_alpha) * theta_0[key] + current_alpha * theta_1[key]
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!```
AI-Casanova commented 1 year ago

Setting device = "cuda" explicitly works.