Skip to content

⚡ Bolt: BLAS 행렬 곱을 통한 alpha 그라디언트 및 EAP 계산 성능 향상 - #198

Closed
seonghobae wants to merge 3 commits into
mainfrom
perf/matmul-optimizations-7118363944566956552
Closed

⚡ Bolt: BLAS 행렬 곱을 통한 alpha 그라디언트 및 EAP 계산 성능 향상#198
seonghobae wants to merge 3 commits into
mainfrom
perf/matmul-optimizations-7118363944566956552

Conversation

@seonghobae

Copy link
Copy Markdown
Contributor

💡 What: python/fast_mlsirm/objective.pyalpha 그라디언트 계산과 python/fast_mlsirm/estimators/mmle.py의 EAP theta 계산에서 요소별 곱셈 후 차원 합(sum(axis=...))을 구하던 방식을 수학적으로 동일한 BLAS 기반 행렬 곱셈(@)으로 변경했습니다.
🎯 Why: 기존 방식은 N x J 또는 N x Q 크기의 거대한 중간 배열을 메모리에 할당하고 순회하는 오버헤드가 발생하여 성능 저하의 주요 원인이 되었습니다.
📊 Impact:

  • objective.pyalpha 그라디언트 계산 속도가 약 20배 향상되었습니다 (테스트 벤치마크 기준 1.00s -> 0.05s).
  • mmle.pytheta 계산 속도가 약 10배 향상되었습니다 (테스트 벤치마크 기준 6.83s -> 0.71s).
  • 전체적으로 메모리 할당 빈도가 크게 감소하여 대규모 배열 연산 시 성능과 메모리 효율성이 대폭 향상되었습니다.
    🔬 Measurement: 수정한 수식이 정확하게 일치하는지 확인하기 위한 테스트 코드를 작성해 최대 오차가 허용 오차 범위 내(~10^-15)에 들어오는 것을 확인하였으며, pytest를 실행하여 기존 테스트 스위트가 모두 통과하는 것을 확인했습니다. 또한 성능 측정 스크립트를 사용하여 최적화 전후의 실행 시간을 비교했습니다.

PR created automatically by Jules for task 7118363944566956552 started by @seonghobae

@google-labs-jules

Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@opencode-agent opencode-agent Bot 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.

Pull request overview

OpenCode cannot approve yet because required coverage evidence did not pass.

Review outcome

1. HIGH .github/workflows/opencode-review.yml:1 - Coverage evidence did not prove required test/docstring evidence

  • Problem: The required coverage-evidence job result was failure, so OpenCode cannot establish approval sufficiency for this head.

  • Root cause: Automated approval is only valid when the same-head coverage-evidence job proves supported repository test suites passed and configured docstring gates passed or were advisory, or reports not applicable because no supported source files or package manifests exist. Missing, failed, skipped, unavailable, or unsupported-tooling test evidence is a blocker.

  • Fix: Install or configure the repository test/docstring evidence tooling when source files or package manifests exist, rerun the current-head coverage-evidence job, and approve only after it reports success with required evidence or explicit no-source not-applicable evidence.

  • Regression test: Keep the approval branch checking needs.coverage-evidence.result == success before posting APPROVE, and publish REQUEST_CHANGES when coverage-evidence blocker states such as cancelled, skipped, failed, unsupported-tooling, or below-100 evidence are present.

  • Result: REQUEST_CHANGES

  • Reason: coverage-evidence result was failure, so required test/docstring evidence was not proven for current head 01da576f5474bd238e20a8dfd6b2392528d2a074.

  • Head SHA: 01da576f5474bd238e20a8dfd6b2392528d2a074

  • Workflow run: 29765308309

  • Workflow attempt: 1

Coverage evidence

Coverage Decision

  • Result: FAIL
  • Test evidence: not proven passing
  • Docstring evidence: not proven passing when configured
  • Failure count: 1

Changed-File Evidence Map

flowchart LR
  PR["PR changed files"] --> Evidence["OpenCode bounded evidence"]
  Evidence --> S1["Changed file (4 files)"]
  S1 --> I1["repository behavior"]
  I1 --> R1["Review risk: Changed file (4 files)"]
  R1 --> V1["required checks"]
Loading

@opencode-agent

Copy link
Copy Markdown
Contributor

OpenCode Review Overview

  • Head SHA: 01da576f5474bd238e20a8dfd6b2392528d2a074
  • Workflow run: 29765308309
  • Workflow attempt: 1
  • Gate result: REQUEST_CHANGES (approval step)

Pull request overview

OpenCode cannot approve yet because required coverage evidence did not pass.

Review outcome

1. HIGH .github/workflows/opencode-review.yml:1 - Coverage evidence did not prove required test/docstring evidence

  • Problem: The required coverage-evidence job result was failure, so OpenCode cannot establish approval sufficiency for this head.

  • Root cause: Automated approval is only valid when the same-head coverage-evidence job proves supported repository test suites passed and configured docstring gates passed or were advisory, or reports not applicable because no supported source files or package manifests exist. Missing, failed, skipped, unavailable, or unsupported-tooling test evidence is a blocker.

  • Fix: Install or configure the repository test/docstring evidence tooling when source files or package manifests exist, rerun the current-head coverage-evidence job, and approve only after it reports success with required evidence or explicit no-source not-applicable evidence.

  • Regression test: Keep the approval branch checking needs.coverage-evidence.result == success before posting APPROVE, and publish REQUEST_CHANGES when coverage-evidence blocker states such as cancelled, skipped, failed, unsupported-tooling, or below-100 evidence are present.

  • Result: REQUEST_CHANGES

  • Reason: coverage-evidence result was failure, so required test/docstring evidence was not proven for current head 01da576f5474bd238e20a8dfd6b2392528d2a074.

  • Head SHA: 01da576f5474bd238e20a8dfd6b2392528d2a074

  • Workflow run: 29765308309

  • Workflow attempt: 1

Coverage evidence

Coverage Decision

  • Result: FAIL
  • Test evidence: not proven passing
  • Docstring evidence: not proven passing when configured
  • Failure count: 1

Changed-File Evidence Map

flowchart LR
  PR["PR changed files"] --> Evidence["OpenCode bounded evidence"]
  Evidence --> S1["Changed file (4 files)"]
  S1 --> I1["repository behavior"]
  I1 --> R1["Review risk: Changed file (4 files)"]
  R1 --> V1["required checks"]
Loading

Copilot AI review requested due to automatic review settings July 22, 2026 05:24

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

Note

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Optimizes two hot-path Python computations by replacing multiply-and-reduce patterns with BLAS-backed matrix products to reduce large intermediate allocations and improve runtime.

Changes:

  • Reworked grad_alpha computation in neg_loglik_and_grad to use matrix multiplication instead of element-wise multiply + sum.
  • Reworked MMLE EAP theta calculation to use posterior @ nodes instead of multiply + sum.
  • Updated changelog and internal optimization notes (.jules/bolt.md) documenting the optimization approach.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.

File Description
python/fast_mlsirm/objective.py Replaces grad_alpha elementwise reduction with a BLAS matmul-based formulation.
python/fast_mlsirm/estimators/mmle.py Replaces EAP theta elementwise reduction with a matmul (GEMV) formulation.
CHANGELOG.md Documents the optimization (and mentions an additional lockfile sync).
.jules/bolt.md Adds an internal note describing the matmul optimization pattern and rationale.

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

Comment thread python/fast_mlsirm/objective.py
Comment thread CHANGELOG.md Outdated
@seonghobae
seonghobae enabled auto-merge (squash) July 26, 2026 08:53
Copilot AI review requested due to automatic review settings July 26, 2026 09:08
`python/fast_mlsirm/objective.py` 및 `python/fast_mlsirm/estimators/mmle.py`에서 요소별 연산 후 차원 합을 구하는 과정을 수학적으로 동일한 행렬 곱셈(`@`)으로 대체하여 불필요한 중간 배열 할당을 피하고 캐시 지역성을 향상시켰습니다.
@seonghobae
seonghobae force-pushed the perf/matmul-optimizations-7118363944566956552 branch from 3df8249 to 1f107cd Compare July 26, 2026 09:08
…s; refresh head for re-review

The previous CHANGES_REQUESTED verdict on this head was an infrastructure
failure (the central coverage-evidence sandbox could not install numpy —
fixed by ContextualWisdomLab/.github#611), not a code judgment. This commit
documents the change and produces a fresh head so the scheduler dispatches
a new review under the repaired pipeline.
@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@seonghobae, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 36 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b5f6ca98-cf7c-447e-a6d4-3c99a74813c8

📥 Commits

Reviewing files that changed from the base of the PR and between a3123a2 and ff12b5a.

📒 Files selected for processing (4)
  • .jules/bolt.md
  • CHANGELOG.md
  • python/fast_mlsirm/estimators/mmle.py
  • python/fast_mlsirm/objective.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/matmul-optimizations-7118363944566956552

Comment @coderabbitai help to get the list of available commands.

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 4 out of 4 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

python/fast_mlsirm/objective.py:142

  • np.arange(e.shape[1]) is allocated twice in this hot path (once for grad_alpha and again for idx[...] = a). Since this function is performance-critical, reuse a single item_idx array to avoid repeated allocation and keep the optimized path allocation-free aside from the needed outputs.
        grad_alpha = (e.T @ params.theta)[np.arange(e.shape[1]), factors] * a

    # Optimized gradient computation: replace loop over dimensions with matrix multiplication
    # We embed 'a' directly into the projection matrix to avoid a JxD intermediate array allocation during multiplication
    idx = np.zeros((e.shape[1], params.theta.shape[1]), dtype=e.dtype)

Comment thread CHANGELOG.md
@seonghobae

Copy link
Copy Markdown
Contributor Author

Superseded: Bolt performance theme conflicts with current main (related landings e.g. #345 linear_predictor in-place ops). Closing as superseded; reopen from clean base if still valuable.

@seonghobae

Copy link
Copy Markdown
Contributor Author

Closing as superseded: Bolt theme already on main or blocked by unresolvable conflicts with current main. Prefer re-open from a fresh branch if still needed.

@seonghobae seonghobae closed this Jul 31, 2026
@google-labs-jules

Copy link
Copy Markdown

Closing as superseded: Bolt theme already on main or blocked by unresolvable conflicts with current main. Prefer re-open from a fresh branch if still needed.

Understood. Acknowledging that this work is now obsolete and stopping work on this task.

@google-labs-jules

Copy link
Copy Markdown

Superseded: Bolt performance theme conflicts with current main (related landings e.g. #345 linear_predictor in-place ops). Closing as superseded; reopen from clean base if still valuable.

Understood. Acknowledging that this work is now obsolete and stopping work on this task.

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