mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-03-16 14:47:33 +08:00
Merge afa96152b8 into 593be209a4
This commit is contained in:
commit
e456e643a2
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,6 +2,7 @@ __pycache__/
|
||||
*.py[cod]
|
||||
/output/
|
||||
/input/
|
||||
/cache/
|
||||
!/input/example.png
|
||||
/models/
|
||||
/temp/
|
||||
|
||||
@ -32,6 +32,26 @@ import comfy.memory_management
|
||||
import comfy.utils
|
||||
import comfy.quant_ops
|
||||
|
||||
|
||||
def get_container_ram_total():
|
||||
cgroup_v2_limit = "/sys/fs/cgroup/memory.max"
|
||||
cgroup_v1_limit = "/sys/fs/cgroup/memory/memory.limit_in_bytes"
|
||||
try:
|
||||
if os.path.exists(cgroup_v2_limit):
|
||||
with open(cgroup_v2_limit, "r") as f:
|
||||
limit = int(f.read().strip())
|
||||
elif os.path.exists(cgroup_v1_limit):
|
||||
with open(cgroup_v1_limit, "r") as f:
|
||||
limit = int(f.read().strip())
|
||||
else:
|
||||
limit = psutil.virtual_memory().total
|
||||
if limit == 9223372036854771712:
|
||||
limit = psutil.virtual_memory().total
|
||||
return limit
|
||||
except:
|
||||
return psutil.virtual_memory().total
|
||||
|
||||
|
||||
class VRAMState(Enum):
|
||||
DISABLED = 0 #No vram present: no need to move models to vram
|
||||
NO_VRAM = 1 #Very low vram: enable all the options to save vram
|
||||
@ -211,11 +231,13 @@ def get_total_memory(dev=None, torch_total_too=False):
|
||||
dev = get_torch_device()
|
||||
|
||||
if hasattr(dev, 'type') and (dev.type == 'cpu' or dev.type == 'mps'):
|
||||
mem_total = psutil.virtual_memory().total
|
||||
# 核心修改:读取容器内存
|
||||
mem_total = get_container_ram_total()
|
||||
mem_total_torch = mem_total
|
||||
else:
|
||||
# GPU逻辑保持不变
|
||||
if directml_enabled:
|
||||
mem_total = 1024 * 1024 * 1024 #TODO
|
||||
mem_total = 1024 * 1024 * 1024
|
||||
mem_total_torch = mem_total
|
||||
elif is_intel_xpu():
|
||||
stats = torch.xpu.memory_stats(dev)
|
||||
@ -254,7 +276,7 @@ def mac_version():
|
||||
return None
|
||||
|
||||
total_vram = get_total_memory(get_torch_device()) / (1024 * 1024)
|
||||
total_ram = psutil.virtual_memory().total / (1024 * 1024)
|
||||
total_ram = get_total_memory(torch.device("cpu")) / (1024 * 1024)
|
||||
logging.info("Total VRAM {:0.0f} MB, total RAM {:0.0f} MB".format(total_vram, total_ram))
|
||||
|
||||
try:
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import asyncio
|
||||
import bisect
|
||||
import os
|
||||
import gc
|
||||
import itertools
|
||||
import psutil
|
||||
@ -523,8 +524,41 @@ class RAMPressureCache(LRUCache):
|
||||
|
||||
def poll(self, ram_headroom):
|
||||
def _ram_gb():
|
||||
return psutil.virtual_memory().available / (1024**3)
|
||||
|
||||
fallback_to_host_available = False
|
||||
cgroup_mem_limit_path = "/sys/fs/cgroup/memory.max"
|
||||
cgroup_mem_usage_path = "/sys/fs/cgroup/memory.current"
|
||||
|
||||
if not os.path.exists(cgroup_mem_limit_path):
|
||||
cgroup_mem_limit_path = "/sys/fs/cgroup/memory/memory.limit_in_bytes"
|
||||
cgroup_mem_usage_path = "/sys/fs/cgroup/memory/memory.usage_in_bytes"
|
||||
|
||||
try:
|
||||
with open(cgroup_mem_limit_path, "r") as f:
|
||||
raw_limit = f.read().strip()
|
||||
if raw_limit == "max":
|
||||
fallback_to_host_available = True
|
||||
mem_limit = psutil.virtual_memory().total
|
||||
else:
|
||||
mem_limit = int(raw_limit)
|
||||
if mem_limit == 9223372036854771712:
|
||||
fallback_to_host_available = True
|
||||
mem_limit = psutil.virtual_memory().total
|
||||
except (FileNotFoundError, ValueError):
|
||||
fallback_to_host_available = True
|
||||
mem_limit = psutil.virtual_memory().total
|
||||
|
||||
if fallback_to_host_available:
|
||||
return psutil.virtual_memory().available / (1024**3)
|
||||
|
||||
try:
|
||||
with open(cgroup_mem_usage_path, "r") as f:
|
||||
mem_used = int(f.read().strip())
|
||||
except (FileNotFoundError, ValueError):
|
||||
mem_used = psutil.virtual_memory().total - psutil.virtual_memory().available
|
||||
|
||||
mem_available = max(0, mem_limit - mem_used)
|
||||
return mem_available / (1024**3)
|
||||
|
||||
if _ram_gb() > ram_headroom:
|
||||
return
|
||||
gc.collect()
|
||||
|
||||
3
styles/default.csv
Normal file
3
styles/default.csv
Normal file
@ -0,0 +1,3 @@
|
||||
name,prompt,negative_prompt
|
||||
❌Low Token,,"embedding:EasyNegative, NSFW, Cleavage, Pubic Hair, Nudity, Naked, censored"
|
||||
✅Line Art / Manga,"(Anime Scene, Toonshading, Satoshi Kon, Ken Sugimori, Hiromu Arakawa:1.2), (Anime Style, Manga Style:1.3), Low detail, sketch, concept art, line art, webtoon, manhua, hand drawn, defined lines, simple shades, minimalistic, High contrast, Linear compositions, Scalable artwork, Digital art, High Contrast Shadows, glow effects, humorous illustration, big depth of field, Masterpiece, colors, concept art, trending on artstation, Vivid colors, dramatic",
|
||||
|
Loading…
Reference in New Issue
Block a user