[Metal] Let compile callback declare payload format via (payload, fmt)#19924
[Metal] Let compile callback declare payload format via (payload, fmt)#19924echuraev wants to merge 1 commit into
Conversation
e5a2a73 to
ea78822
Compare
There was a problem hiding this comment.
Code Review
This pull request updates the Metal codegen build process to support a backward-compatible contract for the tvm_callback_metal_compile callback, allowing it to return either a compiled payload or a (payload, format) pair. It also adds corresponding unit tests to verify source passthrough and rejection of mixed formats. The feedback suggests correcting a minor typo ('Backwaard-compatible') in a comment within codegen_metal.cc.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
A tvm_callback_metal_compile used purely for debugging/inspection may return the MSL source unchanged. Previously, merely registering the callback forced the module format to "metallib", so the runtime tried to load the text source as a binary metallib and failed with "Invalid library file" (issue apache#18798). The callback may now return a (payload, format) pair to declare the payload format. A bare str/bytes return keeps the legacy metallib behavior. All kernels of a module share a single declared format, so a callback that mixes formats across kernels (including a legacy metallib return alongside a (payload, "metal") return) is rejected at codegen time instead of producing a module that fails to load.
ea78822 to
95c1004
Compare
A tvm_callback_metal_compile used purely for debugging/inspection may return the MSL source unchanged. Previously, merely registering the callback forced the module format to "metallib", so the runtime tried to load the text source as a binary metallib and failed with "Invalid library file" (issue #18798).
The callback may now return a (payload, format) pair to declare the payload format. A bare str/bytes return keeps the legacy metallib behavior. All kernels of a module share a single declared format, so a callback that mixes formats across kernels (including a legacy metallib return alongside a (payload, "metal") return) is rejected at codegen time instead of producing a module that fails to load.