Spaces:
Sleeping
Sleeping
apehex commited on
Commit ·
2699bf3
1
Parent(s): 75344c6
Download the models without instantiating them.
Browse files- app.py +5 -3
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import gradio
|
|
|
|
| 2 |
import spaces
|
| 3 |
|
| 4 |
import psaiops.common.model
|
|
@@ -9,12 +10,13 @@ import psaiops.score.human.app as _app
|
|
| 9 |
# META #########################################################################
|
| 10 |
|
| 11 |
# additional args used when loading the model
|
| 12 |
-
|
|
|
|
| 13 |
_app.MODELS = ['qwen/qwen3.5-9b', 'qwen/qwen3.5-27b']
|
| 14 |
|
| 15 |
# frontload the models on the CPU to avoid downloading them from the GPU slot
|
| 16 |
for __m in _app.MODELS:
|
| 17 |
-
|
| 18 |
|
| 19 |
# but do not instantiate unless necessary
|
| 20 |
_MODEL = None
|
|
@@ -34,7 +36,7 @@ def fetch_model() -> object:
|
|
| 34 |
global _MODEL
|
| 35 |
# control when the model is downloaded to avoid moving it to the CPU
|
| 36 |
if _MODEL is None:
|
| 37 |
-
_MODEL = psaiops.common.model.get_model(name=_app.MODELS[0], device='cuda', **
|
| 38 |
# tuple of objects or (None, None)
|
| 39 |
return _MODEL
|
| 40 |
|
|
|
|
| 1 |
import gradio
|
| 2 |
+
import huggingface_hub
|
| 3 |
import spaces
|
| 4 |
|
| 5 |
import psaiops.common.model
|
|
|
|
| 10 |
# META #########################################################################
|
| 11 |
|
| 12 |
# additional args used when loading the model
|
| 13 |
+
_MODEL_CFG = {}
|
| 14 |
+
_LOAD_CFG = {'repo_type': 'model', 'ignore_patterns': ['*.onnx', '*.tflite', '*.msgpack'],}
|
| 15 |
_app.MODELS = ['qwen/qwen3.5-9b', 'qwen/qwen3.5-27b']
|
| 16 |
|
| 17 |
# frontload the models on the CPU to avoid downloading them from the GPU slot
|
| 18 |
for __m in _app.MODELS:
|
| 19 |
+
huggingface_hub.snapshot_download(repo_id=__m, **_LOAD_CFG)
|
| 20 |
|
| 21 |
# but do not instantiate unless necessary
|
| 22 |
_MODEL = None
|
|
|
|
| 36 |
global _MODEL
|
| 37 |
# control when the model is downloaded to avoid moving it to the CPU
|
| 38 |
if _MODEL is None:
|
| 39 |
+
_MODEL = psaiops.common.model.get_model(name=_app.MODELS[0], device='cuda', **_MODEL_CFG)
|
| 40 |
# tuple of objects or (None, None)
|
| 41 |
return _MODEL
|
| 42 |
|
requirements.txt
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
accelerate>=1.11
|
| 2 |
gradio>=6.0
|
|
|
|
| 3 |
kernels>=0.11
|
| 4 |
psaiops>=0.10.3
|
| 5 |
spaces>=0.47
|
|
|
|
| 1 |
accelerate>=1.11
|
| 2 |
gradio>=6.0
|
| 3 |
+
huggingface_hub>=1.5
|
| 4 |
kernels>=0.11
|
| 5 |
psaiops>=0.10.3
|
| 6 |
spaces>=0.47
|