-
Notifications
You must be signed in to change notification settings - Fork 434
gguf: Add ability to load local file #656
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
Conversation
Note that we already have const blob = await Fileblob.create("./local-file");
const chunk1 = await blob.slice(start, end).then(slice => slice.arrayBuffer());
const chunk2 = ... There are also It could be copied over or shared. Or a small improvement: no need for streams to get a chunk you can do it like this: const file = await open(this.path, "r");
try {
const chunk = await file.read(buffer, 0, end-start, start);
} finally {
await file.close();
} And soon with typescript 5.5 beta: await using file = await open(this.path, "r");
const chunk = await file.read(buffer, 0, end-start, start); anyway, just passing notes, will leave it up to you folks :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm not opposed to this (an alternative would be to document how to simply start a local webserver from where your files are)
Thanks @coyotte508 for the suggestion. I ended up copying
Otherwise, for now, it works fine on both node & browser. Feel free to tell me if you have other ideas. |
regarding conflicts: I think you can remove |
@ngxson merged it 🚀 Would you mind adding a section on how to load locally in the readme https://github.com/huggingface/huggingface.js/blob/main/packages/gguf/README.md#usage ? Thanks a lot ! |
@mishig25 Sure, thanks for reminding, I totally forgot that. |
Follow up #655 and #656 (comment) Added some examples on how to use local file + strictly typed --------- Co-authored-by: Julien Chaumond <[email protected]> Co-authored-by: Mishig <[email protected]>
Being able to load a local gguf file can be useful when we want to debug a gguf file.
Without this PR, this ability could be done by using file-fetch. However, that won't work with big models, since the whole file is loaded into RAM.
This PR add a new
RangeViewLocalFile
internal class that extendsRangeView
. It redirects calls tofetchChunk()
tofs.createReadStream
with the appropriate byte range. This allows the library to read specific chunk from a local file.For security reason, this ability is locked under
localFile: boolean
param. By default, it is disabled (i.e. when this library is run on hub backend, this param is disabled if unspecified)gguf.spec.ts