Skip to content

Export: preserve Dtype state values in export callback arguments#3145

Merged
awni merged 3 commits intoml-explore:mainfrom
skryl:fix-export
Feb 19, 2026
Merged

Export: preserve Dtype state values in export callback arguments#3145
awni merged 3 commits intoml-explore:mainfrom
skryl:fix-export

Conversation

@skryl
Copy link
Contributor

@skryl skryl commented Feb 19, 2026

Proposed changes

This PR fixes export callback state serialization for primitives that include Dtype in their state (for example AsType), so callback arguments preserve dtype values instead of dropping them.

Add explicit handling for Dtype during state unpacking:

else if constexpr (std::is_same_v<T, Dtype>) {
  unpacked_state.push_back(state);
}

It also adds a regression test to validate callback behavior and updates export docs with callback payload details.

Problem

In mlx/export.cpp, the state unpacking logic did not handle Dtype in tuple/variant flattening.
As a result, primitives with dtype state (for example AsType, NumberOfElements) could emit incomplete arguments during export.

Why this is needed

Downstream IR/export consumers rely on complete primitive arguments. Missing dtype state breaks robust graph export/lowering paths and forces downstream inference fallbacks.

Checklist

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the necessary documentation (if needed)

Copy link
Member

@awni awni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@awni awni merged commit f2f2d16 into ml-explore:main Feb 19, 2026
16 checks passed
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.

2 participants

Comments