-
Notifications
You must be signed in to change notification settings - Fork 223
MoE Prefill Streaming & DDTree Batched Verify #349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
620934c
feat(dflash): MoE prefill streaming engine with mmap + batched GPU eval
howard0su 975a98b
perf(dflash): skip CPU when all routed experts are in VRAM (bitmask f…
howard0su 74d1d39
perf(dflash): add cached hot-only batched graph for prefill sub-batches
howard0su a85d62a
perf(dflash): skip MMQ sub-batch workaround on sm_80+ (full-batch pre…
howard0su 6f784f7
perf(dflash): batched MoE verify for DDTree speculative decode
howard0su 0dd35e2
fix(dflash): address PR review comments (P1 + P2)
howard0su 727bfdb
fix(gguf_mmap): add missing <cstdint> include
5397df7
fix(moe): gate MMQ full-batch mul_mat_id by batch size on reduced hot…
89e4897
fix(moe): integrate streaming storage with mainline LRU expert cache
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| #!/usr/bin/env python3 | ||
| """ | ||
| bench_moe_prefill_streaming.py — End-to-end benchmark comparing prefill | ||
| throughput with and without MoE streaming. | ||
|
|
||
| Usage: | ||
| # Against a running server (streaming enabled): | ||
| python bench_moe_prefill_streaming.py --url http://localhost:8080 | ||
|
|
||
| # Compare two servers (streaming vs baseline): | ||
| python bench_moe_prefill_streaming.py \ | ||
| --url-streaming http://localhost:8080 \ | ||
| --url-baseline http://localhost:8081 | ||
|
|
||
| Measures prompt eval tok/s at varying prompt lengths. | ||
| """ | ||
|
|
||
| import argparse | ||
| import json | ||
| import time | ||
| import sys | ||
| from urllib.request import urlopen, Request | ||
| from urllib.error import URLError | ||
|
|
||
|
|
||
| def generate_prompt(n_tokens: int) -> str: | ||
| """Generate a prompt that's approximately n_tokens long.""" | ||
| # Average ~1.3 tokens per word in English | ||
| words_needed = max(1, int(n_tokens / 1.3)) | ||
| base = "The quick brown fox jumps over the lazy dog. " | ||
| words = base.split() | ||
| prompt_words = [] | ||
| for i in range(words_needed): | ||
| prompt_words.append(words[i % len(words)]) | ||
| return " ".join(prompt_words) | ||
|
|
||
|
|
||
| def bench_prefill(url: str, prompt: str, max_tokens: int = 1) -> dict: | ||
| """Send a completion request and measure prefill time.""" | ||
| payload = { | ||
| "model": "default", | ||
| "messages": [{"role": "user", "content": prompt}], | ||
| "max_tokens": max_tokens, | ||
| "temperature": 0.0, | ||
| "stream": False, | ||
| } | ||
|
|
||
| req = Request( | ||
| f"{url}/v1/chat/completions", | ||
| data=json.dumps(payload).encode(), | ||
| headers={"Content-Type": "application/json"}, | ||
| ) | ||
|
|
||
| t0 = time.perf_counter() | ||
| try: | ||
| with urlopen(req, timeout=120) as resp: | ||
| body = json.loads(resp.read()) | ||
| except URLError as e: | ||
| return {"error": str(e)} | ||
| t1 = time.perf_counter() | ||
|
|
||
| usage = body.get("usage", {}) | ||
| prompt_tokens = usage.get("prompt_tokens", 0) | ||
| # The server reports timings in the response if available | ||
| timings = body.get("timings", {}) | ||
| prefill_ms = timings.get("prompt_ms", (t1 - t0) * 1000) | ||
|
|
||
| return { | ||
| "prompt_tokens": prompt_tokens, | ||
| "wall_ms": (t1 - t0) * 1000, | ||
| "prefill_ms": prefill_ms, | ||
| "tok_per_s": prompt_tokens / (prefill_ms / 1000) if prefill_ms > 0 else 0, | ||
| } | ||
|
|
||
|
|
||
| def run_sweep(url: str, prompt_lengths: list, n_warmup: int = 1, n_iter: int = 3) -> list: | ||
| """Run prefill benchmark at various prompt lengths.""" | ||
| results = [] | ||
|
|
||
| for n_tok in prompt_lengths: | ||
| prompt = generate_prompt(n_tok) | ||
|
|
||
| # Warmup | ||
| for _ in range(n_warmup): | ||
| bench_prefill(url, prompt) | ||
|
|
||
| # Measure | ||
| measurements = [] | ||
| for _ in range(n_iter): | ||
| r = bench_prefill(url, prompt) | ||
| if "error" in r: | ||
| print(f" ERROR at T={n_tok}: {r['error']}", file=sys.stderr) | ||
| break | ||
| measurements.append(r) | ||
|
|
||
| if measurements: | ||
| avg_prefill_ms = sum(m["prefill_ms"] for m in measurements) / len(measurements) | ||
| avg_tok_s = sum(m["tok_per_s"] for m in measurements) / len(measurements) | ||
| actual_tokens = measurements[0]["prompt_tokens"] | ||
| results.append({ | ||
| "target_tokens": n_tok, | ||
| "actual_tokens": actual_tokens, | ||
| "avg_prefill_ms": avg_prefill_ms, | ||
| "avg_tok_per_s": avg_tok_s, | ||
| }) | ||
| print(f" T={n_tok:5d} actual={actual_tokens:5d} " | ||
| f"prefill={avg_prefill_ms:8.1f} ms " | ||
| f"tok/s={avg_tok_s:8.1f}") | ||
|
|
||
| return results | ||
|
|
||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser(description="MoE prefill streaming benchmark") | ||
| parser.add_argument("--url", type=str, help="Server URL to benchmark") | ||
| parser.add_argument("--url-streaming", type=str, help="Server URL with streaming enabled") | ||
| parser.add_argument("--url-baseline", type=str, help="Server URL with baseline (CPU cold)") | ||
| parser.add_argument("--prompt-lengths", type=str, default="128,256,512,1024,2048,4096,8192", | ||
| help="Comma-separated prompt lengths to test") | ||
| parser.add_argument("--n-iter", type=int, default=3, help="Iterations per measurement") | ||
| parser.add_argument("--n-warmup", type=int, default=1, help="Warmup iterations") | ||
| args = parser.parse_args() | ||
|
|
||
| prompt_lengths = [int(x) for x in args.prompt_lengths.split(",")] | ||
|
|
||
| if args.url: | ||
| print(f"\n=== Benchmarking: {args.url} ===") | ||
| results = run_sweep(args.url, prompt_lengths, args.n_warmup, args.n_iter) | ||
| print(f"\n{'T':>8} {'Prefill ms':>12} {'tok/s':>10}") | ||
| print("-" * 35) | ||
| for r in results: | ||
| print(f"{r['actual_tokens']:>8} {r['avg_prefill_ms']:>12.1f} {r['avg_tok_per_s']:>10.1f}") | ||
|
|
||
| elif args.url_streaming and args.url_baseline: | ||
| print(f"\n=== Baseline: {args.url_baseline} ===") | ||
| baseline = run_sweep(args.url_baseline, prompt_lengths, args.n_warmup, args.n_iter) | ||
|
|
||
| print(f"\n=== Streaming: {args.url_streaming} ===") | ||
| streaming = run_sweep(args.url_streaming, prompt_lengths, args.n_warmup, args.n_iter) | ||
|
|
||
| print(f"\n{'T':>8} {'Baseline ms':>12} {'Stream ms':>12} {'Speedup':>8}") | ||
| print("-" * 50) | ||
| stream_map = {s["target_tokens"]: s for s in streaming} | ||
| for b in baseline: | ||
| s = stream_map.get(b["target_tokens"]) | ||
| if not s: | ||
| continue | ||
| speedup = b["avg_prefill_ms"] / s["avg_prefill_ms"] if s["avg_prefill_ms"] > 0 else 0 | ||
| print(f"{b['actual_tokens']:>8} {b['avg_prefill_ms']:>12.1f} " | ||
| f"{s['avg_prefill_ms']:>12.1f} {speedup:>7.2f}x") | ||
| else: | ||
| parser.error("Provide --url or both --url-streaming and --url-baseline") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Unsigned integer overflow in range validation:
offset + lengthonsize_tcan wrap around, causing the clamp to be skipped and an invalid oversized range to be passed tomadvise/PrefetchVirtualMemory. Useif (length > size_ - offset)instead.Prompt for AI agents