question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 3 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
rusty1scommented, Mar 2, 2021

You are right! This should be fixed in master. Thanks!

0reactions
Linux-cpp-lispcommented, Mar 4, 2021

Fully resolved in #2199.

Read more comments on GitHub >

github_iconTop Results From Across the Web

OSError when import torch_geometric · Issue #3575
Installation I am trying to set up a Conda environment with the exact same versions of all the packages as in a paper...
Read more >
Creating Your Own Datasets - PyTorch Geometric
Although PyG already contains a lot of useful datasets, you may wish to create your own ... import torch from torch_geometric.data import InMemoryDataset, ......
Read more >
Installation — pytorch_geometric documentation
Installation via Pip Wheels · Ensure that at least PyTorch 1.12.0 is installed: · Find the CUDA version PyTorch was installed...
Read more >
Advanced Mini-Batching — pytorch_geometric documentation
PyG automatically takes care of batching multiple graphs into a single giant graph with the help of the torch_geometric.loader.DataLoader class.
Read more >
torch_geometric.data — pytorch_geometric documentation
A data object describing a heterogeneous graph, holding multiple node and/or edge types in disjunct storage objects. Batch. A data object describing a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found