Skip to content

[fly][gr] Unify the gr read api for both prefill and decode - #56

Merged
luocheng25 merged 5 commits into
tingqli:devfrom
apinge:gr_read_api
Sep 29, 2026
Merged

luocheng25 merged 5 commits into
tingqli:devfrom
apinge:gr_read_api

Conversation

@apinge

@apinge apinge commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

This PR makes following changes:

  1. Unifies gr read apis for prefill and deocde.
from pyhip.ops.gr_read import gr_read, prepare_weights

packed_down, packed_up = prepare_weights(w_down, w_up)
y = gr_read(x, packed_down, packed_up)
# Optional: if an output tensor is provided, write into it and return the same tensor.
y = gr_read(x, packed_down, packed_up, output=out)
  1. Removes test case's dependency on /opt/sglang and adds tests/ops/gr_read/baselines.py which containes current sglang implementation (torch compile and triton kernel)
  2. Removes the old test logic and quires rocm-smi among multiple stages and between each batch. Because rocm-smi utilization data has sampling lag, it is not reliable for frequent idle checks. The benchmark requires the gpu to be idle before running (gpu utilization <=5% VRAM usages <=20%). The new implementation performs idle check only once before warmup.
  3. Moves benchmark tests to benchmarks/gr_read

Test

acc

 python3 -m pytest -q tests/ops/gr_read/test_gr_read.py

perf

python3 benchmarks/gr_read/bench_gr_read_compare.py --gpu 2

@apinge apinge changed the title [fly][gr] Unify the gr read api for both prefill and decode. [fly][gr] Unify the gr read api for both prefill and decode Sep 28, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Timed Total calls do not record their actual address-sensitive internal workspace allocations.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Unifies decode and prefill behind the public gr_read API and makes performance baselines self-contained.

Changes:

  • Adds cached, graph-compatible functional dispatch with optional output tensors.
  • Adds frozen Torch/Triton baselines and expanded API tests.
  • Reworks benchmarking to use a single startup hardware gate.
File Description
src/​pyhip/​ops/​gr_read/​__init__.py Exports the unified API.
src/​pyhip/​ops/​gr_read/​flydsl/​__init__.py Re-exports gr_read.
src/​pyhip/​ops/​gr_read/​flydsl/​host.py Implements dispatch, validation, and compilation caching.
tests/​ops/​gr_read/​baselines.py Adds frozen performance baselines.
tests/​ops/​gr_read/​bench_gr_read_compare.py Updates benchmark protocols and hardware gating.
tests/​ops/​gr_read/​test_gr_read.py Adds API, graph, cache, and baseline coverage.
tests/​ops/​gr_read/​readme.md Documents the API and benchmark process.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +293 to +295
emit({'type': 'addresses', 'rows': rows, 'total_entry': 'gr_read',
'total_partial': 'allocated internally for each call; P_stages is only used by stage measurements',
'buffers': [{k: address(v) for (k, v) in (('X', c.x), ('WD_raw', c.wd), ('WU_raw', c.wu), ('WD_packed', c.pd), ('WU_packed', c.pu), ('P_stages', c.p), ('Y', c.y), ('Baseline_WD', c.baseline_wd), ('Baseline_WU', c.baseline_wu), ('Baseline_Y', c.baseline_y)) if v is not None} for c in cases]})

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only affects the exported json and does not impact normal functionality. I have also updated the related tests.

@@ -1,13 +1,12 @@
# SPDX-License-Identifier: MIT

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please move this file to the folder pyhip/benchmarks/gr_read and add a readme.md in the pyhip/benchmarks/gr_read which should include the performance data and the code sample for using this ops?
We expect the following contract:

  • there is a benchscirpt in pyhip/benchmarkds/gr_read to
    • do the tuning(optional, if needed)
    • test overall performance
    • generate performance report
  • there is a readme.md in pyhip/benchmarkds/gr_read for the end user to quickly lookup the performance data and the code snippets to do the integration
  • there may some test scripts in tests/ops/gr_read/ for each kernel, such as GRReadDecode GRReadPrefill etc.(it's for the new kernel, the existing can be unchanged.)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have moved the perf tests and readme to pyhip/benchmarks and left the acc test (for both prefill and decode) in tests/ops/gr_read/.
The only remaining part is the auto-tuning step, which still relies on many empirically tuned values for gfx942 (80cu).

@luocheng25 luocheng25 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@luocheng25
luocheng25 merged commit 5e45f9b into tingqli:dev Sep 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants