Spaces:
Sleeping
Sleeping
KAPO transformers runtime rollout
Browse files- .env +3 -2
- bootstrap_space_runtime.py +3 -2
- brain_server/api/main.py +14 -0
- kapo.env +3 -2
- requirements.txt +3 -0
.env
CHANGED
|
@@ -16,14 +16,15 @@ HF_SPACE_DOCKER=1
|
|
| 16 |
KAGGLE_AUTO_BOOTSTRAP=0
|
| 17 |
KAPO_BOOTSTRAP_URL=https://drive.google.com/uc?export=download&id=19jyBWsQ9ciJVPi2PUigu5ti3gJ24A6TG
|
| 18 |
KAPO_COMPUTE_PROFILE=cpu
|
|
|
|
| 19 |
KAPO_HF_INFERENCE_API=1
|
| 20 |
KAPO_HF_TRANSFORMERS_RUNTIME=0
|
| 21 |
KAPO_LAZY_EMBED_STARTUP=1
|
| 22 |
KAPO_LAZY_MODEL_STARTUP=1
|
| 23 |
KAPO_PATCH_BUNDLE_URL=https://drive.google.com/uc?export=download&id=16rIe05GZihhAz7ba8E-WibKaJKbh9eu1
|
| 24 |
KAPO_PATCH_MANIFEST_URL=https://drive.google.com/uc?export=download&id=1jLuPMCA3hp9qstZZtpBNzTK0XOmLrV8b
|
| 25 |
-
KAPO_REMOTE_ENV_PASSWORD_B64=
|
| 26 |
-
KAPO_REMOTE_ENV_URL_B64=
|
| 27 |
KAPO_SHARED_STATE_BACKEND=google_drive
|
| 28 |
MODEL_PROFILE_ID=hf-coder-qwen25-coder-7b-instruct
|
| 29 |
MODEL_REPO=Qwen/Qwen2.5-Coder-1.5B-Instruct
|
|
|
|
| 16 |
KAGGLE_AUTO_BOOTSTRAP=0
|
| 17 |
KAPO_BOOTSTRAP_URL=https://drive.google.com/uc?export=download&id=19jyBWsQ9ciJVPi2PUigu5ti3gJ24A6TG
|
| 18 |
KAPO_COMPUTE_PROFILE=cpu
|
| 19 |
+
KAPO_DISABLE_EMBEDDINGS=1
|
| 20 |
KAPO_HF_INFERENCE_API=1
|
| 21 |
KAPO_HF_TRANSFORMERS_RUNTIME=0
|
| 22 |
KAPO_LAZY_EMBED_STARTUP=1
|
| 23 |
KAPO_LAZY_MODEL_STARTUP=1
|
| 24 |
KAPO_PATCH_BUNDLE_URL=https://drive.google.com/uc?export=download&id=16rIe05GZihhAz7ba8E-WibKaJKbh9eu1
|
| 25 |
KAPO_PATCH_MANIFEST_URL=https://drive.google.com/uc?export=download&id=1jLuPMCA3hp9qstZZtpBNzTK0XOmLrV8b
|
| 26 |
+
KAPO_REMOTE_ENV_PASSWORD_B64=bHVnbGxlOWpFdUZtNldRMVNVTWZZVjUtQ0NTc1NWUEM
|
| 27 |
+
KAPO_REMOTE_ENV_URL_B64=aHR0cHM6Ly9kcml2ZS5nb29nbGUuY29tL3VjP2V4cG9ydD1kb3dubG9hZCZpZD0xbk5VYmplUHZUZ0pzOTlGRHZuZ3ZwNm9zYlhDSlhxcVk
|
| 28 |
KAPO_SHARED_STATE_BACKEND=google_drive
|
| 29 |
MODEL_PROFILE_ID=hf-coder-qwen25-coder-7b-instruct
|
| 30 |
MODEL_REPO=Qwen/Qwen2.5-Coder-1.5B-Instruct
|
bootstrap_space_runtime.py
CHANGED
|
@@ -24,14 +24,15 @@ DEFAULT_ENV = {
|
|
| 24 |
"KAGGLE_AUTO_BOOTSTRAP": "0",
|
| 25 |
"KAPO_BOOTSTRAP_URL": "https://drive.google.com/uc?export=download&id=19jyBWsQ9ciJVPi2PUigu5ti3gJ24A6TG",
|
| 26 |
"KAPO_COMPUTE_PROFILE": "cpu",
|
|
|
|
| 27 |
"KAPO_HF_INFERENCE_API": "1",
|
| 28 |
"KAPO_HF_TRANSFORMERS_RUNTIME": "0",
|
| 29 |
"KAPO_LAZY_EMBED_STARTUP": "1",
|
| 30 |
"KAPO_LAZY_MODEL_STARTUP": "1",
|
| 31 |
"KAPO_PATCH_BUNDLE_URL": "https://drive.google.com/uc?export=download&id=16rIe05GZihhAz7ba8E-WibKaJKbh9eu1",
|
| 32 |
"KAPO_PATCH_MANIFEST_URL": "https://drive.google.com/uc?export=download&id=1jLuPMCA3hp9qstZZtpBNzTK0XOmLrV8b",
|
| 33 |
-
"KAPO_REMOTE_ENV_PASSWORD_B64": "
|
| 34 |
-
"KAPO_REMOTE_ENV_URL_B64": "
|
| 35 |
"KAPO_SHARED_STATE_BACKEND": "google_drive",
|
| 36 |
"MODEL_PROFILE_ID": "hf-coder-qwen25-coder-7b-instruct",
|
| 37 |
"MODEL_REPO": "Qwen/Qwen2.5-Coder-1.5B-Instruct",
|
|
|
|
| 24 |
"KAGGLE_AUTO_BOOTSTRAP": "0",
|
| 25 |
"KAPO_BOOTSTRAP_URL": "https://drive.google.com/uc?export=download&id=19jyBWsQ9ciJVPi2PUigu5ti3gJ24A6TG",
|
| 26 |
"KAPO_COMPUTE_PROFILE": "cpu",
|
| 27 |
+
"KAPO_DISABLE_EMBEDDINGS": "1",
|
| 28 |
"KAPO_HF_INFERENCE_API": "1",
|
| 29 |
"KAPO_HF_TRANSFORMERS_RUNTIME": "0",
|
| 30 |
"KAPO_LAZY_EMBED_STARTUP": "1",
|
| 31 |
"KAPO_LAZY_MODEL_STARTUP": "1",
|
| 32 |
"KAPO_PATCH_BUNDLE_URL": "https://drive.google.com/uc?export=download&id=16rIe05GZihhAz7ba8E-WibKaJKbh9eu1",
|
| 33 |
"KAPO_PATCH_MANIFEST_URL": "https://drive.google.com/uc?export=download&id=1jLuPMCA3hp9qstZZtpBNzTK0XOmLrV8b",
|
| 34 |
+
"KAPO_REMOTE_ENV_PASSWORD_B64": "bHVnbGxlOWpFdUZtNldRMVNVTWZZVjUtQ0NTc1NWUEM",
|
| 35 |
+
"KAPO_REMOTE_ENV_URL_B64": "aHR0cHM6Ly9kcml2ZS5nb29nbGUuY29tL3VjP2V4cG9ydD1kb3dubG9hZCZpZD0xbk5VYmplUHZUZ0pzOTlGRHZuZ3ZwNm9zYlhDSlhxcVk",
|
| 36 |
"KAPO_SHARED_STATE_BACKEND": "google_drive",
|
| 37 |
"MODEL_PROFILE_ID": "hf-coder-qwen25-coder-7b-instruct",
|
| 38 |
"MODEL_REPO": "Qwen/Qwen2.5-Coder-1.5B-Instruct",
|
brain_server/api/main.py
CHANGED
|
@@ -118,6 +118,14 @@ def _feature_enabled(name: str, default: bool = False) -> bool:
|
|
| 118 |
return str(value).strip().lower() in {"1", "true", "yes", "on"}
|
| 119 |
|
| 120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
def _remote_brain_only() -> bool:
|
| 122 |
return _feature_enabled("REMOTE_BRAIN_ONLY", default=False)
|
| 123 |
|
|
@@ -258,6 +266,9 @@ def ensure_model_loaded(repo_id: str, filename: str, hf_token: str | None = None
|
|
| 258 |
|
| 259 |
def _load_embed_model() -> None:
|
| 260 |
global EMBED_MODEL
|
|
|
|
|
|
|
|
|
|
| 261 |
if EMBED_MODEL is not None:
|
| 262 |
return
|
| 263 |
|
|
@@ -273,6 +284,9 @@ def _load_default_model() -> None:
|
|
| 273 |
repo_id = str(os.getenv("MODEL_REPO", DEFAULT_MODEL_REPO) or DEFAULT_MODEL_REPO).strip()
|
| 274 |
filename = str(os.getenv("MODEL_FILE", "") or "").strip()
|
| 275 |
provider = str(os.getenv("BRAIN_PROVIDER", "") or os.getenv("BRAIN_TEMPLATE", "") or "").strip().lower()
|
|
|
|
|
|
|
|
|
|
| 276 |
if not filename and (_feature_enabled("KAPO_HF_INFERENCE_API", default=False) or "huggingface" in provider or "hf-space" in provider):
|
| 277 |
MODEL = None
|
| 278 |
MODEL_ERROR = None
|
|
|
|
| 118 |
return str(value).strip().lower() in {"1", "true", "yes", "on"}
|
| 119 |
|
| 120 |
|
| 121 |
+
def _hf_transformers_runtime_enabled() -> bool:
|
| 122 |
+
return _feature_enabled("KAPO_HF_TRANSFORMERS_RUNTIME", default=False)
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
def _embeddings_enabled() -> bool:
|
| 126 |
+
return not _feature_enabled("KAPO_DISABLE_EMBEDDINGS", default=False)
|
| 127 |
+
|
| 128 |
+
|
| 129 |
def _remote_brain_only() -> bool:
|
| 130 |
return _feature_enabled("REMOTE_BRAIN_ONLY", default=False)
|
| 131 |
|
|
|
|
| 266 |
|
| 267 |
def _load_embed_model() -> None:
|
| 268 |
global EMBED_MODEL
|
| 269 |
+
if not _embeddings_enabled():
|
| 270 |
+
logger.info("Embedding model disabled by configuration")
|
| 271 |
+
return
|
| 272 |
if EMBED_MODEL is not None:
|
| 273 |
return
|
| 274 |
|
|
|
|
| 284 |
repo_id = str(os.getenv("MODEL_REPO", DEFAULT_MODEL_REPO) or DEFAULT_MODEL_REPO).strip()
|
| 285 |
filename = str(os.getenv("MODEL_FILE", "") or "").strip()
|
| 286 |
provider = str(os.getenv("BRAIN_PROVIDER", "") or os.getenv("BRAIN_TEMPLATE", "") or "").strip().lower()
|
| 287 |
+
if _hf_transformers_runtime_enabled():
|
| 288 |
+
ensure_model_loaded(repo_id, filename, hf_token=os.getenv("HF_TOKEN"))
|
| 289 |
+
return
|
| 290 |
if not filename and (_feature_enabled("KAPO_HF_INFERENCE_API", default=False) or "huggingface" in provider or "hf-space" in provider):
|
| 291 |
MODEL = None
|
| 292 |
MODEL_ERROR = None
|
kapo.env
CHANGED
|
@@ -16,14 +16,15 @@ HF_SPACE_DOCKER=1
|
|
| 16 |
KAGGLE_AUTO_BOOTSTRAP=0
|
| 17 |
KAPO_BOOTSTRAP_URL=https://drive.google.com/uc?export=download&id=19jyBWsQ9ciJVPi2PUigu5ti3gJ24A6TG
|
| 18 |
KAPO_COMPUTE_PROFILE=cpu
|
|
|
|
| 19 |
KAPO_HF_INFERENCE_API=1
|
| 20 |
KAPO_HF_TRANSFORMERS_RUNTIME=0
|
| 21 |
KAPO_LAZY_EMBED_STARTUP=1
|
| 22 |
KAPO_LAZY_MODEL_STARTUP=1
|
| 23 |
KAPO_PATCH_BUNDLE_URL=https://drive.google.com/uc?export=download&id=16rIe05GZihhAz7ba8E-WibKaJKbh9eu1
|
| 24 |
KAPO_PATCH_MANIFEST_URL=https://drive.google.com/uc?export=download&id=1jLuPMCA3hp9qstZZtpBNzTK0XOmLrV8b
|
| 25 |
-
KAPO_REMOTE_ENV_PASSWORD_B64=
|
| 26 |
-
KAPO_REMOTE_ENV_URL_B64=
|
| 27 |
KAPO_SHARED_STATE_BACKEND=google_drive
|
| 28 |
MODEL_PROFILE_ID=hf-coder-qwen25-coder-7b-instruct
|
| 29 |
MODEL_REPO=Qwen/Qwen2.5-Coder-1.5B-Instruct
|
|
|
|
| 16 |
KAGGLE_AUTO_BOOTSTRAP=0
|
| 17 |
KAPO_BOOTSTRAP_URL=https://drive.google.com/uc?export=download&id=19jyBWsQ9ciJVPi2PUigu5ti3gJ24A6TG
|
| 18 |
KAPO_COMPUTE_PROFILE=cpu
|
| 19 |
+
KAPO_DISABLE_EMBEDDINGS=1
|
| 20 |
KAPO_HF_INFERENCE_API=1
|
| 21 |
KAPO_HF_TRANSFORMERS_RUNTIME=0
|
| 22 |
KAPO_LAZY_EMBED_STARTUP=1
|
| 23 |
KAPO_LAZY_MODEL_STARTUP=1
|
| 24 |
KAPO_PATCH_BUNDLE_URL=https://drive.google.com/uc?export=download&id=16rIe05GZihhAz7ba8E-WibKaJKbh9eu1
|
| 25 |
KAPO_PATCH_MANIFEST_URL=https://drive.google.com/uc?export=download&id=1jLuPMCA3hp9qstZZtpBNzTK0XOmLrV8b
|
| 26 |
+
KAPO_REMOTE_ENV_PASSWORD_B64=bHVnbGxlOWpFdUZtNldRMVNVTWZZVjUtQ0NTc1NWUEM
|
| 27 |
+
KAPO_REMOTE_ENV_URL_B64=aHR0cHM6Ly9kcml2ZS5nb29nbGUuY29tL3VjP2V4cG9ydD1kb3dubG9hZCZpZD0xbk5VYmplUHZUZ0pzOTlGRHZuZ3ZwNm9zYlhDSlhxcVk
|
| 28 |
KAPO_SHARED_STATE_BACKEND=google_drive
|
| 29 |
MODEL_PROFILE_ID=hf-coder-qwen25-coder-7b-instruct
|
| 30 |
MODEL_REPO=Qwen/Qwen2.5-Coder-1.5B-Instruct
|
requirements.txt
CHANGED
|
@@ -7,4 +7,7 @@ requests==2.32.3
|
|
| 7 |
python-json-logger==2.0.7
|
| 8 |
cryptography>=43.0.0,<46.0.0
|
| 9 |
huggingface_hub>=0.33.5,<2.0
|
|
|
|
|
|
|
|
|
|
| 10 |
starlette>=0.40.0,<1.0
|
|
|
|
| 7 |
python-json-logger==2.0.7
|
| 8 |
cryptography>=43.0.0,<46.0.0
|
| 9 |
huggingface_hub>=0.33.5,<2.0
|
| 10 |
+
torch>=2.2,<3.0
|
| 11 |
+
transformers==4.57.6
|
| 12 |
+
accelerate>=1.0,<2.0
|
| 13 |
starlette>=0.40.0,<1.0
|