Skip to content

Create default random key lazily - #3278

Merged
zcbenz merged 1 commit into
ml-explore:mainfrom
zcbenz:random-key
Mar 19, 2026
Merged

zcbenz merged 1 commit into
ml-explore:mainfrom
zcbenz:random-key

Conversation

@zcbenz

@zcbenz zcbenz commented Mar 19, 2026

Copy link
Copy Markdown
Member

Refs #3148, #3078, #3216.

Only create random key when mx.random.state is accessed, or when random APIs are used (which would create a key implicitly). This avoid initializing GPU device when running import mlx.core, which has been preventing us from doing any kind of error handling.

Also the random key is now declared as thread local, to remove race conditions when using random APIs in multi-threads.

@angeloskath angeloskath left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🚀

@zcbenz
zcbenz merged commit 21c11fc into ml-explore:main Mar 19, 2026
16 checks passed
@zcbenz
zcbenz deleted the random-key branch March 19, 2026 11:22
@BrewTestBot BrewTestBot mentioned this pull request Apr 22, 2026
1 task done
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.

2 participants