-
Notifications
You must be signed in to change notification settings - Fork 250
feat(ds4): add default-off HIP GPU phase profiler #554
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
Open
cheese-cakee
wants to merge
11
commits into
Luce-Org:main
Choose a base branch
from
cheese-cakee:codex/perf-ds4-gpu-profiler
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
42261ca
fix(ds4): preserve exact speculative verification
cheese-cakee 101db96
fix(ds4): parse parity trace as boolean
cheese-cakee 1790e70
feat(ds4): add default-off HIP GPU phase profiler
cheese-cakee 3fbed5f
fix(ds4): guard profiler end() against the idle sentinel phase
cheese-cakee 8f24320
feat(ds4): include the layer range in GPU profile records
cheese-cakee c0c9e67
refactor(ds4): make zero-call phase emission an explicit profiler policy
cheese-cakee e24a134
docs(ds4): note wrapper-read variables in the environment inventory
cheese-cakee 4c24ea8
fix(ds4): keep GPU profiler syncs outside existing telemetry windows
cheese-cakee 5e5a074
docs(ds4): mark parity trace as a debug-only per-row cost
cheese-cakee 1f8c9be
refactor(ds4): pass GPU profiler options as a struct
cheese-cakee 90ac4e5
fix(ds4): validate GPU profiler metadata
cheese-cakee 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
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
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
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,137 @@ | ||
| #!/usr/bin/env python3 | ||
| """Model-backed token parity regression for the public DS4 fused-verify flag.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| import json | ||
| import os | ||
| import re | ||
| import subprocess | ||
| import tempfile | ||
| import time | ||
| import urllib.request | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| TOKEN_RE = re.compile(r"\[ds4-parity-tokens\] n=\d+ ids=\[([0-9 ]*)\]") | ||
|
|
||
|
|
||
| def wait_ready(port: int, proc: subprocess.Popen[bytes], timeout: float) -> None: | ||
| deadline = time.monotonic() + timeout | ||
| url = f"http://127.0.0.1:{port}/health" | ||
| while time.monotonic() < deadline: | ||
| if proc.poll() is not None: | ||
| raise RuntimeError(f"server exited before readiness: {proc.returncode}") | ||
| try: | ||
| with urllib.request.urlopen(url, timeout=2) as response: | ||
| if response.status == 200: | ||
| return | ||
| except OSError: | ||
| time.sleep(1) | ||
| raise TimeoutError(f"server did not become ready within {timeout:.0f}s") | ||
|
|
||
|
|
||
| def stop_server(proc: subprocess.Popen[bytes]) -> None: | ||
| if proc.poll() is not None: | ||
| return | ||
| proc.terminate() | ||
| try: | ||
| proc.wait(timeout=30) | ||
| except subprocess.TimeoutExpired: | ||
| proc.kill() | ||
| proc.wait(timeout=10) | ||
|
|
||
|
|
||
| def run_case(args: argparse.Namespace, fused_requested: bool, log_path: Path) -> list[int]: | ||
| env = os.environ.copy() | ||
| for name in ( | ||
| "DFLASH_DS4_FUSED_VERIFY", | ||
| "DFLASH_DS4_ALLOW_APPROX_FUSED_VERIFY", | ||
| "DFLASH_DS4_SEQ_VERIFY", | ||
| "DFLASH_DS4_DSPARK_DEBUG", | ||
| ): | ||
| env.pop(name, None) | ||
| env.update({ | ||
| "DFLASH_DS4_SPEC": "1", | ||
| "DFLASH_DS4_DRAFT": str(args.draft), | ||
| "DFLASH_DS4_SPEC_Q": "4", | ||
| "DFLASH_DS4_ADAPTIVE_WIDTH": "0", | ||
| "DFLASH_DS4_PARITY_TRACE": "1", | ||
| "LUCE_MMVQ_MAX_NCOLS": "4", | ||
| }) | ||
| if fused_requested: | ||
| env["DFLASH_DS4_FUSED_VERIFY"] = "1" | ||
|
|
||
| cmd = [ | ||
| str(args.server_bin), str(args.target), | ||
| "--host", "127.0.0.1", "--port", str(args.port), | ||
| "--max-ctx", str(args.max_ctx), "--chunk", "512", | ||
| "--target-device", "hip:0", "--ds4-fused-decode", | ||
| ] | ||
| with log_path.open("wb") as log: | ||
| proc = subprocess.Popen(cmd, env=env, stdout=log, stderr=subprocess.STDOUT) | ||
| try: | ||
| wait_ready(args.port, proc, args.startup_timeout) | ||
| body = json.dumps({ | ||
| "model": "dflash", | ||
| "messages": [{"role": "user", "content": args.prompt}], | ||
| "temperature": 0, | ||
| "seed": 1234, | ||
| "max_tokens": args.max_tokens, | ||
| "stream": False, | ||
| }).encode() | ||
| request = urllib.request.Request( | ||
| f"http://127.0.0.1:{args.port}/v1/chat/completions", | ||
| data=body, | ||
| headers={"Content-Type": "application/json"}, | ||
| ) | ||
| with urllib.request.urlopen(request, timeout=args.request_timeout) as response: | ||
| if response.status != 200: | ||
| raise RuntimeError(f"generation returned HTTP {response.status}") | ||
| json.load(response) | ||
| finally: | ||
| stop_server(proc) | ||
|
|
||
| matches = TOKEN_RE.findall(log_path.read_text(errors="replace")) | ||
| if not matches: | ||
| raise RuntimeError(f"token trace missing from {log_path}") | ||
| return [int(token) for token in matches[-1].split()] | ||
|
|
||
|
|
||
| def main() -> int: | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument("--server-bin", required=True, type=Path) | ||
| parser.add_argument("--target", required=True, type=Path) | ||
| parser.add_argument("--draft", required=True, type=Path) | ||
| parser.add_argument("--port", type=int, default=18084) | ||
| parser.add_argument("--max-ctx", type=int, default=4096) | ||
| parser.add_argument("--max-tokens", type=int, default=32) | ||
| parser.add_argument("--startup-timeout", type=float, default=180) | ||
| parser.add_argument("--request-timeout", type=float, default=600) | ||
| parser.add_argument( | ||
| "--prompt", | ||
| default="Explain why a bicycle stays upright while moving.", | ||
| ) | ||
| args = parser.parse_args() | ||
| for path in (args.server_bin, args.target, args.draft): | ||
| if not path.is_file(): | ||
| parser.error(f"file not found: {path}") | ||
|
|
||
| with tempfile.TemporaryDirectory(prefix="ds4-fused-parity-") as tmp: | ||
| tmp_path = Path(tmp) | ||
| normal = run_case(args, False, tmp_path / "normal.log") | ||
| fused_flag = run_case(args, True, tmp_path / "fused-flag.log") | ||
|
|
||
| if normal != fused_flag: | ||
| limit = min(len(normal), len(fused_flag)) | ||
| first = next((i for i in range(limit) if normal[i] != fused_flag[i]), limit) | ||
| print(f"FAIL: first token mismatch at {first}: normal={normal[first:first+4]} " | ||
| f"fused_flag={fused_flag[first:first+4]}") | ||
| return 1 | ||
| print(f"PASS: {len(normal)} generated token IDs are identical") | ||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| raise SystemExit(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
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.
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.
Uh oh!
There was an error while loading. Please reload this page.