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

Function read_gguf_file

utils/generate-dummy-bitnet-model.py:990–1017  ·  view source on GitHub ↗

Reads and prints key-value pairs and tensor information from a GGUF file in an improved format. Parameters: - gguf_file_path: Path to the GGUF file.

(gguf_file_path)

Source from the content-addressed store, hash-verified

988 logger.info(f"Model successfully exported to '{fname_out}'")
989
990def read_gguf_file(gguf_file_path):
991 """
992 Reads and prints key-value pairs and tensor information from a GGUF file in an improved format.
993
994 Parameters:
995 - gguf_file_path: Path to the GGUF file.
996 """
997
998 reader = GGUFReader(gguf_file_path)
999
1000 # List all key-value pairs in a columnized format
1001 print("Key-Value Pairs:") # noqa: NP100
1002 max_key_length = max(len(key) for key in reader.fields.keys())
1003 for key, field in reader.fields.items():
1004 value = field.parts[field.data[0]]
1005 print(f"{key:{max_key_length}} : {value}") # noqa: NP100
1006 print("----") # noqa: NP100
1007
1008 # List all tensors
1009 print("Tensors:") # noqa: NP100
1010 tensor_info_format = "{:<30} | Shape: {:<15} | Size: {:<12} | Quantization: {}"
1011 print(tensor_info_format.format("Tensor Name", "Shape", "Size", "Quantization")) # noqa: NP100
1012 print("-" * 80) # noqa: NP100
1013 for tensor in reader.tensors:
1014 shape_str = "x".join(map(str, tensor.shape))
1015 size_str = str(tensor.n_elements)
1016 quantization_str = tensor.tensor_type.name
1017 print(tensor_info_format.format(tensor.name, shape_str, size_str, quantization_str)) # noqa: NP100
1018
1019def parse_args() -> argparse.Namespace:
1020 parser = argparse.ArgumentParser(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected