Skip to content

Conversation

@drivanov
Copy link
Contributor

@drivanov drivanov commented Nov 15, 2025

The test_to_hetero_lazy_cuda occasionally triggers the following warning:

  /usr/local/lib/python3.12/dist-packages/torch_geometric/nn/to_hetero_transformer.py:151: UserWarning: There exist 
node types ({'v0'}) whose representations do not get updated during message passing as they do not occur as destination 
type in any edge type. This may lead to unexpected behavior.

This warning can nondeterministically escalate into an AttributeError, causing the test to fail:

====================== FAILURES ======================
________________ test_to_hetero_lazy_cuda _________________

    @onlyCUDA
    def test_to_hetero_lazy_cuda():
        class Model(torch.nn.Module):
            def __init__(self):
                super().__init__()
                self.conv = GATv2Conv(
                    (-1, -1),
                    out_channels=2,
                    add_self_loops=False,
                    edge_dim=-1,
                    heads=1,
                ).to('cuda')
    
            def forward(self, x, edge_index, edge_attr):
                return self.conv(x, edge_index, edge_attr)
    
        data = FakeHeteroDataset(edge_dim=10)[0].to('cuda')
        model = to_hetero(Model(), data.metadata())
        out_dict = model(data.x_dict, data.edge_index_dict, data.edge_attr_dict)
        assert len(out_dict) == len(data.node_types)
        for out in out_dict.values():
>           assert out.is_cuda
E           AttributeError: 'NoneType' object has no attribute 'is_cuda'

test/nn/test_to_hetero_transformer.py:564: AttributeError

The root cause is that the synthetic FakeHeteroDataset includes a node type (v0) that never appears as a destination in any edge type, so its representation is never updated. This fix ensures that all node types participate as destinations (via self-loop edges), preventing the warning and stabilizing the test.

Solution originated from ChatGPT guidance.

@codecov
Copy link

codecov bot commented Nov 15, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.09%. Comparing base (c211214) to head (2cecdfd).
⚠️ Report is 145 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #10531      +/-   ##
==========================================
- Coverage   86.11%   85.09%   -1.02%     
==========================================
  Files         496      510      +14     
  Lines       33655    35962    +2307     
==========================================
+ Hits        28981    30602    +1621     
- Misses       4674     5360     +686     

☔ 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.

Copy link
Member

@akihironitta akihironitta left a comment

Choose a reason for hiding this comment

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

Hi @drivanov, thank you for sending a fix here. How can I reproduce the issue this PR is trying to fix? I ran the test case quite tens of times in master, but I cannot reproduce it.

@drivanov
Copy link
Contributor Author

drivanov commented Dec 28, 2025

Hi @akihironitta:
As I explained, this failure is nondeterministic. Therefore, try to use --count option for pytest. To do that, you will need to install pytest-repeat:

pip install pytest-repeat

Run this test with

pytest --count=100 /opt/pyg/pytorch_geometric/test/nn/test_to_hetero_transformer.py::test_to_hetero_lazy_cuda

On systems with A100 or H200 GPU cards, the observed failure rate varies between 2% and 10%.

For instance, it's what I see:

FAILED ../opt/pyg/pytorch_geometric/test/nn/test_to_hetero_transformer.py::test_to_hetero_lazy_cuda[10-100] - AttributeError: 'NoneType' object has no attribute 'is_cuda'
FAILED ../opt/pyg/pytorch_geometric/test/nn/test_to_hetero_transformer.py::test_to_hetero_lazy_cuda[35-100] - AttributeError: 'NoneType' object has no attribute 'is_cuda'
FAILED ../opt/pyg/pytorch_geometric/test/nn/test_to_hetero_transformer.py::test_to_hetero_lazy_cuda[47-100] - AttributeError: 'NoneType' object has no attribute 'is_cuda'
FAILED ../opt/pyg/pytorch_geometric/test/nn/test_to_hetero_transformer.py::test_to_hetero_lazy_cuda[61-100] - AttributeError: 'NoneType' object has no attribute 'is_cuda'
FAILED ../opt/pyg/pytorch_geometric/test/nn/test_to_hetero_transformer.py::test_to_hetero_lazy_cuda[71-100] - AttributeError: 'NoneType' object has no attribute 'is_cuda'
FAILED ../opt/pyg/pytorch_geometric/test/nn/test_to_hetero_transformer.py::test_to_hetero_lazy_cuda[73-100] - AttributeError: 'NoneType' object has no attribute 'is_cuda'
FAILED ../opt/pyg/pytorch_geometric/test/nn/test_to_hetero_transformer.py::test_to_hetero_lazy_cuda[90-100] - AttributeError: 'NoneType' object has no attribute 'is_cuda'
FAILED ../opt/pyg/pytorch_geometric/test/nn/test_to_hetero_transformer.py::test_to_hetero_lazy_cuda[95-100] - AttributeError: 'NoneType' object has no attribute 'is_cuda'
FAILED ../opt/pyg/pytorch_geometric/test/nn/test_to_hetero_transformer.py::test_to_hetero_lazy_cuda[97-100] - AttributeError: 'NoneType' object has no attribute 'is_cuda'
====================================================================== 9 failed, 91 passed, 9 warnings in 3.12s =======================================================================

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants