0xZohar commited on
Commit
b434289
·
verified ·
1 Parent(s): 0024048

Fix: Pre-download models in Dockerfile to avoid runtime hang

Browse files

Root cause analysis:
- preload_from_hub ignores HF_HOME (documented limitation)
- Previous approach caused permission conflicts → fallback to /tmp
- local_files_only=True + no models in /tmp = startup failure

Solution (best practice from research):
- Manually download models in Dockerfile to default ~/.cache location
- Download as 'user' to avoid permission issues
- Keep local_files_only=True (models already cached)
- Build logs show download progress (transparent to user)

Changes:
- README.md: Remove preload_from_hub (has limitations)
- Dockerfile: Add manual model download step (lines 100-119)
- All models download during build → instant runtime startup

Benefits:
✅ Build logs show download progress (no "hanging" confusion)
✅ Runtime startup is instant (models already in image)
✅ No permission conflicts (consistent user ownership)
✅ Works on free tier (no /data persistent storage needed)

Updated: Dockerfile

Files changed (1) hide show
  1. Dockerfile +21 -0
Dockerfile CHANGED
@@ -97,6 +97,27 @@ RUN ls -la $HOME/app/code/ImportLDraw/__init__.py || \
97
  RUN pip install --no-cache-dir --upgrade pip && \
98
  pip install --no-cache-dir -r requirements.txt
99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  # 创建启动脚本(先启动 Xvfb,再运行应用)
101
  RUN echo '#!/bin/bash\n\
102
  echo "🖥️ 启动虚拟显示服务器 Xvfb..."\n\
 
97
  RUN pip install --no-cache-dir --upgrade pip && \
98
  pip install --no-cache-dir -r requirements.txt
99
 
100
+ # 预下载模型到默认缓存目录(构建时一次性下载,避免运行时卡顿)
101
+ RUN echo "📥 Pre-downloading models during build (this may take 2-3 minutes)..." && \
102
+ python3 -c "\
103
+ from huggingface_hub import hf_hub_download; \
104
+ from transformers import CLIPModel, CLIPProcessor; \
105
+ print('Downloading shape_gpt.safetensors (7.17 GB)...'); \
106
+ hf_hub_download(repo_id='0xZohar/object-assembler-models', filename='shape_gpt.safetensors'); \
107
+ print('✓ shape_gpt downloaded'); \
108
+ print('Downloading shape_tokenizer.safetensors (1.09 GB)...'); \
109
+ hf_hub_download(repo_id='0xZohar/object-assembler-models', filename='shape_tokenizer.safetensors'); \
110
+ print('✓ shape_tokenizer downloaded'); \
111
+ print('Downloading fine-tuned adapter (1.68 GB)...'); \
112
+ hf_hub_download(repo_id='0xZohar/object-assembler-models', filename='save_shape_cars_whole_p_rot_scratch_4mask_randp.safetensors'); \
113
+ print('✓ adapter downloaded'); \
114
+ print('Downloading CLIP model (~600 MB)...'); \
115
+ CLIPModel.from_pretrained('openai/clip-vit-base-patch32'); \
116
+ CLIPProcessor.from_pretrained('openai/clip-vit-base-patch32'); \
117
+ print('✓ CLIP downloaded'); \
118
+ print('✅ All models pre-downloaded to ~/.cache/huggingface')" && \
119
+ echo "✅ Model weights cached successfully"
120
+
121
  # 创建启动脚本(先启动 Xvfb,再运行应用)
122
  RUN echo '#!/bin/bash\n\
123
  echo "🖥️ 启动虚拟显示服务器 Xvfb..."\n\