Skip to content

⚡ Bolt: 파이썬 루프 오버헤드 최소화를 위한 MMLE EM Newton-Raphson 업데이트 벡터화 - #231

Closed
seonghobae wants to merge 1 commit into
mainfrom
bolt/vectorize-mmle-10366567336462927092
Closed

⚡ Bolt: 파이썬 루프 오버헤드 최소화를 위한 MMLE EM Newton-Raphson 업데이트 벡터화#231
seonghobae wants to merge 1 commit into
mainfrom
bolt/vectorize-mmle-10366567336462927092

Conversation

@seonghobae

Copy link
Copy Markdown
Contributor

💡 What:
python/fast_mlsirm/estimators/mmle.pyfit_mmle_2pl 함수에서 M-step 내 아이템 최적화 로직의 순차적인 for 루프를 제거하고, 스칼라 연산을 2D 행렬 곱셈(@) 기반의 벡터화 연산으로 대체했습니다. 또한 active_mask를 도입하여 아직 수렴하지 않았거나 singular 상태에 빠지지 않은 아이템만 효율적으로 업데이트하도록 구현했습니다.

🎯 Why:
수백에서 수천 개의 문항(Item)에 대해 MMLE를 적합할 때, 아이템 수만큼 반복되는 파이썬 내 스칼라 Newton-Raphson 루프는 심각한 병목(bottleneck)을 유발합니다. 이를 C 기반의 NumPy 계층으로 내려보냄으로써 전체적인 메모리 복사를 줄이고 연산 속도를 대폭 높일 수 있습니다.

📊 Impact:
이 벡터화 최적화로 인해 문항 수가 많은 데이터에 대해 추정 시간이 극적으로 단축됩니다 (예: 스크립트 기반 벤치마크 테스트에서 약 15배 속도 향상, 8.15초 -> 0.48초). 이 과정에서 원본 로직의 Edge Case (수렴 처리, 특이값 처리 등)를 안전하게 유지하여 정확도 손실 없이 성능을 극대화했습니다.

🔬 Measurement:

  • 변경된 파일에 대해 uv run ruff formatuv run ruff check 통과를 확인했습니다.
  • 파이썬 전체 테스트 스위트 (uv run pytest tests)를 통과했습니다.
  • Rust Core 연산 부하에 영향을 미치지 않는지 파악하기 위해 전체 Rust 작업 공간 테스트 (cargo test --workspace)가 성공적으로 종료됨을 확인했습니다.

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

Copilot AI review requested due to automatic review settings July 23, 2026 19:18
@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.

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 optimizes the MMLE 2PL estimator’s M-step in fit_mmle_2pl by removing the per-item Python Newton–Raphson loop and replacing it with a vectorized update over all active items, reducing Python overhead for large item counts while preserving the existing convergence/singularity handling semantics.

Changes:

  • Vectorized the Newton–Raphson item-parameter updates using an active_mask to update only unconverged/non-singular items each step.
  • Kept the E-step and overall EM convergence logic intact, with only a minor formatting-only adjustment to person_loglik.
  • Added a performance note to .jules/bolt.md documenting the MMLE item-loop vectorization learning/action.

Reviewed changes

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

File Description
python/fast_mlsirm/estimators/mmle.py Replaces per-item Newton updates with a masked vectorized Newton loop using matrix multiplications for node aggregation.
.jules/bolt.md Documents the performance rationale/pattern for removing the per-item Newton loop in MMLE via vectorization.

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

Copilot AI review requested due to automatic review settings July 25, 2026 20:50

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

Comment on lines +125 to +127
# Optimized item parameter calibration: replace the outer loop over items
# with a fully vectorized approach using a boolean active_mask and 2D matrix multiplications.
# This reduces Newton-Raphson Python looping overhead significantly (e.g., ~15x faster for 100 items).
@seonghobae
seonghobae enabled auto-merge (squash) July 26, 2026 08:56
python/fast_mlsirm/estimators/mmle.py의 fit_mmle_2pl 함수 내부 M-step에서 아이템별로 반복되던 `for i in range(n_items):` 루프를 `active_mask`와 2D 행렬 곱셈(`@`)을 사용하는 전체 벡터화 방식으로 리팩토링했습니다. 이를 통해 파이썬 스칼라 루프 오버헤드를 대폭 줄여 눈에 띄는 성능 개선을 이루었습니다.
Copilot AI review requested due to automatic review settings July 26, 2026 09:13
@seonghobae
seonghobae force-pushed the bolt/vectorize-mmle-10366567336462927092 branch from 789f0b2 to ad658d3 Compare July 26, 2026 09:13
@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: 24 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: 35c10c87-2a2d-4859-9e0b-1f595f103213

📥 Commits

Reviewing files that changed from the base of the PR and between 44a3ecf and ad658d3.

📒 Files selected for processing (2)
  • .jules/bolt.md
  • python/fast_mlsirm/estimators/mmle.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bolt/vectorize-mmle-10366567336462927092

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 2 out of 2 changed files in this pull request and generated no new comments.

Copy link
Copy Markdown
Contributor Author

중복 정리: mmle.py M-step Newton-Raphson 벡터화로, 리뷰 대기 중인 #162 와 동일 대상·동일 취지입니다. 그룹당 대표 1건만 남기는 백로그 정리 방침에 따라 닫습니다. 필요 시 재오픈 가능합니다.


Generated by Claude Code

@google-labs-jules

Copy link
Copy Markdown

중복 정리: mmle.py M-step Newton-Raphson 벡터화로, 리뷰 대기 중인 #162 와 동일 대상·동일 취지입니다. 그룹당 대표 1건만 남기는 백로그 정리 방침에 따라 닫습니다. 필요 시 재오픈 가능합니다.


Generated by Claude Code

알겠습니다. 이 작업은 다른 PR(#162)과 중복되므로 닫는다는 방침을 확인했습니다. 현재 작업을 중단하겠습니다.

@seonghobae seonghobae closed this Jul 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.

2 participants