Skip to content

Commit e4d2d87

Browse files
author
Mishig
authored
[gguf] RE_GGUF_SHARD_FILE (#601)
I need on the frontend to detect which gguf file is sharded or not cc: @ggerganov @madgetr
1 parent 2aedeb5 commit e4d2d87

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

packages/gguf/src/gguf.spec.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it } from "vitest";
2-
import { GGMLQuantizationType, gguf } from "./gguf";
2+
import { GGMLQuantizationType, RE_GGUF_SHARD_FILE, gguf } from "./gguf";
33

44
const URL_LLAMA = "https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGUF/resolve/191239b/llama-2-7b-chat.Q2_K.gguf";
55
const URL_MISTRAL_7B =
@@ -220,4 +220,13 @@ describe("gguf", () => {
220220
dtype: GGMLQuantizationType.F32,
221221
});
222222
});
223+
224+
it("should detect sharded gguf filename", async () => {
225+
const ggufPath = "grok-1/grok-1-q4_0-00003-of-00009.gguf"; // https://huggingface.co/ggml-org/models/blob/fcf344adb9686474c70e74dd5e55465e9e6176ef/grok-1/grok-1-q4_0-00003-of-00009.gguf
226+
const match = ggufPath.match(RE_GGUF_SHARD_FILE);
227+
228+
expect(RE_GGUF_SHARD_FILE.test(ggufPath)).toEqual(true);
229+
expect(match?.[1]).toEqual("00003");
230+
expect(match?.[2]).toEqual("00009");
231+
});
223232
});

packages/gguf/src/gguf.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export type { MetadataBaseValue, MetadataValue, Version, GGUFMetadata, GGUFTenso
55
export { GGUFValueType, GGMLQuantizationType } from "./types";
66

77
export const RE_GGUF_FILE = /\.gguf$/;
8+
export const RE_GGUF_SHARD_FILE = /-(\d{5})-of-(\d{5})\.gguf$/;
89

910
const isVersion = (version: number): version is Version => version === 1 || version === 2 || version === 3;
1011

0 commit comments

Comments
 (0)