[Bug] Default value of `num_bases` can crash RelGraphConv module
See original GitHub issue🐛 Bug
As stated in the Doc, the optional input argument num_bases
of RelGraphConv
is None
by default. However, if we actually set num_bases=None
or simply not specify it, the code will crash…
It crashed because when num_bases=None
, it will raise the value error at here:
https://github.com/dmlc/dgl/blob/2cf05c53420546443a267d91ec624887d0078278/python/dgl/nn/pytorch/linear.py#L93-L94
We may need to fix the doc and RelGraphConv
interface, to make it clear that num_bases
is not optional (definitely not None
) and has to be specified as a positive integer<=num. relations .
To Reproduce
Step(s) to reproduce the behavior:
- whenever construct
RelGraphConv
as:conv = RelGraphConv(in_feat, out_feat, num_rels, num_bases=None)
orconv = RelGraphConv(in_feat, out_feat, num_rels)
Output stack:
Traceback (most recent call last):
File "entity.py", line 93, in <module>
model = RGCN(in_size, 16, out_size, num_rels).to(device)
File "entity.py", line 15, in __init__
self.conv1 = RelGraphConv(h_dim, h_dim, num_rels, regularizer='basis',
File "/opt/conda/lib/python3.8/site-packages/dgl/nn/pytorch/conv/relgraphconv.py", line 105, in __init__
self.linear_r = TypedLinear(in_feat, out_feat, num_rels, regularizer, num_bases)
File "/opt/conda/lib/python3.8/site-packages/dgl/nn/pytorch/linear.py", line 94, in __init__
raise ValueError('Missing "num_bases" for basis regularization.')
ValueError: Missing "num_bases" for basis regularization.
Expected behavior
It should not crash with a default value.
Environment
- DGL Version (e.g., 1.0): 0.9
- Backend Library & Version (e.g., PyTorch 0.4.1, MXNet/Gluon 1.3): Pytorch 1.13
- OS (e.g., Linux): Linux
- How you installed DGL (
conda
,pip
, source): source
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
RelGraphConv — DGL 0.8.2post1 documentation - DGL Docs
Default applies no regularization. num_bases (int, optional) – Number of bases. Needed when regularizer is specified. Default: None ...
Read more >dgl/relgraphconv.py at master · dmlc/dgl - GitHub
Python package built to ease deep learning on graph, on top of existing DL frameworks. - dgl/relgraphconv.py at master · dmlc/dgl.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Right, this is what I understood. I will resolve this with a bugfix PR.
As @jermainewang said,
num_bases
should also be optional. If it is not provided, it should be set tonum_rels
.