1
- import { describe , expect , it } from "vitest" ;
1
+ import { beforeAll , describe , expect , it } from "vitest" ;
2
+ import type { GGUFParseOutput } from "./gguf" ;
2
3
import { GGMLQuantizationType , gguf , ggufAllShards , parseGgufShardFilename } from "./gguf" ;
3
4
import fs from "node:fs" ;
4
5
@@ -12,8 +13,19 @@ const URL_V1 =
12
13
"https://huggingface.co/tmadge/testing/resolve/66c078028d1ff92d7a9264a1590bc61ba6437933/tinyllamas-stories-260k-f32.gguf" ;
13
14
const URL_SHARDED_GROK =
14
15
"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" ;
15
17
16
18
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
+
17
29
it ( "should parse a llama2 7b" , async ( ) => {
18
30
const { metadata, tensorInfos } = await gguf ( URL_LLAMA ) ;
19
31
@@ -228,16 +240,10 @@ describe("gguf", () => {
228
240
} ) ;
229
241
230
242
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
241
247
} ) ;
242
248
243
249
it ( "should detect sharded gguf filename" , async ( ) => {
0 commit comments