-
Notifications
You must be signed in to change notification settings - Fork 32k
Description
System Info
transformers version: latest (installed via pip today, 2026-02-05)
sentence-transformers version: latest
torch version: 2.x (from pytorch/pytorch Docker image)
Python version: 3.11+
OS: Linux (Docker container)
Who can help?
Information
- The official example scripts
- My own modified scripts
Tasks
- An officially supported task in the
examplesfolder - My own task or dataset
Reproduction
Minimal reproduction:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("all-MiniLM-L6-v2")Or directly:
from transformers import AutoModelResults in:
NameError: name 'nn' is not defined
The error occurs during the import chain when transformers attempts to load a module that references nn.Module or similar torch.nn constructs without first importing torch.nn as nn.
Expected behavior
The import should succeed without errors. This worked with previous versions of transformers.
Additional context
This appears to be a similar regression to #38269 ("NameError: name 'Replicate' is not defined"), which was caused by a missing import in transformers/integrations/tensor_parallel.py.
The current error (nn not defined) suggests another module has a similar missing import issue, likely referencing nn.Module without the corresponding import torch.nn as nn statement.
Workaround: Pinning transformers<4.53.0 (or to the last known working version) resolves the issue.