Skip to content

Encapsulate logic to detach inference results - #1076

Merged
drewoldag merged 5 commits into
mainfrom
claude/amazing-mccarthy-783971
Oct 14, 2026
Merged

drewoldag merged 5 commits into
mainfrom
claude/amazing-mccarthy-783971

Conversation

@drewoldag

Copy link
Copy Markdown
Collaborator

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.

drewoldag and others added 3 commits October 7, 2026 22:58
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>
@drewoldag drewoldag self-assigned this Oct 14, 2026
@codecov

codecov Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.04%. Comparing base (dd5caeb) to head (044daec).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI 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.

🟢 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
drewoldag marked this pull request as ready for review October 14, 2026 13:16

@mtauraso mtauraso left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks great

@drewoldag
drewoldag merged commit 240763c into main Oct 14, 2026
8 checks passed
@drewoldag
drewoldag deleted the claude/amazing-mccarthy-783971 branch October 14, 2026 21:28
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.

4 participants