Why the transformers, tokenizers, and numpy stack breaks with conflicts, and how to fix it
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. transformers 4.46.0 requires tokenizers<0.21,>=0.20, but you have tokenizers 0.19.1 which is incompatible
Also appears as
- ImportError: numpy.core.multiarray failed to import
- ValueError: numpy.dtype size changed, may indicate binary incompatibility
Short answer
The Hugging Face stack (transformers, tokenizers, accelerate) is released in tightly coupled lockstep versions, so upgrading one package independently over time leaves combinations that were never tested together and break silently at import or runtime. The fix is resolving the entire stack in a single pip install pass from a fresh virtual environment, guided by a pinned requirements.txt, rather than incrementally patching individual packages.
Affects: Any ML environment built up over time with individual pip install and pip install -U commands, especially around transformers, tokenizers, accelerate, peft, and numpy.
Fastest path to a resolved environment
- 1Create a fresh virtual environment rather than trying to fix the current one in place.
- 2Write a single requirements.txt pinning transformers, tokenizers, accelerate, numpy, and torch to versions known to work together, checked against the transformers release notes.
- 3Install everything in one pip install -r requirements.txt pass so pip's resolver sees the full constraint set at once.
- 4Run pip check afterward to confirm no unresolved conflicts remain.
- 5If any package requires numpy 1.x specifically, pin numpy<2 explicitly rather than letting it float to the latest major version.
How to confirm this is your problem
- pip prints a dependency resolver warning naming an exact version conflict between transformers and tokenizers
- ImportError referencing numpy.core.multiarray failing to import after an unrelated package upgrade
- ValueError about numpy.dtype size changed, indicating binary incompatibility between compiled extensions
- Code that worked last month breaks after a routine pip install -U of a single package
Root causes and fixes
transformers, tokenizers, and accelerate installed or upgraded independently over time
These packages are released together as a coordinated set, with transformers pinning compatible version ranges for tokenizers and accelerate in its own dependency metadata. Running pip install -U transformers alone, without also updating its companions, or vice versa, leaves a combination that was never actually tested together by the maintainers, producing import errors or subtly wrong behavior at runtime.
Fix: Resolve the entire Hugging Face stack together in a single pip install pass using a requirements.txt that pins compatible versions, rather than upgrading individual packages ad hoc.
pip install -U transformers tokenizers accelerate pip check
A major numpy version bump breaks binary compatibility with older compiled packages
Numpy 2.0 changed its C API in ways that broke binary compatibility with packages compiled against the numpy 1.x API, including some older torch, scipy, and pandas builds. Any package that has not yet been rebuilt or rereleased against numpy 2.x will fail to import or throw a dtype size mismatch error when numpy silently upgrades as a transitive dependency.
Fix: Pin numpy explicitly to a 1.x version (numpy<2) in your requirements.txt if any dependency in your stack has not yet published a numpy 2.x compatible release, and verify with pip check.
pip install 'numpy<2'
Installing packages incrementally over a long session instead of one resolve pass
pip's dependency resolver only considers the full constraint set of packages installed in a single pip install invocation. Running many separate pip install commands over hours or days as needs arise means each installation only satisfies constraints known at that moment, and later installs can silently downgrade or upgrade a shared dependency without re-checking compatibility with everything installed earlier.
Fix: Consolidate your intended package set into a single requirements.txt file and install it all at once from a fresh environment, letting pip's resolver see every constraint simultaneously.
Mixing conda-installed and pip-installed packages for the same library
Conda and pip maintain separate package metadata and do not coordinate dependency resolution with each other. Installing a library like numpy through conda and then a dependent library like transformers through pip in the same environment can result in pip installing its own conflicting copy of a shared dependency that conda already manages, corrupting the environment silently.
Fix: Pick one package manager per environment, either entirely conda or entirely pip with venv, and avoid mixing the two for the same set of interdependent ML libraries.
A transitive dependency of a fine-tuning library pins an old shared package version
Libraries like peft or trl for fine-tuning depend on huggingface-hub and other shared packages, and an older release of one of these fine-tuning libraries can pin an outdated version of a package that a newer transformers release also depends on but expects a newer version of, creating a three-way conflict that is harder to spot than a direct two-package mismatch.
Fix: When adding a new fine-tuning library to an existing environment, re-resolve the entire requirements.txt together rather than pip installing just the new library on top of the existing environment.
Diagnostic commands
Check for any currently broken dependency combinations
pip check
Lists every package whose installed dependencies are not satisfied by what is actually present, which is the fastest way to see the full scope of conflicts before attempting a fix.
Check the exact versions of the core stack currently installed
pip list | grep -E "torch|transformers|tokenizers|numpy|accelerate"
Compare these versions against the compatibility ranges listed in the transformers release notes for the version you intend to run.
Confirm the Hugging Face stack actually imports cleanly together
python -c "import transformers, tokenizers; print(transformers.__version__, tokenizers.__version__)"
A clean print of both versions with no traceback confirms the immediate conflict is resolved; an ImportError here points to a deeper binary incompatibility, often numpy-related.
Check whether numpy's major version is the source of an import error
python -c "import numpy; print(numpy.__version__)"
A 2.x version alongside older compiled packages that predate numpy 2.0 support is a common, easy-to-overlook root cause of dtype and binary incompatibility errors.
Stopping it from happening again
- Maintain a single pinned requirements.txt or lockfile for your ML stack and install it in one pass whenever it changes.
- Re-resolve the full environment whenever adding a new library, rather than layering pip installs onto an existing environment indefinitely.
- Pin numpy explicitly to a tested major version until every dependency in your stack has confirmed numpy 2.x compatibility.
- Run pip check as a routine step in CI so dependency conflicts are caught before deployment, not discovered in production.
When this becomes an architecture problem
If you manage many services with overlapping but slightly different ML dependency requirements, or need reproducible air-gapped installs, move from ad hoc requirements.txt files to a proper lockfile tool and container-based artifact pipeline rather than continuing to resolve conflicts by hand on each machine.
Frequently asked questions
Why did upgrading just one package break everything else?
The Hugging Face ML stack, including transformers, tokenizers, and accelerate, is released as a tightly coupled set of packages with cross-pinned version ranges. Upgrading only one of them with pip install -U leaves the others at versions that were never tested against the new one, which is why a seemingly isolated upgrade cascades into broader import or runtime failures.
Should I pin numpy below version 2?
Yes, if any package in your environment, such as an older torch or scipy build, has not yet published a numpy 2.x compatible release. Numpy 2.0 changed its C API in ways that break binary compatibility with packages compiled against the older API, so pinning numpy<2 avoids ImportError and dtype size mismatch failures until your full stack is confirmed compatible.
Is it better to use conda or pip for an ML environment?
Either works, but avoid mixing them for the same interdependent packages within one environment. Conda and pip resolve dependencies independently and do not coordinate with each other, so installing overlapping libraries through both package managers in the same environment is a common and hard-to-diagnose source of silent conflicts.
How do I prevent this from recurring every few months?
Maintain a single pinned requirements.txt or lockfile that captures your entire working ML stack, and re-resolve the whole file in one install pass whenever you need to add or upgrade anything, rather than running individual pip install -U commands over time. Running pip check as part of CI catches conflicts before they reach production.
Size it properly next time
Free calculators that prevent this class of failure before you provision hardware.
On-Prem AI Deployment Checklist
A 30-point pre-deployment checklist covering use cases, hardware, security, model operations, and rollout for self-hosted enterprise LLMs.
Free ToolSelf-Hosted LLM Hardware Estimator
Estimate the VRAM footprint, GPU count, and hardware budget required to self-host an open-weight LLM with your concurrency and context needs.
Free ToolAir-Gapped LLM Deployment Checklist
A practical control checklist for deploying and maintaining large language models in a fully air-gapped environment, from initial staging through ongoing patching and drift detection.
Related problems
vLLM fails to install or import due to torch and CUDA mismatches
vLLM ships prebuilt wheels compiled against a specific, exact torch and CUDA version, and it uses custom CUDA kernels that only work with that pairing. Most install failures happen because torch was already installed separately, or an existing environment has an incompatible CUDA toolkit, so the fix is almost always a fresh virtual environment where pip resolves vLLM and its exact torch dependency together in one pass.
FlashAttention install fails during compilation or gets killed
FlashAttention's pip install compiles CUDA kernels from source unless an exact prebuilt wheel exists for your torch, CUDA, Python, and C++ ABI combination, and that compilation is extremely RAM-hungry per parallel job. The build gets silently OOM-killed on machines without enough memory unless you limit MAX_JOBS, and separately fails if your CUDA toolkit does not match the version torch itself was built against.
gcc or g++ version rejected while building CUDA extensions
Every CUDA toolkit release only supports compiling with a specific range of gcc and g++ major versions, and nvcc explicitly rejects anything outside that range rather than risk generating broken code. This most often surfaces on recently released Linux distributions whose default gcc is newer than what an older, already-installed CUDA toolkit supports, and the fix is installing a supported older gcc/g++ version alongside the default and pointing CC and CXX at it for the build.
CUDA version mismatch between PyTorch and the system driver
PyTorch ships its own bundled CUDA runtime inside the wheel, so it never uses your system's CUDA toolkit (the one nvcc reports). The only number that matters is the driver's maximum supported CUDA version, shown top right in nvidia-smi output. Fix the mismatch by installing a torch wheel built for a CUDA version at or below that number, not by touching nvcc or the toolkit.
GuidevLLM Production Deployment: A Practitioner's Guide
Deploy vLLM in production: continuous batching, PagedAttention, config flags that matter, and the metrics to watch before you trust it with real traffic.
GuideOn-Prem LLM Deployment Architecture: Reference Guide
Reference architecture for on-prem LLM deployment: inference servers, GPU sizing, RAG pipelines, and security zones for regulated manufacturers.
Still stuck, or tired of fighting your own infrastructure?
Netray deploys and operates on-prem AI for regulated manufacturers and defense suppliers. We have debugged this stack in production, on air-gapped networks, at scale.