Fix: Add error handling for memory buffer allocation in ggml_init to prevent segmentation fault#142
Open
ahmetkca wants to merge 1 commit intoantimatter15:masterfrom
Open
Fix: Add error handling for memory buffer allocation in ggml_init to prevent segmentation fault#142ahmetkca wants to merge 1 commit intoantimatter15:masterfrom
ahmetkca wants to merge 1 commit intoantimatter15:masterfrom
Conversation
- Check if mem_buffer is NULL - Print error message to stderr - Print debug message - End critical section - Return NULL if memory buffer allocation fails
This was referenced Mar 24, 2023
|
Seems very nice. Suddenly I haven't been able to run my 30B alpaca model that was previously running fine. I haven't touched or updated a single thing. Crashing while loading the model with no errors. I wonder if this would fix? |
hongxiayang
reviewed
Apr 3, 2023
| /*.scratch_save =*/ { 0, 0, NULL, }, | ||
| }; | ||
|
|
||
| if (ctx->mem_buffer == NULL) { |
There was a problem hiding this comment.
There is a GGML_ASSERT macro which can be used.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When loading a large language model like Alpaca 30B, the
ggml_initfunction tries to allocate a significant amount of memory (25.5 GB). Even if the system has sufficient RAM (e.g., 32 GB), the available memory might not be enough due to other processes or system requirements. In the current implementation, we blindly try to allocate the required memory without checking if themallocoperation was successful or failed. If the memory allocation fails, it can result in segmentation faults and undefined behavior.I encountered this issue when trying to load the Alpaca 30B model and experienced a segmentation fault. To address this problem, we should check the return value of
mallocand handle memory allocation failures properly.Changes
ggml_init.Motivation
By checking the return value of
mallocand not creating theggml_contextwhen memory allocation fails, we can provide better error handling and prevent segmentation faults. This approach will also make it easier for users to identify the cause of the problem when there isn't enough available memory for the required allocation.Request for Feedback
I would appreciate feedback on the error handling implementation, the additional context provided, and any suggestions for improvements.