llama.cpp icon indicating copy to clipboard operation
llama.cpp copied to clipboard

Not having enough memory just causes a segfault or something

Open LoganDark opened this issue 1 year ago • 7 comments

So. I'm trying to build with CMake on Windows 11 and the thing just stops after it's done loading the model.

image

And apparently, this is a segfault.

Screenshot_20230318_121935

Yay yay yyayy yyayay

this is a memory allocation failure it seems, from me not having enough memory. not like llama.cpp Tells Me That lmao, it just segfaults

(ctx->mem_buffer is nullptr which probably means the malloc just failed)

LoganDark avatar Mar 18 '23 07:03 LoganDark

can confirm clearing tons of memory seems to make it work:

image

LoganDark avatar Mar 18 '23 07:03 LoganDark

Performing the quantization step from f16 down to q4_0 significantly helps with the memory usage (I am dumb but eventually figured this out even though I was supposed to do it anyway)

It does make the model extra drunk though (which I guess is to be expected from the 7B version)

LoganDark avatar Mar 18 '23 11:03 LoganDark

I was wondering why the q4_0 was giving such a wierd responses

gadzbi123 avatar Mar 18 '23 15:03 gadzbi123

I was wondering why the q4_0 was giving such a wierd responses

q4_0 will say 2 + 2 = 10, then proceeds to explain how that's because they are in their "respective ranges" of "-5 through 8" by not being "greater than 9 or lesser than -4", but that's also an off-by-one error, not like it matters because what?

image

It's actually hilarious

LoganDark avatar Mar 18 '23 20:03 LoganDark

Detecting when a stack overflow is going to happen in a portable way is tricky. If we could use malloc() to allocate this memory it would be able to fail gracefully.

tjohnman avatar Mar 19 '23 19:03 tjohnman

Detecting when a stack overflow is going to happen in a portable way is tricky.

Is this a stack overflow? ctx->mem_buffer is null. Clearly an actual allocation failed first and the segfault happened because of an attempt to access something through the resulting null pointer. Which could have been detected earlier and handled cleanly without segfaulting (i.e. printing an error message and exiting)

LoganDark avatar Mar 19 '23 19:03 LoganDark

You're right, my bad. In that case it should be easier to deal with.

tjohnman avatar Mar 19 '23 19:03 tjohnman

There is now an assert that checks mem_buffer, even in non-debug builds: https://github.com/ggerganov/llama.cpp/blob/173d0e6419e8f8f3c1f4f13201b777f4c60629f3/ggml.c#L4571

Closing this as it's quite old, please re-open if you still encounter the problem with a recent revision.

sw avatar May 06 '23 18:05 sw

There is now an assert that checks mem_buffer, even in non-debug builds:

Yep, that looks like it would fix it~

Closing this as it's quite old

Actually you'd be closing it because it's solved lol

LoganDark avatar May 06 '23 23:05 LoganDark