mrhangetsbetter commited on
Commit
c6383e8
·
verified ·
1 Parent(s): 88f3e88

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -4
app.py CHANGED
@@ -3,7 +3,6 @@ import sys
3
  import site
4
 
5
  # ================= 强力 CPU 环境全面拟真补丁 =================
6
- # 拦截启动参数
7
  if "--use-sage-attention" in sys.argv:
8
  sys.argv.remove("--use-sage-attention")
9
 
@@ -21,9 +20,8 @@ try:
21
  torch.cuda.device_count = lambda: 0
22
  torch.cuda.current_device = lambda: 0
23
 
24
- # 2. 【核心修复】伪造 GPU 内存统计数据,防止 KeyError
25
  def mock_memory_stats(*args, **kwargs):
26
- # 模拟一个拥有基础显存键值的字典,让 ComfyUI 读取时不崩溃
27
  return {
28
  'reserved_bytes.all.current': 0,
29
  'reserved_bytes.all.peak': 0,
@@ -36,6 +34,17 @@ try:
36
  torch.cuda.memory_reserved = lambda *args, **kwargs: 0
37
  torch.cuda.max_memory_reserved = lambda *args, **kwargs: 0
38
 
 
 
 
 
 
 
 
 
 
 
 
39
  # 3. 构造设备代理类,保持 type 身份
40
  _orig_device = torch.device
41
 
@@ -57,7 +66,7 @@ try:
57
  TorchDeviceProxy.__qualname__ = _orig_device.__qualname__
58
 
59
  torch.device = TorchDeviceProxy
60
- print("🤖 [CPU Patch] Seamless TorchDeviceProxy and MemoryStats deployed.")
61
  except Exception as e:
62
  print(f"⚠️ [CPU Patch] Error while generating proxy patch: {e}")
63
 
 
3
  import site
4
 
5
  # ================= 强力 CPU 环境全面拟真补丁 =================
 
6
  if "--use-sage-attention" in sys.argv:
7
  sys.argv.remove("--use-sage-attention")
8
 
 
20
  torch.cuda.device_count = lambda: 0
21
  torch.cuda.current_device = lambda: 0
22
 
23
+ # 2. 伪造 GPU 内存统计数据 C++ 运行时属性
24
  def mock_memory_stats(*args, **kwargs):
 
25
  return {
26
  'reserved_bytes.all.current': 0,
27
  'reserved_bytes.all.peak': 0,
 
34
  torch.cuda.memory_reserved = lambda *args, **kwargs: 0
35
  torch.cuda.max_memory_reserved = lambda *args, **kwargs: 0
36
 
37
+ # 【核心修复】:拦截 mem_get_info,返回假的 (空闲显存, 总显存),直接给它 16GB 虚拟显存
38
+ torch.cuda.mem_get_info = lambda *args, **kwargs: (16 * 1024 * 1024 * 1024, 16 * 1024 * 1024 * 1024)
39
+
40
+ # 额外拦截设备属性查询,防止接下来报错
41
+ class MockDeviceProperties:
42
+ name = "Kaggle/HuggingFace CPU-Fake GPU"
43
+ major = 8
44
+ minor = 0
45
+ total_memory = 16 * 1024 * 1024 * 1024
46
+ torch.cuda.get_device_properties = lambda *args, **kwargs: MockDeviceProperties()
47
+
48
  # 3. 构造设备代理类,保持 type 身份
49
  _orig_device = torch.device
50
 
 
66
  TorchDeviceProxy.__qualname__ = _orig_device.__qualname__
67
 
68
  torch.device = TorchDeviceProxy
69
+ print("🤖 [CPU Patch] Advanced TorchCuda/MemGetInfo mock deployed.")
70
  except Exception as e:
71
  print(f"⚠️ [CPU Patch] Error while generating proxy patch: {e}")
72