-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Generalize convert scripts #3838
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
4823b9b
Initial generic convert script
Galunid 2220124
Remove comments
Galunid 0ff2371
Make gguf_writer member of Model, rework tokenizer export
Galunid 8618b4e
Add [UNTESTED] Baichuan support
Galunid 989db34
Missing variable
Galunid 550b925
Missing variable
Galunid 443f7d5
Call add_tensor before write_* functions
Galunid 08918b7
MPT conversion fix
Galunid 3bb9844
Get rid of dumb print
Galunid 0afa75a
Add Falcon support
Galunid 94ba1db
Add Starcoder and Refact
Galunid 6f6856c
[Untested] Initial Persimmon support
Galunid b9c664a
Woops
Galunid 0743f7a
Fix variable
Galunid dc3115f
Add another alias to n_layers
Galunid b2ba44e
Flake8 fixes
Galunid c94df09
Rework tokenizer handling
Galunid 235acc1
Small refactor
Galunid f4b9a7e
Remove 'old' conversion scripts
Galunid 3ec89dc
Use 'IntEnum' instead of 'Enum'
Galunid 4fdd7cd
Review fixes, persimmon fixes
Galunid 8f31dc5
fix mypy errors
cebtenzzre 66ccd62
sort imports
cebtenzzre e9abcc9
fix linter complaints
cebtenzzre 007be85
model.py : add missing future import
cebtenzzre 03c9683
Restore support for RWForCausalLM
Galunid fd30850
Add big endian support
Galunid e64f4de
Revert "Remove 'old' conversion scripts" - needed for testing
Galunid 2120195
Yarn rope for baichuan
Galunid 087f88c
Rename convert-generic -> convert-hf-to-gguf
Galunid f7de892
Move util to gguf-py/gguf
Galunid 781bc54
Move everything to convert-hf-to-gguf.py
Galunid fefc3db
address review comments
cebtenzzre 648252e
Fix flake8 complaints
Galunid 05fb6f4
sort imports
cebtenzzre 7a3433b
store_true defaults to False, not None
Galunid 73780f5
Change ftype from int value to str value
Galunid 88b0d9e
Review fixes
Galunid b714883
Rename variable
Galunid 6a83bce
parse_args improvements
Galunid 2862d16
Remove outdated scripts
Galunid c79c358
Merge branch 'master' into generic-convert
Galunid 2789ad9
Fix import path
Galunid 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 hidden or 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,69 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from __future__ import annotations | ||
|
||
import os | ||
import sys | ||
from pathlib import Path | ||
|
||
if 'NO_LOCAL_GGUF' not in os.environ: | ||
sys.path.insert(1, str(Path(__file__).parent / 'gguf-py' / 'gguf')) | ||
|
||
import gguf | ||
import model | ||
import util | ||
|
||
args = util.parse_args() | ||
|
||
dir_model = args.model | ||
ftype = args.ftype | ||
if not dir_model.is_dir(): | ||
print(f'Error: {args.model} is not a directory', file = sys.stderr) | ||
sys.exit(1) | ||
|
||
# possible tensor data types | ||
# ftype == 0 -> float32 | ||
# ftype == 1 -> float16 | ||
|
||
# map from ftype to string | ||
ftype_str = ["f32", "f16"] | ||
|
||
if args.outfile is not None: | ||
fname_out = args.outfile | ||
else: | ||
# output in the same directory as the model by default | ||
fname_out = dir_model / f'ggml-model-{ftype_str[ftype]}.gguf' | ||
|
||
|
||
print("gguf: loading model " + dir_model.name) | ||
|
||
hparams = model.Model.load_hparams(dir_model) | ||
|
||
model_class = model.Model.from_model_architecture(hparams["architectures"][0]) | ||
model_instance = model_class(dir_model, ftype, fname_out) | ||
|
||
print("gguf: get model metadata") | ||
|
||
model_instance.set_gguf_parameters() | ||
|
||
# TOKENIZATION | ||
print("gguf: get tokenizer metadata") | ||
|
||
print("gguf: get gpt2 tokenizer vocab") | ||
|
||
model_instance.set_vocab() | ||
|
||
# write model | ||
print("gguf: write header") | ||
model_instance.gguf_writer.write_header_to_file() | ||
print("gguf: write metadata") | ||
model_instance.gguf_writer.write_kv_data_to_file() | ||
if not args.vocab_only: | ||
print("gguf: write tensors") | ||
model_instance.write_tensors() | ||
model_instance.gguf_writer.write_tensors_to_file() | ||
|
||
model_instance.gguf_writer.close() | ||
|
||
print(f"gguf: model successfully exported to '{fname_out}'") | ||
print("") |
Galunid marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
This file contains hidden or 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,23 @@ | ||
import argparse | ||
|
||
from pathlib import Path | ||
|
||
def parse_args() -> argparse.Namespace: | ||
parser = argparse.ArgumentParser(description="Convert a stablelm model to a GGML compatible file") | ||
parser.add_argument( | ||
"--vocab-only", action="store_true", | ||
help="extract only the vocab", | ||
) | ||
parser.add_argument( | ||
"--outfile", type=Path, | ||
help="path to write to; default: based on input", | ||
) | ||
parser.add_argument( | ||
"model", type=Path, | ||
help="directory containing model file, or model file itself (*.bin)", | ||
) | ||
parser.add_argument( | ||
"ftype", type=int, choices=[0, 1], default=1, nargs='?', | ||
help="output format - use 0 for float32, 1 for float16", | ||
) | ||
return parser.parse_args() |
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.
Uh oh!
There was an error while loading. Please reload this page.