Skip to content

Commit

Permalink
improve: support --cpu mode in comfy launch
Browse files Browse the repository at this point in the history
  • Loading branch information
ltdrdata committed Apr 22, 2024
1 parent aed1d86 commit d452877
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
24 changes: 17 additions & 7 deletions comfy_cli/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <path>]")
@app.command(help="Launch ComfyUI: ?[--workspace <path>] ?[--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)

Expand Down

0 comments on commit d452877

Please sign in to comment.