ImportError: cannot import name 'X' from 'sentence_transformers' (or .models, .util, .losses, ...): which versions have it
Old import paths still work: sentence-transformers 5.4.0 (2026-04-09) moved its modules but serves 133 old paths through an import hook, with a DeprecationWarning. So an import that fails is usually one of these. models.BERT, models.RoBERTa and the other per-architecture modules left in 2.0.0 (2021-06-24); use models.Transformer. util.snapshot_download left in 5.1.0 (2025-08-06); import it from huggingface_hub. cannot import name 'cached_download' from 'huggingface_hub' while importing sentence_transformers means your sentence-transformers is older than 2.3.0 (2024-01-29): upgrade it. Your version can also be older than the name, for example SparseEncoder needs 5.0.0. For any other name, paste the error below.
Corrected on 2026-12-05: this page read only the first release of each minor version, so a name added or removed in a patch release was dated to the next minor. For example, from sentence_transformers import CrossEncoder works from 0.3.8 (2020-10-19), not only from 0.4.0. Every release was then read once from PyPI: 6 top-level names (and 642 module-and-name pairs in all) differ in some patch release from the first release of the same minor. The lookup now gives those patch releases. The per-minor ranges are unchanged.
Examples:
Runs in your browser on sentence_transformers.json (199 KB); nothing you paste is sent anywhere. Covers 6,679 module-and-name pairs in 375 modules, old paths included.
Which names were really removed?
These are the removals people hit; the lookup has all of them.
| Import | Works in | Fails from | Use instead |
|---|---|---|---|
from sentence_transformers.models import BERT | 0.1.0 to 1.2.1 | 2.0.0 | models.Transformer("model-name"), which loads any Hugging Face model (since 0.3.0). |
from sentence_transformers.models import RoBERTa | 0.3.0 to 1.2.1 | 2.0.0 | models.Transformer("model-name"), which loads any Hugging Face model (since 0.3.0). |
from sentence_transformers.models import T5 | 0.3.0 to 2.1.0 | 2.2.0 | models.Transformer("model-name"), which loads any Hugging Face model (since 0.3.0). |
from sentence_transformers.util import cached_download | 2.0.0 to 2.2.2 | 2.3.0 | huggingface_hub.hf_hub_download; see the huggingface_hub page linked below. |
from sentence_transformers.util import hf_hub_url | 2.0.0 to 2.2.2 | 2.3.0 | |
from sentence_transformers.util import snapshot_download | 2.0.0 to 5.0.0 | 5.1.0 | from huggingface_hub import snapshot_download; sentence-transformers itself imports it from there. |
from sentence_transformers.util import hf_hub_download | 2.3.0 to 5.0.0 | 5.1.0 | from huggingface_hub import hf_hub_download. |
Where did sentence-transformers 5.4.0 move each module?
The old path keeps working; the new one avoids the warning. The hook prints "Importing from '...' is deprecated and will be removed in a future version. Please use '...' instead." These are the module-level moves; the hook also serves the old per-class files, such as sentence_transformers.losses.MultipleNegativesRankingLoss.
| Old path (still works) | New path from 5.4.0 |
|---|---|
sentence_transformers.data_collator | sentence_transformers.sentence_transformer.data_collator |
sentence_transformers.datasets | sentence_transformers.sentence_transformer.datasets |
sentence_transformers.evaluation | sentence_transformers.sentence_transformer.evaluation |
sentence_transformers.losses | sentence_transformers.sentence_transformer.losses |
sentence_transformers.model_card | sentence_transformers.sentence_transformer.model_card |
sentence_transformers.models | sentence_transformers.sentence_transformer.modules |
sentence_transformers.models.tokenizer | sentence_transformers.sentence_transformer.modules.tokenizer |
sentence_transformers.peft_mixin | sentence_transformers.base.peft_mixin |
sentence_transformers.quantization | sentence_transformers.util.quantization |
sentence_transformers.readers | sentence_transformers.sentence_transformer.readers |
sentence_transformers.sampler | sentence_transformers.base.sampler |
sentence_transformers.similarity_functions | sentence_transformers.util.similarity |
sentence_transformers.sparse_encoder.models | sentence_transformers.sparse_encoder.modules |
sentence_transformers.trainer | sentence_transformers.sentence_transformer.trainer |
sentence_transformers.training_args | sentence_transformers.sentence_transformer.training_args |
Which modules are gone for good?
| Module | Gone in | Date (PyPI) |
|---|---|---|
sentence_transformers.evaluation.MSEEvaluatorFromDataFrame | 5.4.0 | 2026-04-09 |
sentence_transformers.fit_mixin | 5.4.0 | 2026-04-09 |
sentence_transformers.losses.GlobalOrthogonalRegularizationLoss | 5.4.0 | 2026-04-09 |
sentence_transformers.model_card_templates | 5.4.0 | 2026-04-09 |
sentence_transformers.models.T5 | 2.2.0 | 2022-02-10 |
sentence_transformers.models.ALBERT | 2.0.0 | 2021-06-24 |
sentence_transformers.models.BERT | 2.0.0 | 2021-06-24 |
sentence_transformers.models.CamemBERT | 2.0.0 | 2021-06-24 |
sentence_transformers.models.DistilBERT | 2.0.0 | 2021-06-24 |
sentence_transformers.models.RoBERTa | 2.0.0 | 2021-06-24 |
sentence_transformers.models.WKPooling | 2.0.0 | 2021-06-24 |
sentence_transformers.models.XLMRoBERTa | 2.0.0 | 2021-06-24 |
sentence_transformers.models.XLNet | 2.0.0 | 2021-06-24 |
sentence_transformers.cross_encoder.evaluation.CRRerankingEvaluator | 1.0.0 | 2021-03-18 |
sentence_transformers.datasets.EncodeDataset | 1.0.0 | 2021-03-18 |
sentence_transformers.datasets.sampler | 1.0.0 | 2021-03-18 |
sentence_transformers.datasets.sampler.LabelSampler | 1.0.0 | 2021-03-18 |
sentence_transformers.data_samplers | 0.4.0 | 2020-12-22 |
sentence_transformers.evaluation.BinaryEmbeddingSimilarityEvaluator | 0.4.0 | 2020-12-22 |
sentence_transformers.evaluation.EnhancedBinaryEmbeddingSimilarityEvaluator | 0.4.0 | 2020-12-22 |
sentence_transformers.losses.test_batch_hard_triplet_loss | 0.4.0 | 2020-12-22 |
sentence_transformers.config | 0.2.0 | 2019-08-16 |
sentence_transformers.dataset_readers | 0.2.0 | 2019-08-16 |
sentence_transformers.encoder | 0.2.0 | 2019-08-16 |
sentence_transformers.input_example | 0.2.0 | 2019-08-16 |
sentence_transformers.models.TransformerModel | 0.2.0 | 2019-08-16 |
sentence_transformers.test_batch_hard_triplet_loss | 0.2.0 | 2019-08-16 |
How was this read, and how was it checked?
From the source of each release tag, with Python's ast module; no release was installed or imported. A module's names are everything it binds at module level. The old paths come from the aliases each release installs: the DEPRECATED_MODULE_PATHS table and its import hook (5.4.0 on), and direct sys.modules[...] assignments (4.0.0 on); an old path gets the names of the module it points to. Dates come from PyPI.
Checks, by a second reading: (1) each of the 79 top-level names is found as plain text in __init__.py, or is a module, in every release of its range (1,149 name-and-release pairs). (2) A regular expression finds 4,645 definitions in 1,700 file versions; all are among the names read. (3) A regular expression finds the same 1,100 aliases (summed over releases) as the reading. (4) 8 known facts hold.
Limits
- Nothing was installed or run. "Has it" means the import statement resolves in the source.
- The ranges use the first release of each minor version (and the newest). Every release was also read once (76 releases, from the files on PyPI, with the same rules, the module aliases included): 6 top-level names and 642 module-and-name pairs in all differ in some patch release from the first release of their minor. The lookup prints those patch releases under the range.
- The deprecated paths may be removed in a future release; the hook's message says so. The lookup follows the release you give.
Questions
Does "from sentence_transformers.models import Transformer" still work after 5.4.0?
Yes. sentence-transformers 5.4.0 (2026-04-09) moved its modules, for example sentence_transformers.models to sentence_transformers.sentence_transformer.modules, and installs an import hook that serves 133 old paths from their new places, with a DeprecationWarning. An old path that fails on 5.4.0 or later fails for another reason: the name was removed, or it was never in that module.
How do I fix "cannot import name 'BERT' from 'sentence_transformers.models'"?
sentence-transformers 2.0.0 (2021-06-24) removed the per-architecture modules (BERT, RoBERTa, DistilBERT, XLNet and others). Use models.Transformer("bert-base-uncased"), which loads any Hugging Face model, or pin pip install "sentence-transformers<2.0.0".
Importing sentence_transformers fails with "cannot import name 'cached_download' from 'huggingface_hub'". What do I upgrade?
sentence-transformers. Releases before 2.3.0 (2024-01-29) import cached_download, which huggingface_hub removed in 0.26.0. pip install -U "sentence-transformers>=2.3.0" fixes it; the huggingface_hub page linked below has the details.
Where did sentence_transformers.util.snapshot_download go?
sentence-transformers 5.1.0 (2025-08-06) turned util into a package and stopped passing snapshot_download along. Import it from huggingface_hub, where it always came from.
Sources
- huggingface/sentence-transformers, release tags v0.1.0 to v6.3.0: every
.pyfile under sentence_transformers/; the aliases in util/deprecated_import.py; release dates from PyPI. - Report: cached_download error with sentence-transformers 2.2.2 and huggingface_hub 0.26.0.
The same data as JSON: sentence_transformers.json, licensed CC BY 4.0.
Related: "cannot import name 'cached_download' from 'huggingface_hub'" · "... from 'transformers'" · "... from 'datasets'" · "... from 'peft', 'trl' or 'accelerate'".