Skip to content

Comments

Handle None values in _inner_loop tensor conversion#689

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-prepare-data-none-error
Draft

Handle None values in _inner_loop tensor conversion#689
Copilot wants to merge 2 commits intomainfrom
copilot/fix-prepare-data-none-error

Conversation

Copy link
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
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

2 participants