Skip to content

bench(rocm,rope): use a real cos/sin cache in bench_rope - #270

Merged
demandal25 merged 1 commit into
amd-integrationfrom
worktree-fix-rope-cos-sin-cache
Jul 29, 2026
Merged

bench(rocm,rope): use a real cos/sin cache in bench_rope#270
demandal25 merged 1 commit into
amd-integrationfrom
worktree-fix-rope-cos-sin-cache

Conversation

@demandal25

@demandal25 demandal25 commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes the cos/sin cache in the ROCm RoPE benchmark so it holds a real cos‖sin table instead of random values.

What changed

  • benchmarks/rocm_benchmarks/bench_rope.py_shared_cos_sin_cache() built the table with torch.randn, so values were unbounded and did not satisfy cos²+sin²=1. That made the --accuracy error numbers non-representative and let inplace runs drift (repeated rotations were not norm-preserving). It now builds a proper RoPE cos‖sin table using the same construction as benchmarks/bench_rope.py / tests/test_helpers/rope_reference.py (inv_freq = 1/θ^(2i/d), θ=1e4). Shape (65536, 128), dtype float32, and the ~32 MiB shared-tensor footprint are unchanged.

This addresses the Copilot review on PR #267 (discussion r3468044946).

Test plan

  • Validated the new cache on-GPU (ROCm 7.2 / torch 2.9.1 container): shape (65536, 128), values in [-1, 1], max|cos²+sin²-1| ≈ 1.2e-7 (float32 epsilon), ~32 MiB — matches the prior tensor's shape/dtype/size.
  • pre-commit run --files benchmarks/rocm_benchmarks/bench_rope.py — all hooks pass.
  • No pytest coverage applies: bench_rope.py is a benchmark script (not in the test suite).

_shared_cos_sin_cache() built the cos||sin table with torch.randn, so
values were unbounded and did not satisfy cos^2+sin^2=1. That made the
--accuracy error numbers non-representative and let inplace runs drift,
since repeated rotations were not norm-preserving.

Build a proper RoPE cos||sin table instead (same construction as
benchmarks/bench_rope.py / tests/test_helpers/rope_reference.py): entries
are bounded in [-1, 1] and rotations are norm-preserving. Shape, dtype
(float32) and ~32 MiB footprint are unchanged.

Addresses Copilot review on PR #267 (discussion r3468044946).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 29, 2026 14:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes the ROCm RoPE benchmark’s cos/sin cache so it is a mathematically valid RoPE cos‖sin table (rather than random data), making the benchmark’s --accuracy output and repeated inplace-rotation behavior meaningful. It also updates internal PR-workflow documentation to reflect that the canonical repo is now AMD-Ecosystem/flashinfer.

Changes:

  • Replace the ROCm benchmark’s random cos/sin cache initialization with a standard RoPE frequency-based construction (θ=1e4), matching existing reference implementations.
  • Add a _ROPE_THETA constant to make the cache construction explicit and consistent.
  • Retarget PR-workflow docs and safeguards from ROCm/flashinfer to AMD-Ecosystem/flashinfer.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
benchmarks/rocm_benchmarks/bench_rope.py Builds a correct RoPE cos‖sin cache (bounded, norm-preserving) for accurate benchmarking and comparisons.
CLAUDE.md Updates PR-target guidance to the new AMD-Ecosystem/flashinfer repo slug.
.claude/skills/pr-workflow/SKILL.md Retargets gh/API/GraphQL examples and safeguards to AMD-Ecosystem/flashinfer.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings July 29, 2026 16:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings July 29, 2026 16:15
@demandal25
demandal25 force-pushed the worktree-fix-rope-cos-sin-cache branch from 8bccfad to 1fd74c8 Compare July 29, 2026 16:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@demandal25 demandal25 changed the title bench(rocm,rope): use a real cos/sin cache in bench_rope + retarget PR docs to AMD-Ecosystem bench(rocm,rope): use a real cos/sin cache in bench_rope Jul 29, 2026
@demandal25
demandal25 merged commit b9e49fc into amd-integration Jul 29, 2026
1 check passed
@demandal25
demandal25 deleted the worktree-fix-rope-cos-sin-cache branch July 29, 2026 16:38
demandal25 added a commit that referenced this pull request Jul 29, 2026
## Summary

Repo and PR-workflow documentation updates, split out of #270 so that PR
stays focused on the benchmark code change.

### What changed

- **`CLAUDE.md`** — retarget the PR-target safeguard to
`AMD-Ecosystem/flashinfer` (the repo moved from `ROCm/flashinfer`); add
a "PR / issue body formatting" rule (GitHub renders a single newline
inside a paragraph as `<br>`, so rendered bodies must not be
hard-wrapped); add "Branch naming" and "CRITICAL: ask before pushing to
remote" sections ported from the `AMD-Ecosystem/flashinfer-bench`
pr-workflow skill.
- **`.claude/skills/pr-workflow/SKILL.md`** — retarget the repo slug,
`gh repo set-default` check, `gh api` paths, and GraphQL `owner` to
`AMD-Ecosystem`.

## Test plan

- [x] `pre-commit run --files CLAUDE.md
.claude/skills/pr-workflow/SKILL.md` — markdownlint and the other hooks
pass.
- Docs-only change; no code paths touched, so no pytest applies.

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

2 participants