-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] Crash in item()
.
#82
Comments
Sure, there may be more to the message -- it is throwing an exception here:
That is this line: https://github.com/ml-explore/mlx/blob/main/mlx/ops.cpp#L328 msg << "[reshape] Cannot reshape array of size " << a.size()
<< " into shape " << shape << ".";
throw std::invalid_argument(msg.str()); You are doing an array index operation, not a reshape, but there are reshapes inside the indexing code. It would be good to see what the exception message is -- if there is a crashlog it might be in there. If you get this in Xcode you can go to frame 9 and:
(I think that is the right call, but maybe |
Another two cases. It appears they are due to the same issue. (Crash when I wonder if running it on the CPU will make a difference? Case 1:
Case 2:
|
These look a little different -- I think it might be an assertion failure inside the pthread mutex. Are you using threads or async? |
If you have a snippet that can reproduce the error I can investigate it. |
Three cases above are in a thread. I can’t provide meaningful snippets. I just simply call “item” and it occurs occasionally. Found no pattern to reproduce them |
MLXArray is not thread safe -- you can't create one on one thread and evaluate it (e.g/ calling Try it without threads and see how it fares, if you can. |
throw std::invalid_argument(
"[eval] Attempting to eval an array without a primitive."); and I can reproduce that in python -- it looks like an issue in mlx.core. |
Filed ml-explore/mlx#1083. |
Strange, there used to be a snippet of code in here! Anyway, per the discussion in the other issue, this is the problem: func foo(x: MLXArray) -> MLXArray {
let y = MLX.softmax(x, axis: -1)
let logits = y[0,0,0].item(Float.self)
return MLX.full([1, 100], values: MLXArray(logits))
} The call to func foo(x: MLXArray) -> MLXArray {
let y = MLX.softmax(x, axis: -1)
let logits = y[0,0,0]
return MLX.full([1, 100], values: y)
} |
Oops! I deleted the snippet because it didn't accurately reflect my question. |
More crash info:
|
OK, that is trying to access memory that is not mapped. The most likely cause is out of bounds indexing: the underlying What does |
I am pretty sure that the I think there are some data racing issues, and changing the default device seems to trigger some
|
Well, running everything on the cpu probably isn't getting all the advantages of mlx :-) If you ever have a repo that can reproduce the issue I would be happy to investigate further. If not, are we ok to close this? |
It might be an issue with core as well.. hard to tell because there is no code to repro here. But @tqtifnypmb if you are able to provide the Swift repro code or similar code in Python that would be useful. |
I would very much like to help, I've tried to extract a minimal repo. But in the process, I found that the logic is the same as whisper-mlx, so I guess using whisper should be the same. It's worth noting that most of the crashes come from the iOS system. The frequency on macOS is very low. |
Code:
Occurs occasionally, not 100% reproducible
Crash Stacks:
Any hints about what is happening behind the scenes or how to fix it?
Thanks
The text was updated successfully, but these errors were encountered: