From d452877179f4d24405c5e92244b359b3dbf98b0d Mon Sep 17 00:00:00 2001 From: "Dr.Lt.Data" Date: Tue, 23 Apr 2024 00:54:24 +0900 Subject: [PATCH] improve: support --cpu mode in `comfy launch` --- README.md | 4 ++++ comfy_cli/cmdline.py | 24 +++++++++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 3ec179c..a95a341 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,10 @@ Comfy provides commands that allow you to easily run the installed ComfyUI. `comfy launch` +- To run in CPU mode: + + `comfy launch --cpu` + ### Managing Packages comfy allows you to easily install, update, and remove packages for ComfyUI. Here are some examples: diff --git a/comfy_cli/cmdline.py b/comfy_cli/cmdline.py index 06dfb5f..6a1c366 100644 --- a/comfy_cli/cmdline.py +++ b/comfy_cli/cmdline.py @@ -90,37 +90,47 @@ def run( run_inner.execute(workflow_file) -def launch_comfyui(_env_checker): +def launch_comfyui(_env_checker, cpu): _env_checker.config['DEFAULT']['recent_path'] = os.getcwd() _env_checker.write_config() - subprocess.run(["python", "main.py"]) + if cpu: + subprocess.run(["python", "main.py", "--cpu"]) + else: + subprocess.run(["python", "main.py"]) -@app.command(help="Launch ComfyUI: ?[--workspace ]") +@app.command(help="Launch ComfyUI: ?[--workspace ] ?[--cpu]") def launch(workspace: Annotated[ str, typer.Option( show_default=False, help="Path to ComfyUI workspace") - ] = None): + ] = None, + cpu: Annotated[ + bool, + lambda: typer.Option( + default=False, + help="enable CPU mode") + ] = False, + ): _env_checker = EnvChecker() if workspace is not None: comfyui_path = os.path.join(workspace, 'ComfyUI') if os.path.exists(comfyui_path): os.chdir(comfyui_path) print(f"\nLaunch ComfyUI from repo: {_env_checker.comfy_repo.working_dir}\n") - launch_comfyui(_env_checker) + launch_comfyui(_env_checker, cpu) else: print(f"\nInvalid ComfyUI not found in specified workspace: {workspace}\n", file=sys.stderr) elif _env_checker.comfy_repo is not None: print(f"\nLaunch ComfyUI from current repo: {_env_checker.comfy_repo.working_dir}\n") - launch_comfyui(_env_checker) + launch_comfyui(_env_checker, cpu) elif _env_checker.config['DEFAULT'].get('recent_path') is not None: comfy_path = _env_checker.config['DEFAULT'].get('recent_path') print(f"\nLaunch ComfyUI from recent repo: {comfy_path}\n") os.chdir(comfy_path) - launch_comfyui(_env_checker) + launch_comfyui(_env_checker, cpu) else: print(f"\nComfyUI is not available.\n", file=sys.stderr)