ImportError: cannot import name 'spacing' from 'pangu' — pangu is unpinned and pangu>=5.0.0 removed spacing (breaks import nemo.collections.llm on a fresh 2.4.1 install)
Describe the bug
nemo_toolkit declares pangu without a version bound (in the nlp-only, deploy and all extras), and pangu removed the spacing function in 5.0.0 (2026-07-31) and renamed the API again in 6.0.0 (2026-09-18, current latest). A fresh install now resolves pangu==6.0.0, and importing the LLM collection fails at import time:
File ".../nemo/collections/llm/bert/model/bert_spec.py", line 16, in <module>
from nemo.collections.nlp.modules.common.megatron.utils import ApexGuardDefaults
File ".../nemo/collections/nlp/__init__.py", line 15, in <module>
from nemo.collections.nlp import data, losses, models, modules
File ".../nemo/collections/nlp/models/__init__.py", line 31, in <module>
from nemo.collections.nlp.models.machine_translation import MTEncDecModel
...
File ".../nemo/collections/common/tokenizers/chinese_tokenizers.py", line 40, in <module>
from pangu import spacing
ImportError: cannot import name 'spacing' from 'pangu'The import is at module level in nemo/collections/common/tokenizers/chinese_tokenizers.py (line 40 on main) and inside a function in nemo/collections/common/tokenizers/en_ja_tokenizers.py (line 89 on main), so import nemo.collections.llm breaks even for users who never touch the Chinese/Japanese tokenizers.
pangu public API by release (read from the wheels on PyPI):
- 4.0.6.1 (2019-02-08):
spacing,spacing_text,spacing_file,cli - 5.0.0 (2026-07-31):
spacing_text,spacing_file,has_proper_spacing,cli—spacingremoved - 6.0.0 (2026-09-18):
space_text,space_file,has_proper_spacing,cli— renamed again
Steps/Code to reproduce bug
- Start from
nvcr.io/nvidia/pytorch:25.08-py3(Python 3.12, torch 2.8.0a0). pip install "nemo_toolkit[nlp-only]==2.4.1"— the resolver pickspangu==6.0.0(observed 2026-09-29; any install after 2026-07-31 gets ≥ 5.0.0).python -c "import nemo.collections.llm"→ theImportErrorabove.pip install pangu==4.0.6.1→ the import succeeds.
Expected behavior
import nemo.collections.llm works on a fresh install. Either pin the dependency (pangu<5) or make the import tolerant of the new API, for example try: from pangu import spacing / except ImportError: from pangu import space_text as spacing (5.0.0 exposes spacing_text, 6.0.0 space_text; the two signatures should be checked before aliasing). Since the tokenizers are only needed for Chinese/Japanese text, a lazy import inside the tokenizer classes would also stop the whole nemo.collections.llm import from depending on it.
Environment overview
- Environment location: Docker (
nvcr.io/nvidia/pytorch:25.08-py3) on AWS - Method of NeMo install:
pip install "nemo_toolkit[nlp-only]==2.4.1"(not present in the base image)
Environment details
- Python 3.12, PyTorch 2.8.0a0 (NGC 25.08), nemo_toolkit 2.4.1, pangu 6.0.0 (resolved)
Additional context
The same unpinned pangu requirement is present on main, so the breakage is not specific to 2.4.1. No GPU is needed to reproduce.
Source: NVIDIA-NeMo/Speech