Add exportGraphToDot diagnostic utility#388
Open
arkavo-com wants to merge 1 commit intoml-explore:mainfrom
Open
Add exportGraphToDot diagnostic utility#388arkavo-com wants to merge 1 commit intoml-explore:mainfrom
arkavo-com wants to merge 1 commit intoml-explore:mainfrom
Conversation
Exposes the C++ export_to_dot function via a Swift-friendly API. Essential for diagnosing dtype contamination and graph topology differences between Swift and Python. Usage: let logits = model(input, cache: cache) exportGraphToDot(path: "/tmp/graph.dot", output: logits) // Then: grep -c 'label ="AsType"' /tmp/graph.dot // Non-zero AsType count indicates dtype mismatches This was critical for discovering that Swift MLX models can silently inject 1000+ AsType nodes from float32 literal defaults, causing 100x Metal cache churn vs Python. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
davidkoski
reviewed
Apr 6, 2026
| const mlx_imported_function xfunc, | ||
| const mlx_vector_array args, | ||
| const mlx_map_string_to_array kwargs); | ||
| int mlx_export_to_dot_file(const char* path, mlx_array output); |
Collaborator
There was a problem hiding this comment.
We need this change on the mlx-c side. I suspect you made changes locally to that. it is a good idea, I will talk to Ronan.
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.
Summary
Exposes the existing C++
export_to_dotgraph visualization function through a Swift API.Why this matters
This utility was essential for discovering a critical performance issue where Swift MLX models silently inject
AsType(type cast) nodes from float32 literal defaults. By diffing the DOT graph between Python and Swift, we found:MLXArray.ones()defaulting to float32)The 1046 extra AsType nodes caused 237 MB of Metal cache churn per token (vs Python's 2.3 MB) and a 12% generation speed regression.
Without this diagnostic, the root cause would have been invisible — the model produced correct output and all individual operation tests showed perfect buffer donation.
Test plan
🤖 Generated with Claude Code