Repository navigation
Encapsulate logic to detach inference results - #1076
Merged
Merged
Conversation
InferStreamSession.process() saved dict results correctly through the batch-saving callback but then called .detach() on the result, which raised AttributeError for models whose infer_batch returns a dict of tensors (allowed since #940). process() now returns a dict of numpy arrays in that case, mirroring _save_batch's conversion; single-tensor results still come back as one numpy array. Iterating the session yields the same value. Adds manual-mode tests for both return shapes and a data-source-mode test, checking that the saved results load back with one column per key. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The tracer shims model methods found through dir() but restores them from the class's own __dict__, so after a trace run an inherited method is left set to None on a registered subclass. DictReturnLoopback inherited forward from HyraxLoopback, which made its tests fail whenever xdist scheduled them in the same worker as a trace test. Declaring forward on the class sidesteps that. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The save-batch callback and InferStreamSession.process() each had their own copy of the logic that detaches a model's tensor (or dict of tensors) and converts it to numpy on the CPU. Move it into pytorch_ignite.results_to_numpy and call it from both. process() now raises the helper's RuntimeError instead of an AttributeError when a model returns something other than a tensor or dict of tensors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1076 +/- ##
==========================================
+ Coverage 70.85% 71.04% +0.19%
==========================================
Files 92 92
Lines 9346 9349 +3
==========================================
+ Hits 6622 6642 +20
+ Misses 2724 2707 -17 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The refactoring preserves existing behavior while adequately testing the new dictionary-output support.
0 open findings
What changed in this PR
Centralizes tensor-to-NumPy conversion and extends streaming inference to support dictionary outputs.
Changes:
- Adds and tests
results_to_numpy. - Reuses it for saved and streamed inference results.
- Adds tensor and dictionary streaming tests.
| File | Description |
|---|---|
src/hyrax/pytorch_ignite.py |
Adds shared conversion helper. |
src/hyrax/verbs/infer_stream.py |
Supports NumPy dictionary results. |
tests/hyrax/test_pytorch_ignite.py |
Tests conversion behavior. |
tests/hyrax/test_infer_stream.py |
Tests streamed tensor and dictionary outputs. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
drewoldag
marked this pull request as ready for review
October 14, 2026 13:16
maxwest-uw
approved these changes
Oct 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There is a growning number of places where we
.detach().to('cpu').numpy()a vector or dictionary of vectors.When this was in one location, it was fine, then we duplicated logic in infer_stream, and now it's likely needed in the lsdb-ml package as well. So instead of copying it all over the place, this PR puts the logic in a single function.