betterwithage commited on
Commit
26cbbf2
·
verified ·
1 Parent(s): 2b1c616

chore(sync): mirror backend .py + Dockerfile to Space (hf-sync-backend)

Browse files

Automated backend sync from szl-holdings/a11oy main via hf-sync-backend.
Updated (differed from the Space): Dockerfile

Keeps the Space-built backend (serve.py + the Dockerfile-COPY'd .py
modules) identical to GitHub main so the Space never rebuilds from a
stale backend and new endpoints don't 404 there.

Files changed (1) hide show
  1. Dockerfile +71 -8
Dockerfile CHANGED
@@ -414,12 +414,12 @@ COPY szl_llm_registry.py ./szl_llm_registry.py
414
  COPY szl_elite_console.py ./szl_elite_console.py
415
  COPY szl_alloy_models.py ./szl_alloy_models.py
416
 
417
- # OPTIONAL live CPU demo tier: try to install llama.cpp + fetch ONE tiny
418
- # Apache-2.0 GGUF (Qwen2.5-Coder-0.5B-Instruct Q4_K_M) so the demo tier can
419
- # serve REAL output on cpu-basic. Both steps are NON-FATAL (`|| echo ...`): if
420
- # the wheel build or download fails on this hardware, the alloy layer falls back
421
- # to the HONEST tower-side label and NEVER fakes output. We never redistribute
422
- # the weight in our repo — it is fetched from the original HF repo at build time.
423
  # OPTIONAL live CPU demo tier wheel — PINNED PREBUILT (no source compile).
424
  # Previously `pip install "llama-cpp-python>=0.2.79"` built the wheel FROM SOURCE,
425
  # which fails to compile on CPU-only CI/hardware and was silently swallowed by the
@@ -439,8 +439,71 @@ RUN pip install --no-cache-dir \
439
  --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cpu \
440
  "llama-cpp-python==0.3.19" \
441
  || echo "[a11oy] llama-cpp-python prebuilt wheel unavailable on this platform -> alloy demo tier falls back to honest tower-side label"
442
- RUN mkdir -p /app/models && python -c "from huggingface_hub import hf_hub_download; hf_hub_download(repo_id='Qwen/Qwen2.5-Coder-0.5B-Instruct-GGUF', filename='qwen2.5-coder-0.5b-instruct-q4_k_m.gguf', local_dir='/app/models')" \
443
- || echo "[a11oy] GGUF fetch skipped/failed -> alloy demo tier falls back to honest tower-side label"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
444
  ENV A11OY_ALLOY_GGUF=/app/models/qwen2.5-coder-0.5b-instruct-q4_k_m.gguf
445
 
446
  # ADDITIVE (Live-Data Layer, 2026-06-06, Warhacker): SHARED live-feed proxy module
 
414
  COPY szl_elite_console.py ./szl_elite_console.py
415
  COPY szl_alloy_models.py ./szl_alloy_models.py
416
 
417
+ # LIVE CPU demo tier: install llama.cpp + fetch ONE tiny Apache-2.0 GGUF
418
+ # (Qwen2.5-Coder-0.5B-Instruct Q4_K_M) so the demo tier serves REAL output on
419
+ # cpu-basic. The wheel install stays best-effort (honest tower-side fallback if
420
+ # no prebuilt wheel), but the GGUF weight below is now RELIABLY fetched (pinned
421
+ # revision + retry + integrity verify) so the published image always carries it.
422
+ # We never redistribute the weight in our repo — it is fetched from the HF repo.
423
  # OPTIONAL live CPU demo tier wheel — PINNED PREBUILT (no source compile).
424
  # Previously `pip install "llama-cpp-python>=0.2.79"` built the wheel FROM SOURCE,
425
  # which fails to compile on CPU-only CI/hardware and was silently swallowed by the
 
439
  --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cpu \
440
  "llama-cpp-python==0.3.19" \
441
  || echo "[a11oy] llama-cpp-python prebuilt wheel unavailable on this platform -> alloy demo tier falls back to honest tower-side label"
442
+ # GGUF weight RELIABLY PRESENT (pinned revision + retry + integrity verify), NOT best-effort.
443
+ # Previously a single best-effort `hf_hub_download(...) || echo` step: a transient download
444
+ # failure silently shipped an image with NO model, so the alloy demo tier always degraded to
445
+ # the tower-side label. Now we pin the EXACT repo revision, retry with backoff, and HARD-VERIFY
446
+ # the downloaded file's byte size + sha256 against the published LFS digest. The build FAILS LOUD
447
+ # if the weight is not reliably present, so every published image genuinely carries the GGUF and
448
+ # the demo tier serves REAL on-CPU output. The honest tower-side fallback in szl_alloy_models.py
449
+ # remains for any runtime where the weight is absent (e.g. local dev / bring-your-own-weights).
450
+ # Apache-2.0 weight; fetched from the original HF repo, never redistributed in this repo.
451
+ ARG A11OY_ALLOY_GGUF_REPO=Qwen/Qwen2.5-Coder-0.5B-Instruct-GGUF
452
+ ARG A11OY_ALLOY_GGUF_FILE=qwen2.5-coder-0.5b-instruct-q4_k_m.gguf
453
+ ARG A11OY_ALLOY_GGUF_REV=ebb2015119c907b064c512bf053e945850b5875f
454
+ ARG A11OY_ALLOY_GGUF_SHA256=1d9614638d18024d0fbb36575a15f1302a3adf044df10345688ec4f6e1c4ff32
455
+ ARG A11OY_ALLOY_GGUF_SIZE=491400064
456
+ RUN python3 <<'GGUFPY'
457
+ import hashlib, os, sys, time
458
+ from huggingface_hub import hf_hub_download
459
+
460
+ repo = os.environ["A11OY_ALLOY_GGUF_REPO"]
461
+ fname = os.environ["A11OY_ALLOY_GGUF_FILE"]
462
+ rev = os.environ["A11OY_ALLOY_GGUF_REV"]
463
+ want_sha = os.environ["A11OY_ALLOY_GGUF_SHA256"].lower()
464
+ want_size = int(os.environ["A11OY_ALLOY_GGUF_SIZE"])
465
+ dest = "/app/models"
466
+ os.makedirs(dest, exist_ok=True)
467
+
468
+ def verify(p):
469
+ if not p or not os.path.exists(p):
470
+ return "missing"
471
+ sz = os.path.getsize(p)
472
+ if sz != want_size:
473
+ return "size %d != expected %d" % (sz, want_size)
474
+ h = hashlib.sha256()
475
+ with open(p, "rb") as f:
476
+ for chunk in iter(lambda: f.read(1 << 20), b""):
477
+ h.update(chunk)
478
+ got = h.hexdigest()
479
+ if got != want_sha:
480
+ return "sha256 %s != expected %s" % (got, want_sha)
481
+ return None
482
+
483
+ last = None
484
+ for attempt in range(1, 7):
485
+ try:
486
+ p = hf_hub_download(repo_id=repo, filename=fname, revision=rev, local_dir=dest)
487
+ last = verify(p)
488
+ if last is None:
489
+ print("[a11oy] GGUF verified present: %s (%d bytes, sha256 ok, rev %s)"
490
+ % (fname, want_size, rev[:12]), flush=True)
491
+ sys.exit(0)
492
+ print("[a11oy] attempt %d: integrity check failed: %s" % (attempt, last), flush=True)
493
+ try:
494
+ os.remove(p)
495
+ except OSError:
496
+ pass
497
+ except Exception as e:
498
+ last = "%s: %s" % (type(e).__name__, str(e)[:200])
499
+ print("[a11oy] attempt %d: download failed: %s" % (attempt, last), flush=True)
500
+ time.sleep(min(60, 5 * attempt))
501
+
502
+ sys.stderr.write("[a11oy] FATAL: could not obtain a verified GGUF after retries: %s\n" % last)
503
+ sys.exit(1)
504
+ GGUFPY
505
+ # Drop transient download metadata; the real weight stays at /app/models/<file>.
506
+ RUN rm -rf /app/models/.cache /root/.cache/huggingface 2>/dev/null || true
507
  ENV A11OY_ALLOY_GGUF=/app/models/qwen2.5-coder-0.5b-instruct-q4_k_m.gguf
508
 
509
  # ADDITIVE (Live-Data Layer, 2026-06-06, Warhacker): SHARED live-feed proxy module