Codeprocastinator/optimized-tinyllama-covalent
0119
1#!/usr/bin/env python32import sys3from pathlib import Path4 5import numpy as np6 7# Necessary to load the local gguf package8sys.path.insert(0, str(Path(__file__).parent.parent))9 10from gguf import GGUFWriter # noqa: E40211 12 13# Example usage:14def writer_example() -> None:15 # Example usage with a file16 gguf_writer = GGUFWriter("example.gguf", "llama")17 18 gguf_writer.add_block_count(12)19 gguf_writer.add_uint32("answer", 42) # Write a 32-bit integer20 gguf_writer.add_float32("answer_in_float", 42.0) # Write a 32-bit float21 gguf_writer.add_custom_alignment(64)22 23 tensor1 = np.ones((32,), dtype=np.float32) * 100.024 tensor2 = np.ones((64,), dtype=np.float32) * 101.025 tensor3 = np.ones((96,), dtype=np.float32) * 102.026 27 gguf_writer.add_tensor("tensor1", tensor1)28 gguf_writer.add_tensor("tensor2", tensor2)29 gguf_writer.add_tensor("tensor3", tensor3)30 31 gguf_writer.write_header_to_file()32 gguf_writer.write_kv_data_to_file()33 gguf_writer.write_tensors_to_file()34 35 gguf_writer.close()36 37 38if __name__ == '__main__':39 writer_example()40 