Skip to content

Create default random key lazily#3278

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

Create default random key lazily#3278
zcbenz merged 1 commit intoml-explore:mainfrom
zcbenz:random-key

Conversation

@zcbenz
Copy link
Copy Markdown
Collaborator

@zcbenz zcbenz commented Mar 19, 2026

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.

Copy link
Copy Markdown
Member

@angeloskath angeloskath left a comment

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