Tianshuo-Xu commited on
Commit
743a20a
·
1 Parent(s): d84e45a

precache fa3 kernel and font before gpu task

Browse files
Files changed (2) hide show
  1. app.py +23 -2
  2. inference.py +4 -0
app.py CHANGED
@@ -88,10 +88,11 @@ _preloaded_embedding = None
88
  _preloaded_tokenizer = None
89
  _cached_t5_dir = None
90
  _cached_clip_dir = None
 
91
 
92
  def preload_model_files():
93
  """Pre-download model files to cache at startup (no GPU needed)"""
94
- global _preloaded_embedding, _preloaded_tokenizer, _cached_t5_dir, _cached_clip_dir
95
  from huggingface_hub import snapshot_download, hf_hub_download
96
 
97
  hf_token = os.environ.get("HF_TOKEN", None)
@@ -136,8 +137,28 @@ def preload_model_files():
136
  print("✓ VAE cached")
137
  except Exception as e:
138
  print(f"Warning: Could not pre-download VAE: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
 
140
- # 5. Pre-load InternVL embedding to CPU memory (saves ~5s in GPU session)
141
  if local_dir:
142
  try:
143
  intern_vlm_path = os.path.join(local_dir, "internvl_embedding")
 
88
  _preloaded_tokenizer = None
89
  _cached_t5_dir = None
90
  _cached_clip_dir = None
91
+ _cached_font_path = None
92
 
93
  def preload_model_files():
94
  """Pre-download model files to cache at startup (no GPU needed)"""
95
+ global _preloaded_embedding, _preloaded_tokenizer, _cached_t5_dir, _cached_clip_dir, _cached_font_path
96
  from huggingface_hub import snapshot_download, hf_hub_download
97
 
98
  hf_token = os.environ.get("HF_TOKEN", None)
 
137
  print("✓ VAE cached")
138
  except Exception as e:
139
  print(f"Warning: Could not pre-download VAE: {e}")
140
+
141
+ # 5. Font file used for condition image rendering
142
+ try:
143
+ _cached_font_path = hf_hub_download(
144
+ repo_id="TSXu/Unicalli_Pro",
145
+ filename="FangZhengKaiTiFanTi-1.ttf",
146
+ token=hf_token,
147
+ )
148
+ os.environ["UNICALLI_FONT_PATH"] = _cached_font_path
149
+ print(f"✓ Font cached at: {_cached_font_path}")
150
+ except Exception as e:
151
+ print(f"Warning: Could not pre-download font: {e}")
152
+
153
+ # 6. Flash Attention 3 kernel package (large) pre-cache
154
+ try:
155
+ from kernels import get_kernel
156
+ get_kernel("kernels-community/vllm-flash-attn3")
157
+ print("✓ Flash Attention 3 kernel cached")
158
+ except Exception as e:
159
+ print(f"Warning: Could not pre-cache Flash Attention 3 kernel: {e}")
160
 
161
+ # 7. Pre-load InternVL embedding to CPU memory (saves ~5s in GPU session)
162
  if local_dir:
163
  try:
164
  intern_vlm_path = os.path.join(local_dir, "internvl_embedding")
inference.py CHANGED
@@ -303,6 +303,10 @@ class CalligraphyGenerator:
303
  Returns:
304
  Path to the local font file
305
  """
 
 
 
 
306
  if os.path.exists(font_path):
307
  return font_path
308
 
 
303
  Returns:
304
  Path to the local font file
305
  """
306
+ cached_font_path = os.environ.get("UNICALLI_FONT_PATH")
307
+ if cached_font_path and os.path.exists(cached_font_path):
308
+ return cached_font_path
309
+
310
  if os.path.exists(font_path):
311
  return font_path
312