-
Notifications
You must be signed in to change notification settings - Fork 242
Description
Description
I encountered a hard crash when importing GLiNER inside a recent NVIDIA PyTorch Docker container (25.11-py3).
The issue is related to the hard dependency on apex.amp. While apex is installed in this environment, the legacy amp module seems to be deprecated/removed in favor of PyTorch's native AMP (torch.cuda.amp), causing the import to fail immediately.
Environment details
OS/Environment: Docker (nvcr.io/nvidia/pytorch:25.11-py3)
GLiNER version: (Latest from pip)
PyTorch version: 2.9.1
CUDA: 13.0 (As provided by the container)
Steps to Reproduce
- Launch the container
docker run --gpus all -it --rm --ipc=host \
-v $HOME/.cache/huggingface:/root/.cache/huggingface \
-v ${PWD}:/workspace -w /workspace \
nvcr.io/nvidia/pytorch:25.11-py3- Install GLiNER
pip install gliner- Attempt import
python -c 'from gliner import GLiNER'Traceback:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python3.12/dist-packages/gliner/__init__.py", line 3, in <module>
from .model import GLiNER
File "/usr/local/lib/python3.12/dist-packages/gliner/model.py", line 37, in <module>
from .training import Trainer, TrainingArguments
File "/usr/local/lib/python3.12/dist-packages/gliner/training/__init__.py", line 1, in <module>
from .trainer import Trainer, TrainingArguments
File "/usr/local/lib/python3.12/dist-packages/gliner/training/trainer.py", line 22, in <module>
from apex import amp
ImportError: cannot import name 'amp' from 'apex' (/usr/local/lib/python3.12/dist-packages/apex/__init__.py)
Note, this issue also affects GLiNER2 (https://github.com/fastino-ai/GLiNER2/blob/765cab59181d39bd3c01204920799527b15f9f6d/gliner2/trainer.py#L12)
For anyone wanting to only run inference, a simple fix is to just wrap the import statement in a try/except block, replacing
GLiNER/gliner/training/trainer.py
Line 22 in 7a06586
| from apex import amp |
try:
from apex import amp
except ImportError:
print("Failed to import amp from apex")But perhaps it would be worth migrating to native torch.amp to resolve this?