Skip to content

Fixed llama_set_state_data declaration not matching definition #1540

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

Closed
wants to merge 1 commit into from

Conversation

niansa
Copy link
Contributor

@niansa niansa commented May 20, 2023

Nothing to comment here.

@ggerganov
Copy link
Member

Probably looking at something outdated - I changed the definition today:

https://github.com/ggerganov/llama.cpp/blob/affc76edfdefa7b326f526e463cc65ff13fcfb92/llama.cpp#L2676

@ggerganov ggerganov closed this May 20, 2023
@niansa niansa deleted the patch-1 branch May 20, 2023 12:33
@niansa niansa restored the patch-1 branch May 20, 2023 12:38
@niansa
Copy link
Contributor Author

niansa commented May 20, 2023

@ggerganov actually nope, it's still in master like that
https://github.com/ggerganov/llama.cpp/blob/master/llama.h#L154

@niansa
Copy link
Contributor Author

niansa commented May 20, 2023

Seems like you've reverted your fix right after you've commited it...

@ggerganov
Copy link
Member

ggerganov commented May 20, 2023

I changed const uint8_t * src to uint8_t * src on purpose (both declaration and definition), because in the implementation we assign it to void * which used to generate a compile warning about not being const correct:

8a203f9

@niansa
Copy link
Contributor Author

niansa commented May 20, 2023

Hmm, not sure if it's better to require the API user to do a const_cast rather doing that internally...

@imaami
Copy link
Contributor

imaami commented May 20, 2023

I changed const uint8_t * src to uint8_t * src on purpose (both declaration and definition), because in the implementation we assign it to void * which used to generate a compile warning about not being const correct:

8a203f9

Is it possible that the source buffer is modified during llama_set_state_data()? If so, then non-const is the correct type, but in that case the API should clearly document that the input data may be modified.

Looks like the cast to void * is done when assigning the pointer to ggml_tensor::data, which is void *. Is there a reason why that member can't be void const *data? Is it sometimes used to store the address of memory that gets modified? If that's the case then it seems a tad problematic in itself.

Requiring the caller to const_cast a potentially read-only buffer to non-const is sus, and the alternative of making a temporary copy every time isn't that great either. No matter how you put it it's just wrong to cast towards less const-ness, even if it happens inside the implementation (like casting a potentially read-only data pointer to void *).

If ggml_tensor::data can't be made void const * then a C-style hacky solution would be replacing it with

    union {
        void *data;
        void const *cdata;
    };

and changing the implementation to only use one or the other union member depending on the pointer value's origin. Of course this only makes sense if the correct choice is obvious from the context alone, otherwise it would need a runtime tag member, in which case it might just be better to have two separate pointers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants