Save 4 hours! We auto-setup your workflow! Free!

Drop your workflow.json — we handle every dependency, custom node, and model. Just open the link and run.

Auto-Setup Workflow Json (Free) Now!
ComfyUI > Nodes > ComfyUI-lhyNodes > Set CUDA Device

ComfyUI Node: Set CUDA Device

Class Name

CudaDevicePatcher

Category
lhyNodes/Utils
Author
lihaoyun6 (Account age: 3821days)
Extension
ComfyUI-lhyNodes
Latest Updated
2026-05-31
Github Stars
0.02K

How to Install ComfyUI-lhyNodes

Install this extension via the ComfyUI Manager by searching for ComfyUI-lhyNodes
  • 1. Click the Manager button in the main menu
  • 2. Select Custom Nodes Manager button
  • 3. Enter ComfyUI-lhyNodes in the search bar
After installation, click the Restart button to restart ComfyUI. Then, manually refresh your browser to clear the cache and access the updated list of nodes.

Visit ComfyUI Online for ready-to-use ComfyUI environment

  • Free trial available
  • 16GB VRAM to 80GB VRAM GPU machines
  • 400+ preloaded models/nodes
  • Freedom to upload custom models/nodes
  • 200+ ready-to-run workflows
  • 100% private workspace with up to 200GB storage
  • Dedicated Support

Run ComfyUI Online

Set CUDA Device Description

Dynamically modify CUDA_VISIBLE_DEVICES for GPU resource management in multi-GPU setups.

Set CUDA Device:

The CudaDevicePatcher node is designed to dynamically modify the environment variable CUDA_VISIBLE_DEVICES during runtime. This node is particularly useful for managing and optimizing GPU resources in a multi-GPU setup. By altering the CUDA_VISIBLE_DEVICES variable, you can control which GPUs are visible to your application, effectively enabling or disabling specific GPUs for processing tasks. This capability is essential for optimizing performance, managing resource allocation, and ensuring that specific tasks are executed on the desired GPU. The node provides a straightforward method to adjust GPU visibility without requiring deep technical knowledge, making it accessible for AI artists and developers who need to manage GPU resources efficiently.

Set CUDA Device Input Parameters:

any

This parameter accepts any type of input data. It serves as a pass-through, allowing you to input any data type that you want to process or modify. The any parameter does not directly impact the execution of the node but ensures that the input data is preserved and returned as part of the output. There are no specific minimum, maximum, or default values for this parameter, as it is designed to be flexible and accommodate any data type.

device

The device parameter is a string that specifies the GPU devices you want to make visible to your application. By setting this parameter, you can control which GPUs are available for processing tasks. The value of this parameter should be a string representing the GPU indices, such as "0" for the first GPU or "0,1" for the first and second GPUs. The default value is an empty string, which means no specific GPUs are set, and the system's default GPU visibility settings are used. This parameter is crucial for optimizing GPU resource allocation and ensuring that tasks are executed on the desired GPUs.

Set CUDA Device Output Parameters:

any

This output parameter returns the input data unchanged. It serves as a pass-through, ensuring that the data you input into the node is preserved and available for further processing or analysis. The any output is essential for maintaining data integrity and continuity in your workflow.

original

The original output parameter is a string that contains the original value of the CUDA_VISIBLE_DEVICES environment variable before it was modified by the node. This output is important for tracking changes and understanding the initial GPU visibility settings. By providing the original value, you can easily revert to the previous configuration if needed or use it for comparison and analysis.

Set CUDA Device Usage Tips:

  • Use the device parameter to specify the exact GPUs you want to utilize for your tasks. This can help optimize performance by ensuring that tasks are executed on the most suitable GPUs.
  • If you are unsure about which GPUs to use, start with the default settings and gradually adjust the device parameter based on your performance observations and requirements.
  • Keep track of the original output to understand the initial GPU configuration and make informed decisions about resource allocation.

Set CUDA Device Common Errors and Solutions:

Invalid device string

  • Explanation: The device parameter contains an invalid string that does not correspond to any available GPU indices.
  • Solution: Ensure that the device parameter is set to a valid string representing the GPU indices, such as "0" or "0,1". Check your system's GPU configuration to verify the available indices.

No GPUs available

  • Explanation: The specified GPUs in the device parameter are not available or not recognized by the system.
  • Solution: Verify that the GPUs specified in the device parameter are correctly installed and recognized by your system. Use system tools to check the status of your GPUs and ensure they are functioning properly.

Environment variable not set

  • Explanation: The CUDA_VISIBLE_DEVICES environment variable could not be set due to system restrictions or permissions.
  • Solution: Ensure that your application has the necessary permissions to modify environment variables. Check your system's security settings and adjust them if necessary to allow changes to environment variables.

Set CUDA Device Related Nodes

Go back to the extension to check out more related nodes.
ComfyUI-lhyNodes
RunComfy
Copyright 2025 RunComfy. All Rights Reserved.

RunComfy is the premier ComfyUI platform, offering ComfyUI online environment and services, along with ComfyUI workflows featuring stunning visuals. RunComfy also provides AI Models, enabling artists to harness the latest AI tools to create incredible art.

Set CUDA Device