transformers
28ec08c4 - 🚨 Exporters: `ExportedModel`, Hub save/load, one backend registry (#50029)

Commit
23 days ago
🚨 Exporters: `ExportedModel`, Hub save/load, one backend registry (#50029) * Exporters: return ExportArtifacts, split backends into export_artifact/save_artifact `export()` and `export_for_generation()` return an `ExportArtifacts`, a mapping of `ExportedComponent`s (the backend's program and the metadata recorded while tracing it), saved with `save_pretrained`. Backends implement `export_artifact` and `save_artifact`, and register through `register_backend`. The configs drop their saving fields. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Exporters: load and push ExportArtifacts, record the saved graphs' own names `ExportArtifacts.from_pretrained` loads an export from a local directory or the Hub (only the files the manifest names), through each backend's `load_artifact`; `push_to_hub` and `save_pretrained(push_to_hub=True)` upload it. ONNX and OpenVINO record their final graph's input and output names in the metadata. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Exporters: prefix OpenVINO's saved files with `openvino_` `.xml` / `.bin` don't name their format, so OpenVINO components save as `openvino_<name>.xml`, as optimum-intel's do. Other backends keep `<name>.<ext>`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Exporters: simplify the artifacts API after review `ExportFormat` is a `StrEnum`, so configs serialize as they are and custom backends use plain strings. The registry lookup splits into `get_export_config_class` and `get_exporter_class`. The metadata drops the fields that described the traced program rather than the saved graph. Overlapping tests are merged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Exporters: name a single graph a program, load ONNX lazily, test against the Hub `export_program` / `save_program` / `load_program`, `program_files` and `.program` replace the `artifact` names, which now only mean the `ExportArtifacts` container. A loaded ONNX graph doesn't read its weights; calling it runs the saved file in ONNX Runtime. `get_exporter_class` / `get_export_config_class` are public. Hub tests move to `test_hub.py`, with staging tests pushing and loading a real export. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Exporters: load saved ONNX lazily, record positional metadata for ExecuTorch A loaded ONNX program reads its graph without the weights, and a call runs the saved file in ONNX Runtime. `num_user_outputs` and `constant_inputs` are recorded again for Dynamo and ExecuTorch, whose saved programs bind positionally; ONNX and OpenVINO drop them, as they describe the traced program rather than those saved graphs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Exporters: load through cached_files, plain ExportMetadata fields, record the export config Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Exporters: register a backend by its exporter, export every component through one path Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Exporters: feed bf16 inputs to OpenVINO as bf16 tensors NumPy has no bf16, so `tensor.numpy()` raised on a bf16 input. Pass an `openvino.Tensor` holding the bf16 bits instead (OpenVINO's Python API exposes a bf16 buffer as float16, so the bits are copied through an int16 view). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Exporters: import torch in the quantizers' utils only when it's available Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Exporters: an export returns an ExportedModel, not ExportArtifacts It holds the exported graphs in `components` instead of being a Mapping over them, so the runtime can extend it rather than wrap it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Exporters: simplify the export plumbing - export_program returns an ExportMetadata, not a dict re-wrapped by the caller - export_program gets the converted config; export() is the one place that converts it - drop the constant_inputs / num_user_outputs metadata nothing reads - one unknown-format check in the backend registry - the public API keeps register_backend and the Auto classes; the registry internals stay in exporters.auto - drop the AutoHfExporter.from_pretrained placeholder Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Tests: expect the single unknown-format error for a missing format Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Exporters: an ONNX export's program is its onnx_ir.Model, not an ONNXProgram The program is the graph, as for OpenVINO; running it is the runtime's job, which owns the ONNX Runtime session. A loaded graph keeps its weights in `model.onnx.data` and its file in `meta["path"]`, which ONNX Runtime opens to read them (`onnx_ir` can't read them through the Hub cache's symlinks). Drops the SavedOnnxProgram subclass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Exporters: an ONNX export loaded from the Hub cache saves again; save/load tests per backend - The Hub cache links `model.onnx.data` to a blob outside the snapshot, which onnx_ir refuses to read: the loaded graph's weights now read from the blob, so it can be saved, quantized or fused again. Only that file is redirected. - tests/exporters/test_save_load.py: the save/load round trips, one class per backend, plus bfloat16 and Hub-cache ONNX cases. test_runtime.py keeps the decode runtime tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Exporters: save loaded exports again safely; load remote-code configs and newer manifests - Programs are written aside and moved into place: re-saving a loaded OpenVINO export into its own directory no longer rewrites the weights it still maps (a bus error), nor copies a loaded .pte onto itself. - A loaded ExecuTorch program is read from its file and saved again by copying it. - `ExportedModel.from_pretrained` takes `trust_remote_code` for the config of a model whose code lives in its repo. - A manifest from a newer transformers loads with a warning; metadata fields this version doesn't know are skipped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Exporters: convert the export config where it is used Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Exporters: clearer names; the export config serializes itself - `ExportConfigMixin.to_json_string` replaces the free `export_config_metadata`, as the other config mixins do. - `_describe_traced_kwarg`, `_backend_for`, `openvino_input_value`, and `save_pretrained`'s manifest `entries`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Exporters: to_json_string without a trailing newline Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Exporters: a runnable ONNX quantization example; inline the one-use config lookup Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Tests: configs are serialized now, just never read back from a dict Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Exporters: import repeat_kv only with torch, so the OpenVINO exporter imports without it Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Parents
Loading