huggingface/transformers · error · NotImplementedError
{type(self).__name__} does not implement `export`. Pick a co
Error message
{type(self).__name__} does not implement `export`. Pick a concrete exporter (`DynamoExporter`, `OnnxExporter`, `ExecutorchExporter`), or override `export` in your subclass with a backend-specific tracing pipeline that consumes `config` and returns the runtime artifact. What it means
The base HfExporter.export is an abstract stub that always raises NotImplementedError with guidance text. It fires when export() is invoked on the base class or on a subclass that overrode export_for_generation but not export. The message names the concrete exporters to use (DynamoExporter, OnnxExporter, ExecutorchExporter) or tells you to implement a backend-specific tracing pipeline.
Source
Thrown at src/transformers/exporters/base.py:126
"""
Export the model and return the backend-specific program object.
Args:
model ([`PreTrainedModel`]):
The model to export.
sample_inputs (`dict[str, torch.Tensor | Cache]`):
**Forward** kwargs — what you'd pass to `model(**sample_inputs)`. These are used
directly as the example inputs during tracing. For an autoregressive decode-step
export, this means you need to include `past_key_values`, `cache_position`, etc.
If you only have generation-style inputs, use [`~HfExporter.export_for_generation`]
instead — it runs `model.generate` for you and exports each stage.
config ([`~transformers.exporters.configs.ExportConfigMixin`]):
Backend-specific configuration.
Returns:
Backend-specific export artifact.
"""
raise NotImplementedError(
f"{type(self).__name__} does not implement `export`. Pick a concrete exporter "
"(`DynamoExporter`, `OnnxExporter`, `ExecutorchExporter`), or override `export` "
"in your subclass with a backend-specific tracing pipeline that consumes `config` "
"and returns the runtime artifact."
)
def export_for_generation(
self,
model: PreTrainedModel,
sample_inputs: MutableMapping[str, torch.Tensor | Cache],
config: ExportConfigMixin | dict[str, ExportConfigMixin],
generation_config: GenerationConfig | None = None,
multi_token_decode: bool = False,
) -> dict[str, object]:
"""
Decompose a generative model and export each component independently.
Thin wrapper around [`~exporters.utils.decompose_for_generation`] that callsView on GitHub (pinned to a597f97485)
Solutions
- Use a concrete exporter: DynamoExporter(), OnnxExporter(), or ExecutorchExporter().
- In a custom subclass, override export(self, model, sample_inputs, config) with your tracing pipeline that returns the runtime artifact.
- If you wanted auto-dispatch by config, go through AutoHfExporter.from_config(config).export(...).
Example fix
# before HfExporter().export(model, inputs, OnnxConfig()) # NotImplementedError # after from transformers.exporters.exporter_onnx import OnnxExporter OnnxExporter().export(model, inputs, OnnxConfig())
Defensive patterns
Strategy: validation
Validate before calling
from transformers.exporters.base import HfExporter assert type(exporter) is not HfExporter, "use a concrete exporter: Dynamo/Onnx/Executorch" assert type(exporter).export is not HfExporter.export, "subclass must override export()" exporter.export(model, inputs, cfg)
Type guard
def is_concrete_exporter(obj) -> bool:
from transformers.exporters.base import HfExporter
return isinstance(obj, HfExporter) and type(obj).export is not HfExporter.export Try / catch
try:
exporter.export(model, inputs, cfg)
except NotImplementedError as e:
if "does not implement `export`" in str(e):
exporter = AutoHfExporter.from_config(cfg) # dispatch to the right concrete exporter
else:
raise Prevention
- Never instantiate HfExporter directly; construct the backend-specific class
- In custom exporter plugins, define export() before anything else and keep a test that calls it
When it happens
Trigger: Instantiating HfExporter() directly (the @abstractmethod is not enforced at construction in all Python versions/setups) and calling .export(); subclassing HfExporter for a custom backend without overriding export(); calling export on a partially-built custom exporter.
Common situations: Writing a custom backend plugin and forgetting the export method; refactoring a subclass and dropping the override; mistaking the base class for a dispatcher that picks a backend automatically.
Related errors
- AutoHfExporter.from_pretrained is not implemented yet. Load/
- Exporter must extend HfExporter
- Export config must extend ExportConfigMixin
- This method should be implemented by the derived class.
- `num_head` was provided as a list of length {len(num_heads)}
AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14).
Data as JSON: /api/errors/5af45f08ccef79fa.
Report an issue: GitHub.