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

Method write_all

convert.py:949–981  ·  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

947
948 @staticmethod
949 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:
950 check_vocab_size(params, vocab)
951
952 of = OutputFile(fname_out, params.arch, endianess=endianess)
953
954 # meta data
955 of.add_meta_arch(params)
956 of.add_meta_vocab(vocab)
957 of.add_meta_special_vocab(svocab)
958
959 # tensor info
960 for name, lazy_tensor in model.items():
961 of.add_tensor_info(name, lazy_tensor)
962
963 of.write_meta()
964 of.write_tensor_info()
965
966 # tensor data
967 ndarrays_inner = bounded_parallel_map(OutputFile.do_item, model.items(), concurrency = concurrency)
968 if ftype == GGMLFileType.MostlyQ8_0:
969 ndarrays = bounded_parallel_map(OutputFile.maybe_do_quantize, ndarrays_inner, concurrency = concurrency, max_workers = concurrency, use_processpool_executor = True)
970 else:
971 ndarrays = map(OutputFile.maybe_do_quantize, ndarrays_inner)
972
973 start = time.time()
974 for i, ((name, lazy_tensor), ndarray) in enumerate(zip(model.items(), ndarrays)):
975 elapsed = time.time() - start
976 size = ' x '.join(f"{dim:6d}" for dim in lazy_tensor.shape)
977 padi = len(str(len(model)))
978 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}")
979 of.gguf.write_tensor_data(ndarray)
980
981 of.close()
982
983def pick_output_type(model: LazyModel, output_type_str: str | None) -> GGMLFileType:
984 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