(fname_out: Path, ftype: GGMLFileType, params: Params, model: LazyModel, vocab: Vocab, svocab: gguf.SpecialVocab, concurrency: int = DEFAULT_CONCURRENCY, endianess: gguf.GGUFEndian = gguf.GGUFEndian.LITTLE)
| 914 | |
| 915 | @staticmethod |
| 916 | def write_all(fname_out: Path, ftype: GGMLFileType, params: Params, model: LazyModel, vocab: Vocab, svocab: gguf.SpecialVocab, concurrency: int = DEFAULT_CONCURRENCY, endianess: gguf.GGUFEndian = gguf.GGUFEndian.LITTLE) -> None: |
| 917 | check_vocab_size(params, vocab) |
| 918 | |
| 919 | of = OutputFile(fname_out, params.arch, endianess=endianess) |
| 920 | |
| 921 | # meta data |
| 922 | of.add_meta_arch(params) |
| 923 | of.add_meta_vocab(vocab) |
| 924 | of.add_meta_special_vocab(svocab) |
| 925 | |
| 926 | # tensor info |
| 927 | for name, lazy_tensor in model.items(): |
| 928 | of.add_tensor_info(name, lazy_tensor) |
| 929 | |
| 930 | of.write_meta() |
| 931 | of.write_tensor_info() |
| 932 | |
| 933 | # tensor data |
| 934 | ndarrays_inner = bounded_parallel_map(OutputFile.do_item, model.items(), concurrency = concurrency) |
| 935 | if ftype == GGMLFileType.MostlyQ8_0: |
| 936 | ndarrays = bounded_parallel_map(OutputFile.maybe_do_quantize, ndarrays_inner, concurrency = concurrency, max_workers = concurrency, use_processpool_executor = True) |
| 937 | else: |
| 938 | ndarrays = map(OutputFile.maybe_do_quantize, ndarrays_inner) |
| 939 | |
| 940 | start = time.time() |
| 941 | for i, ((name, lazy_tensor), ndarray) in enumerate(zip(model.items(), ndarrays)): |
| 942 | elapsed = time.time() - start |
| 943 | size = ' x '.join(f"{dim:6d}" for dim in lazy_tensor.shape) |
| 944 | padi = len(str(len(model))) |
| 945 | print(f"[{i+1:{padi}d}/{len(model)}] Writing tensor {name:38s} | size {size:16} | type {lazy_tensor.data_type.name:4} | T+{int(elapsed):4}") |
| 946 | of.gguf.write_tensor_data(ndarray) |
| 947 | |
| 948 | of.close() |
| 949 | |
| 950 | def pick_output_type(model: LazyModel, output_type_str: str | None) -> GGMLFileType: |
| 951 | wq_type = model[gguf.TENSOR_NAMES[gguf.MODEL_TENSOR.ATTN_Q].format(bid=0)+".weight"].data_type |
no test coverage detected