This commit is contained in:
chukangkang 2026-03-16 11:55:58 +09:00 committed by GitHub
commit e456e643a2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 65 additions and 5 deletions

1
.gitignore vendored
View File

@ -2,6 +2,7 @@ __pycache__/
*.py[cod]
/output/
/input/
/cache/
!/input/example.png
/models/
/temp/

View File

@ -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:

View File

@ -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
View 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",
1 name prompt negative_prompt
2 ❌Low Token embedding:EasyNegative, NSFW, Cleavage, Pubic Hair, Nudity, Naked, censored
3 ✅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