huggingface/transformers · error · ImportError

{type(self).__name__} requires newer versions of: {', '.join

Error message

{type(self).__name__} requires newer versions of: {', '.join(outdated)}

What it means

The same dependency guard raises ImportError when every required package is present but at least one is older than the hard minimum in the exporter's min_versions (e.g. DynamoExporter requires torch>=2.11.0). All violations are collected and reported in one message with the required minimum and the found version, so you can upgrade everything in a single step.

Source

Thrown at src/transformers/exporters/base.py:91

                installed_base = installed.split("+", 1)[0]
                tested_base = tested.split("+", 1)[0]
                if installed_base != tested_base:
                    drift.append((pkg, installed_base, tested_base))

        if missing:
            specs = ", ".join(
                f"{pkg}=={self.tested_versions[pkg]}" if pkg in self.tested_versions else pkg for pkg in missing
            )
            raise ImportError(f"To use {type(self).__name__}, please install the following dependencies: {specs}")

        # Enforce hard minimums; collect all violations and report once, rather than failing on the first.
        outdated = []
        for pkg, minimum in self.min_versions.items():
            _, installed = _is_package_available(pkg, return_version=True)
            if installed == "N/A" or version.parse(installed.split("+", 1)[0]) < version.parse(minimum):
                outdated.append(f"{pkg}>={minimum} (found {installed})")
        if outdated:
            raise ImportError(f"{type(self).__name__} requires newer versions of: {', '.join(outdated)}")

        if drift:
            details = ", ".join(f"{pkg}: installed {got}, tested {want}" for pkg, got, want in drift)
            logger.warning(
                f"{type(self).__name__} is experimental and patches many backend internals; "
                f"behaviour may differ from what was validated. Version drift detected — {details}. "
                f"If you hit issues, try the tested versions."
            )

    @abstractmethod
    def export(
        self,
        model: PreTrainedModel,
        sample_inputs: MutableMapping[str, torch.Tensor | Cache],
        config: ExportConfigMixin,
    ):
        """
        Export the model and return the backend-specific program object.

View on GitHub (pinned to a597f97485)

Solutions

  1. Upgrade each listed package to at least the stated minimum: pip install -U "torch>=2.11.0".
  2. Prefer the tested version (e.g. torch==2.12.0) to also avoid the version-drift warning that follows.
  3. If you cannot upgrade, use a different exporter backend whose min_versions your stack satisfies.

Example fix

# before
DynamoExporter().export(model, inputs, DynamoConfig())  # ImportError: torch>=2.11.0 (found 2.5.1)

# after (shell)
# pip install "torch>=2.11.0"
DynamoExporter().export(model, inputs, DynamoConfig())
Defensive patterns

Strategy: validation

Validate before calling

from packaging.version import Version
import torch
from transformers.exporters.exporter_dynamo import DynamoExporter  # example

for pkg, minimum in DynamoExporter.min_versions.items():
    installed = importlib.metadata.version(pkg)
    assert Version(installed.split("+")[0]) >= Version(minimum), f"{pkg}>={minimum} required, found {installed}"

Try / catch

try:
    DynamoExporter().export(model, inputs, cfg)
except ImportError as e:
    if "requires newer versions" in str(e):
        raise SystemExit("Upgrade torch, then re-run: " + str(e))
    raise

Prevention

When it happens

Trigger: Running DynamoExporter.export with torch 2.10 or older; ExecutorchExporter with an executorch below its minimum; the installed build is a pre-release whose version parses below the floor.

Common situations: Downgrading torch for another library and then trying to export; environment pinned by a training stack (torch 2.5) while the exporters need bleeding-edge torch; '+'-suffixed local builds where only the base version is compared.

Related errors


AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14). Data as JSON: /api/errors/f940ca6c38a21c00. Report an issue: GitHub.