Add metadata to exported functions#3682
Open
Ritesh102000 wants to merge 1 commit into
Open
Conversation
Add an optional string-to-string `metadata` dictionary to `export_function`/`exporter`, serialized into the `.mlxfn` header, and a `return_metadata` flag on `import_function` to read it back. This mirrors the existing `save_safetensors`/`load` metadata convention. The metadata is also exposed in C++ via `ImportedFunction::metadata()`. Closes ml-explore#2410
zcbenz
reviewed
Jun 16, 2026
| auto function_count = deserialize<int>(is); | ||
| ftable->shapeless = deserialize<bool>(is); | ||
| auto metadata_pairs = | ||
| deserialize<std::vector<std::pair<std::string, std::string>>>(is); |
Collaborator
There was a problem hiding this comment.
What would happen when importing functions exported from previous versions without metadata support? (There is no need to be compatible but I'm curious about the behavior)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed changes
This adds support for saving metadata along with an exported function, as requested in #2410.
mx.export_function(..., metadata={...})andmx.exporter(..., metadata={...})store adict[str, str]in the.mlxfnheader.mx.import_function(file, return_metadata=True)returns the imported function together with its metadata.ImportedFunction::metadata().I kept the metadata as a string-to-string dictionary to match the existing
save_safetensors/loadmetadata API. The issue mentioned possibly allowingUnion[str, int, float]values — happy to widen it if you'd prefer, but I went with string keys/values for consistency. Passingmetadatatogether with a callback raises, since it is only written when exporting to a file.Closes #2410
Checklist