liuhuijie commited on
Commit
399083d
·
1 Parent(s): bb6812b
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -9,6 +9,8 @@ import spaces
9
  from PIL import Image
10
  from huggingface_hub import snapshot_download
11
  import gc
 
 
12
  try:
13
  import pynvml
14
  pynvml.nvmlInit()
@@ -38,14 +40,14 @@ SUGGESTED_PROMPTS = [
38
  ]
39
  CUSTOM_OPTION = "✍️ Enter custom prompt..."
40
 
41
- def check_memory_usage():
42
  process = psutil.Process(os.getpid())
43
  memory_mb = process.memory_info().rss / 1024 / 1024
44
- print(f"🖥️ 当前内存使用: {memory_mb:.2f} MB")
45
 
46
  # 系统总内存
47
  total_memory = psutil.virtual_memory().total / 1024 / 1024 / 1024
48
- print(f"💾 系统总内存: {total_memory:.2f} GB")
49
 
50
  def load_models():
51
  global pipeline, style_generator, unitok, processor, code_freq, local_repo_dir
@@ -99,6 +101,7 @@ def load_models():
99
  unitok_state_dict = torch.load(os.path.join(codebook_path, "model.pth"), map_location="cpu")
100
  unitok.load_state_dict(unitok_state_dict)
101
  unitok.to(device, dtype=weight_type)
 
102
  print('='*10, 'before pipeline')
103
  pipeline = CoTylePipeline.from_pretrained(
104
  local_repo_dir,
@@ -109,7 +112,7 @@ def load_models():
109
  requires_safety_checker=False,
110
 
111
  )
112
-
113
  qwen_text_visual_encoder = Qwen2_5_VLForConditionalGeneration_Quant.from_pretrained(
114
  local_repo_dir,
115
  subfolder="text_encoder",
@@ -117,7 +120,7 @@ def load_models():
117
  qwen_text_visual_encoder = Qwen2_5_VL_Quant(unitok, qwen_text_visual_encoder)
118
  qwen_text_visual_encoder.to(device, dtype=weight_type)
119
  pipeline.text_encoder = qwen_text_visual_encoder
120
-
121
  processor = Qwen2VLProcessor.from_pretrained(
122
  local_repo_dir,
123
  subfolder="processor",
 
9
  from PIL import Image
10
  from huggingface_hub import snapshot_download
11
  import gc
12
+ import psutil
13
+ import os
14
  try:
15
  import pynvml
16
  pynvml.nvmlInit()
 
40
  ]
41
  CUSTOM_OPTION = "✍️ Enter custom prompt..."
42
 
43
+ def check_memory_usage(tag):
44
  process = psutil.Process(os.getpid())
45
  memory_mb = process.memory_info().rss / 1024 / 1024
46
+ print(f"{tag}\t🖥️ 当前内存使用: {memory_mb:.2f} MB")
47
 
48
  # 系统总内存
49
  total_memory = psutil.virtual_memory().total / 1024 / 1024 / 1024
50
+ print(f"{tag}\t💾 系统总内存: {total_memory:.2f} GB")
51
 
52
  def load_models():
53
  global pipeline, style_generator, unitok, processor, code_freq, local_repo_dir
 
101
  unitok_state_dict = torch.load(os.path.join(codebook_path, "model.pth"), map_location="cpu")
102
  unitok.load_state_dict(unitok_state_dict)
103
  unitok.to(device, dtype=weight_type)
104
+ check_memory_usage('before pipeline')
105
  print('='*10, 'before pipeline')
106
  pipeline = CoTylePipeline.from_pretrained(
107
  local_repo_dir,
 
112
  requires_safety_checker=False,
113
 
114
  )
115
+ check_memory_usage('before qwen')
116
  qwen_text_visual_encoder = Qwen2_5_VLForConditionalGeneration_Quant.from_pretrained(
117
  local_repo_dir,
118
  subfolder="text_encoder",
 
120
  qwen_text_visual_encoder = Qwen2_5_VL_Quant(unitok, qwen_text_visual_encoder)
121
  qwen_text_visual_encoder.to(device, dtype=weight_type)
122
  pipeline.text_encoder = qwen_text_visual_encoder
123
+ check_memory_usage('after qwen')
124
  processor = Qwen2VLProcessor.from_pretrained(
125
  local_repo_dir,
126
  subfolder="processor",