A container cooperation and environment fingerprint-based ComfyUI consistent deployment and operation governance system
By using image solidification and model attachment methods, combined with container orchestration and hardware awareness technologies, the inconsistent generation results and model management difficulties of ComfyUI in multi-node environments have been resolved, achieving efficient and stable deployment and resource optimization.
Patent Information
- Application Number
- CN202611277588.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-21
- Publication Date
- 2026-11-24
AI Technical Summary
The existing ComfyUI deployment solution has difficulty in ensuring the consistency of generated results in a multi-node environment, has difficulty in managing model files, lacks closed-loop support for development and production, and has low deployment efficiency.
A dual-track consistency control scheme of image + data externalization is adopted, which solidifies the ComfyUI core engine and plugin environment in Docker image and mounts model files through physical volume mapping. Combined with container orchestration technology and hardware-aware adaptive startup, it realizes version locking and model asset decoupling at the environment level. At the same time, a development/production dual-mode switching mechanism and an automated testing module are introduced.
It achieves consistency of generated results in a multi-node environment, improves deployment and model management efficiency, reduces deployment risks, and ensures the stability of AI generation quality and optimized utilization of hardware resources.
Smart Images

Figure CN123157232A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of artificial intelligence, cloud computing and containerized deployment technology, and in particular to a solution for multi-container standardized deployment, environment consistency governance, hardware-aware optimization and automated regression testing for the ComfyUI generation engine. Background Technology
[0002] ComfyUI, as a mainstream inference engine in the current AIGC field, is widely used in tasks such as image generation and video processing due to its flexible architecture based on workflow nodes. As AIGC business moves from single-machine experiments to large-scale production, how to stably and consistently deploy ComfyUI services in a multi-node environment has become a technical challenge that the industry urgently needs to solve.
[0003] Existing deployment solutions for AI inference engines can be mainly divided into two categories: The first category is containerized deployment methods based on a single image package. This type of solution packages the application code, runtime environment, and dependencies together into an image for distribution (such as Chinese patent CN119396425B). The advantage of this method is that the deployment process is automated, but it has significant drawbacks in the ComfyUI scenario: First, the versions of third-party plugins (Custom Nodes) are frequently iterated, and the version drift of plugins between different nodes can easily lead to inconsistent generation results; second, the AI model files (Checkpoints, LoRA, etc.) are huge, and if they are packaged into an image, it will lead to low distribution efficiency, while if they are mounted through volumes, it is difficult to ensure version uniformity.
[0004] The second category is deployment methods based on configuration management tools. These solutions utilize tools like Ansible to execute installation scripts on the target server (e.g., Chinese patents CN120994314A and CN121257715A). While this method avoids the problem of bloated images, it is essentially a "process-oriented" environment replication, dependent on script integrity and execution order. System differences between different servers can lead to environment drift. More critically, existing solutions generally lack support for a closed-loop "development → production" process—plugin configurations and dependency versions debugged online by developers in interactive containers are difficult to accurately capture and replicate to the production environment.
[0005] This invention addresses the aforementioned problems by proposing a dual-track consistency control scheme of "image + data externalization". Unlike existing technologies, this invention embeds the ComfyUI core engine and plugin environment into a Docker image, achieving version locking at the environment level; simultaneously, it mounts massive model files through physical volume mapping, decoupling model assets from the runtime environment. Building upon this, a development / production dual-mode switching mechanism is introduced, supporting the persistence of environment snapshots after development environment debugging into production images. This is further supplemented by hardware-aware adaptive startup and environment fingerprint cloning technology, effectively solving the problems of difficulty in ensuring environment consistency, difficulty in model asset management, and the lack of a closed-loop development-production system in multi-node deployments. Summary of the Invention
[0006] In a first aspect, the disclosed embodiments of the present invention provide a method for multi-container collaborative ComfyUI consistent deployment and environment governance, including: The ComfyUI core engine and third-party plugin environment are embedded in a Docker image, and model files are mounted from the host machine to the container through physical volume mapping, achieving decoupling and consistency between the runtime environment and model assets; By integrating inference engine containers, API wrapper containers, large language model inference containers, and resource monitoring containers through container orchestration technology, a multi-container collaborative architecture is formed. The inference engine container is used to solidify the AI runtime environment and execute image generation tasks. The API wrapper container is used to encapsulate business logic and distribute external requests to the inference engine container. The large language model inference container is used to provide auxiliary language model processing capabilities and interconnect with the inference engine container through the container network. The resource monitoring container is used to collect the load status and memory usage of the underlying GPU in real time.
[0007] Preferably, the method further includes Configure a dual-mode switching mechanism between development and production modes; In the development mode, the inference engine container runs in an interactive terminal mode, supporting developers to install plugins and debug workflows online. In the production mode, the inference engine container runs as a GUI-less API service.
[0008] Preferably, before switching from development mode to production mode, an environment cleanup script is executed to remove agent configurations, cached data, and temporary files within the container, ensuring the purity of the production image.
[0009] Preferred options also include: The automated testing module reads YAML-formatted test case configuration files and drives the execution of test cases. Generate a visual test report that compares the input parameters with the AI-generated image; The automated testing module is integrated into the CI / CD pipeline to verify the stability of AI-generated effects before image release.
[0010] Preferred options also include: The environment backup and restore unit backs up the Python dependency version of the current runtime environment, the hash value of the ComfyUI core repository, and the Git hash value of each plugin node into a structured JSON file. Based on the JSON file, an execution environment identical to the source environment is replicated on the target server.
[0011] Preferred options also include: The resource monitoring container collects GPU status information in real time. The deployment script implements hardware detection routing, automatically allocates corresponding video memory management parameters based on the identified graphics card model, and dynamically adjusts the video memory release strategy.
[0012] Secondly, the disclosed embodiments of the present invention also provide a multi-container collaborative ComfyUI consistency deployment and environment governance system, the system comprising: The multi-container collaboration module is used to integrate the inference engine container, API wrapper container, large language model inference container, and resource monitoring container through container orchestration technology to form a multi-container collaboration architecture. Among them, the inference engine container is used to solidify the ComfyUI core engine and third-party plugin environment, and mount the model files through physical volume mapping to achieve decoupling and consistency between the runtime environment and model assets. The dual-mode switching module is used to configure the dual-mode switching mechanism between development mode and production mode. In the development mode, the inference engine container runs in an interactive terminal mode, supporting developers to install plugins and debug workflows online. Before switching from development mode to production mode, an environment cleanup script is executed to remove agent configurations, cached data, and temporary files in the container. In the production mode, the inference engine container runs in a GUI-less API service mode. The hardware adaptive scheduling module is used to collect GPU status information in real time through the resource monitoring container, implement hardware detection routing in the deployment script, automatically allocate corresponding video memory management parameters according to the identified graphics card model, and dynamically adjust the video memory release strategy. The environment fingerprint management module is used to back up the Python dependency version, ComfyUI core repository hash value, and Git hash value of each plugin node of the current runtime environment into a structured JSON file, and replicate the execution environment consistent with the source environment on the target server based on the JSON file; An automated testing module is used to read YAML format test case configuration files, drive test case execution, generate a visual test report that compares input parameters with AI-generated images, and integrate the automated testing module into the CI / CD pipeline to verify the stability of AI generation effects before image release.
[0013] Preferably, the system supports seamless migration from single-machine deployment to Kubernetes cluster; in the Kubernetes environment, model assets are managed through the PV / PVC mechanism, and the automated elastic scaling of the raw image cluster is achieved by utilizing Deployment and Service resources.
[0014] Preferably, the automated testing module is further configured to: display the parallel comparison results of the input parameters and the AI-generated image, supporting manual or algorithmic auditing of the stability of the generation effect.
[0015] Preferably, the structured data file backed up by the environment backup and recovery unit includes at least: the ComfyUI core repository hash value, the Git hash value of each plugin node, the list of Python dependency versions, and the Python interpreter parameter configuration.
[0016] The beneficial effects of this invention are as follows: (1) Reduced risk of going live: Through automated and visual regression testing, the defect detection rate after image update is increased by more than 90%.
[0017] (2) Strong architecture scalability: Supports lossless migration from single-machine deployment to large-scale cluster (K8s).
[0018] (3) Enhanced deployment flexibility: One-click cross-server expansion is achieved, ensuring consistency of output from different nodes (error close to 0).
[0019] (4) Improved collaboration efficiency: Environment fingerprinting technology has evolved the handover between development and operation from "document level" to "atomic level", and the environment replication time has been shortened from hours to minutes.
[0020] (5) Quality closed loop: Through visual regression testing, the stability of AI generation quality in frequent iterations is ensured.
[0021] (6) Maximizing hardware benefits: Targeted parameter tuning improved the single-machine image generation concurrency capability by 20%-30%. Attached Figure Description
[0022] To more clearly illustrate the technical solutions of the embodiments of this disclosure, the accompanying drawings used in the embodiments will be briefly described below. These drawings are incorporated in and constitute a part of this specification. They illustrate embodiments conforming to this disclosure and, together with the specification, serve to explain the technical solutions of this disclosure. It should be understood that the following drawings only show some embodiments of this disclosure and should not be considered as limiting the scope. Those skilled in the art can obtain other related drawings based on these drawings without creative effort.
[0023] Figure 1 This is a schematic diagram of a multi-container collaborative architecture provided in an embodiment of the present invention; Figure 2 This is a schematic diagram of environmental governance and production mirror flow provided in an embodiment of the present invention; Figure 3 A schematic diagram of automated testing logic provided in an embodiment of the present invention; Figure 4 A schematic diagram of an environment replication logic provided in an embodiment of the present invention; Figure 5 A flowchart illustrating the steps of a multi-container collaborative ComfyUI consistency deployment and environment governance method provided in this embodiment of the invention; Figure 6 This is a structural diagram of a multi-container collaborative ComfyUI consistency deployment and environment governance system provided in an embodiment of the present invention. Detailed Implementation
[0024] The embodiments of the present invention will now be described in detail with reference to the accompanying drawings to make the technical solution of the present invention clearer and more complete. It should be noted that the described embodiments are for illustrative purposes only and are not intended to limit the present invention. Other implementation methods that can be made by those skilled in the art based on the content of the present invention without creative effort should all fall within the protection scope of the present invention.
[0025] In this invention and its claims, unless otherwise expressly stated, the terms "comprising," "including," and similar expressions should be understood to indicate the presence of the listed items without excluding the presence or addition of other items. The words "an," "an," and similar terms should not be construed as limited to the singular in this invention and may include multiple items.
[0026] Furthermore, the accompanying drawings in this invention are merely illustrative and not necessarily drawn to scale. The same reference numerals denote components with the same or similar functions. To clearly illustrate this invention, specific details are provided in the following embodiments. Those skilled in the art should understand that these details are not essential for implementing this invention, and other methods can be used to implement it without affecting the basic idea of the invention.
[0027] The overall process described in the embodiments of the present invention is as follows: Figure 5 Specifically, it is as follows: I. Steps and procedures for ComfyUI consistent deployment and environment governance with multi-container collaboration: This embodiment uses a typical AIGC business scenario as an example. This scenario requires the deployment of a ComfyUI image generation service that supports multi-node parallel inference, requires that the generated results remain highly consistent across different nodes, and can automatically optimize the video memory configuration based on the GPU model. A GPU server cluster has been deployed in the region, containing various models of NVIDIA graphics cards (such as RTX 4090, RTX 4080, RTX 4070, etc.), providing the hardware foundation for this invention.
[0028] S1: Decoupling of deployment and runtime environment in multi-container collaborative architecture This step corresponds to Figure 1 The diagram illustrates a multi-container collaborative architecture. Here, 101 represents the Wrapper API container, responsible for encapsulating business logic and providing external interface services; 102 represents the Runtime inference container, responsible for solidifying the AI runtime environment and executing generation tasks; 103 represents the LLM inference platform, responsible for providing auxiliary large language model processing capabilities (such as prompt word optimization); 104 represents the DCGM resource monitoring container, responsible for independently collecting and observing the underlying hardware load status; 105 represents the model storage volume, responsible for mounting massive model assets and ensuring sharing among multiple containers; and 106 represents the physical GPU hardware layer, responsible for providing underlying computing power support.
[0029] This step deploys four core components—an inference engine container, an API wrapper container, a large language model inference container, and a resource monitoring container—using container orchestration technology, achieving decoupling and consistency between the runtime environment and model assets. The system supports both Docker Compose and Kubernetes orchestration modes; this embodiment uses Docker Compose as an example.
[0030] (1) Construction and solidification of the inference engine container The inference engine container is the core computing unit of the system, responsible for solidifying the AI runtime environment and executing image generation tasks. The container is built according to the "environment solidification" principle: the ComfyUI core engine, Python runtime environment, all third-party plugins (Custom Nodes) and their dependencies are packaged together into a Docker image.
[0031] The specific construction process is as follows: ① Base Image Selection: Select the CUDA base image provided by NVIDIA (such as nvidia / cuda:12.1-base-ubuntu22.04). This image already includes the NVIDIA driver compatibility layer to ensure that the container can access the host machine's GPU resources.
[0032] ② Runtime Environment Installation: Install the Python runtime environment (such as Python 3.10) and system dependencies (such as git, wget, ffmpeg, etc.) on the base image. These dependencies are essential for the normal operation of ComfyUI.
[0033] ③ Obtain the ComfyUI core code: Use the Git clone command to obtain the ComfyUI core code from the official repository (e.g., https: / / github.com / comfyanonymous / ComfyUI.git), and switch to the specified version tag or commit hash. Execute `pip install -r requirements.txt` to install the ComfyUI core dependencies.
[0034] ④ Third-party plugin installation: Iterate through the pre-defined plugin list (such as ComfyUI-Impact-Pack, ComfyUI-Manager, ComfyUI-IPAdapter-Plus, etc.), perform a Git clone operation on each plugin, and place its code into the container's custom_nodes directory. For plugins that require additional dependencies, execute their built-in installation scripts (such as install.py).
[0035] ⑤ Image Consolidation: After completing the above installation steps, execute `docker commit` to solidify the current container state into a base image and assign it a versioning tag (e.g., comfy-base:20251225.v1). This image can serve as a unified template for subsequent production deployments, ensuring a completely consistent running environment when different nodes start up.
[0036] (2) Decoupling and mounting of model assets Massive model files (Checkpoints, LoRA, ControlNet, etc.) are mounted from the host machine to the container via physical volume mapping, avoiding the inefficiency of distribution caused by packaging them into the image. The specific implementation is as follows: ① Host machine model directory planning: Establish a unified model storage directory on the host machine, classifying and storing models according to their type. For example:
[0037] ② Container Mount Configuration: In the container orchestration configuration, mount this directory as read-only to the model directory of the inference engine container (e.g., / workspace / ComfyUI / models). This directory mapping is implemented through the volumes configuration item, ensuring that the container can access model files on the host machine when it starts.
[0038] ③ Extensions in Kubernetes Environments: For Kubernetes environments, persistent storage management of model assets is achieved through the PV / PVC mechanism. First, a persistent volume (PV) is created pointing to shared storage (such as NFS or Ceph). Then, a persistent volume declaration (PVC) is created. Finally, this PVC is referenced in the Pod's Volume mount configuration. Multiple inference engine Pods can share the same PVC, ensuring model version consistency across different nodes.
[0039] Through the aforementioned dual-track mechanism of "image solidification + data externalization," the runtime environment and model assets are decoupled: the image is responsible for the consistency of the code and plugin environment, while the physical volume is responsible for the unified management of model files. When model files need to be updated, only the files on the host machine or shared storage need to be updated, without rebuilding the image, effectively solving the problem of image bloat caused by excessively large model files.
[0040] (3) Deployment of API wrapper containers The API wrapper container is responsible for encapsulating business logic and distributing requests. This container provides a RESTful API interface to the outside world. After receiving user requests, it performs preprocessing operations such as parameter validation, authentication and authorization, and request rate limiting in sequence, and then forwards the task to the inference engine container.
[0041] The specific implementation is as follows: ① Interface definition: Define the standard API interface specification, including the request path (e.g., / generate), request method (POST), request parameters (e.g., prompt, workflow, steps, cfg_scale, etc.), and response format (image Base64 encoding or URL).
[0042] ② Parameter Validation: Perform validity checks on received request parameters, including checking required parameters, parameter type, and parameter range (e.g., steps can range from 1 to 50). For invalid requests, return a clear error code and error message.
[0043] ③ Authentication and Authorization: Integrate API key or OAuth2 authentication mechanisms to verify the legitimacy of the request source. Only clients with valid credentials are allowed to access the inference service, preventing malicious attacks and resource abuse.
[0044] ④ Request Distribution: Distribute requests to the corresponding inference engine containers based on workflow type or load balancing strategy. Supports multiple distribution algorithms such as round-robin, least connections, and consistent hashing.
[0045] ⑤ Response Encapsulation: The generated image and metadata returned by the inference engine container are encapsulated into a unified JSON response and returned to the client. Request logs are also recorded for subsequent auditing and analysis.
[0046] By separating the API gateway logic from the inference engine, the system decouples the business layer from the computing layer, facilitating independent expansion and upgrades.
[0047] (4) Deployment of large language model inference container The large language model inference container provides auxiliary language model processing capabilities for scenarios such as prompt word optimization, workflow parsing, and parameter auto-completion. This container runs as an independent service and is interconnected with the inference engine container via an intra-container network.
[0048] The specific implementation is as follows: ① Container image selection: Choose a lightweight large language model inference image, such as the official Ollama image (ollama / ollama:latest), which supports rapid deployment of various open source large language models (such as Llama 2, Mistral, Qwen, etc.).
[0049] ② Model preloading: Based on business needs, preload the specified language model when the container starts. For example, specify the loading of the Qwen2.5-7B-Instruct model via environment variables or startup command for prompt word optimization tasks.
[0050] ③ API Interface Exposure: The container exposes a standard RESTful API interface (such as / api / generate), accepts prompt text input, and returns enhanced prompt text output.
[0051] ④ Intra-container network communication: In the Docker Compose configuration, place the inference engine container and the large language model container on the same network (e.g., comfy-net). The inference engine container calls the API interface of the large language model container through the service name (e.g., http: / / ollama:11434 / api / generate).
[0052] ⑤ Prompt word optimization process: When the prompt words entered by the user are relatively brief, the inference engine container can call the large language model container to semantically enhance the prompt words. For example, the user input "a cat" can be expanded to "a cute orange cat, sitting on the windowsill, sunlight shining on its fur, 4K high definition, rich in detail", thereby improving the generation effect.
[0053] (5) Deployment of resource monitoring containers The resource monitoring container is used to collect the load status and memory usage of the underlying GPU in real time. The container runs in privileged mode, interacts with the GPU hardware through the NVIDIA Management Library (NVML), collects various metrics at fixed intervals (e.g., every 5 seconds), and exposes the monitoring data through an HTTP endpoint in Prometheus format.
[0054] The specific implementation is as follows: ① Container image selection: Select the DCGM-Exporter image (nvidia / dcgm-exporter:latest) provided by NVIDIA. This image integrates NVIDIA Data Center GPU Management (DCGM) tools and can comprehensively collect GPU hardware metrics.
[0055] ② GPU device access configuration: Add the --runtime=nvidia parameter when starting the container and set the environment variable NVIDIA_VISIBLE_DEVICES=all to ensure that the container can access all GPU devices on the host machine.
[0056] ③ Metric Collection and Exposure: DCGM-Exporter collects the following metrics every 5 seconds: GPU utilization (DCGM_FI_DEV_GPU_UTIL), memory usage (DCGM_FI_DEV_MEMORY_UTIL), memory temperature (DCGM_FI_DEV_MEMORY_TEMP), GPU core temperature (DCGM_FI_DEV_GPU_TEMP), power consumption (DCGM_FI_DEV_POWER_USAGE), and PCIe throughput (DCGM_FI_DEV_PCIE_RX_BYTES, DCGM_FI_DEV_PCIE_TX_BYTES). These metrics are exposed in Prometheus format via an HTTP endpoint (default port 9400).
[0057] ④ Monitoring Data Consumption: Before startup, the deployment script calls this endpoint to obtain information such as the current node's GPU model and total video memory, which is used for hardware adaptive scheduling. Simultaneously, the Prometheus monitoring system can periodically crawl this endpoint, persistently storing the metric data for real-time observation and alerting by operations and maintenance personnel.
[0058] S2: Dynamic switching between development and production modes This step corresponds to Figure 2The diagram illustrates the environment governance workflow. In this workflow, 201 represents the interactive container in development mode, providing a debugging environment for developers; 202 represents the governance phase, responsible for snapshotting and cleansing the environment, including 2021 generating the environment fingerprint, 2022 executing a cleanup script to remove redundancy, and 2023 committing the image; 203 represents the production environment image, responsible for providing standardized, GUI-less inference services in the production cluster. This step details the specific implementation of the dual-mode switching mechanism between development and production modes, as well as the execution logic of the environment cleanup script.
[0059] (1) Start-up and debugging of development mode In development mode, the inference engine container runs in an interactive terminal mode, providing developers with a complete debugging environment. The container startup command is as follows:
[0060] Key parameters for this command: -it: Allocate an interactive terminal, allowing developers to execute commands. --rm: Automatically deletes the container after it exits, preventing residual data. -v . / custom_nodes: / workspace / ComfyUI / custom_nodes: Mounts the local custom plugin directory into the container, enabling "hot reloading" debugging capabilities. Developers can modify the plugin source code and the changes will take effect without restarting the container. -p 8188:8188: Exposes the web interface port of ComfyUI, allowing developers to access it via a browser for workflow visualization and debugging. --gpus all: Allocate all GPUs to ensure the container can perform inference tasks. / bin / bash: Overrides the default startup command and enters the bash shell. Once inside the container, developers can perform the following operations: ① Install a new plugin online: Execute the command `git clone https: / / github.com / xxx / custom-node.git custom_nodes / ` to clone the new plugin repository to the `custom_nodes` directory inside the container. Since this directory is synchronized with the host machine via volume mounting, the installed plugin will persist after the container restarts.
[0061] ② Debug Workflow: Access http: / / localhost:8188 via your browser to enter the ComfyUI graphical workflow editor. Developers can drag and drop nodes, connect workflows, adjust parameters, and preview the generated results in real time.
[0062] ③ Adjust Python dependencies: Execute `pip install new-package` to install new Python dependency packages. The installed dependency packages will be written to the container's writable layer and can be persisted through subsequent image commit operations.
[0063] ④ Modify plugin source code: Navigate to the plugin directory via the terminal and directly edit the Python source code file. The modified code takes effect immediately without requiring a container restart.
[0064] (2) Backup and generation of environmental fingerprints After development and debugging are complete, the system invokes the environment backup and restore unit to generate a "genetic" snapshot of the current runtime environment with a single click. This snapshot is stored in JSON format and includes: ① ComfyUI core repository information: Get the hash value of the current HEAD commit using `git -C / workspace / ComfyUI rev-parse HEAD`, and get the remote repository address using `git -C / workspace / ComfyUI remote get-url origin`.
[0065] ② Third-party plugin information: Traverse each subdirectory under the / workspace / ComfyUI / custom_nodes directory, execute git rev-parse HEAD for each plugin to obtain the hash value of the current version, and record the plugin's Git repository address and name.
[0066] ③ Python dependency information: Execute the pip freeze command to obtain the list of dependency packages and their version numbers for the current Python environment, and generate a dependency list in requirements format.
[0067] ④ Environment variable information: Read runtime-related environment variables, such as PYTHONPATH, CUDA_VISIBLE_DEVICES, TORCH_CUDA_ARCH_LIST, etc.
[0068] ⑤ System environment information: Records the operating system distribution information (such as Ubuntu 22.04) and kernel version, which is used to assist in environment replication.
[0069] All collected information is organized into a JSON structure, forming an environment fingerprint file (such as env_snapshot.json). This file can be archived, version-controlled, and transferred across regions as an "environment gene".
[0070] (3) Cleanup process before image submission Before committing the production image, execute the environment cleanup script to remove redundant data within the container. The main cleanup functions of the cleanup script cleanup_before_commit.sh include: ① Clean up proxy configuration: Execute `unset HTTP_PROXY HTTPS_PROXY` to clear the proxy environment variables and prevent proxy information from being leaked.
[0071] ② Pip cache cleanup: Execute `rm -rf ~ / .cache / pip / *` to delete the cached package files downloaded by pip, reducing the image size.
[0072] ③ Clean up the apt cache: Execute `apt-get clean` and `rm -rf / var / lib / apt / lists / *` to delete the apt package manager cache.
[0073] ④ Clean up temporary files: Execute `rm -rf / tmp / *` to delete files in the temporary directory.
[0074] ⑤ Shell history cleanup: Execute `history -c` to clear the history of commands in the current session to prevent the leakage of sensitive commands.
[0075] ⑥ Python bytecode cleanup: Execute `find / workspace -name "*.pyc" -delete` to delete the bytecode files generated by Python compilation.
[0076] By following the above cleanup steps, the purity of the production image is ensured, and the leakage of sensitive information and the expansion of the image size are avoided.
[0077] (4) Image submission and production mode switching The `docker commit` command persists the current container state as a production image and pushes it to a private image repository. The commit command is as follows:
[0078] The pushed image comes with a version tag, such as comfy-prod:20251225.4090d.v1. The tag contains information such as date, target graphics card model, and version number, which facilitates traceability and management.
[0079] In production mode, the container starts as a GUI-less API service, exposing only the API interface and disabling the web interface. The startup command is as follows:
[0080] Key parameters for this command: -d: Run in daemon mode, without attaching an interactive terminal. --api-only: A ComfyUI-specific startup parameter that disables the web interface and enables only the API service. --listen 0.0.0.0: Listens on all network interfaces, allowing external requests to access them. --port 8188: Specifies the API service port In production mode, containers no longer accept interactive terminal connections; all requests are processed via API, reducing security risks and improving resource utilization.
[0081] S3: Hardware-Aware Adaptive Startup Strategy This step details the implementation principle of the hardware-aware adaptive startup strategy. The system uses a resource monitoring container to monitor the GPU hardware status in real time, and implements hardware detection routing and dynamically allocates video memory management parameters in the deployment script.
[0082] (1) Real-time acquisition of GPU hardware information Before startup, the deployment script calls the HTTP endpoint of the DCGM-Exporter container (e.g., http: / / localhost:9400 / metrics) to parse the returned Prometheus-formatted metrics. Key metrics include:
[0083] (2) Decision logic of hardware detection routing The deployment script includes a built-in hardware parameter mapping table that maps the identified GPU model to its corresponding memory management parameters. The mapping rules are set based on the differences in memory capacity and architecture among different graphics cards. ① High-end graphics cards (≥24GB VRAM, such as RTX 4090, A100): Allocate the --normalvram parameter to allow the entire model to be loaded into VRAM for optimal inference speed. Simultaneously set the --highvram auxiliary parameter to enable VRAM pre-allocation strategy and reduce VRAM fragmentation.
[0084] ② Mid-range graphics cards (16GB VRAM, such as RTX 4080, RTX 4080 SUPER): Allocate the `--lowvram` parameter to employ a block loading strategy, balancing VRAM usage while ensuring availability. Set the `--cpu` parameter to roll back some non-critical calculations to the CPU, avoiding VRAM overflow.
[0085] ③ Entry-level graphics cards (12GB VRAM, such as RTX 4070, RTX 3060): Allocate the --novram parameter to adopt a more aggressive VRAM management strategy, frequently reclaiming VRAM. Simultaneously set the --cpu-vae parameter to move the VAE encoding / decoding process to the CPU, reducing VRAM usage.
[0086] In addition, the system dynamically adjusts the video memory release strategy based on the real-time video memory usage rate: when the video memory usage rate exceeds a preset threshold (such as 90%), it actively triggers ComfyUI's video memory reclamation mechanism (calls torch.cuda.empty_cache()) to clean up unused cache tensors.
[0087] (3) Mechanism for the activation of adaptive parameters The deployment script appends the detected parameters to the container startup command, which is then passed to the inference engine container as command-line arguments. For example:
[0088] When the container starts, it reads these parameters and configures ComfyUI's video memory management module. Through this mechanism, the same deployment script can automatically adapt to the optimal parameters on nodes with different hardware configurations, achieving self-adaptation to hardware differences.
[0089] S4: Off-site replication based on environmental fingerprinting This step corresponds to Figure 4 The environment replication logic is shown below. Here, 400 represents the environment fingerprint structure (JSON), responsible for storing the environment's "genetic" information; 401 represents the core engine hash value; 402 represents the version number set of the plugin node Git Hash set and the ComfyUI official node registry; 403 represents the Python interpreter parameters; 404 represents the plugin extension function status bit; and 500 represents the target execution environment, responsible for executing the replication actions corresponding to 501-504 based on the fingerprint information to achieve environment alignment across different servers.
[0090] This step details the implementation of the environment fingerprint backup and recovery unit. Deployers only need a JSON fingerprint file to replicate a completely identical development environment on a remote server.
[0091] (1) Collection and structured storage of environmental fingerprints The environment backup and recovery unit collects environment fingerprint information in the following ways: ① Core repository information: Get the hash value of the current HEAD commit using `git -C / workspace / ComfyUI rev-parse HEAD`, get the current branch name using `git -C / workspace / ComfyUI rev-parse --abbrev-ref HEAD`, and get the remote repository address using `git -C / workspace / ComfyUI remote get-url origin`.
[0092] ② Plugin information: Traverse each subdirectory under the / workspace / ComfyUI / custom_nodes directory, execute git rev-parse HEAD to get the hash value of the current version for each plugin, execute git remote get-urlorigin to get the remote repository address, and record the plugin name and path.
[0093] ③ Python dependency information: Execute the pip freeze command to obtain the list of dependency packages and their version numbers for the current Python environment, and generate a dependency list in requirements format.
[0094] ④ Environment variable information: Read runtime-related environment variables, such as PYTHONPATH, CUDA_VISIBLE_DEVICES, TORCH_CUDA_ARCH_LIST, etc.
[0095] ⑤ System environment information: Obtain the operating system kernel version using uname -a, and obtain the distribution information using cat / etc / os-release.
[0096] All collected information was organized into a JSON structure to form an environment fingerprint file. An example of the file structure is shown below:
[0097] The fingerprint file can be stored in a version control system or shared storage for subsequent environment replication and audit traceability.
[0098] (2) Fingerprint-based remote environment replication On the target server, the deployment team executes an environment recovery script, passing in a fingerprint file as input. The recovery script reconstructs the environment according to the following steps: ① Create working directory: Create the ComfyUI working directory (e.g., / workspace / ComfyUI) according to the configuration in the fingerprint file.
[0099] ② Clone the core repository: Execute `git clone` <repository><target_dir>Clone the ComfyUI core code, then execute `git checkout`.<commit_hash> Switch to the submitted version of the fingerprint file record.
[0100] ③ Install the Python environment: Install the corresponding version of the Python interpreter according to the Python version requirements in the fingerprint file. If the Python version on the target server does not match, you can install a specific version using pyenv or conda.
[0101] ④ Install dependencies: Execute `pip install -r requirements.txt` to install the ComfyUI core dependencies. Then iterate through the Python dependency list in the fingerprint file and execute `pip install`. <package> == <version>Install the specified version of the dependency packages.
[0102] ⑤ Clone plugins: Iterate through the list of plugins in the fingerprint file and execute `git clone` on each plugin. <repository>custom_nodes / <name>Clone the plugin code, then execute `git checkout`.<commit_hash> Switch to the specified version.
[0103] ⑥ Configure environment variables: Based on the environment variable configuration in the fingerprint file, set the environment variables for the current session (e.g., export PYTHONPATH= / workspace / ComfyUI).
[0104] Through the above process, the target server can replicate an execution environment completely identical to the source environment within minutes. Compared with the traditional "document-level" environment handover (which requires manually recording the list of plugins and their version numbers, and then manually installing them one by one), this invention reduces the environment replication time from hours to minutes and eliminates version errors introduced by human operation.
[0105] S5: Automated Visual Regression Testing This step corresponds to Figure 3 The diagram illustrates the automated testing logic. Here, 301 represents the YAML-formatted test case configuration, responsible for defining test metrics and expected results; 302 represents the automated testing engine, responsible for driving test case execution and comparing outputs; and 303 represents the visual test report, responsible for intuitively displaying the matching relationship between input parameters and AI-generated images through side-by-side layout.
[0106] This step details the implementation principles of the configuration-driven automated visual regression testing system. This test is integrated into the CI / CD pipeline to ensure the stability of the AI-generated results before each image release.
[0107] (1) Configuration-based management of test cases The system establishes an independent test project and defines test cases using a YAML configuration file. The structure of the configuration file test_cases.yaml is as follows:
[0108]
[0109] Each test case contains the following key fields:
[0110] The test case library can be categorized and managed according to business scenarios, such as basic text-to-image tests, image-to-image tests, ControlNet tests, etc., supporting incremental additions and version evolution. The configuration file adopts a structured YAML format, which facilitates version control and automated parsing.
[0111] (2) Execution process of automated testing engine The test engine reads the YAML configuration file and executes the test cases sequentially. The execution flow of each test case is as follows: ① Request Construction: Construct the API request based on the input parameters of the test case. For test cases involving reference images (such as raw images and ControlNet), the test engine reads the reference image file from the test project directory, performs Base64 encoding, and embeds it into the request body.
[0112] ② API Call: Send an HTTP POST request to the target ComfyUI service, calling the / generate interface. The request carries the input parameters defined in the test case, including workflow type, prompt words, number of sampling steps, guidance strength, image size, random seed, etc.
[0113] ③ Response Reception: Receive the response returned by the service. A successful response includes metadata such as the Base64 encoded data of the generated image, execution time, and the model version used.
[0114] ④ Execution time record: Record the time difference from request initiation to response reception and compare it with the execution_time_max threshold of the test case.
[0115] ⑤ Response Status Verification: Verify if the HTTP response status code is 200. If it is not 200, the test fails and the error message is recorded.
[0116] ⑥ Image Decoding and Saving: Decode the Base64 encoded image data in the response into binary format and save it to the output directory of the test project. The file naming rule is {case_id}_output.png.
[0117] ⑦ Similarity Comparison: Compare the similarity with the baseline image. The baseline image is the generated result that has passed verification in the previous version and is stored in the baselines directory of the test project. The similarity is calculated using the Structural Similarity Index (SSIM) algorithm. The SSIM algorithm evaluates the similarity between two images from three dimensions: brightness, contrast, and structure, with values ranging from 0 to 1. The higher the value, the more similar the images are.
[0118] ⑧ Result Recording: Record the test results (test case ID, name, similarity, execution time, status) to the result set. For test cases with similarity below the threshold, additionally record the difference heatmap data.
[0119] (3) Generation of visual test reports After the test is completed, the system generates a visual test report in HTML format. The report uses a responsive layout and supports access on both desktop and mobile devices. The report content includes the following modules: ① Test Execution Summary: Displays the total number of test cases, the number of passes, the number of failures, and the success rate. The test pass rate is displayed intuitively using a green progress bar.
[0120] ② Test Case Details Table: This table displays the detailed results of each test case, including the following:
[0121] ③ Failed Test Case Difference Analysis: For test cases that do not meet the similarity standard, the system generates a difference heatmap. The difference heatmap compares pixels down to the pixel level, highlighting the areas of difference between the generated image and the baseline image in red, helping testers quickly locate the problem. The generation logic of the difference heatmap is as follows: calculate the RGB difference of each pixel in the two images, normalize the difference, and map it to the heatmap color (the greater the difference, the redder the color).
[0122] ④ Overall evaluation conclusion: The evaluation conclusion is automatically generated based on the test results, such as "Pass: All test cases meet the standard" or "Fail: X test cases did not meet the standard. Please check the image quality."
[0123] The report can be exported as a PDF for easy archiving and sharing. Additionally, the report can be automatically pushed to relevant personnel via email or WeChat Work.
[0124] (4) Integration method of CI / CD pipeline This test system integrates with the CI / CD pipeline via a command-line interface. The test script run_regression_test.py provides the following command-line parameters:
[0125] In a GitLab CI / CD pipeline, configure as follows:
[0126] The test results serve as the conditions for releasing access control: if the test passes (success rate reaches 100%), the subsequent deployment steps will continue; if the test fails, the release process will be blocked, and an alarm notification will be sent via the WeChat Work robot. The notification will include the ID and name of the failed test case, the similarity score, the report link, and other information.
[0127] II. ComfyUI Consistent Deployment and Environment Governance System with Multi-Container Collaboration Reference Figure 6 This disclosure also provides a multi-container collaborative ComfyUI consistency deployment and environment governance system for implementing the above methods. The system includes: The multi-container collaboration module is used to integrate the inference engine container, API wrapper container, large language model inference container, and resource monitoring container through container orchestration technology to form a multi-container collaboration architecture. Among them, the inference engine container is used to solidify the ComfyUI core engine and third-party plugin environment, and mount the model files through physical volume mapping to achieve decoupling and consistency between the runtime environment and model assets.
[0128] The dual-mode switching module is used to configure the dual-mode switching mechanism between development mode and production mode. In the development mode, the inference engine container runs in an interactive terminal mode, supporting developers to install plugins and debug workflows online. Before switching from development mode to production mode, an environment cleanup script is executed to remove agent configurations, cached data, and temporary files in the container. In the production mode, the inference engine container runs in a GUI-less API service mode.
[0129] The hardware adaptive scheduling module is used to collect GPU status information in real time through the resource monitoring container, implement hardware detection routing in the deployment script, automatically allocate corresponding video memory management parameters according to the identified graphics card model, and dynamically adjust the video memory release strategy.
[0130] The environment fingerprint management module is used to back up the Python dependency versions, ComfyUI core repository hash value, and Git hash values of each plugin node of the current runtime environment into a structured JSON file, and to replicate an execution environment consistent with the source environment on the target server based on the JSON file. The structured data file includes at least: the ComfyUI core repository hash value, the Git hash value of each plugin node, a list of Python dependency versions, and Python interpreter parameter configuration.
[0131] An automated testing module is used to read YAML-formatted test case configuration files, drive test case execution, generate a visual test report that compares input parameters with AI-generated images, and integrate this automated testing module into the CI / CD pipeline to verify the stability of the AI-generated effects before image release. The automated testing module is also configured to display the side-by-side comparison results of input parameters and AI-generated images, supporting manual or algorithmic auditing of the stability of the generated effects.
[0132] This Kubernetes integration module supports seamless migration of systems from single-machine deployments to Kubernetes clusters. In a Kubernetes environment, it manages model assets through PV / PVC mechanisms and leverages Deployment and Service resources to achieve automated elastic scaling of the Kubernetes cluster. Specifically, it creates persistent volumes pointing to shared storage and declares persistent volumes for Pod mounting; defines Deployment resources, sets the replica count and resource requests, and uses HorizontalPodAutoscaler to achieve automatic scaling based on GPU utilization; and defines Service resources to expose API endpoints within the cluster.
[0133] The specific implementation principles of the above modules have been explained in detail in the method embodiments, and will not be repeated here.
[0134] The basic principles of this disclosure have been described above with reference to specific embodiments. However, it should be noted that the advantages, benefits, and effects mentioned in this disclosure are merely examples and not limitations, and should not be considered as essential features of each embodiment of this disclosure. Furthermore, the specific details disclosed above are for illustrative and facilitative purposes only, and are not limitations. These details do not limit the scope of this disclosure to the necessity of employing the aforementioned specific details for implementation.
[0135] In this disclosure, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. The block diagrams of devices, apparatuses, devices, and systems involved in this disclosure are merely illustrative examples and are not intended to require or imply that they must be connected, arranged, or configured in the manner shown in the block diagrams. As those skilled in the art will recognize, these devices, apparatuses, devices, and systems can be connected, arranged, and configured in any manner. Words such as "comprising," "including," "having," etc., are open-ended terms meaning "including but not limited to," and are used interchangeably with them. The terms "or" and "and" as used herein refer to the terms "and / or," and are used interchangeably with them unless the context clearly indicates otherwise. The term "such as" as used herein refers to the phrase "such as but not limited to," and is used interchangeably with it.
[0136] Additionally, as used herein, the "or" used in a list of items beginning with "at least one" indicates a separate list, such that a list of, for example, "at least one of A, B, or C" means A or B or C, or AB or AC or BC, or ABC (i.e., A and B and C). Furthermore, the word "exemplary" does not imply that the described example is preferred or better than other examples.
[0137] It should also be noted that in the systems and methods of this disclosure, the components or steps can be decomposed and / or recombined. These decompositions and / or recombinations should be considered as equivalent solutions to this disclosure.
[0138] Various changes, substitutions, and modifications can be made to the technology described herein without departing from the teachings defined by the appended claims. Furthermore, the scope of the claims of this disclosure is not limited to the specific aspects of the processes, machines, manufactures, events, means, methods, and actions described above. Currently existing or later-developed processes, machines, manufactures, events, means, methods, or actions that perform substantially the same function or achieve substantially the same result as the corresponding aspects described herein can be utilized. Therefore, the appended claims include such processes, machines, manufactures, events, means, methods, or actions within their scope.
[0139] The above description of the disclosed aspects is provided to enable any person skilled in the art to make or use this disclosure. Various modifications to these aspects will be readily apparent to those skilled in the art, and the general principles defined herein may be applied to other aspects without departing from the scope of this disclosure. Therefore, this disclosure is not intended to be limited to the aspects shown herein, but rather to be carried out within the widest scope consistent with the principles and novel features disclosed herein.
[0140] The above description has been given for purposes of illustration and description. Furthermore, this description is not intended to limit the embodiments of this disclosure to the forms disclosed herein. Although numerous exemplary aspects and embodiments have been discussed above, those skilled in the art will recognize certain variations, modifications, alterations, additions, and sub-combinations thereof.< / name> < / repository> < / version> < / package> < / repository>
Claims
1. A method for coordinating multi-container ComfyUI consistent deployment and environment governance, characterized in that, include: The ComfyUI core engine and third-party plugin environment are embedded in a Docker image, and model files are mounted from the host machine to the container through physical volume mapping, achieving decoupling and consistency between the runtime environment and model assets; By integrating inference engine containers, API wrapper containers, large language model inference containers, and resource monitoring containers through container orchestration technology, a multi-container collaborative architecture is formed. The inference engine container is used to solidify the AI runtime environment and execute image generation tasks. The API wrapper container is used to encapsulate business logic and distribute external requests to the inference engine container. The large language model inference container is used to provide auxiliary language model processing capabilities and interconnect with the inference engine container through the container network. The resource monitoring container is used to collect the load status and memory usage of the underlying GPU in real time.
2. The method according to claim 1, characterized in that, Also includes: Configure a dual-mode switching mechanism between development and production modes; In the development mode, the inference engine container runs in an interactive terminal mode, supporting developers to install plugins and debug workflows online. In the production mode, the inference engine container runs as a GUI-less API service.
3. The method according to claim 2, characterized in that, Before switching from development mode to production mode, execute an environment cleanup script to remove agent configurations, cached data, and temporary files from the container to ensure the purity of the production image.
4. The method according to claim 1, characterized in that, Also includes: The automated testing module reads YAML-formatted test case configuration files and drives the execution of test cases. Generate a visual test report that compares the input parameters with the AI-generated image; The automated testing module is integrated into the CI / CD pipeline to verify the stability of AI-generated effects before image release.
5. The method according to claim 1, characterized in that, Also includes: The environment backup and restore unit backs up the Python dependency version of the current runtime environment, the hash value of the ComfyUI core repository, and the Git hash value of each plugin node into a structured JSON file. Based on the JSON file, an execution environment identical to the source environment is replicated on the target server.
6. The method according to claim 1, characterized in that, Also includes: The resource monitoring container collects GPU status information in real time. The deployment script implements hardware detection routing, automatically allocates corresponding video memory management parameters based on the identified graphics card model, and dynamically adjusts the video memory release strategy.
7. A multi-container collaborative ComfyUI consistent deployment and environment governance system, characterized in that, The system for implementing the method of any one of claims 1 to 6 comprises: The multi-container collaboration module is used to integrate the inference engine container, API wrapper container, large language model inference container, and resource monitoring container through container orchestration technology to form a multi-container collaboration architecture. Among them, the inference engine container is used to solidify the ComfyUI core engine and third-party plugin environment, and mount the model files through physical volume mapping to achieve decoupling and consistency between the runtime environment and model assets. The dual-mode switching module is used to configure the dual-mode switching mechanism between development mode and production mode. In the development mode, the inference engine container runs in an interactive terminal mode, supporting developers to install plugins and debug workflows online. Before switching from development mode to production mode, an environment cleanup script is executed to remove agent configurations, cached data, and temporary files in the container. In the production mode, the inference engine container runs in a GUI-less API service mode. The hardware adaptive scheduling module is used to collect GPU status information in real time through the resource monitoring container, implement hardware detection routing in the deployment script, automatically allocate corresponding video memory management parameters according to the identified graphics card model, and dynamically adjust the video memory release strategy. The environment fingerprint management module is used to back up the Python dependency version, ComfyUI core repository hash value, and Git hash value of each plugin node of the current runtime environment into a structured JSON file, and replicate the execution environment consistent with the source environment on the target server based on the JSON file; An automated testing module is used to read YAML format test case configuration files, drive test case execution, generate a visual test report that compares input parameters with AI-generated images, and integrate the automated testing module into the CI / CD pipeline to verify the stability of AI generation effects before image release.
8. The system according to claim 7, characterized in that, The system supports seamless migration from single-machine deployment to Kubernetes cluster; in the Kubernetes environment, it manages model assets through PV / PVC mechanism and uses Deployment and Service resources to achieve automated elastic scaling of the generated image cluster.
9. The system according to claim 7, characterized in that, The automated testing module is also configured to display the side-by-side comparison results of the input parameters and the AI-generated image, supporting manual or algorithmic auditing of the stability of the generated effect.
10. The system according to claim 7, characterized in that, The structured data files backed up by the environment backup and recovery unit include at least: the hash value of the ComfyUI core repository, the Git hash value of each plugin node, the list of Python dependency versions, and the Python interpreter parameter configuration.
Citation Information
Patent Citations
A cloud-native artificial intelligence and machine learning development method and system
CN119396425B
Container operation method based on artificial intelligence
CN120994314A
Multi-modal model reasoning method, framework, equipment and medium
CN121257715A
