()
| 413 | |
| 414 | |
| 415 | def main(): |
| 416 | parser = get_argument_parser() |
| 417 | args = parser.parse_args() |
| 418 | args_sanity_checks(args) |
| 419 | if args.dataset is None: |
| 420 | exp_name = f"{get_exp_name(args.config)}_{args.precision}_dummy_cal_{args.num_chunks}_chunks" |
| 421 | else: |
| 422 | exp_name = ( |
| 423 | f"{get_exp_name(args.config)}_{args.precision}_{args.num_chunks}_chunks" |
| 424 | ) |
| 425 | if args.platform == "DX4": |
| 426 | platform_b = b"mt6991" |
| 427 | elif args.platform == "DX3": |
| 428 | platform_b = b"mt6989" |
| 429 | else: |
| 430 | raise ValueError( |
| 431 | f"Platform should be either DX3 or DX4, but got {args.platform}" |
| 432 | ) |
| 433 | print_args(args, exp_name) |
| 434 | |
| 435 | config, weight_dir, tokenizer_class, chunk_class = resolve_model_classes( |
| 436 | args.config |
| 437 | ) |
| 438 | tokenizer = tokenizer_class.from_pretrained(weight_dir) |
| 439 | if args.preformatter is not None: |
| 440 | preformatter = Preformatter(args.preformatter) |
| 441 | |
| 442 | head_dim = int(config.head_dim) |
| 443 | |
| 444 | # Evenly distribute the layers across chunks. |
| 445 | num_blocks_per_chunk = [ |
| 446 | (config.num_hidden_layers // args.num_chunks) |
| 447 | + (i < (config.num_hidden_layers % args.num_chunks)) |
| 448 | for i in range(args.num_chunks) |
| 449 | ] |
| 450 | check_all_chunks_same_num_layer(num_blocks_per_chunk) # noqa: F405 |
| 451 | |
| 452 | output_folder = os.path.join("pte", exp_name) |
| 453 | |
| 454 | # Load all collected checkpoint files into one giant state_dict |
| 455 | state_dict = load_checkpoints(weight_dir) |
| 456 | |
| 457 | dump_embedding_lut_for_cmdline(weight_dir, state_dict, config) |
| 458 | |
| 459 | export_shapes, max_num_token, max_cache_size = get_export_shapes(args.shapes) |
| 460 | print(f"export shapes: {export_shapes}") |
| 461 | print(f"Max Num Token: {max_num_token}") |
| 462 | print(f"Max Cache Size: {max_cache_size}") |
| 463 | |
| 464 | if args.dataset is not None: |
| 465 | embedding_layer = get_embedding_layer(config, weight_dir, state_dict) |
| 466 | |
| 467 | # Instantiate model chunks |
| 468 | print("Instantiating submodels") |
| 469 | models = [] |
| 470 | for chunk_idx, num_blocks in enumerate(num_blocks_per_chunk): |
| 471 | chunk = chunk_class( |
| 472 | config, |
no test coverage detected