Skip to content

Commit 33e0b1b

Browse files
authored
gguf: test local file with big metadata (#777)
Ref comment: #767 (comment) This file have 32MB of just metadata (no tensor), can be useful for testing or benchmarking. Due to its large size, running the download process inside the test case may cause timeout (so I moved it to `beforeAll`)
1 parent 0027a40 commit 33e0b1b

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

packages/gguf/src/gguf.spec.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { describe, expect, it } from "vitest";
1+
import { beforeAll, describe, expect, it } from "vitest";
2+
import type { GGUFParseOutput } from "./gguf";
23
import { GGMLQuantizationType, gguf, ggufAllShards, parseGgufShardFilename } from "./gguf";
34
import fs from "node:fs";
45

@@ -12,8 +13,19 @@ const URL_V1 =
1213
"https://huggingface.co/tmadge/testing/resolve/66c078028d1ff92d7a9264a1590bc61ba6437933/tinyllamas-stories-260k-f32.gguf";
1314
const URL_SHARDED_GROK =
1415
"https://huggingface.co/Arki05/Grok-1-GGUF/resolve/ecafa8d8eca9b8cd75d11a0d08d3a6199dc5a068/grok-1-IQ3_XS-split-00001-of-00009.gguf";
16+
const URL_BIG_METADATA = "https://huggingface.co/ngxson/test_gguf_models/resolve/main/gguf_test_big_metadata.gguf";
1517

1618
describe("gguf", () => {
19+
beforeAll(async () => {
20+
// download the gguf for "load file" test, save to .cache directory
21+
if (!fs.existsSync(".cache")) {
22+
fs.mkdirSync(".cache");
23+
}
24+
const res = await fetch(URL_BIG_METADATA);
25+
const arrayBuf = await res.arrayBuffer();
26+
fs.writeFileSync(".cache/model.gguf", Buffer.from(arrayBuf));
27+
});
28+
1729
it("should parse a llama2 7b", async () => {
1830
const { metadata, tensorInfos } = await gguf(URL_LLAMA);
1931

@@ -228,16 +240,10 @@ describe("gguf", () => {
228240
});
229241

230242
it("should parse a local file", async () => {
231-
// download the file and save to .cache folder
232-
if (!fs.existsSync(".cache")) {
233-
fs.mkdirSync(".cache");
234-
}
235-
const res = await fetch(URL_V1);
236-
const arrayBuf = await res.arrayBuffer();
237-
fs.writeFileSync(".cache/model.gguf", Buffer.from(arrayBuf));
238-
239-
const { metadata } = await gguf(".cache/model.gguf", { allowLocalFile: true });
240-
expect(metadata).toMatchObject({ "general.name": "tinyllamas-stories-260k" });
243+
const parsedGguf = await gguf(".cache/model.gguf", { allowLocalFile: true });
244+
const { metadata } = parsedGguf as GGUFParseOutput<{ strict: false }>; // custom metadata arch, no need for typing
245+
expect(metadata["dummy.1"]).toBeDefined(); // first metadata in the list
246+
expect(metadata["dummy.32767"]).toBeDefined(); // last metadata in the list
241247
});
242248

243249
it("should detect sharded gguf filename", async () => {

0 commit comments

Comments
 (0)