Nicholas Bumgarner commited on
Commit
cdad13a
·
1 Parent(s): b356ed7

Add Start Mixer button + start_mixer function for fast mixing ring engine

Browse files
Files changed (1) hide show
  1. app.py +48 -5
app.py CHANGED
@@ -38,11 +38,13 @@ RING_OUT_PATH = "/tmp/phoenix_ring_out"
38
  RING_CAPACITY = 4096
39
  RING_BUF_SIZE = RING_CAPACITY * 4 + 16
40
  PHOENIX_BIN = "/tmp/phoenix"
 
41
  CHAT_TIMEOUT_S = 30
42
  SENTINEL_QUIT = 0xFFFFFFFE
43
 
44
  # ── Global state ──
45
  _phoenix_proc = None
 
46
  _ring_in_mm = None
47
  _ring_out_mm = None
48
  _ring_in_fd = None
@@ -271,6 +273,45 @@ def start_phoenix_manual():
271
  return " Booting... check Engine Status for progress"
272
 
273
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
274
  def stop_phoenix():
275
  global _phoenix_proc, _ring_in_mm, _ring_out_mm, _ring_in_fd, _ring_out_fd
276
  # Send quit signal via ring buffer (no lock needed for ring_push)
@@ -358,12 +399,12 @@ with gr.Blocks(title="Phox — Wave-Rider Brain") as demo:
358
  gr.Markdown("""
359
  # 🌀 Phox — Wave-Rider Inference Engine
360
 
361
- **BQSM v8 + Phoenix Brain**: A Kuramoto oscillator interference engine
362
- running on Gemma-4-12B ternary weights (80% sparse, 2-bit). No matmul —
363
- the ring IS the computation.
364
 
365
- Chat with Phox below. The wave-rider carries your tokens through 48 layers
366
- of traveling wave activation. Self-tuning via gradient lens profiles.
367
  """)
368
 
369
  with gr.Row():
@@ -379,10 +420,12 @@ with gr.Blocks(title="Phox — Wave-Rider Brain") as demo:
379
  gr.Markdown("### Controls")
380
  with gr.Row():
381
  start_btn = gr.Button("Start Engine", variant="primary")
 
382
  stop_btn = gr.Button("Stop Engine", variant="secondary")
383
  status_text = gr.Textbox(label="Engine Output", interactive=False)
384
 
385
  start_btn.click(fn=start_phoenix_manual, outputs=status_text)
 
386
  stop_btn.click(fn=stop_phoenix, outputs=status_text)
387
 
388
  # Periodic status refresh using gr.Timer (Gradio 6.x API)
 
38
  RING_CAPACITY = 4096
39
  RING_BUF_SIZE = RING_CAPACITY * 4 + 16
40
  PHOENIX_BIN = "/tmp/phoenix"
41
+ MIXER_BIN = "/tmp/mixer"
42
  CHAT_TIMEOUT_S = 30
43
  SENTINEL_QUIT = 0xFFFFFFFE
44
 
45
  # ── Global state ──
46
  _phoenix_proc = None
47
+ _mixer_proc = None
48
  _ring_in_mm = None
49
  _ring_out_mm = None
50
  _ring_in_fd = None
 
273
  return " Booting... check Engine Status for progress"
274
 
275
 
276
+ def start_mixer():
277
+ """Start the mixing ring engine (lighter-weight alternative to phoenix)."""
278
+ global _mixer_proc
279
+ # Check if already running
280
+ if _mixer_proc and _mixer_proc.poll() is None:
281
+ return "Mixer already running"
282
+ # Download binary to /tmp
283
+ if not os.path.exists(MIXER_BIN):
284
+ try:
285
+ hf_hub_download(
286
+ repo_id=MODEL_REPO,
287
+ filename="mixer",
288
+ local_dir="/tmp",
289
+ local_dir_use_symlinks=False,
290
+ )
291
+ os.chmod(MIXER_BIN, 0o755)
292
+ except Exception as e:
293
+ return f"Failed to download mixer binary: {e}"
294
+ # Ensure model exists
295
+ if not os.path.exists(MODEL_PATH):
296
+ os.makedirs(MODEL_SUBDIR, exist_ok=True)
297
+ try:
298
+ hf_hub_download(
299
+ repo_id=MODEL_REPO,
300
+ filename=MODEL_FILENAME,
301
+ local_dir=MODEL_SUBDIR,
302
+ local_dir_use_symlinks=False,
303
+ )
304
+ except Exception as e:
305
+ return f"Failed to download model: {e}"
306
+ # Launch mixer binary — it runs inference and outputs to stdout
307
+ _mixer_proc = subprocess.Popen(
308
+ [MIXER_BIN, MODEL_PATH, "-s", "2"],
309
+ stdout=open(STATE_LOG, 'a'),
310
+ stderr=subprocess.STDOUT,
311
+ )
312
+ return f"Mixer started (PID {_mixer_proc.pid}) — check daemon log"
313
+
314
+
315
  def stop_phoenix():
316
  global _phoenix_proc, _ring_in_mm, _ring_out_mm, _ring_in_fd, _ring_out_fd
317
  # Send quit signal via ring buffer (no lock needed for ring_push)
 
399
  gr.Markdown("""
400
  # 🌀 Phox — Wave-Rider Inference Engine
401
 
402
+ **Two engines available:**
403
+ - **Phox Brain** (heavy): 2.98GB model, ~1.1 tok/s, full wave-rider physics
404
+ - **Mixing Ring** (fast): 100-ring topology, ~8000+ tok/s, parallel settle
405
 
406
+ Both use the same Gemma-4-12B ternary weights via mmap. Click the appropriate
407
+ button to start, then chat below.
408
  """)
409
 
410
  with gr.Row():
 
420
  gr.Markdown("### Controls")
421
  with gr.Row():
422
  start_btn = gr.Button("Start Engine", variant="primary")
423
+ mixer_btn = gr.Button("Start Mixer (fast)", variant="secondary")
424
  stop_btn = gr.Button("Stop Engine", variant="secondary")
425
  status_text = gr.Textbox(label="Engine Output", interactive=False)
426
 
427
  start_btn.click(fn=start_phoenix_manual, outputs=status_text)
428
+ mixer_btn.click(fn=start_mixer, outputs=status_text)
429
  stop_btn.click(fn=stop_phoenix, outputs=status_text)
430
 
431
  # Periodic status refresh using gr.Timer (Gradio 6.x API)