Repository navigation
fix(mlx): relax Metal context-store timeout by default - #7141
Conversation
There was a problem hiding this comment.
Code Review
This pull request configures the Apple Silicon Metal context-store timeout by setting the AGX_RELAX_CDM_CTXSTORE_TIMEOUT environment variable to "1" on Darwin arm64 systems, while preserving any existing user-defined values. It also introduces a comprehensive test suite to verify this behavior and ensure the environment variable is set before MLX initialization. There are no review comments, so I have no feedback to provide.
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.
9221fdd to
0874960
Compare
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because no GitHub Actions runner was available. Make sure your repository has a runner available to run Copilot's review, or add a copilot-setup-steps.yml file specifying one with the runs-on attribute. See the docs for more details.
Sets a safer default for Metal’s context-store timeout on Apple Silicon so MLX workloads are less likely to hit the watchdog, while keeping any user-provided environment value authoritative.
Changes:
- Default
AGX_RELAX_CDM_CTXSTORE_TIMEOUT=1on macOS arm64 viaos.environ.setdefault. - Gate the behavior to Apple Silicon only, and keep explicit env overrides (including empty string /
"0") intact.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0874960980
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
0874960 to
4aa3955
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4aa39558c9
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
4aa3955 to
e69cb30
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
|
Putting the default in both bootstraps is the right design. I verified it on an Apple Silicon Mac (M1, MLX 0.31.2). After the in-process setdefault, C-level getenv (what the AGX driver reads) returns "1", and a real Metal matmul runs cleanly. Importing this branch sets AGX_RELAX_CDM_CTXSTORE_TIMEOUT before the first mlx module lookup, while a pre-PR install leaves it unset. Every MLX entry point (Python API, Studio workers, CLI train and export) passes through one of the two bootstraps before any MLX import. The watchdog suppression itself rests on the upstream thread, where the MLX maintainer suggested this variable and the reporter confirmed it resolved the M2 case. The M5 report shows it is not universal, which your description already frames as best effort. Thanks @Lyxot. Merging. |
Summary
AGX_RELAX_CDM_CTXSTORE_TIMEOUTto1on Apple Silicon before MLX modules can initialize through the normal Python API or Studio workers.0and an empty string, withos.environ.setdefault.Why
Sustained MLX workloads can hit Metal's context-store/interactivity watchdog while a display is active, as reported in ml-explore/mlx#3267. The driver setting helped the reported M2 case, but it is private and does not guarantee protection on every chip or workload.
The setting must exist before MLX or Metal initializes. The
unslothpackage bootstrap covers normal Python API and export imports, while Studio's hardware bootstrap mirrors the default for training and inference workers that import MLX directly without first importingunsloth.Behavior and risk
This is an Apple-Silicon-only, process-scoped default. It does not modify shell profiles or system configuration, and an explicitly supplied environment value always remains authoritative.
Because the variable is undocumented and has not protected every reported system, this PR treats it as a best-effort mitigation rather than a universal watchdog fix.
Validation
Direct
import unslothsubprocess probes confirmed: