Any import from `torch_geometric` loads `matplotlib` (and a lot more)
See original GitHub issue🐛 Bug
Because torch_geometric
imports *
from .nn
, which imports *
from .models
, which imports all of the models, a lot of unnecessary dependencies get loaded whenever anything is imported from torch_geometric
.
I came across this behavior because it was filling my logging with matplotlib
messages, but even with logging disabled it would be good for performance if heavy libraries that do file I/O like matplotlib
are only loaded if they are needed. This can be particularly important for start-up performance on clusters with networked filesystems.
To Reproduce
import logging
logging.basicConfig(level=logging.DEBUG)
import torch
from torch_geometric.data import Data
d = Data(x=torch.zeros(10, 3))
print(d)
Gives many pages of matplotlib
debug logging, followed by the expected
Data(x=[10, 3])
Expected behavior
That matplotlib
(and other libraries that aren’t necessary for basic functions) won’t be loaded for any import from torch_geometric
, giving an output of just
Data(x=[10, 3])
Environment
- OS: Linux
- Python version: 3.8.5 / Anaconda
- PyTorch version: 1.7.1
- CUDA/cuDNN version: N/A
- GCC version: N/A
- Any other relevant information: N/A
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (7 by maintainers)
Top GitHub Comments
You are right! This should be fixed in master. Thanks!
Fully resolved in #2199.