huggingface / huggingface.js

Utilities to use the Hugging Face Hub API
https://hf.co/docs/huggingface.js
MIT License
1.29k stars 160 forks source link

👾Fix chunk count not incrementing when parsing additional chunks in a local file #767

Closed ryan-the-crayon closed 2 weeks ago

ryan-the-crayon commented 2 weeks ago

When parsing a local GGUF and the metadata section does not fit in the same chunk, the parser would try to load more chunks. However, in the local file implementation range view, the chunk count is not incremented, resulting it not actually loading in more data.

mishig25 commented 2 weeks ago

cc: @ngxson

ngxson commented 2 weeks ago

LGTM. Thanks! I don't understand why I missed this line of code :eyes:

mishig25 commented 2 weeks ago

@ryan-the-crayon thanks a lot for the contribution! Anyway, you can add a test case ? https://github.com/huggingface/huggingface.js/blob/e2689f8c7b02d8eb05e3b7869f8e02f7e495ea93/packages/gguf/src/gguf.spec.ts#L230-L241

ngxson commented 2 weeks ago

FYI, I made a gguf with 32MB of metadata (metadata usually takes less than 2MB): https://huggingface.co/ngxson/test_gguf_models/blob/main/gguf_test_big_metadata.gguf

The test would be:

const parsedGguf = await gguf(".cache/model.gguf", { allowLocalFile: true });
const { metadata } = (parsedGguf as GGUFParseOutput<{ strict: false }>); // custom metadata arch, no need for typing
expect(metadata['dummy.1']).toBeDefined(); // first metadata in the list
expect(metadata['dummy.32767']).toBeDefined(); // last metadata in the list
CPP code to generate gguf ```cpp #include "ggml.h" #include #include int main(int argc, char ** argv) { struct gguf_context * ctx = gguf_init_empty(); gguf_set_val_str(ctx, "general.architecture", "gguf_test_big_metadata"); char str1kb[1025]; std::memset(str1kb, 'A', 1024); str1kb[1024] = '\0'; for (int i = 0; i < 32 * 1024; i++) { gguf_set_val_str(ctx, ("dummy." + std::to_string(i)).c_str(), str1kb); } gguf_write_to_file(ctx, "gguf_test_big_metadata.gguf", false); gguf_free(ctx); } ```
mishig25 commented 2 weeks ago

@ryan-the-crayon @ngxson merged and the new version of @huggingface/gguf.js with the fix is released