Fix #5749: GINDataset 数据类型错误#7923
Open
Whning0513 wants to merge 1 commit into
Open
Conversation
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.
Fix #5749
问题描述
Issue #5749:
GINDataset在加载图数据时抛出异常:当使用
GINDataset("MUTAG", self_loop=True, degree_as_nlabel=False)时触发。根因分析
问题 1: 条件判断方向错误(主要 bug)
原代码第 224 行:
当节点具有额外属性(attributes)时,实际
len(nrow) > tmp(即tmp < len(nrow)),但原代码使用了
>运算符,导致正确的属性数据不会被解析为 node attributes,而是被当作相邻节点索引的一部分传入
g.add_edges(j, nrow[2:])。这些属性数据是浮点型,传入后 DGL 期望整数类型的节点 ID,从而导致类型断言失败。
问题 2: 节点标签未指定数据类型
原代码第 260 行:
未显式指定
dtype。nlabels是 Python 整数列表,PyTorch 在某些平台(如 FreeBSD)上可能将其推断为
float32而非int64,导致 DGL 内部类型检查失败。问题 3: 图标签未指定数据类型
原代码第 272 行:
同问题 2,未显式指定
dtype,存在跨平台类型推断不确定性。修改内容
elif tmp > len(nrow):elif tmp < len(nrow):# has node attributesF.tensor(nlabels)F.tensor(nlabels, F.int64)F.tensor(self.labels)F.tensor(self.labels, F.int64)文件清单
gindt.py— 修改后的完整源文件patch.diff— 统一格式的补丁文件README.md— 本说明文件参考资料