[ExecuTorch][MLX] lowering memory/export improvements - #21795
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/21795
Note: Links to docs will display an error until the docs builds have been completed. ❌ 4 Pending, 1 Unrelated Failure, 1 Unclassified FailureAs of commit 3e84925 with merge base 3b5bf0f ( UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:
FLAKY - The following job failed but was likely due to flakiness present on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
|
@claude review this code |
|
Claude finished @metascroy's task in 4m 53s —— View job Code review
I read the full diff across all 12 files. This is a careful, well-documented change and I couldn't find a correctness bug that would produce a wrong Design: the
|
| from executorch.extension.llm.export.gguf import ExportableGGUFTensor | ||
|
|
||
| weight_target, raw = P.get_placeholder_target_and_tensor(weight_node) | ||
| weight_target = P.get_placeholder_target(weight_node) |
There was a problem hiding this comment.
i feel like the preprocessing part for q4k/q5k/q6k are pretty much the same. Can we unify the logic by using utliy function or a common parent class?
| self._builder = MLXProgramBuilder(edge_program) | ||
| self._builder.check_support_only() | ||
| builder = MLXProgramBuilder(edge_program) | ||
| with mem_phase("partition: check_support"): |
There was a problem hiding this comment.
will the memory block here impact the exportation speed in real world production?
Muse Glimmer dflash + image (16 GB Q4_K target + 1.5 GB draft + 1.3 GB mmproj):
What changed
Support checks no longer repack weights. The partitioner decided "can MLX
lower this?" by running each handler, which for quantized ops means fully
dequantizing and repacking the weight. exir asks several times per export, so
every weight was repacked 4x. Handlers can now answer from node metadata via an
optional
supported()/register_support_check; anything without one keepsthe old run-and-catch, so nothing regresses.
Raw blobs are freed as they're repacked.
repack_mlxleft the originalGGUF bytes in the ExportedProgram until a sweep that only ran after the whole
graph was built, so raw and repacked weights were live simultaneously (+16 GB).
It now releases each blob on the spot, memoized per weight so tied
embedding/lm_head repacks once.
Two guards, since a wrongly-released weight used to fail silently:
serialization now raises naming the constant instead of emitting a
.ptewitha missing weight, and release is a no-op during support checks, where it would
corrupt the caller's own program.
ET_MLX_MEM_PROFILE=1adds phase-attributed peak-footprint logging (off bydefault); it's what located the regression above.