MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / write_all

Method write_all

convert-dense.py:916–948  ·  view source on GitHub ↗
(fname_out: Path, ftype: GGMLFileType, params: Params, model: LazyModel, vocab: Vocab, svocab: gguf.SpecialVocab, concurrency: int = DEFAULT_CONCURRENCY, endianess: gguf.GGUFEndian = gguf.GGUFEndian.LITTLE)

Source from the content-addressed store, hash-verified

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
950def 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

Callers 1

mainFunction · 0.45

Calls 15

add_meta_archMethod · 0.95
add_meta_vocabMethod · 0.95
add_tensor_infoMethod · 0.95
write_metaMethod · 0.95
write_tensor_infoMethod · 0.95
closeMethod · 0.95
mapFunction · 0.85
strFunction · 0.85
timeMethod · 0.80
joinMethod · 0.80
check_vocab_sizeFunction · 0.70

Tested by

no test coverage detected