2025, Nov 07 17:00
How to Resolve the MISTRAL_INPUTS_DOCSTRING ImportError When Loading NVIDIA/NV-Embed-v2 in Hugging Face Transformers
Hit an ImportError for MISTRAL_INPUTS_DOCSTRING when loading NVIDIA NV-Embed-v2 in Hugging Face Transformers? Check version; fix by pinning 4.42.4.
When loading NVIDIA/NV-Embed-v2 via Hugging Face Transformers, some users run into an ImportError tied to Mistral internals. The snag appears as soon as the model is instantiated with trust_remote_code enabled and typically points to a missing symbol inside the Mistral implementation.
Minimal example that reproduces the issue
The following snippet demonstrates a standard embedding setup that triggers the error in incompatible environments:
from transformers import AutoTokenizer, AutoModel
repo_id = "NVIDIA/nv-embed-v2"
enc_tok = AutoTokenizer.from_pretrained(repo_id)
enc_model = AutoModel.from_pretrained(repo_id, trust_remote_code=True)
enc_model.eval()
In environments where the problem occurs, the Python traceback references a missing name in modeling_mistral.py.
ImportError: cannot import name 'MISTRAL_INPUTS_DOCSTRING' from 'transformers.models.mistral.modeling_mistral'
What is actually going on
The root cause is a version mismatch in the Transformers package. The symbol MISTRAL_INPUTS_DOCSTRING exists in Transformers up to 4.51.3 and is removed starting from 4.52.0, including newer 4.53.x lines. If your runtime resolves to a newer Transformers build while your code expects the symbol to exist, importing Mistral internals fails and raises the ImportError. This often happens when a different virtual environment is active, when the IDE is using a different interpreter than your terminal, or when the interpreter wasn’t restarted after upgrading the library.
How to verify your runtime
Don’t rely on assumptions—check exactly what your current Python process is running. Verify the Transformers version inside the same interpreter where you execute the model code:
import transformers
print(transformers.__version__)
If needed, also confirm the Python version and the interpreter path to ensure you are using the expected virtual environment:
import sys
print(sys.version)
print(sys.executable)
Fix: pin a compatible Transformers version and restart the interpreter
If the reported version is not compatible, install a version where the symbol exists. Users have confirmed 4.42.4 works, and the model card suggests 4.42.2. After installation, restart your IDE or Python session so the new version is actually used by the runtime.
pip install -U transformers==4.42.4
Once the environment is consistent, the original code does not need to change. For completeness, here is the same setup with distinct local names:
from transformers import AutoTokenizer, AutoModel
repo_id = "NVIDIA/nv-embed-v2"
enc_tok = AutoTokenizer.from_pretrained(repo_id)
enc_model = AutoModel.from_pretrained(repo_id, trust_remote_code=True)
enc_model.eval()
Why this matters
Embedding models that rely on trust_remote_code may reference internal pieces of specific library versions. If your environment silently upgrades to a build where an internal symbol is removed, code that used to work suddenly breaks. Reproducible ML pipelines depend on version pinning and verifying the exact interpreter used by the tooling, especially when switching between terminal sessions, notebooks, and IDEs.
Takeaways
When you hit ImportError around MISTRAL_INPUTS_DOCSTRING while loading NVIDIA/NV-Embed-v2, confirm the Transformers version from the running process, ensure the right venv and interpreter are active, and pin a known-good release such as 4.42.4, considering the model card’s guidance for 4.42.2 as well. After reinstalling, restart the IDE to pick up the correct dependency set. This small routine saves time and keeps embedding workflows consistent and predictable.