is mx.load lazy eval? #1292
-
From my understanding, the weights = {}
for wf in weight_files:
weights.update(mx.load(wf)) The weight dict is not fully loaded until we call |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Yes exactly. Until you actually run There are some caveats with lazy loading. If a python file-like object is provided, then with open(weight_file) as f:
weights = mx.load(f)
# we couldn't wait cause the file here is closed |
Beta Was this translation helpful? Give feedback.
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