Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions comfy/cli_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def from_string(cls, value: str):

parser.add_argument("--reserve-vram", type=float, default=None, help="Set the amount of vram in GB you want to reserve for use by your OS/other software. By default some amount is reserved depending on your OS.")
parser.add_argument("--vram-headroom", type=float, default=0, help="Set the amount of vram in GB for DynamicVRAM to maintain as extra headroom above default. ComfyUI will try and keep this much VRAM completely free and unused, even counting VRAM from other apps.")
parser.add_argument("--disable-nvml-pressure", action="store_true", help="Use CUDA instead of NVML for DynamicVRAM memory pressure.")

parser.add_argument("--async-offload", nargs='?', const=2, type=int, default=None, metavar="NUM_STREAMS", help="Use async weight offloading. An optional argument controls the amount of offload streams. Default is 2. Enabled by default on Nvidia.")
parser.add_argument("--disable-async-offload", action="store_true", help="Disable async weight offloading.")
Expand Down
21 changes: 17 additions & 4 deletions comfy/model_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,19 @@ def pin_eviction_tiers(loaded, evict_active):
tiers.append((PIN_SUBSETS, True, True))
return tiers

def registration_eviction_tiers(evict_active):
subsets = PIN_SUBSETS + LOADED_PIN_SUBSETS
tiers = [
(subsets, False, False),
(subsets, True, False),
]
if evict_active:
tiers.extend([
(subsets, False, True),
(subsets, True, True),
])
return tiers

def free_pins(size, evict_active=False, loaded=False):
freed = 0
for subsets, current_prompt, active in pin_eviction_tiers(loaded, evict_active):
Expand Down Expand Up @@ -703,19 +716,19 @@ def ensure_pin_budget(size, evict_active=False, loaded=False):
to_free = shortfall + PIN_PRESSURE_HYSTERESIS
return free_pins(to_free, evict_active=evict_active, loaded=loaded) >= shortfall

def free_registrations(shortfall, evict_active=True, loaded=False):
def free_registrations(shortfall, evict_active=True):
if MAX_PINNED_MEMORY <= 0:
return False
if shortfall <= 0:
return True

shortfall += REGISTERABLE_PIN_HYSTERESIS
for subsets, current_prompt, active in pin_eviction_tiers(loaded, evict_active):
for subsets, current_prompt, active in registration_eviction_tiers(evict_active):
shortfall -= free_model_pins(shortfall, subsets, current_prompt, active, registrations=True)
return shortfall <= REGISTERABLE_PIN_HYSTERESIS

def ensure_pin_registerable(size, evict_active=True, loaded=False):
return free_registrations(TOTAL_PINNED_MEMORY + size - MAX_PINNED_MEMORY, evict_active=evict_active, loaded=loaded)
def ensure_pin_registerable(size, evict_active=True):
return free_registrations(TOTAL_PINNED_MEMORY + size - MAX_PINNED_MEMORY, evict_active=evict_active)

class LoadedModel:
def __init__(self, model: ModelPatcher):
Expand Down
6 changes: 3 additions & 3 deletions comfy/pinned_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def get_pin(module, subset="weights"):

_, _, stack_split, pinned_size, *_ = module._pin_state[subset]
size = pin.nbytes
comfy.model_management.ensure_pin_registerable(size, loaded=subset.endswith("-loaded"))
comfy.model_management.ensure_pin_registerable(size)

if torch.cuda.cudart().cudaHostRegister(pin.data_ptr(), size, 1) != 0:
comfy.model_management.discard_cuda_async_error()
Expand Down Expand Up @@ -93,7 +93,7 @@ def pin_memory(module, subset="weights", size=None):

comfy.memory_management.extra_ram_release(comfy.memory_management.RAM_CACHE_HEADROOM)
if (not comfy.model_management.ensure_pin_budget(size, loaded=loaded) or
not comfy.model_management.ensure_pin_registerable(registerable_size, loaded=loaded)):
not comfy.model_management.ensure_pin_registerable(registerable_size)):
return _steal_pin(module, stack, buckets, size, priority, subset)

offset = hostbuf.size
Expand All @@ -105,7 +105,7 @@ def pin_memory(module, subset="weights", size=None):
pin.untyped_storage()._comfy_hostbuf = hostbuf
if torch.cuda.cudart().cudaHostRegister(pin.data_ptr(), size, 1) != 0:
comfy.model_management.discard_cuda_async_error()
comfy.model_management.free_registrations(size, loaded=loaded)
comfy.model_management.free_registrations(size)
if torch.cuda.cudart().cudaHostRegister(pin.data_ptr(), size, 1) != 0:
comfy.model_management.discard_cuda_async_error()
del pin
Expand Down
21 changes: 12 additions & 9 deletions comfy_api_nodes/nodes_minimax.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ def _hailuo03_model_inputs(include_ratio: bool = True, allow_adaptive: bool = Tr
),
IO.Combo.Input(
"resolution",
options=["2K"],
options=["768P", "2K"],
tooltip="Resolution of the output video.",
),
]
Expand Down Expand Up @@ -578,11 +578,12 @@ def define_schema(cls):
],
is_api_node=True,
price_badge=IO.PriceBadge(
depends_on=IO.PriceBadgeDepends(widgets=["model.duration"]),
depends_on=IO.PriceBadgeDepends(widgets=["model.resolution", "model.duration"]),
expr="""
(
$dur := $lookup(widgets, "model.duration");
{"type": "usd", "usd": $dur * 0.1859}
$rate := $lookup(widgets, "model.resolution") = "768p" ? 0.1287 : 0.1859;
{"type": "usd", "usd": $dur * $rate}
)
""",
),
Expand Down Expand Up @@ -660,11 +661,12 @@ def define_schema(cls):
],
is_api_node=True,
price_badge=IO.PriceBadge(
depends_on=IO.PriceBadgeDepends(widgets=["model.duration"]),
depends_on=IO.PriceBadgeDepends(widgets=["model.resolution", "model.duration"]),
expr="""
(
$dur := $lookup(widgets, "model.duration");
{"type": "usd", "usd": $dur * 0.1859}
$rate := $lookup(widgets, "model.resolution") = "768p" ? 0.1287 : 0.1859;
{"type": "usd", "usd": $dur * $rate}
)
""",
),
Expand Down Expand Up @@ -818,20 +820,21 @@ def define_schema(cls):
is_api_node=True,
price_badge=IO.PriceBadge(
depends_on=IO.PriceBadgeDepends(
widgets=["model.duration"],
widgets=["model.resolution", "model.duration"],
input_groups=["model.reference_images", "model.reference_videos"],
),
expr="""
(
$dur := $lookup(widgets, "model.duration");
$rate := $lookup(widgets, "model.resolution") = "768p" ? 0.1287 : 0.1859;
$imgsRaw := $lookup(inputGroups, "model.reference_images");
$imgs := $imgsRaw ? $imgsRaw : 0;
$vidsRaw := $lookup(inputGroups, "model.reference_videos");
$vids := $vidsRaw ? $vidsRaw : 0;
$base := $dur * 0.1859 + ($imgs > 5 ? ($imgs - 5) * 0.0572 : 0);
$base := $dur * $rate + ($imgs > 5 ? ($imgs - 5) * 0.0572 : 0);
$vids > 0
? {"type": "range_usd", "min_usd": $base + $vids * 2 * 0.1859,
"max_usd": $base + 15 * 0.1859, "format": {"approximate": true}}
? {"type": "range_usd", "min_usd": $base + $vids * 2 * $rate,
"max_usd": $base + 15 * $rate, "format": {"approximate": true}}
: {"type": "usd", "usd": $base}
)
""",
Expand Down
11 changes: 8 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,16 @@ def dump_traceback_on_sigint(signum, frame):
import comfy_aimdo.control

if enables_dynamic_vram():
simple_vram_headroom = None if args.reserve_vram is None else int(args.reserve_vram * 1024 ** 3)
try:
comfy_aimdo.control.init(simple_vram_headroom=None if args.reserve_vram is None else int(args.reserve_vram * 1024 ** 3))
comfy_aimdo.control.init(simple_vram_headroom=simple_vram_headroom, nvml_pressure=not args.disable_nvml_pressure)
except TypeError:
# comfy-aimdo 0.4.9 protocol.
comfy_aimdo.control.init()
# comfy-aimdo 0.4.10 protocol.
try:
comfy_aimdo.control.init(simple_vram_headroom=simple_vram_headroom)
except TypeError:
# comfy-aimdo 0.4.9 protocol.
comfy_aimdo.control.init()

if os.name == "nt":
os.environ['MIMALLOC_PURGE_DELAY'] = '0'
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ SQLAlchemy>=2.0.0
filelock
av>=16.0.0
comfy-kitchen==0.2.26
comfy-aimdo==0.4.10
comfy-aimdo==0.4.11
requests
simpleeval>=1.0.0
blake3
Expand Down
Loading