GATConv layer slows down code due to following warning

I tried DGL 0.5.2, but still failed to reproduce the error. Can you try reinstalling DGL? Which OS do you use? How did you install DGL?

Yes, I have tried uninstalling and reinstalling. I just did again, and still get the error. I work on Mac OS but also have a virtual machine workstation that runs on linux where the error also occurs. I install using pip install dgl from the command line in the Conda environment I use. It is also DGL 0.5.2 that is/was installed as when I pip uninstall dgl I get asked to confirm whether I want to uninstall DGL 0.5.2.

I’m still unable to reproduce the warning. What’s your PyTorch version?

the PyTorch version I am using is 1.7.0

I have the same warning displayed for any DGL command and any python command. Don’t know what is wrong. I had uninstalled my previous version as well.

/home/user/.local/lib/python3.6/site-packages/dgl/base.py:45: DGLWarning: DGLGraph.len is deprecated.Please directly call DGLGraph.number_of_nodes.
return warnings.warn(message, category=category, stacklevel=1)

I have to use the warnings library to supress it as
import warnings
warnings.filterwarnings("ignore")

How I installed DGL - pip install dgl-cu101
Ubuntu 16.04
Python3.6
DGL 0.5.2

NOTE: I found out that the warning only appears when I run the command in Spyder Console, any command, throws warning

import sys
/home/user/.local/lib/python3.6/site-packages/dgl/base.py:45: DGLWarning: DGLGraph.len is deprecated.Please directly call DGLGraph.number_of_nodes.
return warnings.warn(message, category=category, stacklevel=1)

Hello, @mufeili , I have the same warning.

E:\Python36\lib\site-packages\dgl\base.py:45: DGLWarning: DGLGraph.len is deprecated.Please directly call DGLGraph.number_of_nodes.
return warnings.warn(message, category=category, stacklevel=1)

My previous version of DGL is 0.4, and there is no warning. Since I upgrade DGL to 0.6, I have the above warning.
NOTE1: In pycharm, DEBUG code have the above warning, but RUN code do not have the above warning.
NOTE2: Is there a way to install the previous version of dgl using pip?

DGL 0.6’s GATConv’s performance is much much better than DGL 0.4’s and I don’t recommend you to use DGL 0.4

Thank you for your advice.
I am looking at the difference between v0.4 and v0.6, and find that the example in v0.4 uses dgl.DGLGraph() to create a graph (DGL at a Glance — DGL 0.4.3post2 documentation), while v0.6 uses dgl.graph() to create a graph (DGL at a Glance — DGL 0.6.0 documentation). What is the difference between them?

We simplified the graph creation API as dgl.graph(...), and the returned object has type DGLGraph.
btw, since DGL 0.5 on our DGLGraph class support more than one edge type and DGL 0.4’s DGLGraph support only one edge type.

@mufeili I am still receiving this error on DGL 0.6. I confirmed I am running DGL 0.6 by running dgl.__version__ and I had installed it by first pip uninstalling dgl and then pip installing dgl. I get the error just when making a dgl graph object from a networkx graph by using g = dgl.from_networkx(graph). The exact error I get is DGLWarning: DGLGraph.__len__ is deprecated.Please directly call DGLGraph.number_of_nodes. return warnings.warn(message, category=category, stacklevel=1)

Could you check if a GPU version and a CPU version co-exist in your installation? That might cause problems.

If you use a conda environment, you can check with

conda list dgl

(This works as long as you are in a conda environment, even if you actually installed the packages with pip).

Otherwise, you can check with

pip freeze |grep dgl

I tried this, and all that got returned was # Name Version Build Channel dgl 0.6.0 pypi_0 pypi.

I ran the following without a warning with DGL 0.6:

import dgl
import networkx as nx
g = nx.Graph([(0, 1), (1, 2)])
gg = dgl.from_networkx(g)

Could you run the script above with -W error option so that it can treat all warnings as errors and display a traceback?

python -W error script.py

Normally in 0.6 the script above should complete without errors even with the -W error option. If your warning keeps showing up then this option should show you a traceback so we can further pinpoint where the problem is.

Hi, I ran this and no error occurred on the terminal. What does this mean with regards to where the error comes from? I usually run in PyCharm if that makes a difference.

The reason is that according to your post:

I’m making sure where the call of DGLGraph.__len__ occurs in dgl.from_networkx call by treating all warnings as errors with -W error option.

But since the error did not occur in terminal, I would suggest either
(1) running your program in terminal and see if the same warning/error would occur, or
(2) running the script in PyCharm, but with the -W error option. PyCharm should be able to specify Python flags somewhere.

My suspicion is that the reason is that the terminal and PyCharm are using two different Python environments, one of them using DGL 0.6.0 and the other using an older version.

1 Like

Thanks for the reply – I tried running from PyCharm (even the script we just used) and I get the error but not when running from terminal. I’m not sure how/why they would be running from different DGL versions; I tried opening a console within pycharm to run dgl.__version__ and it returns 0.6.0.

edit:
as an update I just ran a different file using DGL in the same project and did not receive a warning.

Just to make sure: could you try print(dgl.__version__, dgl) within the script and run the script in PyCharm (i.e. without console)? I’m not an expert of PyCharm, and my guess is that the PyCharm console may be using a different environment from PyCharm IDE.

1 Like

There seems to be some difference.

From the terminal the output is 0.6.0 <module 'dgl' from '/Users/username/opt/anaconda3/envs/misc/lib/python3.8/site-packages/dgl/__init__.py'>

and from the PyCharm console the output is 0.6.0 <module 'dgl' from '/Users/username/opt/anaconda3/envs/misc/lib/python3.8/site-packages/dgl/__init__.py'>
followed by the error /Users/username/opt/anaconda3/envs/misc/lib/python3.8/site-packages/dgl/base.py:45: DGLWarning: DGLGraph.__len__ is deprecated.Please directly call DGLGraph.number_of_nodes. return warnings.warn(message, category=category, stacklevel=1) where the error message looks like it is pointing to dgl/base.py:45 – does this seem to be the cause of the error would you say?

Did the error come with a stacktrace (only available if you run with the -W error option)?

No, I ran this in PyCharm not using the terminal in PyCharm (i.e. by just pressing the ‘play’ button). I just tried using the terminal that is within PyCharm and and I don’t get the error here. I might need post on StackOverflow as I have no idea why running it in that way from Pycharm means it points to a different location of dgl!