146 Commits
Author SHA1 Message Date
li-lizhe 2176b74083 Add 'auto' device option to nodes with hardcoded CUDA/CPU device lists
Several nodes only exposed a 'cuda'/'cpu' device dropdown, forcing users on
any other ComfyUI-supported accelerator (Ascend NPU, XPU, MPS) to run on CPU
even when their device is available.

Add a shared DEVICE_LIST_OPTIONS constant and get_device() helper in
imagefunc.py that resolve 'auto' to ComfyUI's default device, and use them in
the VITMatte-based matting nodes and the VQA model loader so non-CUDA devices
can be selected from the UI.
2026-09-16 10:08:47 +08:00
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 d94bef1ee5 Ultra nodes support vitmatte-base-composition-1k 2026-01-30 14:31:45 +08:00
chflame163 a1875e824c commit DistortDisplace node 2026-01-08 17:50:29 +08:00
chflame163 5840264d0d fix bug of converting BF16 tensor to pillow image 2025-12-29 15:52:57 +08:00
chflame163 67f664efdc support numpy 2.x 2025-03-12 13:51:14 +08:00
chflame163 84d357ad82 fix bug of image_beauty 2025-01-15 22:47:59 +08:00
chflame163 d8338b3043 fix a bug of RMBGUltra 2024-12-23 19:59:48 +08:00
bigcat88 efa88cc935 fixed incorrect results for RmBgUltraV2 node 2024-12-21 14:02:21 +02:00
chflame163 666541eb06 Merge pull request #460 from Visionatrix/main
rmbg1.4: use "comfy.get_torch_device()" instead if "torch.cuda.is_available"
2024-12-20 22:38:21 +08:00
bigcat88 7fa2d0d357 use "comfy.model_management.get_torch_device()" instead if "torch.cuda.is_available" 2024-12-20 14:54:47 +02:00
chflame163 c6ac429ef6 support for short format hexcolor strings of imagefunc.py 2024-12-20 14:29:41 +08:00
chflame163 1b7d63f840 commit NameToColor node 2024-12-19 19:17:46 +08:00
chflame163 184e83baf9 fix bug of function mask_area 2024-12-17 21:02:51 +08:00
chflame163 755604a9df update imagefunc.py 2024-12-17 18:44:14 +08:00
chflame163 ac9e179489 commit RoundedRectangle node 2024-12-16 16:40:17 +08:00
chflame163 140c04a054 fix checkmodelpath function 2024-12-11 20:34:42 +08:00
chflame163 0653b6c26b fix vitmatte model loader 2024-12-11 20:18:28 +08:00
chflame163 a3d00bf117 update readme 2024-12-10 22:21:53 +08:00
macro chen a267afb24b Split some of the dependencies that are prone to problems into ComfyUI_LayerStyle_Advance 2024-12-05 17:26:51 +08:00
lobst f08d17bccd Enabled remote VitMatte Model download 2024-11-14 00:32:26 -05:00
Xumin Yu b0b68c8194 Update imagefunc.py 2024-11-06 08:06:02 +08:00
chflame163 2df6cf23ed fix image2mask issue 2024-10-23 18:18:34 +08:00
chflame163 0e59ff09c9 fix image2mask function 2024-10-22 20:00:03 +08:00
chflame163 a1a37ed73b fix import timm.models._registry 2024-10-16 18:13:38 +08:00
chflame163 62e90e068d commit LlamaVision,JoyCaption2 and JoyCaption2ExtraOptions nodes 2024-10-10 18:50:07 +08:00
chflame163 28c1a4f308 LoadFlorenceModel node support new version PromptGen-v1.5 model 2024-09-30 19:49:30 +08:00
chflame163 92f6366d56 commit TextJoinV2 node 2024-09-29 12:07:34 +08:00
chflame163 ab0ec27e1a fix verbose log of resource_dir.ini bug 2024-09-24 22:00:38 +08:00
chflame163 245d3f82c3 fix bug of scan font files 2024-09-24 10:35:05 +08:00
chflame163 5716dd0a54 fix bug 2024-09-23 20:30:59 +08:00
chflame163 be52ed80d8 commit GrayValue node, support defining multiple folders in resource-dir.ini 2024-09-23 20:16:58 +08:00
chflame163 15d3bb1fd9 commit GetMainColors and ColorName node, Duplicate Brightness & Contrast node as BrightnessContrastV2, and Color of Shadow & Highlight node as ColorofShadowHighlightV2 2024-09-15 00:03:38 +08:00
chflame163 366cd88619 florence2 nodes support MiaoshouAI/Florence-2-large-PromptGen-v1.5 and MiaoshouAI/Florence-2-base-PromptGen-v1.5 2024-09-11 18:50:58 +08:00
chflame163 f38f395add commit BiRefNetUltraV2 and LoadBiRefNetModel nodes, fix repair_dependency scropts 2024-09-05 14:28:05 +08:00
chflame163 f62e577217 ObjectDetector nodes add bboxes sort option 2024-09-03 18:21:33 +08:00
chflame163 0defae285a commit SAM2 and ObjectDetectors nodes 2024-09-02 22:05:37 +08:00
chflame163 deedca42ca Commit ImageTaggerSave and ImageAutoCropV3 nodes 2024-08-25 18:55:28 +08:00
chflame163 18e21036ef commit ImageReel,ImageReelComposit,CheckMaskV2 nodes 2024-08-24 17:22:48 +08:00
chflame163 65820e056a fix bug of florence2 model loader 2024-08-23 10:51:32 +08:00
chflame163 0426cb92e3 optimize node loading speed 2024-08-22 19:25:48 +08:00
chflame163 6e0993ca4e commit Florence2Ultra, Florence2Image2Prompt, LoadFlorence2Model nodes 2024-07-28 16:35:54 +08:00
chflame163 502f3f2a4e commit SegformerUltraV2, SegformerClothesPipeline and SegformerFashionPipeline nodes 2024-07-23 16:32:42 +08:00
chflame163 ddd0472d81 commit TransparentBackgroundUltra node, add install_requirements.bat to easy install dependency package 2024-07-20 22:25:21 +08:00
chflame163 15b5814348 optimize QwenPrompt2Image node 2024-07-19 13:02:44 +08:00
chflame163 9ab68757de fix vitmatte load models from local 2024-07-18 15:33:33 +08:00
chflame163 8bf41601df GetColorToneV2 node add 'mask' method of color_of option 2024-07-16 22:24:30 +08:00
chflame163 aed1162b28 LutApply node add the strenght option 2024-07-11 19:01:41 +08:00
chflame163 d5599aff98 Ultra nodes add run VitMatte on CUDA option 2024-06-29 14:31:12 +08:00
chflame163 b352799020 commit QueueStop node 2024-06-27 18:58:53 +08:00