6 Commits
Author SHA1 Message Date
li-lizhe 6555d35004 Use ComfyUI's device selection instead of hardcoded CUDA checks
Several model-loading and processing paths pick their device with
`"cuda" if torch.cuda.is_available() else "cpu"`, and move tensors with
`.cuda()` guarded by the same check:

- `imagefunc.load_RMBG_model` / `RMBG`
- `imagefunc.get_masked_VITMatte_image` (vitmatte)
- `imagefunc.UformGen2QwenChat`
- `imagefunc.clear_memory`
- `blendmodes.rgb_to_hsv_via_torch` / `hsv_to_rgb_via_torch`

On any non-CUDA accelerator that ComfyUI itself supports (e.g. Ascend NPU
via torch_npu, which ComfyUI's own `comfy.model_management.get_torch_device`
returns a `torch.device("npu")` for), these paths silently fall back to the
CPU or, for `.cuda()`, move the input to a CUDA device that does not exist.

This repo already imports `comfy.model_management` (e.g. in `purge_vram.py`),
so use its device selection for consistency with the rest of ComfyUI:

- `load_RMBG_model`, `UformGen2QwenChat`, and the blendmode helpers now use
  `comfy.model_management.get_torch_device()`.
- `RMBG` moves the input to the device of the (lru-cached) model itself
  instead of probing CUDA, so it also follows device changes correctly.
- the vitmatte path uses the ComfyUI device unless the caller explicitly
  asked for CPU; a hardcoded "cuda" request without CUDA available now logs
  and uses the ComfyUI default.
- cache clearing also calls `torch.accelerator.empty_cache()` when a
  non-CUDA accelerator is present (`torch.accelerator` is the device-agnostic
  PyTorch API).

Verified on Ascend 910B (torch 2.14.0a0 + torch_npu 2.14.0) with
ComfyUI-master's `comfy.model_management` implementation:
`get_torch_device()` returns `torch.device("npu", 0)`, a conv2d forward and
an RMBG-style model/input flow run on `npu:0`, and
`torch.accelerator.empty_cache()` is callable. On CUDA machines the selected
device is unchanged (`cuda`).
2026-09-02 16:02:58 +08:00
chflame163 0426cb92e3 optimize node loading speed 2024-08-22 19:25:48 +08:00
ClownsharkBatwing 6430326893 Add files via upload 2024-08-15 13:11:54 -04:00
chflame 182355e3e5 commit AutoAdjust node 2024-05-13 21:09:35 +08:00
chflame 25b57cf771 update blendmodes.py 2024-05-12 20:50:24 +08:00
chflame 420d57b552 update new BlendMode V2, commit ImageBlendV2, ImageBlendAdvanceV2, DropShadowV2, InnerShadowV2, OuterGlowV2, InnerGlowV2, StrokeV2, ColorOverlayV2, GradientOverlayV2 nodes 2024-05-03 17:32:15 +08:00