You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Follow up #640
Ref comments:
-
#640 (review)
by @julien-c suggests using a check `metadata["general.architecture"]
=== ...` to select the correct type
-
#640 (comment)
by @coyotte508 suggests using less generic but more verbose code
The type system introduce in this PR allows type-checking at both
compile time & runtime:
```ts
const model: GGUFMetadata<GGUFType.STRICT> = null as any;
if (model["general.architecture"] === "whisper") {
model["encoder.whisper.block_count"] = 0;
// @ts-expect-error because it must be a number
model["encoder.whisper.block_count"] = "abc";
}
if (model["tokenizer.ggml.model"] === undefined) {
// @ts-expect-error because it's undefined
model["tokenizer.ggml.eos_token_id"] = 1;
}
if (model["tokenizer.ggml.model"] === "gpt2") {
// @ts-expect-error because it must be a number
model["tokenizer.ggml.eos_token_id"] = undefined;
model["tokenizer.ggml.eos_token_id"] = 1;
}
if (model["general.architecture"] === "mamba") {
model["mamba.ssm.conv_kernel"] = 0;
// @ts-expect-error because it must be a number
model["mamba.ssm.conv_kernel"] = "abc";
}
if (model["general.architecture"] === "llama") {
// @ts-expect-error llama does not have ssm.* keys
model["mamba.ssm.conv_kernel"] = 0;
}
```
Type checks can be disable with `GGUFMetadata<GGUFType.NON_STRICT>`
0 commit comments