Spaces:
Running on Zero
Running on Zero
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -107,7 +107,20 @@ def _load() -> dict:
|
|
| 107 |
ckpt = read_checkpoint(CKPT)
|
| 108 |
saved = ckpt["config"] if isinstance(ckpt["config"], dict) else dict(vars(ckpt["config"]))
|
| 109 |
config = TransformerConfig.from_saved(saved)
|
| 110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
model = SimpleAttentionNetwork(config=config)
|
| 112 |
tokenizer = get_tokenizer()
|
| 113 |
|
|
@@ -117,7 +130,7 @@ def _load() -> dict:
|
|
| 117 |
|
| 118 |
_CACHE.update({"jax": jax, "jnp": jnp, "params": params, "model": model,
|
| 119 |
"tokenizer": tokenizer, "decode_fn": decode_fn, "config": config,
|
| 120 |
-
"backend": jax.default_backend(),
|
| 121 |
"devices": [str(d) for d in jax.devices()]})
|
| 122 |
return _CACHE
|
| 123 |
|
|
@@ -229,7 +242,7 @@ def _do_score(state: str, instructions: str, levels: list[str]) -> dict:
|
|
| 229 |
"confidence": max(dist.values()) if dist else 0.0}
|
| 230 |
|
| 231 |
|
| 232 |
-
@spaces.GPU(duration=
|
| 233 |
def answer_systemone(state: str, questions: dict) -> dict:
|
| 234 |
"""Run a Jev-shaped request. This is the GPU-decorated entry point."""
|
| 235 |
with _LOCK:
|
|
@@ -250,7 +263,7 @@ def answer_systemone(state: str, questions: dict) -> dict:
|
|
| 250 |
"usage": {"input_tokens": None, "output_tokens": None}}
|
| 251 |
|
| 252 |
|
| 253 |
-
@spaces.GPU(duration=
|
| 254 |
def run_method_comparison() -> dict:
|
| 255 |
"""The scoring-method comparison on three unambiguous cases.
|
| 256 |
|
|
@@ -309,7 +322,7 @@ def health() -> str:
|
|
| 309 |
f"JAX_PLATFORMS={os.environ.get('JAX_PLATFORMS')}")
|
| 310 |
|
| 311 |
|
| 312 |
-
@spaces.GPU(duration=
|
| 313 |
def gpu_probe() -> dict:
|
| 314 |
"""DECISIVE TEST: does JAX initialise on CUDA *inside* a @spaces.GPU function?
|
| 315 |
|
|
@@ -337,7 +350,7 @@ def gpu_probe() -> dict:
|
|
| 337 |
return out
|
| 338 |
|
| 339 |
|
| 340 |
-
@spaces.GPU(duration=
|
| 341 |
def run_selftest() -> dict:
|
| 342 |
"""Known-answer probes, comparing positive vs negative on matched pairs."""
|
| 343 |
with _LOCK:
|
|
|
|
| 107 |
ckpt = read_checkpoint(CKPT)
|
| 108 |
saved = ckpt["config"] if isinstance(ckpt["config"], dict) else dict(vars(ckpt["config"]))
|
| 109 |
config = TransformerConfig.from_saved(saved)
|
| 110 |
+
raw_params = {k: v for k, v in ckpt["params"].items() if not k.startswith("mtp_")}
|
| 111 |
+
|
| 112 |
+
# The published checkpoint is bf16. JAX on this GPU aborts with
|
| 113 |
+
# "Unsupported conversion from bf16 to f16 / LLVM ERROR: Unsupported
|
| 114 |
+
# rounding mode for conversion."
|
| 115 |
+
# so cast everything to float32 up front. NEEDLE_CAST controls this
|
| 116 |
+
# ("float32" default, "bfloat16" to keep the original, "none" to skip).
|
| 117 |
+
_cast = os.environ.get("NEEDLE_CAST", "float32").lower()
|
| 118 |
+
if _cast in ("float32", "float", "f32"):
|
| 119 |
+
params = {k: (v.astype("float32") if hasattr(v, "astype") else v)
|
| 120 |
+
for k, v in raw_params.items()}
|
| 121 |
+
else:
|
| 122 |
+
params = raw_params
|
| 123 |
+
|
| 124 |
model = SimpleAttentionNetwork(config=config)
|
| 125 |
tokenizer = get_tokenizer()
|
| 126 |
|
|
|
|
| 130 |
|
| 131 |
_CACHE.update({"jax": jax, "jnp": jnp, "params": params, "model": model,
|
| 132 |
"tokenizer": tokenizer, "decode_fn": decode_fn, "config": config,
|
| 133 |
+
"backend": jax.default_backend(), "cast": _cast,
|
| 134 |
"devices": [str(d) for d in jax.devices()]})
|
| 135 |
return _CACHE
|
| 136 |
|
|
|
|
| 242 |
"confidence": max(dist.values()) if dist else 0.0}
|
| 243 |
|
| 244 |
|
| 245 |
+
@spaces.GPU(duration=120)
|
| 246 |
def answer_systemone(state: str, questions: dict) -> dict:
|
| 247 |
"""Run a Jev-shaped request. This is the GPU-decorated entry point."""
|
| 248 |
with _LOCK:
|
|
|
|
| 263 |
"usage": {"input_tokens": None, "output_tokens": None}}
|
| 264 |
|
| 265 |
|
| 266 |
+
@spaces.GPU(duration=120)
|
| 267 |
def run_method_comparison() -> dict:
|
| 268 |
"""The scoring-method comparison on three unambiguous cases.
|
| 269 |
|
|
|
|
| 322 |
f"JAX_PLATFORMS={os.environ.get('JAX_PLATFORMS')}")
|
| 323 |
|
| 324 |
|
| 325 |
+
@spaces.GPU(duration=120)
|
| 326 |
def gpu_probe() -> dict:
|
| 327 |
"""DECISIVE TEST: does JAX initialise on CUDA *inside* a @spaces.GPU function?
|
| 328 |
|
|
|
|
| 350 |
return out
|
| 351 |
|
| 352 |
|
| 353 |
+
@spaces.GPU(duration=120)
|
| 354 |
def run_selftest() -> dict:
|
| 355 |
"""Known-answer probes, comparing positive vs negative on matched pairs."""
|
| 356 |
with _LOCK:
|