2023-04-06 03:41:23 +00:00
import argparse
2023-06-05 18:19:02 +00:00
import enum
2024-07-16 15:26:11 +00:00
import os
from typing import Optional
2023-09-13 15:38:20 +00:00
import comfy . options
2023-06-05 18:19:02 +00:00
2024-07-16 15:26:11 +00:00
2023-06-05 18:19:02 +00:00
class EnumAction ( argparse . Action ) :
"""
Argparse action for handling Enums
"""
def __init__ ( self , * * kwargs ) :
# Pop off the type value
enum_type = kwargs . pop ( " type " , None )
# Ensure an Enum subclass is provided
if enum_type is None :
raise ValueError ( " type must be assigned an Enum when using EnumAction " )
if not issubclass ( enum_type , enum . Enum ) :
raise TypeError ( " type must be an Enum when using EnumAction " )
# Generate choices from the Enum
choices = tuple ( e . value for e in enum_type )
kwargs . setdefault ( " choices " , choices )
kwargs . setdefault ( " metavar " , f " [ { ' , ' . join ( list ( choices ) ) } ] " )
super ( EnumAction , self ) . __init__ ( * * kwargs )
self . _enum = enum_type
def __call__ ( self , parser , namespace , values , option_string = None ) :
# Convert value back into an Enum
value = self . _enum ( values )
setattr ( namespace , self . dest , value )
2023-04-06 03:41:23 +00:00
parser = argparse . ArgumentParser ( )
2023-04-06 23:06:39 +00:00
parser . add_argument ( " --listen " , type = str , default = " 127.0.0.1 " , metavar = " IP " , nargs = " ? " , const = " 0.0.0.0 " , help = " Specify the IP address to listen on (default: 127.0.0.1). If --listen is provided without an argument, it defaults to 0.0.0.0. (listens on all) " )
2023-04-06 03:41:23 +00:00
parser . add_argument ( " --port " , type = int , default = 8188 , help = " Set the listen port. " )
2024-05-01 00:17:02 +00:00
parser . add_argument ( " --tls-keyfile " , type = str , help = " Path to TLS (SSL) key file. Enables TLS, makes app accessible at https://... requires --tls-certfile to function " )
parser . add_argument ( " --tls-certfile " , type = str , help = " Path to TLS (SSL) certificate file. Enables TLS, makes app accessible at https://... requires --tls-keyfile to function " )
2023-04-06 23:06:39 +00:00
parser . add_argument ( " --enable-cors-header " , type = str , default = None , metavar = " ORIGIN " , nargs = " ? " , const = " * " , help = " Enable CORS (Cross-Origin Resource Sharing) with optional origin or allow all with default ' * ' . " )
2023-10-29 07:55:46 +00:00
parser . add_argument ( " --max-upload-size " , type = float , default = 100 , help = " Set the maximum upload size in MB. " )
2023-04-06 23:06:39 +00:00
parser . add_argument ( " --extra-model-paths-config " , type = str , default = None , metavar = " PATH " , nargs = ' + ' , action = ' append ' , help = " Load one or more extra_model_paths.yaml files. " )
2023-04-06 03:41:23 +00:00
parser . add_argument ( " --output-directory " , type = str , default = None , help = " Set the ComfyUI output directory. " )
2023-08-11 09:00:25 +00:00
parser . add_argument ( " --temp-directory " , type = str , default = None , help = " Set the ComfyUI temp directory (default is in the ComfyUI directory). " )
2023-10-04 22:45:15 +00:00
parser . add_argument ( " --input-directory " , type = str , default = None , help = " Set the ComfyUI input directory. " )
2023-05-06 20:59:40 +00:00
parser . add_argument ( " --auto-launch " , action = " store_true " , help = " Automatically launch ComfyUI in the default browser. " )
2023-08-07 06:22:26 +00:00
parser . add_argument ( " --disable-auto-launch " , action = " store_true " , help = " Disable auto launching the browser. " )
2023-04-06 23:06:39 +00:00
parser . add_argument ( " --cuda-device " , type = int , default = None , metavar = " DEVICE_ID " , help = " Set the id of the cuda device this instance will use. " )
2023-07-17 18:40:29 +00:00
cm_group = parser . add_mutually_exclusive_group ( )
cm_group . add_argument ( " --cuda-malloc " , action = " store_true " , help = " Enable cudaMallocAsync (enabled by default for torch 2.0 and up). " )
2023-07-19 14:20:32 +00:00
cm_group . add_argument ( " --disable-cuda-malloc " , action = " store_true " , help = " Disable cudaMallocAsync. " )
2023-07-17 18:40:29 +00:00
2023-07-02 02:42:35 +00:00
fp_group = parser . add_mutually_exclusive_group ( )
fp_group . add_argument ( " --force-fp32 " , action = " store_true " , help = " Force fp32 (If this makes your GPU work better please report it). " )
fp_group . add_argument ( " --force-fp16 " , action = " store_true " , help = " Force fp16. " )
2023-12-04 16:10:00 +00:00
fpunet_group = parser . add_mutually_exclusive_group ( )
fpunet_group . add_argument ( " --bf16-unet " , action = " store_true " , help = " Run the UNET in bf16. This should only be used for testing stuff. " )
2023-12-11 23:36:29 +00:00
fpunet_group . add_argument ( " --fp16-unet " , action = " store_true " , help = " Store unet weights in fp16. " )
2023-12-04 16:10:00 +00:00
fpunet_group . add_argument ( " --fp8_e4m3fn-unet " , action = " store_true " , help = " Store unet weights in fp8_e4m3fn. " )
fpunet_group . add_argument ( " --fp8_e5m2-unet " , action = " store_true " , help = " Store unet weights in fp8_e5m2. " )
2023-10-13 18:51:10 +00:00
2023-07-06 22:04:28 +00:00
fpvae_group = parser . add_mutually_exclusive_group ( )
fpvae_group . add_argument ( " --fp16-vae " , action = " store_true " , help = " Run the VAE in fp16, might cause black images. " )
2023-08-28 03:06:19 +00:00
fpvae_group . add_argument ( " --fp32-vae " , action = " store_true " , help = " Run the VAE in full precision fp32. " )
fpvae_group . add_argument ( " --bf16-vae " , action = " store_true " , help = " Run the VAE in bf16. " )
2023-07-06 22:04:28 +00:00
2023-12-30 10:38:21 +00:00
parser . add_argument ( " --cpu-vae " , action = " store_true " , help = " Run the VAE on the CPU. " )
2023-11-17 07:56:59 +00:00
fpte_group = parser . add_mutually_exclusive_group ( )
fpte_group . add_argument ( " --fp8_e4m3fn-text-enc " , action = " store_true " , help = " Store text encoder weights in fp8 (e4m3fn variant). " )
fpte_group . add_argument ( " --fp8_e5m2-text-enc " , action = " store_true " , help = " Store text encoder weights in fp8 (e5m2 variant). " )
fpte_group . add_argument ( " --fp16-text-enc " , action = " store_true " , help = " Store text encoder weights in fp16. " )
fpte_group . add_argument ( " --fp32-text-enc " , action = " store_true " , help = " Store text encoder weights in fp32. " )
2024-06-15 05:08:12 +00:00
parser . add_argument ( " --force-channels-last " , action = " store_true " , help = " Force channels last format when inferencing the models. " )
2023-11-17 07:56:59 +00:00
2023-04-28 20:51:35 +00:00
parser . add_argument ( " --directml " , type = int , nargs = " ? " , metavar = " DIRECTML_DEVICE " , const = - 1 , help = " Use torch-directml. " )
2023-04-06 03:41:23 +00:00
2023-08-17 10:12:17 +00:00
parser . add_argument ( " --disable-ipex-optimize " , action = " store_true " , help = " Disables ipex.optimize when loading models with Intel GPUs. " )
2023-06-05 23:59:10 +00:00
class LatentPreviewMethod ( enum . Enum ) :
2023-06-06 05:26:52 +00:00
NoPreviews = " none "
2023-06-05 23:59:10 +00:00
Auto = " auto "
2023-06-05 23:39:56 +00:00
Latent2RGB = " latent2rgb "
2023-06-05 18:19:02 +00:00
TAESD = " taesd "
2023-06-06 05:26:52 +00:00
parser . add_argument ( " --preview-method " , type = LatentPreviewMethod , default = LatentPreviewMethod . NoPreviews , help = " Default preview method for sampler nodes. " , action = EnumAction )
2023-06-05 18:19:02 +00:00
2023-04-06 03:41:23 +00:00
attn_group = parser . add_mutually_exclusive_group ( )
2023-06-26 16:55:07 +00:00
attn_group . add_argument ( " --use-split-cross-attention " , action = " store_true " , help = " Use the split cross attention optimization. Ignored when xformers is used. " )
attn_group . add_argument ( " --use-quad-cross-attention " , action = " store_true " , help = " Use the sub-quadratic cross attention optimization . Ignored when xformers is used. " )
2023-04-06 03:41:23 +00:00
attn_group . add_argument ( " --use-pytorch-cross-attention " , action = " store_true " , help = " Use the new pytorch 2.0 cross attention function. " )
parser . add_argument ( " --disable-xformers " , action = " store_true " , help = " Disable xformers. " )
2024-05-16 08:09:41 +00:00
upcast = parser . add_mutually_exclusive_group ( )
upcast . add_argument ( " --force-upcast-attention " , action = " store_true " , help = " Force enable attention upcasting, please report if it fixes black images. " )
upcast . add_argument ( " --dont-upcast-attention " , action = " store_true " , help = " Disable all upcasting of attention. Should be unnecessary except for debugging. " )
2023-04-06 03:41:23 +00:00
vram_group = parser . add_mutually_exclusive_group ( )
2023-06-15 19:21:37 +00:00
vram_group . add_argument ( " --gpu-only " , action = " store_true " , help = " Store and run everything (text encoders/CLIP models, etc... on the GPU). " )
2023-04-06 03:41:23 +00:00
vram_group . add_argument ( " --highvram " , action = " store_true " , help = " By default models will be unloaded to CPU memory after being used. This option keeps them in GPU memory. " )
vram_group . add_argument ( " --normalvram " , action = " store_true " , help = " Used to force normal vram use if lowvram gets automatically enabled. " )
vram_group . add_argument ( " --lowvram " , action = " store_true " , help = " Split the unet in parts to use less vram. " )
vram_group . add_argument ( " --novram " , action = " store_true " , help = " When lowvram isn ' t enough. " )
vram_group . add_argument ( " --cpu " , action = " store_true " , help = " To use the CPU for everything (slow). " )
2024-07-16 22:27:09 +00:00
parser . add_argument ( " --default-hashing-function " , type = str , choices = [ ' md5 ' , ' sha1 ' , ' sha256 ' , ' sha512 ' ] , default = ' sha256 ' , help = " Allows you to choose the hash function to use for duplicate filename / contents comparison. Default is sha256. " )
2023-06-15 19:21:37 +00:00
2023-08-17 07:12:37 +00:00
parser . add_argument ( " --disable-smart-memory " , action = " store_true " , help = " Force ComfyUI to agressively offload to regular ram instead of keeping models in vram when it can. " )
2023-12-17 21:59:21 +00:00
parser . add_argument ( " --deterministic " , action = " store_true " , help = " Make pytorch use slower deterministic algorithms when it can. Note that this might not make images deterministic in all cases. " )
2023-08-17 07:12:37 +00:00
2023-04-06 03:41:23 +00:00
parser . add_argument ( " --dont-print-server " , action = " store_true " , help = " Don ' t print server output. " )
parser . add_argument ( " --quick-test-for-ci " , action = " store_true " , help = " Quick test for CI. " )
2023-04-07 19:52:56 +00:00
parser . add_argument ( " --windows-standalone-build " , action = " store_true " , help = " Windows standalone build: Enable convenient things that most people using the standalone windows build will probably enjoy (like auto opening the page on startup). " )
2023-04-06 03:41:23 +00:00
2023-07-28 16:31:41 +00:00
parser . add_argument ( " --disable-metadata " , action = " store_true " , help = " Disable saving prompt metadata in files. " )
2024-07-01 21:54:03 +00:00
parser . add_argument ( " --disable-all-custom-nodes " , action = " store_true " , help = " Disable loading all custom nodes. " )
2023-07-28 16:31:41 +00:00
2024-01-11 22:21:40 +00:00
parser . add_argument ( " --multi-user " , action = " store_true " , help = " Enables per-user storage. " )
2024-01-08 22:06:44 +00:00
2024-03-10 15:37:08 +00:00
parser . add_argument ( " --verbose " , action = " store_true " , help = " Enables more debug prints. " )
2024-07-16 15:26:11 +00:00
# The default built-in provider hosted under web/
DEFAULT_VERSION_STRING = " comfyanonymous/ComfyUI@latest "
parser . add_argument (
" --front-end-version " ,
type = str ,
default = DEFAULT_VERSION_STRING ,
help = """
Specifies the version of the frontend to be used . This command needs internet connectivity to query and
download available frontend implementations from GitHub releases .
The version string should be in the format of :
[ repoOwner ] / [ repoName ] @ [ version ]
where version is one of : " latest " or a valid version number ( e . g . " 1.0.0 " )
""" ,
)
def is_valid_directory ( path : Optional [ str ] ) - > Optional [ str ] :
""" Validate if the given path is a directory. """
if path is None :
return None
if not os . path . isdir ( path ) :
raise argparse . ArgumentTypeError ( f " { path } is not a valid directory. " )
return path
parser . add_argument (
" --front-end-root " ,
type = is_valid_directory ,
default = None ,
help = " The local filesystem path to the directory where the frontend is located. Overrides --front-end-version. " ,
)
2024-03-10 15:37:08 +00:00
2023-09-13 15:38:20 +00:00
if comfy . options . args_parsing :
args = parser . parse_args ( )
else :
args = parser . parse_args ( [ ] )
2023-05-06 20:59:40 +00:00
if args . windows_standalone_build :
args . auto_launch = True
2023-08-07 06:22:26 +00:00
if args . disable_auto_launch :
args . auto_launch = False
2024-03-10 15:37:08 +00:00
import logging
2024-03-11 17:54:56 +00:00
logging_level = logging . INFO
2024-03-10 15:37:08 +00:00
if args . verbose :
logging_level = logging . DEBUG
logging . basicConfig ( format = " %(message)s " , level = logging_level )