Repository navigation
cuda: fix crash when querying memory on device with no free memory. - #25157
Conversation
If a Cuda device has no or limited available memory, the actual call to cudaMemGetInfo() itself can cause a fatal crash due to a cuda out of memory error (there is not enough memory to actually query memory) This causes an issue because we query memory for all devices at startup even if the user isn't trying to use the device for inference. Fix this by making the error non-fatal and assigning zero total/free memory to the device. This will have the downstream effect of the fit algorithm not trying to put any layers on it, which is desired outcome vs hard crashing. this also prevents crashes in cuda enabled builds when user explicitly passes '-dev none'
JohannesGaessler
left a comment
There was a problem hiding this comment.
I think this would correctly handle the edge case where there is insufficient free memory for the cudaMemGetInfo call. I'm not sure whether this PR is potentially masking another issue but with a warning I think it should be fine.
Not sure if llama-server exposes a way to select the devices that should be used for inference, but setting E.g., launch |
|
CC @0cc4m, I thought we used a subprocess to query available memory (in that case, we should not crash host llama-server when querying memory in the CUDA subproc) |
|
Regardless of whether or not a subprocess can be used to retrieve the memory safely, a program trying to fetch memory info via the ggml C API should not experience a crash if the memory is already full. |
My server memory awareness PR (#21231) is currently waiting for @ngxson to finish #24822. I hope we can get it moving again afterwards, it has been stuck for a while. |
ORippler
left a comment
There was a problem hiding this comment.
Regardless of whether or not a subprocess can be used to retrieve the memory safely, a program trying to fetch memory info via the ggml C API should not experience a crash if the memory is already full.
That I agree
|
I assume cphlipot is talking about the autofit feature, both CUDA_VISIBLE_DEVICES and -dev should be able to limit which devices get queried. |
@ORippler I think the way the code is written right now -dev isn't even parsed/evaluated until after we query memory. Memory query in llama-server is actually done at the same time we enumerate devices. I agree this would be nice behavior to have but i still think the existing PR makes sense to implement for a few reasons:
@0cc4m This is supposed to address crashes encountered in multiple cases: autofit, -dev none, and --list-devices. CUDA_VISIBLE_DEVICES does work to limit which devices get queried, and i have been using this as a workaround, but -dev only impacts which devices we use for inference, not which devices we enumerate and query memory from, so you'd still get a crash even with -dev filtering. |
+1, hence my approval of this PR.
I only wanted to point out that this is a potential area of improvement for llama-server (or at least I was surprised to learn we query devices excluded via -dev filtering) |
|
I will merge unless someone objects. |
…ggml-org#25157) If a Cuda device has no or limited available memory, the actual call to cudaMemGetInfo() itself can cause a fatal crash due to a cuda out of memory error (there is not enough memory to actually query memory) This causes an issue because we query memory for all devices at startup even if the user isn't trying to use the device for inference. Fix this by making the error non-fatal and assigning zero total/free memory to the device. This will have the downstream effect of the fit algorithm not trying to put any layers on it, which is desired outcome vs hard crashing. this also prevents crashes in cuda enabled builds when user explicitly passes '-dev none'
…ggml-org#25157) If a Cuda device has no or limited available memory, the actual call to cudaMemGetInfo() itself can cause a fatal crash due to a cuda out of memory error (there is not enough memory to actually query memory) This causes an issue because we query memory for all devices at startup even if the user isn't trying to use the device for inference. Fix this by making the error non-fatal and assigning zero total/free memory to the device. This will have the downstream effect of the fit algorithm not trying to put any layers on it, which is desired outcome vs hard crashing. this also prevents crashes in cuda enabled builds when user explicitly passes '-dev none'
Overview
Make the check that queries available CUDA memory not fatally crash
llama-server if the CUDA device is low on available RAM. instead just
report no ram so llama-server doesn't try to load a model to it.
Additional information
If a Cuda device has no or limited available memory, the actual call
to cudaMemGetInfo() itself can cause a fatal crash due to a cuda out
of memory error (there is not enough memory to actually query memory)
This causes an issue because we query memory for all devices at
startup even if the user isn't trying to use the device for inference.
Fix this by making the error non-fatal and assigning zero total/free
memory to the device. This will have the downstream effect of the fit
algorithm not trying to put any layers on it, which is desired outcome
vs hard crashing.
this also prevents crashes in cuda enabled builds when user explicitly
passes '-dev none'
Caveat: because mmporj does not allow user to select a device and may
still internally decide to use a cuda device, the user may still need
--no-mmproj-offload or --no-mmproj to fully prevent all potentially
fatal cuda allocations. A fix for this is deliberately excluded from
this PR as it is a separate issue.
Partially fixes #25145 (note caveat above for part of that issues that is not fixed)
Requirements