perf(rf3): reuse initialized model runtime#317
Conversation
|
Warning Review limit reached
Next review available in: 43 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughRF3Wrapper now accepts and validates preinitialized models with their inference-engine runtime. Freshly initialized models retain the attached engine context, and ChangesRF3 model reuse
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant GuidanceScript
participant RF3Wrapper
participant RF3Model
participant RF3InferenceEngine
GuidanceScript->>RF3Wrapper: pass preloaded model
RF3Wrapper->>RF3Model: retrieve attached engine
RF3Wrapper->>RF3InferenceEngine: validate checkpoint and device
RF3Wrapper->>RF3Model: validate trainer binding
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR adds support for reusing an already-initialized RosettaFold3 (RF3) runtime context when constructing RF3Wrapper, and wires that through get_model_and_device so callers can pass pre-loaded RF3 models without re-loading checkpoints. This aligns RF3 with existing model-wrapper reuse patterns (Boltz/Protenix) while preserving RF3’s coupled preprocessing + inference engine initialization.
Changes:
- Extend
RF3Wrapperto accept a pre-loadedmodeland reuse its originatingRF3InferenceEngine/trainer/Fabric context instead of creating a new engine. - Forward the optional
modelargument throughget_model_and_device()for RF3 construction. - Add tests covering RF3 model reuse behavior and validation (checkpoint/device mismatch, unsafe reuse).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/sampleworks/models/rf3/wrapper.py |
Accepts pre-loaded RF3 models and reuses the originating inference engine/runtime context with validation. |
src/sampleworks/utils/guidance_script_utils.py |
Forwards model= into the RF3 wrapper path in get_model_and_device(). |
tests/models/test_rf3_device_selection.py |
Adds unit tests verifying RF3 engine/model reuse and rejection of unsafe/mismatched reuse. |
tests/utils/test_guidance_script_utils.py |
Adds a test ensuring get_model_and_device() forwards a pre-loaded model into RF3 wrapper construction. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
marcuscollins
left a comment
There was a problem hiding this comment.
One small nit, just to add a comment on where to find how a particular attribute is set. If you can add that, go ahead and merge. Thanks.
There was a problem hiding this comment.
🧹 Nitpick comments (2)
tests/models/test_rf3_device_selection.py (1)
59-71: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd NumPy-style docstrings to the new stub constructors.
tests/models/test_rf3_device_selection.py#L59-L71: documentStubTrainer.__init__andStubInferenceEngine.__init__.tests/utils/test_guidance_script_utils.py#L45-L46: documentStubRF3Wrapper.__init__.As per coding guidelines, every function and class must include a NumPy-style docstring.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/models/test_rf3_device_selection.py` around lines 59 - 71, Add NumPy-style docstrings to the constructors StubTrainer.__init__ and StubInferenceEngine.__init__ in tests/models/test_rf3_device_selection.py (lines 59-71), documenting their initialization behavior and parameters; also document StubRF3Wrapper.__init__ in tests/utils/test_guidance_script_utils.py (lines 45-46).Source: Coding guidelines
src/sampleworks/models/rf3/wrapper.py (1)
274-279: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd regression coverage for checkpoint mismatches.
This required rejection branch is not exercised by the supplied reuse tests, leaving path normalization or validation regressions undetected. Add a test that reuses
original.modelwith a different checkpoint and expects thisValueError.The PR objectives explicitly require checkpoint mismatches to be rejected.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/sampleworks/models/rf3/wrapper.py` around lines 274 - 279, Add regression coverage in the reuse tests for the checkpoint validation branch in the RF3 wrapper: reuse an instance loaded from original.model while requesting a different checkpoint, and assert that initialization raises ValueError. Ensure the test exercises the normalized engine_checkpoint versus checkpoint_path comparison and verifies mismatched checkpoints are rejected.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/sampleworks/models/rf3/wrapper.py`:
- Around line 274-279: Add regression coverage in the reuse tests for the
checkpoint validation branch in the RF3 wrapper: reuse an instance loaded from
original.model while requesting a different checkpoint, and assert that
initialization raises ValueError. Ensure the test exercises the normalized
engine_checkpoint versus checkpoint_path comparison and verifies mismatched
checkpoints are rejected.
In `@tests/models/test_rf3_device_selection.py`:
- Around line 59-71: Add NumPy-style docstrings to the constructors
StubTrainer.__init__ and StubInferenceEngine.__init__ in
tests/models/test_rf3_device_selection.py (lines 59-71), documenting their
initialization behavior and parameters; also document StubRF3Wrapper.__init__ in
tests/utils/test_guidance_script_utils.py (lines 45-46).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: f9e5e410-0172-49a7-a391-9d6c37ab0f38
📒 Files selected for processing (4)
src/sampleworks/models/rf3/wrapper.pysrc/sampleworks/utils/guidance_script_utils.pytests/models/test_rf3_device_selection.pytests/utils/test_guidance_script_utils.py
|
Addressed the remaining nit in |
Summary
RF3Wrapperto reuse a model from an existing wrapperget_model_and_deviceCloses #291
Why the engine is reused
RF3 preprocessing and model execution are coupled through Foundry's initialized
RF3InferenceEngine. Replacing onlytrainer.state["model"]after initialization would still load the checkpoint and could attach the model to the wrong Fabric runtime. The originating engine is therefore retained with the model and reused as one runtime context.Validation
pytest tests/models/test_rf3_device_selection.py tests/utils/test_guidance_script_utils.py -q(21 passed, 1 skipped)ty checkon touched files inrf3-devruff checkandruff format --checkon touched filesgit diff --checkSummary by CodeRabbit
New Features
Bug Fixes