Skip to content

Commit

Permalink
added tests for gguf-v3
Browse files Browse the repository at this point in the history
  • Loading branch information
biw committed Oct 31, 2023
1 parent cab539a commit ea63c17
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type MetadataBaseValue = string | number | bigint | boolean
type MetadataArray = MetadataBaseValue[]
type MetadataValue = MetadataBaseValue | MetadataArray

type Version = 1 | 2
type Version = 1 | 2 | 3
const isVersion = (version: number): version is Version =>
version === 1 || version === 2 || version === 3

Expand Down Expand Up @@ -134,6 +134,7 @@ const readVersionedSize = async (
value = BigInt(n.value)
break
}
case 3:
case 2: {
const n = await readUint64(fd)
if (n.error) return n
Expand Down
112 changes: 111 additions & 1 deletion test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const fetchPartialFile = async (url: string, start: number, end: number) => {
}

describe('gguf', () => {
it(
test(
'Llama-2-7b-Chat-GGUF ',
async () => {
const file = await fetchPartialFile(
Expand Down Expand Up @@ -68,4 +68,114 @@ describe('gguf', () => {
},
1000 * 30,
)

test(
'Nous-Capybara-7B-v1.9-GGUF',
async () => {
const file = await fetchPartialFile(
'https://huggingface.co/TheBloke/Nous-Capybara-7B-v1.9-GGUF/resolve/main/nous-capybara-7b-v1.9.Q4_K_M.gguf',
0,
// 10mb
1024 * 1024 * 10,
)

const fileName = path.join(
__dirname,
'models',
'nous-capybara-7b-v1.9.Q4_K_M.gguf',
)

await writeFile(fileName, Buffer.from(file))

const { error, metadata } = await gguf(fileName)

expect(error).toBe(undefined)
expect(metadata).not.toBe(undefined)
if (!metadata) return // for types

expect(metadata.general.architecture).toBe('llama')
if (!isLlamaMetadata(metadata)) return // for types

expect(metadata.llama).toBeTruthy()

expect(metadata).toEqual({
general: {
architecture: 'llama',
file_type: 'MOSTLY_Q4_K_M',
name: 'nousresearch_nous-capybara-7b-v1.9',
quantization_version: 2,
},
llama: {
attention: {
head_count: 32,
head_count_kv: 8,
layer_norm_rms_epsilon: 0.000009999999747378752,
},
context_length: 32768,
embedding_length: 4096,
feed_forward_length: 14336,
rope: {
dimension_count: 128,
freq_base: 10000,
},
},
})
},
1000 * 30,
)

test(
'Xwin-MLewd-7B-V0.2-GGUF',
async () => {
const file = await fetchPartialFile(
'https://huggingface.co/TheBloke/Xwin-MLewd-7B-V0.2-GGUF/resolve/main/xwin-mlewd-7b-v0.2.Q4_K_M.gguf',
0,
// 10mb
1024 * 1024 * 10,
)

const fileName = path.join(
__dirname,
'models',
'xwin-mlewd-7b-v0.2.Q4_K_M.gguf',
)

await writeFile(fileName, Buffer.from(file))

const { error, metadata } = await gguf(fileName)

expect(error).toBe(undefined)
expect(metadata).not.toBe(undefined)
if (!metadata) return // for types

expect(metadata.general.architecture).toBe('llama')
if (!isLlamaMetadata(metadata)) return // for types

expect(metadata.llama).toBeTruthy()

expect(metadata).toEqual({
general: {
architecture: 'llama',
file_type: 'MOSTLY_Q4_K_M',
name: 'LLaMA v2',
quantization_version: 2,
},
llama: {
attention: {
head_count: 32,
head_count_kv: 32,
layer_norm_rms_epsilon: 0.000009999999747378752,
},
context_length: 4096,
embedding_length: 4096,
feed_forward_length: 11008,
rope: {
dimension_count: 128,
freq_base: 10000,
},
},
})
},
1000 * 30,
)
})

0 comments on commit ea63c17

Please sign in to comment.