Fix #10632: RandomNodeSplit fails on HeteroData#10654
Open
JiwaniZakir wants to merge 2 commits intopyg-team:masterfrom
Open
Fix #10632: RandomNodeSplit fails on HeteroData#10654JiwaniZakir wants to merge 2 commits intopyg-team:masterfrom
JiwaniZakir wants to merge 2 commits intopyg-team:masterfrom
Conversation
`split='train_rest'` does not use the `key` attribute at all, so the guard that skips node stores lacking `key` (e.g. `y`) was overly restrictive. Node types without a label tensor were silently skipped, leaving HeteroData graphs (such as MovieLens1M) with no masks set. Scope the guard to only `test_rest` and `random` splits, which actually require class labels, and update the HeteroData test accordingly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
for more information, see https://pre-commit.ci
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #10654 +/- ##
==========================================
- Coverage 86.11% 84.18% -1.93%
==========================================
Files 496 510 +14
Lines 33655 36019 +2364
==========================================
+ Hits 28981 30323 +1342
- Misses 4674 5696 +1022 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Closes #10632
Before
RandomNodeSplit.__call__intorch_geometric/transforms/random_node_split.pyskipped any node store that lackedself.key(default:'y'), regardless of thesplitmode. OnHeteroData, this causedsplit='train_rest'to silently skip every node type that had noyattribute, producing a transformed object with no masks at all. Accessing.train_maskon the result then raisedAttributeError: 'HeteroData' has no attribute 'train_mask'.After
The skip condition in
random_node_split.py(line 77) now gates onself.split != 'train_rest'in addition to the key check:train_restdistributes all remaining nodes to the training set without needing class labels, so it correctly processes every node store in aHeteroDataobject — including those without ayattribute (e.g.,authornodes in MovieLens1M or OGB_MAG).test_restandrandomstill require the key to be present because they rely on per-class counts.Changes
torch_geometric/transforms/random_node_split.py: Addedself.split != 'train_rest'guard to the early-continue condition so unlabeled node stores are not skipped when the split mode doesn't requirey.test/transforms/test_random_node_split.py: Rewrotetest_random_node_split_on_hetero_datato:authornodes from 300 → 1000 sonum_val=100, num_test=200fits within the store.train_restonHeteroDatawith both a labeled (paper) and unlabeled (author) node type, asserting exact mask cardinalities.test_restconfirming thatauthor(noy) is still skipped whilepaper(hasy) receives masks.Testing
The updated
test_random_node_split_on_hetero_dataasserts:For
test_restwithnum_train_per_class=10, num_val=100,author(noy) is skipped (len == 1) andpaperreceives all three masks (len == 5).This PR was created with AI assistance (Claude). The changes were reviewed by quality gates and a critic model before submission.