Skip to content

Metal backend: add export-time code signing for Hardened Runtime#18768

Open
mergennachin wants to merge 2 commits intomainfrom
turboquant
Open

Metal backend: add export-time code signing for Hardened Runtime#18768
mergennachin wants to merge 2 commits intomainfrom
turboquant

Conversation

@mergennachin
Copy link
Copy Markdown
Contributor

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.

@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Apr 8, 2026

🔗 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 SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

❌ 3 New Failures, 4 Pending, 6 Unrelated Failures

As of commit ce84793 with merge base 3a62fac (image):

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.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 8, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 8, 2026

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@mergennachin mergennachin force-pushed the turboquant branch 2 times, most recently from f86121f to fa44add Compare April 8, 2026 09:38
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.
@mergennachin mergennachin marked this pull request as ready for review April 27, 2026 19:15
Copilot AI review requested due to automatic review settings April 27, 2026 19:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 on AotiBackend and calls it during preprocess after compilation and before packing the .so.
  • Implements MetalBackend.codesign_so() to run codesign when a codesign_identity compile spec is provided.
  • Wires --codesign-identity through 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.

Comment on lines +7 to 9
import subprocess
import typing
from typing import Any, Dict, final, List
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants