Spaces:
Paused
Fix: Use official HF Spaces preload_from_hub for model caching
Browse filesRoot cause:
- Dockerfile manual download didn't specify cache_dir parameter
- Models downloaded to wrong location (not /home/user/.cache/huggingface/hub)
- local_files_only=True couldn't find files → runtime failure
Solution (Following HF Spaces official documentation):
- Use preload_from_hub feature in README.md (official recommended way)
- Remove manual download code from Dockerfile
- preload_from_hub automatically downloads to ~/.cache/huggingface/hub
- config.py uses HF_HUB_CACHE which matches this path perfectly
Official documentation:
"The preload_from_hub feature allows you to pre-download models during build"
Source: https://huggingface.co/docs/hub/spaces-config-reference
Changes:
- README.md: Added preload_from_hub for both model repos
- Dockerfile: Removed lines 100-119 (manual download code)
- Dockerfile: Added comment explaining preload_from_hub usage
Expected behavior:
✅ Models preloaded during build to ~/.cache/huggingface/hub
✅ Runtime finds models via HF_HUB_CACHE environment variable
✅ CLIP model loads successfully without internet access
Updated: Dockerfile
- Dockerfile +2 -20
|
@@ -97,26 +97,8 @@ 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 |
-
#
|
| 101 |
-
|
| 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', use_safetensors=True); \
|
| 116 |
-
CLIPProcessor.from_pretrained('openai/clip-vit-base-patch32', use_safetensors=True); \
|
| 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\
|
|
|
|
| 97 |
RUN pip install --no-cache-dir --upgrade pip && \
|
| 98 |
pip install --no-cache-dir -r requirements.txt
|
| 99 |
|
| 100 |
+
# 注意:模型通过 README.md 的 preload_from_hub 自动下载(HF Spaces 官方推荐方式)
|
| 101 |
+
# 下载到 ~/.cache/huggingface/hub/ 并在运行时通过 HF_HUB_CACHE 环境变量访问
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
# 创建启动脚本(先启动 Xvfb,再运行应用)
|
| 104 |
RUN echo '#!/bin/bash\n\
|