Avoid importing the `llm` subtree (and pandas) on `import torch_geometric`

Author: frazaneCreated Aug 16, 2026Updated Aug 16, 2026

Proposed Refactor

import torch_geometric pulls in the llm subtree — and pandas with it, when installed — because torch_geometric/__init__.py imports torch_geometric.datasets eagerly and two dataset modules import llm at module level: datasets/web_qsp_dataset.py and datasets/molecule_gpt_dataset.py. Measured on 2.7.0, this adds about 0.15s to a warm import on my system, almost all of it pandas; on clusters with cold network filesystems it is considerably more (up to a few seconds). The imports are still present on master.

Suggest a potential alternative/fix

Defer the llm imports in the two dataset modules to their use sites, as #7448 did for other heavy module-level imports (web_qsp_dataset.py already defers the HuggingFace datasets import this way). Lazy-loading torch_geometric.datasets itself would go further, but that was undone in #6140 so I assume the eager import is deliberate.

Source: pyg-team/pytorch_geometric