Skip to content

Commit f4a4b86

Browse files
test(distributed): add run_distributed_demo.sh + mlx-distributed-spec-decode-demo bridge preset
Two-process (proposer + Qwen3-0.6B verifier) distributed spec-decode over real gRPC sockets, asserting byte-identical-to-greedy. Lets the Mac bridge validate the ADR 0009 distributed engine on-device (mirrors the GPU-host run). Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
1 parent 78dab28 commit f4a4b86

3 files changed

Lines changed: 79 additions & 0 deletions

File tree

inference_engine/bridge/manifest.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,25 @@ def _harness_preset(
102102
PRESETS: Dict[str, Preset] = {
103103
p.name: p
104104
for p in (
105+
Preset(
106+
name="mlx-distributed-spec-decode-demo",
107+
description="ADR 0009 distributed spec-decode, on-device: two local "
108+
"processes (n-gram ProposerService + Qwen3-0.6B verifier) "
109+
"over real gRPC sockets — capability gossip, placement, "
110+
"remote drafts + LOCAL greedy verify, asserting the output "
111+
"is byte-identical to local greedy. Validates the "
112+
"distributed engine on the Mac.",
113+
command_templates=(
114+
(
115+
"bash", "scripts/run_distributed_demo.sh",
116+
"--verifier-id", "Qwen/Qwen3-0.6B",
117+
"--max-new-tokens", "{max_new_tokens}",
118+
),
119+
),
120+
timeout_minutes=45,
121+
params={"max_new_tokens": ("int:max_new_tokens", "48")},
122+
validate_reports=False,
123+
),
105124
Preset(
106125
name="mlx-env-probe",
107126
description="Probe Metal/MLX + mlx.distributed availability.",

scripts/run_distributed_demo.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env bash
2+
# Run the ADR 0009 distributed speculative-decode demo as TWO local processes
3+
# (proposer node + verifier node over real gRPC sockets) and assert the
4+
# distributed output is byte-identical to local greedy. Used for on-device
5+
# validation on the Mac bridge (and runnable anywhere with the deps).
6+
#
7+
# Picks an mlx_lm-free but torch+transformers+grpcio-capable Python: prefers
8+
# KAKEYA_MAC_PYTHON, then the repo venv, then python3.
9+
#
10+
# Usage:
11+
# bash scripts/run_distributed_demo.sh [--verifier-id ID] [--max-new-tokens N]
12+
set -euo pipefail
13+
14+
repo_root="$(cd "$(dirname "$0")/.." && pwd)"
15+
cd "$repo_root"
16+
17+
VERIFIER_ID="Qwen/Qwen3-0.6B"
18+
MAXNEW="48"
19+
while [[ $# -gt 0 ]]; do
20+
case "$1" in
21+
--verifier-id) shift; VERIFIER_ID="${1:?}" ;;
22+
--max-new-tokens) shift; MAXNEW="${1:?}" ;;
23+
*) echo "[dist-demo] ignoring arg: $1" >&2 ;;
24+
esac
25+
shift
26+
done
27+
28+
_can() { [ -n "${1:-}" ] && "$1" -c 'import grpc, torch, transformers' >/dev/null 2>&1; }
29+
PYBIN=""
30+
for c in "${KAKEYA_MAC_PYTHON:-}" "$repo_root/.venv-mac/bin/python3.13" \
31+
"$repo_root/.venv-mac/bin/python" "$HOME/kakeya-venv/bin/python" \
32+
"$(command -v python3 2>/dev/null || true)"; do
33+
if _can "$c"; then PYBIN="$c"; break; fi
34+
done
35+
if [[ -z "$PYBIN" ]]; then
36+
echo "[dist-demo] no Python with grpc+torch+transformers found; set KAKEYA_MAC_PYTHON" >&2
37+
exit 2
38+
fi
39+
echo "[dist-demo] python=$PYBIN verifier=$VERIFIER_ID max_new=$MAXNEW" >&2
40+
41+
export PYTHONPATH="$repo_root:$repo_root/sdks/python"
42+
export HF_HUB_DISABLE_PROGRESS_BARS=1
43+
44+
# Clean any stale demo procs, start the proposer node, run the verifier node.
45+
for p in $(pgrep -f demo_distributed_spec_decode 2>/dev/null || true); do kill "$p" 2>/dev/null || true; done
46+
sleep 1
47+
"$PYBIN" scripts/demo_distributed_spec_decode.py \
48+
--role proposer-node --bind 127.0.0.1:50061 --node-id node-b \
49+
> /tmp/kakeya_dist_proposer.log 2>&1 &
50+
PP=$!
51+
trap 'kill "$PP" 2>/dev/null || true' EXIT
52+
sleep 6
53+
"$PYBIN" scripts/demo_distributed_spec_decode.py \
54+
--role verifier-node --bind 127.0.0.1:50060 --node-id node-a \
55+
--peer 127.0.0.1:50061 --verifier-id "$VERIFIER_ID" \
56+
--max-new-tokens "$MAXNEW"
57+
RC=$?
58+
echo "[dist-demo] VERIFIER_RC=$RC" >&2
59+
exit $RC

tests/inference_engine/bridge/test_manifest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def test_allowlist_contains_exactly_the_documented_presets():
7979
"mlx-batched-manual-sdpa",
8080
"mlx-batched-multitenant",
8181
"mlx-batched-pad-decode",
82+
"mlx-distributed-spec-decode-demo",
8283
"mlx-env-probe",
8384
"mlx-kakeya-chat-smoke",
8485
"mlx-kakeya-chat-stream-probe",

0 commit comments

Comments
 (0)