This commit is contained in:
Jared Van Bortel 2023-11-09 20:59:59 -05:00
parent 7d3580d5b1
commit 5608cd8d89
2 changed files with 9 additions and 11 deletions

View file

@ -92,20 +92,16 @@ def convert_byteorder(reader: gguf.GGUFReader, args: argparse.Namespace) -> None
def main() -> None:
parser = argparse.ArgumentParser(description="Convert GGUF file byte order")
parser.add_argument(
"model",
type=str,
"model", type=str,
help="GGUF format model filename",
)
parser.add_argument(
"order",
type=str,
choices=['big','little','native'],
"order", type=str, choices=['big', 'little', 'native'],
help="Requested byte order",
)
parser.add_argument(
"--dry-run",
action="store_true",
help="Don't actually change anything"
"--dry-run", action="store_true",
help="Don't actually change anything",
)
args = parser.parse_args(None if len(sys.argv) > 1 else ["--help"])
print(f'* Loading: {args.model}')

View file

@ -17,7 +17,7 @@ def minimal_example(filename: str) -> None:
if field is None:
return
part_index = field.data[0]
field.parts[part_index][0] = 2 # Set tokenizer.ggml.bos_token_id to 2
field.parts[part_index][0] = 2 # Set tokenizer.ggml.bos_token_id to 2
#
# So what's this field.data thing? It's helpful because field.parts contains
# _every_ part of the GGUF field. For example, tokenizer.ggml.bos_token_id consists
@ -48,8 +48,10 @@ def set_metadata(reader: GGUFReader, args: argparse.Namespace) -> None:
# look like [GGUFValueType.ARRAY, GGUFValueType.UINT32]
handler = reader.gguf_scalar_to_np.get(field.types[0]) if field.types else None
if handler is None:
print(f'! This tool only supports changing simple values, {repr(args.key)} has unsupported type {field.types}',
file = sys.stderr)
print(
f'! This tool only supports changing simple values, {repr(args.key)} has unsupported type {field.types}',
file = sys.stderr,
)
sys.exit(1)
current_value = field.parts[field.data[0]][0]
new_value = handler(args.value)