MCPcopy Create free account
hub / github.com/microsoft/BitNet / write_all

Method write_all

utils/convert-ms-to-gguf-bitnet.py:1314–1344  ·  view source on GitHub ↗
(
        fname_out: Path, ftype: GGMLFileType, params: Params, model: LazyModel, vocab: BaseVocab, svocab: gguf.SpecialVocab,
        concurrency: int = DEFAULT_CONCURRENCY, endianess: gguf.GGUFEndian = gguf.GGUFEndian.LITTLE,
        pad_vocab: bool = False,
    )

Source from the content-addressed store, hash-verified

1312
1313 @staticmethod
1314 def write_all(
1315 fname_out: Path, ftype: GGMLFileType, params: Params, model: LazyModel, vocab: BaseVocab, svocab: gguf.SpecialVocab,
1316 concurrency: int = DEFAULT_CONCURRENCY, endianess: gguf.GGUFEndian = gguf.GGUFEndian.LITTLE,
1317 pad_vocab: bool = False,
1318 ) -> None:
1319 check_vocab_size(params, vocab, pad_vocab=pad_vocab)
1320
1321 of = OutputFile(fname_out, endianess=endianess)
1322
1323 if 'bitnet' in of.gguf.arch:
1324 svocab.chat_template = "{% for message in messages %}{% if loop.first %}{{ bos_token }}{% endif %}{% if message['role'] == 'user' %}{{ 'Human: ' + message['content'] + '\\n\\nBITNETAssistant: ' + eos_token }}{% elif message['role'] == 'assistant' %}{{ message['content'] + eos_token }}{% endif %}{% endfor %}"
1325
1326 # meta data
1327 of.add_meta_arch(params)
1328 if isinstance(vocab, Vocab):
1329 of.add_meta_vocab(vocab)
1330 of.add_meta_special_vocab(svocab)
1331 else: # NoVocab
1332 of.gguf.add_tokenizer_model(vocab.tokenizer_model)
1333
1334 # tensor info
1335 for name, lazy_tensor in model.items():
1336 of.add_tensor_info(name, lazy_tensor)
1337
1338 of.write_meta()
1339 of.write_tensor_info()
1340
1341 # tensor data
1342 of.write_tensor_data(ftype, model, concurrency)
1343
1344 of.close()
1345
1346
1347def pick_output_type(model: LazyModel, output_type_str: str | None) -> GGMLFileType:

Callers 1

mainFunction · 0.45

Calls 10

add_meta_archMethod · 0.95
add_meta_vocabMethod · 0.95
add_tensor_infoMethod · 0.95
write_metaMethod · 0.95
write_tensor_infoMethod · 0.95
write_tensor_dataMethod · 0.95
closeMethod · 0.95
check_vocab_sizeFunction · 0.70
OutputFileClass · 0.70

Tested by

no test coverage detected