char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
911b437f2
char/aliceai-t5-moe
1#!/usr/bin/env python3 2import sys 3from pathlib import Path 4 5import numpy as np 6 7# Necessary to load the local gguf package 8sys .path .insert (0 ,str (Path (__file__ ).parent .parent )) 9 10from gguf import GGUFWriter # noqa: E402 11 12 13# Example usage: 14def writer_example ()-> None : 15# Example usage with a file 16gguf_writer = GGUFWriter ("example.gguf" ,"llama" ) 17 18gguf_writer .add_block_count (12 ) 19gguf_writer .add_uint32 ("answer" ,42 )# Write a 32-bit integer 20gguf_writer .add_float32 ("answer_in_float" ,42.0 )# Write a 32-bit float 21gguf_writer .add_custom_alignment (64 ) 22 23tensor1 = np .ones ((32 ,),dtype = np .float32 )* 100.0 24tensor2 = np .ones ((64 ,),dtype = np .float32 )* 101.0 25tensor3 = np .ones ((96 ,),dtype = np .float32 )* 102.0 26 27gguf_writer .add_tensor ("tensor1" ,tensor1 ) 28gguf_writer .add_tensor ("tensor2" ,tensor2 ) 29gguf_writer .add_tensor ("tensor3" ,tensor3 ) 30 31gguf_writer .write_header_to_file () 32gguf_writer .write_kv_data_to_file () 33gguf_writer .write_tensors_to_file () 34 35gguf_writer .close () 36 37 38if __name__ == '__main__' : 39writer_example ()