flozi00 commited on
Commit
44e6ccf
·
verified ·
1 Parent(s): e408ca2

zero-gpu: prefetch the checkpoint at startup, not inside the GPU slice

Browse files
BUILD.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
- "built_at": "2026-10-29T16:48:34",
3
- "commit": "8f3c1ee",
4
  "files": 53,
5
  "with_store": false,
6
  "with_card": true
 
1
  {
2
+ "built_at": "2026-10-29T16:58:09",
3
+ "commit": "ef0b6ab",
4
  "files": 53,
5
  "with_store": false,
6
  "with_card": true
traceforge/space/app.py CHANGED
@@ -483,6 +483,23 @@ def build_app(store: Optional[TraceStore] = None,
483
  return app
484
 
485
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
486
  def main(argv: Optional[list[str]] = None) -> int:
487
  import argparse
488
 
@@ -498,6 +515,7 @@ def main(argv: Optional[list[str]] = None) -> int:
498
 
499
  app = build_app()
500
  app.queue(default_concurrency_limit=4)
 
501
  app.launch(server_name=args.host, server_port=args.port,
502
  share=args.share, inbrowser=False, show_error=True,
503
  css=CSS, theme=gr.themes.Base())
 
483
  return app
484
 
485
 
486
+ def _prefetch_in_background() -> None:
487
+ """Pull the checkpoint at startup, not inside a visitor's GPU slice.
488
+
489
+ The 24.8 GB FP8 download takes ~45 s at the ~600 MB/s the Hub gives us.
490
+ Doing it lazily meant the first GPU call of every container spent most of
491
+ its 120 s slice downloading, so the weights are fetched here instead.
492
+ """
493
+ try:
494
+ from traceforge.space.pipeline import _local_mode
495
+ if not _local_mode():
496
+ return
497
+ from traceforge.space.local_llm import prefetch
498
+ prefetch()
499
+ except Exception:
500
+ pass
501
+
502
+
503
  def main(argv: Optional[list[str]] = None) -> int:
504
  import argparse
505
 
 
515
 
516
  app = build_app()
517
  app.queue(default_concurrency_limit=4)
518
+ _prefetch_in_background()
519
  app.launch(server_name=args.host, server_port=args.port,
520
  share=args.share, inbrowser=False, show_error=True,
521
  css=CSS, theme=gr.themes.Base())
traceforge/space/local_llm.py CHANGED
@@ -678,20 +678,32 @@ def _volume_read_mbps(mb: int = 256) -> dict:
678
 
679
  def _ram_gb() -> dict:
680
  """Container memory, so we can tell whether a module-level load fits."""
 
681
  try:
682
  import psutil
683
  vm = psutil.virtual_memory()
684
- return {"total": round(vm.total / 1e9, 1),
685
- "available": round(vm.available / 1e9, 1)}
686
  except Exception:
687
  try:
688
  with open("/proc/meminfo") as fh:
689
  for line in fh:
690
  if line.startswith("MemTotal:"):
691
- return {"total": round(int(line.split()[1]) / 1e6, 1)}
692
  except Exception:
693
  pass
694
- return {}
 
 
 
 
 
 
 
 
 
 
 
695
 
696
 
697
  def health() -> dict:
 
678
 
679
  def _ram_gb() -> dict:
680
  """Container memory, so we can tell whether a module-level load fits."""
681
+ out = {}
682
  try:
683
  import psutil
684
  vm = psutil.virtual_memory()
685
+ out = {"total": round(vm.total / 1e9, 1),
686
+ "available": round(vm.available / 1e9, 1)}
687
  except Exception:
688
  try:
689
  with open("/proc/meminfo") as fh:
690
  for line in fh:
691
  if line.startswith("MemTotal:"):
692
+ out = {"total": round(int(line.split()[1]) / 1e6, 1)}
693
  except Exception:
694
  pass
695
+ # psutil reports the host's RAM; the cgroup limit is what we can use.
696
+ for path in ("/sys/fs/cgroup/memory.max",
697
+ "/sys/fs/cgroup/memory/memory.limit_in_bytes"):
698
+ try:
699
+ with open(path) as fh:
700
+ raw = fh.read().strip()
701
+ if raw.isdigit() and int(raw) < (1 << 62):
702
+ out["cgroup"] = round(int(raw) / 1e9, 1)
703
+ break
704
+ except Exception:
705
+ continue
706
+ return out
707
 
708
 
709
  def health() -> dict: