Skip to content

[AUTO-MERGE] Handle None values in _inner_loop tensor conversion#689

Merged
drewoldag merged 5 commits intomainfrom
copilot/fix-prepare-data-none-error
Mar 3, 2026
Merged

[AUTO-MERGE] Handle None values in _inner_loop tensor conversion#689
drewoldag merged 5 commits intomainfrom
copilot/fix-prepare-data-none-error

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 10, 2026

Change Description

_inner_loop crashes when prepare_inputs returns None values, which occurs in supervised models with missing labels. The function unconditionally calls torch.from_numpy() on all values, including None.

Solution Description

Added None checks before tensor conversion in _inner_loop:

# Before
if isinstance(batch, tuple):
    batch = tuple(torch.from_numpy(i).to(device) for i in batch)
else:
    batch = torch.from_numpy(batch).to(device)

# After  
if isinstance(batch, tuple):
    batch = tuple(torch.from_numpy(i).to(device) if i is not None else None for i in batch)
elif batch is not None:
    batch = torch.from_numpy(batch).to(device)

Added test coverage for tuple with None element, None batch, and regression cases.

Code Quality

  • I have read the Contribution Guide and agree to the Code of Conduct
  • My code follows the code style of this project
  • My code builds (or compiles) cleanly without any errors or warnings
  • My code contains relevant comments and necessary documentation

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • www.cs.toronto.edu
    • Triggering command: /usr/bin/python /usr/bin/python -m ipykernel_launcher -f /tmp/tmpu0iebvur.json --HistoryManager.hist_file=:memory: --from without_precedin--columns=500 --to rst --columns=500 pandoc --eo�� lf --from ve_divs+raw_html--columns=500 --to rst --columns=500 pandoc (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>If prepare_data returns a None, pytorch_ignite will error</issue_title>
<issue_description>Bug report
In _inner_loop, when we try to convert numpy to Tensors, if there is a None that is returned from prepare_data, the conversion will fail.

Max ran into this with a supervised model that used a prepare_data function that returns None when there are no labels. Changing this to return an empty array instead of None fixed the problem, but we should be more accommodating.
</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

- Modified _inner_loop to check for None before converting to tensors
- Added comprehensive tests for None handling in tuples, single values, and edge cases
- All existing tests pass
Copilot AI changed the title [WIP] Fix bug where prepare_data returns None in training loop Handle None values in _inner_loop tensor conversion Feb 10, 2026
Copilot AI requested a review from mtauraso February 10, 2026 21:36
@mtauraso mtauraso marked this pull request as ready for review March 3, 2026 20:21
Copilot AI review requested due to automatic review settings March 3, 2026 20:21
Copy link
Copy Markdown
Collaborator

@mtauraso mtauraso left a comment

Choose a reason for hiding this comment

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

This seems good to merge.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 fixes a crash in Hyrax’s PyTorch Ignite integration when prepare_inputs returns None values (e.g., missing labels in supervised workflows) by skipping tensor conversion for None and adds regression tests to cover the new behavior.

Changes:

  • Update _inner_loop to avoid calling torch.from_numpy() on None values (both for tuple batches and single batches).
  • Add unit tests covering tuple-with-None, None batch, and standard conversion behavior.

Reviewed changes

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

File Description
src/hyrax/pytorch_ignite.py Adds None-aware tensor conversion logic in _inner_loop to prevent torch.from_numpy(None) crashes.
tests/hyrax/test_pytorch_ignite.py Adds targeted tests validating _inner_loop behavior with None inputs and ensuring existing conversion paths still work.

Copy link
Copy Markdown
Collaborator

@drewoldag drewoldag left a comment

Choose a reason for hiding this comment

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

This appears correct to me. It adheres to assumption that what is returned from prepare_inputs is a tuple or a bare array, and seems to handle those cases just fine.

The tests seem to cover the various permutations.

@drewoldag drewoldag enabled auto-merge (squash) March 3, 2026 20:41
@drewoldag drewoldag changed the title Handle None values in _inner_loop tensor conversion [AUTO-MERGE] Handle None values in _inner_loop tensor conversion Mar 3, 2026
@drewoldag drewoldag merged commit 0096924 into main Mar 3, 2026
6 of 7 checks passed
@drewoldag drewoldag deleted the copilot/fix-prepare-data-none-error branch March 3, 2026 20:45
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 64.17%. Comparing base (84fe8b0) to head (0a8251d).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #689      +/-   ##
==========================================
+ Coverage   64.15%   64.17%   +0.02%     
==========================================
  Files          61       61              
  Lines        5989     5990       +1     
==========================================
+ Hits         3842     3844       +2     
+ Misses       2147     2146       -1     

☔ View full report in Codecov by Sentry.
📢 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.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 3, 2026

Before [84fe8b0] After [7e64b43] Ratio Benchmark (Parameter)
failed failed n/a data_cache_benchmarks.DataCacheBenchmarks.time_preload_cache_hsc1k
failed failed n/a data_cache_benchmarks.DataCacheBenchmarks.track_cache_hsc1k_hyrax_size_undercount
failed failed n/a data_request_benchmarks.DatasetRequestBenchmarks.time_request_all_data
1.98±0.02s 2.06±0.03s 1.04 benchmarks.time_infer_help
1.98±0.02s 2.06±0.05s 1.04 benchmarks.time_lookup_help
1.96±0.02s 2.03±0.01s 1.03 benchmarks.time_help
1.97±0.02s 2.02±0.03s 1.03 benchmarks.time_prepare_help
282±3ms 289±3ms 1.02 benchmarks.time_import
38.9±0.4ms 39.6±0.7ms 1.02 benchmarks.time_nb_obj_dir
9.62±0.1ms 9.83±0.05ms 1.02 vector_db_benchmarks.VectorDBSearchBenchmarks.time_search_by_vector_many_shards(128, 'chromadb')

Click here to view all benchmarks.

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.

If prepare_data returns a None, pytorch_ignite will error

4 participants