Spaces:
Running
Running
Download tests/reference/mlc-export.test.ts from leventkoldas/botpsy-0.8b-web: direct link, hf CLI and curl.
- Browser
- Download file 2.41 kB
-
https://huggingface.co/spaces/leventkoldas/botpsy-0.8b-web/resolve/main/tests/reference/mlc-export.test.ts
- Command line
-
hf download hf://spaces/leventkoldas/botpsy-0.8b-web/tests/reference/mlc-export.test.ts
-
curl -L -o mlc-export.test.ts https://huggingface.co/spaces/leventkoldas/botpsy-0.8b-web/resolve/main/tests/reference/mlc-export.test.ts
2.41 kB
| import { createHash } from 'node:crypto'; | |
| import { existsSync, readFileSync } from 'node:fs'; | |
| import { join } from 'node:path'; | |
| import { describe, expect, it } from 'vitest'; | |
| const root = new URL('../..', import.meta.url).pathname; | |
| const dir = join(root, 'artifacts/botpsy-0.8b-mlc'); | |
| const manifestPath = join(dir, 'manifest.json'); | |
| const available = existsSync(manifestPath); | |
| describe.skipIf(!available)('BotPsy MLC export', () => { | |
| const manifest = available | |
| ? JSON.parse(readFileSync(manifestPath, 'utf8')) as { | |
| files: Record<string, { bytes: number; sha256: string }>; | |
| tensorCount: number; | |
| } | |
| : { files: {}, tensorCount: 0 }; | |
| const cache = available | |
| ? JSON.parse(readFileSync(join(dir, 'tensor-cache.json'), 'utf8')) as { | |
| metadata: { ParamSize: number; ParamBytes: number }; | |
| records: Array<{ | |
| dataPath: string; | |
| nbytes: number; | |
| md5sum: string; | |
| records: Array<{ name: string; shape: number[]; nbytes: number; byteOffset: number }>; | |
| }>; | |
| } | |
| : { metadata: { ParamSize: 0, ParamBytes: 0 }, records: [] }; | |
| it('matches the manifest hashes and sizes', () => { | |
| for (const [name, record] of Object.entries(manifest.files)) { | |
| if (name === 'manifest.json') continue; | |
| const bytes = readFileSync(join(dir, name)); | |
| expect(bytes.length, name).toBe(record.bytes); | |
| expect(createHash('sha256').update(bytes).digest('hex'), name).toBe(record.sha256); | |
| } | |
| }); | |
| it('packs every declared tensor inside its shard exactly once', () => { | |
| let records = 0; | |
| for (const shard of cache.records) { | |
| expect(createHash('md5').update(readFileSync(join(dir, shard.dataPath))).digest('hex')).toBe(shard.md5sum); | |
| const spans = shard.records.map((record) => ({ | |
| start: record.byteOffset, | |
| end: record.byteOffset + record.nbytes, | |
| name: record.name, | |
| })); | |
| spans.sort((a, b) => a.start - b.start); | |
| expect(spans[0]?.start).toBe(0); | |
| expect(spans.at(-1)?.end).toBe(shard.nbytes); | |
| for (let index = 1; index < spans.length; index++) { | |
| expect(spans[index]!.start, `${spans[index]!.name} overlaps ${spans[index - 1]!.name}`).toBe(spans[index - 1]!.end); | |
| } | |
| records += shard.records.length; | |
| } | |
| expect(records).toBe(manifest.tensorCount); | |
| expect(cache.metadata.ParamSize).toBe(manifest.tensorCount); | |
| }); | |
| }); | |