Skip to content

gguf: calculate tensor data offset #1076

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

Merged
merged 7 commits into from
Dec 29, 2024
Merged

gguf: calculate tensor data offset #1076

merged 7 commits into from
Dec 29, 2024

Conversation

drazdra
Copy link
Contributor

@drazdra drazdra commented Dec 14, 2024

adding tensors offset within file. offsets stored in metadata are relative to this offset and it's absent in metadata. with this field it's possible to actually access layers in gguf. without of it - offsets shown are useless.

adding tensors offset within file. offsets stored in metadata are relative to this offset and it's absent in metadata. with this field it's possible to actually access layers in gguf. without of it - offsets shown are useless.
@mishig25
Copy link
Collaborator

@drazdra happy to merge after:

  1. linting issues are solved
  2. tensorsOffset is added to https://github.com/huggingface/huggingface.js/blob/main/packages/gguf/src/gguf.spec.ts

@julien-c
Copy link
Member

does this look valid @ngxson @Vaibhavs10?

@mishig25
Copy link
Collaborator

with this field it's possible to actually access layers in gguf. without of it - offsets shown are useless.

@ngxson is this correct?

@drazdra
Copy link
Contributor Author

drazdra commented Dec 16, 2024

sorry about errors, i don't know TS, in my case i just patched the ready file in dist with JS and used it as is.

@ngxson
Copy link
Member

ngxson commented Dec 20, 2024

This will introduce a breaking change for anyone who are using this tensorOffset field. I'd suggest adding a new field for it, for example tensorOffsetInFile. I'll make a PR for that.

@ngxson
Copy link
Member

ngxson commented Dec 21, 2024

I changed the naming to tensorDataOffset instead of tensorsOffset, because it will be more aligned to gguf_get_data_offset(). Here is the equivalent cpp code:

int main(int argc, const char ** argv) {
    struct ggml_context * ctx_meta = NULL;
    struct gguf_init_params gguf_params = {
        /*.no_alloc = */ true,
        /*.ctx      = */ &ctx_meta,
    };
    auto * ctx_gguf = gguf_init_from_file("/Users/ngxson/Downloads/llama-2-7b-chat.Q2_K.gguf", gguf_params);
    printf("gguf_get_data_offset: %zu\n", gguf_get_data_offset(ctx_gguf));
    return 0;
}

Note sure why node test failed, I'll have a look later (I'm using a slow network)

@ngxson ngxson changed the title Update gguf.ts gguf: calculate tensor data offset Dec 21, 2024
@ngxson
Copy link
Member

ngxson commented Dec 21, 2024

Should be ok now, matched the output from cpp code in my last comment.

Pinging @mishig25 for an extra review.

ngxson and others added 2 commits December 29, 2024 12:10
Co-authored-by: Julien Chaumond <julien@huggingface.co>
@ngxson ngxson merged commit 9706030 into huggingface:main Dec 29, 2024
4 checks passed
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.

4 participants