Spaces:
Running
Running
File size: 4,591 Bytes
0ed8124 21ad36a 0ed8124 c2b7fe3 0ed8124 21ad36a 0ed8124 c2b7fe3 0ed8124 21ad36a 0ed8124 c2b7fe3 55c2c6a 3fd9ca4 c3633b1 c2b7fe3 55c2c6a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | import { createHash } from 'node:crypto';
import { readFile } from 'node:fs/promises';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
const source = JSON.parse(await readFile(resolve(root, 'vendor/wllama-bonsai/SOURCE.json'), 'utf8'));
const readme = await readFile(resolve(root, 'README.md'), 'utf8');
if (source.wllamaRevision !== '912c18b75d4358c1405a64646b8dbe43a205943b') {
throw new Error(`Unexpected wllama revision: ${String(source.wllamaRevision)}`);
}
if (source.llamaCppRevision !== '00fa7cb284cbf133fc426733bd64238a3588a33e') {
throw new Error(`Unexpected llama.cpp revision: ${String(source.llamaCppRevision)}`);
}
if (source.schemaVersion !== 2 || !source.patchSet?.sha256 || !source.build?.dawnArchiveSha256) {
throw new Error('Vendored Bonsai wllama provenance is incomplete');
}
const patchBytes = await readFile(resolve(root, source.patchSet.path));
const patchDigest = createHash('sha256').update(patchBytes).digest('hex');
if (patchBytes.byteLength !== source.patchSet.bytes || patchDigest !== source.patchSet.sha256) {
throw new Error(`Bonsai wllama patch-set mismatch: ${patchDigest}`);
}
const readmeProvenance = [
['custom patch set', source.patchSet.sha256],
['custom ESM', source.files.find((file) => file.path === 'vendor/wllama-bonsai/esm/index.js')?.sha256],
['JSPI WASM', source.files.find((file) => file.path === 'public/wasm/wllama.wasm')?.sha256],
['compat WASM', source.files.find((file) => file.path === 'public/wasm/wllama-compat.wasm')?.sha256],
['compat worker', source.files.find((file) => file.path === 'public/wasm/wllama-compat.js')?.sha256],
];
for (const [label, digest] of readmeProvenance) {
if (!digest || !readme.includes(`- ${label}: \`${digest}\``)) {
throw new Error(`README provenance is stale or incomplete for ${label}`);
}
}
for (const file of source.files) {
const bytes = await readFile(resolve(root, file.path));
if (bytes.byteLength !== file.bytes) {
throw new Error(`Byte-size mismatch for ${file.path}: ${bytes.byteLength}`);
}
const digest = createHash('sha256').update(bytes).digest('hex');
if (digest !== file.sha256) {
throw new Error(`SHA-256 mismatch for ${file.path}: ${digest}`);
}
if (file.path.startsWith('public/')) {
const distPath = `dist/${file.path.slice('public/'.length)}`;
const distBytes = await readFile(resolve(root, distPath));
const distDigest = createHash('sha256').update(distBytes).digest('hex');
if (distBytes.byteLength !== file.bytes || distDigest !== file.sha256) {
throw new Error(`Checked-in production artifact mismatch for ${distPath}: ${distDigest}`);
}
}
console.log(`${file.path} ${digest}`);
}
const declarations = await readFile(resolve(root, 'vendor/wllama-bonsai/esm/types/types.d.ts'), 'utf8');
if (!declarations.includes('offload_token_embedding?: boolean')) {
throw new Error('Vendored Bonsai wllama declarations lack offload_token_embedding');
}
if (!declarations.includes('n_ubatch?: number')) {
throw new Error('Vendored Bonsai wllama declarations lack n_ubatch');
}
const wllamaDeclarations = await readFile(resolve(root, 'vendor/wllama-bonsai/esm/wllama.d.ts'), 'utf8');
if (!wllamaDeclarations.includes('forceCompat?: boolean')) {
throw new Error('Vendored Bonsai wllama declarations lack forceCompat');
}
const oaiDeclarations = await readFile(resolve(root, 'vendor/wllama-bonsai/esm/types/oai-compat.d.ts'), 'utf8');
if (!oaiDeclarations.includes('export interface ChatCompletionLogprob {\n id: number;')) {
throw new Error('Vendored Bonsai wllama declarations lack sampled token ids');
}
if (!oaiDeclarations.includes('return_progress?: boolean;')) {
throw new Error('Vendored Bonsai wllama declarations lack prompt-progress opt-in');
}
if (!oaiDeclarations.includes('export interface PromptProgress')) {
throw new Error('Vendored Bonsai wllama declarations lack prompt-progress payloads');
}
if (!oaiDeclarations.includes('prompt_progress?: PromptProgress;')) {
throw new Error('Vendored Bonsai wllama declarations do not expose streamed prompt progress');
}
const moduleSource = await readFile(resolve(root, 'vendor/wllama-bonsai/esm/index.js'), 'utf8');
if (!moduleSource.includes('n_ubatch: params.n_ubatch')) {
throw new Error('Vendored Bonsai wllama module does not forward n_ubatch');
}
if (!moduleSource.includes('const forceCompat = this.config.forceCompat === true')) {
throw new Error('Vendored Bonsai wllama module does not implement forceCompat');
}
|