MCPcopy Create free account
hub / github.com/Pints-AI/1.5-Pints / main

Function main

tokenizer/convert/convert.py:1377–1465  ·  view source on GitHub ↗
(args_in: list[str] | None = None)

Source from the content-addressed store, hash-verified

1375
1376
1377def main(args_in: list[str] | None = None) -> None:
1378 output_choices = ["f32", "f16"]
1379 if np.uint32(1) == np.uint32(1).newbyteorder("<"):
1380 # We currently only support Q8_0 output on little endian systems.
1381 output_choices.append("q8_0")
1382 parser = argparse.ArgumentParser(description="Convert a LLaMA model to a GGML compatible file")
1383 parser.add_argument("--dump", action="store_true", help="don't convert, just show what's in the model")
1384 parser.add_argument("--dump-single", action="store_true", help="don't convert, just show what's in a single model file")
1385 parser.add_argument("--vocab-only", action="store_true", help="extract only the vocab")
1386 parser.add_argument("--outtype", choices=output_choices, help="output format - note: q8_0 may be very slow (default: f16 or f32 based on input)")
1387 parser.add_argument("--vocab-dir", type=Path, help="directory containing tokenizer.model, if separate from model file")
1388 parser.add_argument("--vocab-type", help="vocab types to try in order, choose from 'spm', 'bpe', 'hfft' (default: spm,hfft)", default="spm,hfft")
1389 parser.add_argument("--outfile", type=Path, help="path to write to; default: based on input")
1390 parser.add_argument("model", type=Path, help="directory containing model file, or model file itself (*.pth, *.pt, *.bin)")
1391 parser.add_argument("--ctx", type=int, help="model training context (default: based on input)")
1392 parser.add_argument("--concurrency", type=int, help=f"concurrency used for conversion (default: {DEFAULT_CONCURRENCY})", default=DEFAULT_CONCURRENCY)
1393 parser.add_argument("--big-endian", action="store_true", help="model is executed on big endian machine")
1394 parser.add_argument("--pad-vocab", action="store_true", help="add pad tokens when model vocab expects more than tokenizer metadata provides")
1395 parser.add_argument("--skip-unknown", action="store_true", help="skip unknown tensor names instead of failing")
1396
1397 args = parser.parse_args(args_in)
1398
1399 if args.dump_single:
1400 model_plus = lazy_load_file(args.model)
1401 do_dump_model(model_plus)
1402 return
1403
1404 if not args.vocab_only:
1405 model_plus = load_some_model(args.model)
1406 else:
1407 model_plus = ModelPlus(model = {}, paths = [args.model / 'dummy'], format = 'none', vocab = None)
1408
1409 if args.dump:
1410 do_dump_model(model_plus)
1411 return
1412 endianess = gguf.GGUFEndian.LITTLE
1413 if args.big_endian:
1414 endianess = gguf.GGUFEndian.BIG
1415
1416 params = Params.load(model_plus)
1417 if params.n_ctx == -1:
1418 if args.ctx is None:
1419 raise Exception("The model doesn't have a context size, and you didn't specify one with --ctx\n"
1420 "Please specify one with --ctx:\n"
1421 " - LLaMA v1: --ctx 2048\n"
1422 " - LLaMA v2: --ctx 4096\n")
1423 params.n_ctx = args.ctx
1424
1425 if args.outtype:
1426 params.ftype = {
1427 "f32": GGMLFileType.AllF32,
1428 "f16": GGMLFileType.MostlyF16,
1429 "q8_0": GGMLFileType.MostlyQ8_0,
1430 }[args.outtype]
1431
1432 print(f"params = {params}")
1433
1434 model_parent_path = model_plus.paths[0].parent

Callers 1

convert.pyFile · 0.70

Calls 13

load_vocabMethod · 0.95
lazy_load_fileFunction · 0.85
do_dump_modelFunction · 0.85
load_some_modelFunction · 0.85
ModelPlusClass · 0.85
VocabFactoryClass · 0.85
convert_model_namesFunction · 0.85
pick_output_typeFunction · 0.85
convert_to_output_typeFunction · 0.85
default_outfileFunction · 0.85
write_vocab_onlyMethod · 0.80
write_allMethod · 0.80

Tested by

no test coverage detected