-
I'm doing something like this inside array trans = swapaxes(in, axis, -1, s);
array in_copy(trans.shape(), trans.dtype(), nullptr, {});
copy_gpu(trans, in_copy, CopyType::General, s); which does not work and it took me quite a while to realize that it is because So made it work by adding an array trans = swapaxes(in, axis, -1, s);
metal::eval(trans);
array in_copy(trans.shape(), trans.dtype(), nullptr, {});
copy_gpu(trans, in_copy, CopyType::General, s); which however makes me nervous. Is there a better way to do this? (For context: I'm doing this to pass the array to |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Yes you can't call MLX operations from inside the eval functions.
I'm glad this makes you nervous because that's a bad idea, we shouldn't evaluate anything inside an eval.
There isn't a super clean way to do it. But you can see for example here where we transpose an array inside the eval_cpu. A potentially cleaner option is to refactor the actual impentation of You have to be extra careful with temporary arrays like |
Beta Was this translation helpful? Give feedback.
Yes you can't call MLX operations from inside the eval functions.
I'm glad this makes you nervous because that's a bad idea, we shouldn't evaluate anything inside an eval.
There isn't a super clean way to do it. But you can see for example here where we transpose an array inside the eval_cpu.
A potentially cleaner option is to refactor the actual impentation of
Transpose::eval
so that you can call it from inside youreval_gpu
. A lot of ops work like that where we hav…