Update .gitignore to ignore large files && Adapt to obtaining resources within Docker.

This commit is contained in:
root 2026-03-09 14:43:54 +08:00
parent e4b0bb8305
commit 3fb4fe9a2b
4 changed files with 61 additions and 4 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

@ -383,7 +383,38 @@ class RAMPressureCache(LRUCache):
def poll(self, ram_headroom):
def _ram_gb():
return psutil.virtual_memory().available / (1024**3)
"""读取容器可用内存GB优先从 cgroup v2/v1 读取"""
# === 容器内存检测核心逻辑 ===
# 1. 尝试读取 cgroup v2 内存限制Docker/K8s 主流)
cgroup_mem_limit_path = "/sys/fs/cgroup/memory.max"
cgroup_mem_usage_path = "/sys/fs/cgroup/memory.current"
# 兼容 cgroup v1
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:
mem_limit = int(f.read().strip())
# cgroup v1 中 limit_in_bytes 为 9223372036854771712 表示无限制, fallback 到系统内存
if mem_limit == 9223372036854771712:
mem_limit = psutil.virtual_memory().total
except (FileNotFoundError, ValueError):
mem_limit = psutil.virtual_memory().total
# 读取已使用内存(字节)
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
# 计算可用内存GB
mem_available = mem_limit - mem_used
return mem_available / (1024**3)
# === 替换结束 ===
if _ram_gb() > ram_headroom:
return

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