Nicholas Bumgarner commited on
Commit
adcbc7e
·
1 Parent(s): d0f24f6

Download pre-built phoenix binary from HF Hub instead of compiling on Space

Browse files
Files changed (1) hide show
  1. app.py +28 -19
app.py CHANGED
@@ -4,11 +4,10 @@ Phox on Hugging Face Spaces — BQSM Wave-Rider Inference Engine.
4
 
5
  This app wraps the Phoenix Brain C inference binary in a Gradio interface.
6
  At Space startup it:
7
- 1. Downloads the Gemma-4-12B ternary model from HF Hub
8
- 2. Downloads the Gemma 4 tokenizer (via tokenizers library, no PyTorch needed)
9
- 3. Compiles phoenix_brain.c with AVX2 + OpenMP
10
- 4. Starts phoenix in --chat mode with shared-memory ring buffers
11
- 5. Provides a chat UI via Gradio
12
 
13
  The phoenix binary runs on CPU (AVX2) — the wave-rider physics engine
14
  doesn't use PyTorch, so ZeroGPU doesn't accelerate it directly.
@@ -117,22 +116,32 @@ def boot_phoenix():
117
  _update_boot("download", f"Model download FAILED: {e}")
118
  return
119
 
120
- # Phase 2: Use pre-built binary if available, otherwise compile
121
- _update_boot("build", "Checking phoenix binary...")
122
  if not os.path.exists(PHOENIX_BIN):
123
- src_path = os.path.join(SPACE_DIR, "phoenix_brain.c")
124
- if os.path.exists(src_path):
125
- _update_boot("build", "Compiling phoenix_brain.c (AVX2 + OpenMP)...")
126
- cc = os.environ.get("CC", "cc")
127
- cmd = [cc, "-O3", "-std=c11", "-march=native", "-fopenmp",
128
- src_path, "-o", PHOENIX_BIN, "-lm"]
129
- result = subprocess.run(cmd, capture_output=True, text=True, timeout=120)
130
- if result.returncode != 0:
131
- _update_boot("build", f"Build FAILED: {result.stderr[:500]}")
 
 
 
 
 
 
 
 
 
 
 
 
 
132
  return
133
- else:
134
- _update_boot("build", "No phoenix binary or source found!")
135
- return
136
  _update_boot("build", "Binary ready")
137
 
138
  # Phase 3: Start phoenix
 
4
 
5
  This app wraps the Phoenix Brain C inference binary in a Gradio interface.
6
  At Space startup it:
7
+ 1. Downloads the tokenizer from HF Hub (tokenizers lib, no PyTorch)
8
+ 2. On button click: downloads pre-built phoenix binary + model from HF Hub
9
+ 3. Starts phoenix in --chat mode with shared-memory ring buffers
10
+ 4. Provides a chat UI via Gradio
 
11
 
12
  The phoenix binary runs on CPU (AVX2) — the wave-rider physics engine
13
  doesn't use PyTorch, so ZeroGPU doesn't accelerate it directly.
 
116
  _update_boot("download", f"Model download FAILED: {e}")
117
  return
118
 
119
+ # Phase 2: Download pre-built binary from HF Hub (avoids compilation on Space)
120
+ _update_boot("build", "Downloading phoenix binary from Hub...")
121
  if not os.path.exists(PHOENIX_BIN):
122
+ try:
123
+ hf_hub_download(
124
+ repo_id=MODEL_REPO,
125
+ filename="phoenix",
126
+ local_dir=SPACE_DIR,
127
+ local_dir_use_symlinks=False,
128
+ )
129
+ os.chmod(PHOENIX_BIN, 0o755)
130
+ except Exception as e:
131
+ # Fallback: compile from source
132
+ _update_boot("build", f"Binary download failed, compiling... ({e})")
133
+ src_path = os.path.join(SPACE_DIR, "phoenix_brain.c")
134
+ if os.path.exists(src_path):
135
+ cc = os.environ.get("CC", "cc")
136
+ cmd = [cc, "-O3", "-std=c11", "-march=native", "-fopenmp",
137
+ src_path, "-o", PHOENIX_BIN, "-lm"]
138
+ result = subprocess.run(cmd, capture_output=True, text=True, timeout=120)
139
+ if result.returncode != 0:
140
+ _update_boot("build", f"Build FAILED: {result.stderr[:500]}")
141
+ return
142
+ else:
143
+ _update_boot("build", "No binary or source found!")
144
  return
 
 
 
145
  _update_boot("build", "Binary ready")
146
 
147
  # Phase 3: Start phoenix