Metal backend: add export-time code signing for Hardened Runtime#18768
Metal backend: add export-time code signing for Hardened Runtime#18768mergennachin wants to merge 2 commits intomainfrom
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/18768
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ❌ 3 New Failures, 4 Pending, 6 Unrelated FailuresAs of commit ce84793 with merge base 3a62fac ( NEW FAILURES - The following jobs have failed:
FLAKY - The following jobs failed but were likely due to flakiness present on trunk:
BROKEN TRUNK - The following jobs failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
f86121f to
fa44add
Compare
The Metal AOTI backend extracts a compiled .so from the .pte at runtime and dlopen's it. macOS Hardened Runtime rejects unsigned dlopen'd code, making Metal-backend .pte files unusable in notarized apps. Add a `codesign_so` hook to `AotiBackend` (no-op by default) that runs after AOTInductor compilation and before the .so is packed into the .pte. `MetalBackend` overrides it to run `codesign` when a `codesign_identity` compile spec is provided. Wire `--codesign-identity` through the Voxtral Realtime and Parakeet export scripts. Add an e2e test in test_modules that exports a toy model with ad-hoc signing.
There was a problem hiding this comment.
Pull request overview
Adds an export-time code-signing hook for AOTInductor-produced shared libraries, enabling Metal backend .pte artifacts to work inside macOS Hardened Runtime / notarized apps (where dlopen rejects unsigned code).
Changes:
- Introduces a
codesign_so()hook onAotiBackendand calls it during preprocess after compilation and before packing the.so. - Implements
MetalBackend.codesign_so()to runcodesignwhen acodesign_identitycompile spec is provided. - Wires
--codesign-identitythrough the Voxtral Realtime and Parakeet export scripts and adds Metal tests for signed/unsigned export paths.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| examples/models/voxtral_realtime/export_voxtral_rt.py | Adds --codesign-identity and passes it via a codesign_identity compile spec for Metal exports. |
| examples/models/parakeet/export_parakeet_tdt.py | Adds --codesign-identity and forwards it into Metal partitioner compile specs. |
| backends/apple/metal/tests/test_modules.py | Extends Metal export helper to accept codesign_identity and adds tests for signed/unsigned export. |
| backends/apple/metal/metal_backend.py | Implements Metal-specific .so signing via codesign when requested by compile spec. |
| backends/aoti/aoti_backend.py | Adds a backend hook (codesign_so) and invokes it before embedding the compiled .so into the output. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import subprocess | ||
| import typing | ||
| from typing import Any, Dict, final, List |
There was a problem hiding this comment.
Since this backend now shells out to the codesign tool (see codesign_so further down), it would be good to defensively guard the signing path for non-macOS hosts and/or when codesign isn’t available on PATH. Without that, requesting signing can fail with a low-signal FileNotFoundError rather than a clear, actionable error message.
The Metal AOTI backend extracts a compiled .so from the .pte at runtime
and dlopen's it. macOS Hardened Runtime rejects unsigned dlopen'd code,
making Metal-backend .pte files unusable in notarized apps.
Add a
codesign_sohook toAotiBackend(no-op by default) that runsafter AOTInductor compilation and before the .so is packed into the .pte.
MetalBackendoverrides it to runcodesignwhen acodesign_identitycompile spec is provided. Wire
--codesign-identitythrough the VoxtralRealtime and Parakeet export scripts.