Skip to content

Add metadata to exported functions#3855

Open
eyupcanakman wants to merge 1 commit into
ml-explore:mainfrom
eyupcanakman:feat/export-metadata
Open

Add metadata to exported functions#3855
eyupcanakman wants to merge 1 commit into
ml-explore:mainfrom
eyupcanakman:feat/export-metadata

Conversation

@eyupcanakman

Copy link
Copy Markdown
Contributor

Closes #2410. Exported .mlxfn files can now store a metadata dictionary, so a model's config can live with the function instead of in a separate JSON file.

export_function and exporter take an optional metadata argument, a dict of string keys to string, int, or float values. import_function(file, return_metadata=True) returns the function along with that dict, mirroring load(..., return_metadata=True) for safetensors and gguf. The value shape follows the one suggested in the issue.

Integer and float values are stored as 64-bit so a Python int or float round-trips without narrowing. Metadata is only supported when exporting to a file. Passing it with a callback raises.

The metadata lives in the file header, so a .mlxfn written before this change has no metadata section and won't load in a metadata-aware build. That matches the existing note that exported functions aren't compatible across MLX versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature request] Support saving meta data to mlxfn files and reading them back

1 participant