Repository navigation
Run on Apple Silicon (MPS) - #1
lukaspoloki wants to merge 1 commit into
Conversation
Reviewer's GuideThis PR adds an Apple Silicon/MPS serving path based on shared-prefix packing and token-budget batching with ordinary forward passes, introduces device-aware serving and benchmarking with CUDA→MPS→CPU fallback, documents MPS usage and constraints, and verifies numerical equivalence on CPU and MPS. Sequence diagram for MPS shared-prefix inferencesequenceDiagram
participant Client
participant Server
participant SharedBackend
participant MPS
Client->>Server: Request with option orders
Server->>SharedBackend: run_shared(groups)
SharedBackend->>SharedBackend: _pack(prompts)
SharedBackend->>SharedBackend: _chunks(token budget)
SharedBackend->>MPS: _forward_masked(ids, mask, pos)
MPS-->>SharedBackend: logits for packed rows
SharedBackend->>SharedBackend: _readout(option logits)
SharedBackend-->>Server: probabilities
Server-->>Client: Decision response
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="basal/bench.py" line_range="157" />
<code_context>
ap.add_argument("--model", default="Remek/basal-1.0-4.5B")
ap.add_argument("--vllm-model", dest="vllm_model", default=None, help="checkpoint for --modes vllm (e.g. the NVFP4 repo)")
ap.add_argument("--modes", nargs="+", default=["eager-fp32", "fast"],
- help="eager-fp32, eager, fast, fast-nocompile, fp8, nvfp4, vllm, fast-exit@off|0.999|0.995|0.99|0.98")
+ help="eager-fp32, eager, fast, fast-nocompile, fp8, nvfp4, vllm, fast-exit@off|0.999|0.995|0.99|0.98; "
</code_context>
<issue_to_address>
**issue (broader_impact):** `basal-bench` still defaults to `['eager-fp32', 'fast']`, so running it without an explicit `--modes` on a Mac or CPU constructs `GraphBackend` for `fast`; `GraphBackend.__init__` unconditionally calls `.cuda()` and CUDA graph APIs, causing the benchmark to fail before measuring anything.
**Triggers:** When `basal-bench` is run without `--modes` on a machine without CUDA.
**Suggested fix:** Select `mps` instead of `fast` in the benchmark's default mode list when `default_device()` is not CUDA, or translate the default `fast` mode to `mps` on such devices.
```suggestion
ap.add_argument("--modes", nargs="+", default=["eager-fp32", "fast" if default_device() == "cuda" else "mps"],
```
</issue_to_address>| @@ -120,7 +155,8 @@ def main(): | |||
| ap.add_argument("--model", default="Remek/basal-1.0-4.5B") | |||
| ap.add_argument("--vllm-model", dest="vllm_model", default=None, help="checkpoint for --modes vllm (e.g. the NVFP4 repo)") | |||
| ap.add_argument("--modes", nargs="+", default=["eager-fp32", "fast"], | |||
There was a problem hiding this comment.
issue (broader_impact): basal-bench still defaults to ['eager-fp32', 'fast'], so running it without an explicit --modes on a Mac or CPU constructs GraphBackend for fast; GraphBackend.__init__ unconditionally calls .cuda() and CUDA graph APIs, causing the benchmark to fail before measuring anything.
Triggers: When basal-bench is run without --modes on a machine without CUDA.
Suggested fix: Select mps instead of fast in the benchmark's default mode list when default_device() is not CUDA, or translate the default fast mode to mps on such devices.
| ap.add_argument("--modes", nargs="+", default=["eager-fp32", "fast"], | |
| ap.add_argument("--modes", nargs="+", default=["eager-fp32", "fast" if default_device() == "cuda" else "mps"], |
feat: Apple Silicon backends (MLX, MPS)
|
Thanks a lot for this, and sorry for the slow reply. Apple Silicon support landed through #4 (MLX and MPS) in 1.5.0 and is in v2.0.0: --mode mps with shared-prefix packing, --device cuda|mps|cpu with the cuda → mps → cpu fallback, and basal-bench without CUDA. Since this overlaps that work and now conflicts with the 2.0 engine, I'm closing it. Thank you for the contribution. |
Adds an mps serving mode for M-series Macs. It keeps the shared-prefix packing and token-budget batching of fast, but runs plain forward passes instead of CUDA graphs. The default device is now cuda → mps → cpu, and basal-serve falls back to mps when there is no CUDA. basal-bench also works without CUDA.
Measured on an M3 Pro (18 GB) with the bundled examples, both option orders: 1.5B takes 224 ms per decision (4.0/s, matches fp32 on 43 of 44); 4.5B takes 660 ms (1.5/s, 10.1 GB). That's 1.35–1.4× faster than eager.
New test: the mps path equals separate forward passes, on CPU and MPS. The CUDA code paths are unchanged, but I had no NVIDIA GPU to re-run them on.
Summary by Sourcery
Add Apple Silicon support with an automatically selected MPS backend and CUDA-independent benchmarking.
New Features:
Bug Fixes:
Enhancements:
Documentation:
Tests: