Spaces:
Running
Running
Fix HF job startup: import unsloth first and shim vllm package metadata check.
Browse files- ultimate_sota_training.py +18 -1
ultimate_sota_training.py
CHANGED
|
@@ -30,6 +30,7 @@ Key stability choices:
|
|
| 30 |
|
| 31 |
from __future__ import annotations
|
| 32 |
|
|
|
|
| 33 |
import json
|
| 34 |
import os
|
| 35 |
import random
|
|
@@ -137,6 +138,20 @@ import torch
|
|
| 137 |
from datasets import Dataset
|
| 138 |
|
| 139 |
# --- CRITICAL FIXES FOR HF JOBS ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
# 1. Mock vllm: TRL's GRPOTrainer (v0.18+) has a buggy import path that hard-fails if vllm is missing.
|
| 141 |
# We must provide a mock that satisfies both 'import' and 'importlib.util.find_spec'.
|
| 142 |
import sys
|
|
@@ -160,13 +175,15 @@ def mock_vllm_hierarchy():
|
|
| 160 |
|
| 161 |
mock_vllm_hierarchy()
|
| 162 |
|
|
|
|
|
|
|
|
|
|
| 163 |
# 2. Mock llm_blender: Fix for TRANSFORMERS_CACHE removal in transformers 4.40+.
|
| 164 |
import transformers.utils.hub
|
| 165 |
if not hasattr(transformers.utils.hub, "TRANSFORMERS_CACHE"):
|
| 166 |
transformers.utils.hub.TRANSFORMERS_CACHE = "/tmp"
|
| 167 |
|
| 168 |
from trl import GRPOConfig, GRPOTrainer
|
| 169 |
-
from unsloth import FastLanguageModel
|
| 170 |
|
| 171 |
# --- 1. CONFIGURATION (env-first; defaults match openenv.yaml) ---
|
| 172 |
_DEFAULT_OPENENV_BASE = "https://md896-sql-debug-env.hf.space"
|
|
|
|
| 30 |
|
| 31 |
from __future__ import annotations
|
| 32 |
|
| 33 |
+
import importlib.metadata as importlib_metadata
|
| 34 |
import json
|
| 35 |
import os
|
| 36 |
import random
|
|
|
|
| 138 |
from datasets import Dataset
|
| 139 |
|
| 140 |
# --- CRITICAL FIXES FOR HF JOBS ---
|
| 141 |
+
# 0. Unsloth checks importlib.metadata.version("vllm") at import time.
|
| 142 |
+
# In text-only GRPO runs we don't install vllm, so return a dummy version instead
|
| 143 |
+
# of crashing with PackageNotFoundError.
|
| 144 |
+
_real_pkg_version = importlib_metadata.version
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
def _safe_pkg_version(dist_name: str) -> str:
|
| 148 |
+
if dist_name == "vllm":
|
| 149 |
+
return "0.0.0"
|
| 150 |
+
return _real_pkg_version(dist_name)
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
importlib_metadata.version = _safe_pkg_version
|
| 154 |
+
|
| 155 |
# 1. Mock vllm: TRL's GRPOTrainer (v0.18+) has a buggy import path that hard-fails if vllm is missing.
|
| 156 |
# We must provide a mock that satisfies both 'import' and 'importlib.util.find_spec'.
|
| 157 |
import sys
|
|
|
|
| 175 |
|
| 176 |
mock_vllm_hierarchy()
|
| 177 |
|
| 178 |
+
# Import Unsloth before transformers / trl for its patching path.
|
| 179 |
+
from unsloth import FastLanguageModel
|
| 180 |
+
|
| 181 |
# 2. Mock llm_blender: Fix for TRANSFORMERS_CACHE removal in transformers 4.40+.
|
| 182 |
import transformers.utils.hub
|
| 183 |
if not hasattr(transformers.utils.hub, "TRANSFORMERS_CACHE"):
|
| 184 |
transformers.utils.hub.TRANSFORMERS_CACHE = "/tmp"
|
| 185 |
|
| 186 |
from trl import GRPOConfig, GRPOTrainer
|
|
|
|
| 187 |
|
| 188 |
# --- 1. CONFIGURATION (env-first; defaults match openenv.yaml) ---
|
| 189 |
_DEFAULT_OPENENV_BASE = "https://md896-sql-debug-env.hf.space"
|