(
fname_out: Path, ftype: GGMLFileType, params: Params, model: LazyModel, vocab: Vocab, svocab: gguf.SpecialVocab,
concurrency: int = DEFAULT_CONCURRENCY, endianess: gguf.GGUFEndian = gguf.GGUFEndian.LITTLE,
pad_vocab: bool = False,
)
| 1113 | |
| 1114 | @staticmethod |
| 1115 | def write_all( |
| 1116 | fname_out: Path, ftype: GGMLFileType, params: Params, model: LazyModel, vocab: Vocab, svocab: gguf.SpecialVocab, |
| 1117 | concurrency: int = DEFAULT_CONCURRENCY, endianess: gguf.GGUFEndian = gguf.GGUFEndian.LITTLE, |
| 1118 | pad_vocab: bool = False, |
| 1119 | ) -> None: |
| 1120 | check_vocab_size(params, vocab, pad_vocab=pad_vocab) |
| 1121 | |
| 1122 | of = OutputFile(fname_out, endianess=endianess) |
| 1123 | |
| 1124 | # meta data |
| 1125 | of.add_meta_arch(params) |
| 1126 | of.add_meta_vocab(vocab) |
| 1127 | of.add_meta_special_vocab(svocab) |
| 1128 | |
| 1129 | # tensor info |
| 1130 | for name, lazy_tensor in model.items(): |
| 1131 | of.add_tensor_info(name, lazy_tensor) |
| 1132 | |
| 1133 | of.write_meta() |
| 1134 | of.write_tensor_info() |
| 1135 | |
| 1136 | # tensor data |
| 1137 | ndarrays_inner = bounded_parallel_map(OutputFile.do_item, model.items(), concurrency = concurrency) |
| 1138 | if ftype == GGMLFileType.MostlyQ8_0: |
| 1139 | ndarrays = bounded_parallel_map( |
| 1140 | OutputFile.maybe_do_quantize, ndarrays_inner, concurrency=concurrency, max_workers=concurrency, |
| 1141 | use_processpool_executor=True, |
| 1142 | ) |
| 1143 | else: |
| 1144 | ndarrays = map(OutputFile.maybe_do_quantize, ndarrays_inner) |
| 1145 | |
| 1146 | start = time.time() |
| 1147 | for i, ((name, lazy_tensor), ndarray) in enumerate(zip(model.items(), ndarrays)): |
| 1148 | elapsed = time.time() - start |
| 1149 | size = ' x '.join(f"{dim:6d}" for dim in lazy_tensor.shape) |
| 1150 | padi = len(str(len(model))) |
| 1151 | print( |
| 1152 | 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}" |
| 1153 | ) |
| 1154 | of.gguf.write_tensor_data(ndarray) |
| 1155 | |
| 1156 | of.close() |
| 1157 | |
| 1158 | |
| 1159 | def pick_output_type(model: LazyModel, output_type_str: str | None) -> GGMLFileType: |
no test coverage detected