Skip to content

Commit

Permalink
Merge branch 'vb/add-cp-library' of https://github.com/huggingface/hu…
Browse files Browse the repository at this point in the history
…ggingface.js into vb/add-cp-library
  • Loading branch information
Vaibhavs10 committed Aug 27, 2024
2 parents 1228688 + 847c264 commit 860ab6e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/gguf/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@huggingface/gguf",
"packageManager": "pnpm@8.10.5",
"version": "0.1.9",
"version": "0.1.10",
"description": "a GGUF parser that works on remotely hosted files",
"repository": "https://github.com/huggingface/huggingface.js.git",
"publishConfig": {
Expand Down
9 changes: 7 additions & 2 deletions packages/gguf/src/gguf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export { GGUF_QUANT_DESCRIPTIONS } from "./quant-descriptions";

export const RE_GGUF_FILE = /\.gguf$/;
export const RE_GGUF_SHARD_FILE = /^(?<prefix>.*?)-(?<shard>\d{5})-of-(?<total>\d{5})\.gguf$/;
const PARALLEL_DOWNLOADS = 20;

export interface GgufShardFileInfo {
prefix: string;
Expand Down Expand Up @@ -401,8 +402,13 @@ export async function ggufAllShards(
*/
fetch?: typeof fetch;
additionalFetchHeaders?: Record<string, string>;
parallelDownloads?: number;
}
): Promise<{ shards: GGUFParseOutput[]; parameterCount: number }> {
const parallelDownloads = params?.parallelDownloads ?? PARALLEL_DOWNLOADS;
if (parallelDownloads < 1) {
throw new TypeError("parallelDownloads must be greater than 0");
}
const ggufShardFileInfo = parseGgufShardFilename(url);
if (ggufShardFileInfo) {
const total = parseInt(ggufShardFileInfo.total);
Expand All @@ -413,10 +419,9 @@ export async function ggufAllShards(
urls.push(`${prefix}-${shardIdx.toString().padStart(5, "0")}-of-${total.toString().padStart(5, "0")}.gguf`);
}

const PARALLEL_DOWNLOADS = 20;
const shards = await promisesQueue(
urls.map((shardUrl) => () => gguf(shardUrl, { ...params, computeParametersCount: true })),
PARALLEL_DOWNLOADS
parallelDownloads
);
return {
shards,
Expand Down

0 comments on commit 860ab6e

Please sign in to comment.