-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gguf: better type usage #655
Merged
Merged
Changes from 4 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e061017
refactor typing + usage
ngxson 9a9e771
correct optional fields
ngxson 6d704bc
add non-strict & strict typing mode
ngxson 8767726
lint & format
ngxson c2afbdc
cast between strict & nonStrict
ngxson 5f547dd
style nits
ngxson 31bac8b
refactor options
ngxson 74e8cfd
Merge branch 'main' into xsn/gguf_type_usage
ngxson 8c1bce0
format
ngxson 2e62e41
fix CI
ngxson a2250d3
fix CI (2)
ngxson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { describe, it } from "vitest"; | ||
import type { GGUFStrictType, GGUFMetadata, GGUFNonStrictType } from "./types"; | ||
|
||
describe("gguf-types", () => { | ||
it("GGUFNonStrictType should be correct (at compile time)", async () => { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const model: GGUFMetadata<GGUFNonStrictType> = null as any; | ||
model.kv_count = 123n; | ||
model.abc = 456; // PASS, because it can be anything | ||
}); | ||
|
||
it("GGUFStrictType should be correct (at compile time)", async () => { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const model: GGUFMetadata<GGUFStrictType> = 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; | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use
// @ts-expect-error
instead of// @ts-ignore
in general(no need for eslint-disable this way)
Here I think you can change
const metadata: GGUFMetadata
toconst metadata: GGUFMetadata<GGUFType.NON_STRICT>
to remove the error (not sure if it's the best fix)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 31bac8b