Skip to content

is mx.load lazy eval? #1292

Answered by angeloskath
mzbac asked this question in Q&A
Jul 27, 2024 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Yes exactly. Until you actually run mx.eval(weights) no array has been read from the files (metadata have been read in order to know how many arrays, shapes, types etc).

There are some caveats with lazy loading. If a python file-like object is provided, then load evaluates the arrays immediately. The reason is we cannot be sure that the object will be valid after calling load. For instance the following code will not be lazy

with open(weight_file) as f:
    weights = mx.load(f)
# we couldn't wait cause the file here is closed

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@mzbac
Comment options

Answer selected by mzbac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants