Skip to content

[Metal] Let compile callback declare payload format via (payload, fmt)#19924

Open
echuraev wants to merge 1 commit into
apache:mainfrom
echuraev:echuraev/fix_metal_codegen_hook
Open

[Metal] Let compile callback declare payload format via (payload, fmt)#19924
echuraev wants to merge 1 commit into
apache:mainfrom
echuraev:echuraev/fix_metal_codegen_hook

Conversation

@echuraev

@echuraev echuraev commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

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.

@echuraev echuraev requested review from MasterJH5574 and tqchen July 1, 2026 20:48
@echuraev echuraev force-pushed the echuraev/fix_metal_codegen_hook branch from e5a2a73 to ea78822 Compare July 1, 2026 20:52

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread src/backend/metal/codegen/codegen_metal.cc Outdated
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.
@echuraev echuraev force-pushed the echuraev/fix_metal_codegen_hook branch from ea78822 to 95c1004 Compare July 1, 2026 21:00
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.

1 participant