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

Function export_split

powerinfer-py/powerinfer/export_split.py:53–75  ·  view source on GitHub ↗
(activations_path: str, output_path: str, solved_list: list[int], vram_capacity: int)

Source from the content-addressed store, hash-verified

51 )
52
53def export_split(activations_path: str, output_path: str, solved_list: list[int], vram_capacity: int):
54 predictors = load_activation_weights(Path(activations_path)) # predictor => activation acount
55 gguf_out = GGUFWriter(output_path, "generic.gpu_index")
56 for i, (activation, selected_count) in enumerate(zip(predictors, solved_list)):
57 append_gpu_idx(gguf_out, i, activation, selected_count)
58
59 # set kvs
60 gguf_out.add_block_count(len(predictors))
61 # TODO: better to save the actual capacity that split neurons require
62 gguf_out.add_uint64(gguf.Keys.Split.VRAM_CAPACITY, vram_capacity)
63
64 gguf_out.write_header_to_file()
65 gguf_out.write_kv_data_to_file()
66 gguf_out.write_tensors_to_file()
67 gguf_out.close()
68
69 # post-process: write another unique file header to distinguish from the origianl GGUF file
70 with open(output_path, "r+b") as fout:
71 POWERINFER_MAGIC = int.from_bytes(b"PWRI", "little")
72 fout.write(struct.pack("<I", POWERINFER_MAGIC))
73 fout.write(struct.pack("<I", 3))
74
75 print(f"exported GPU index to {output_path}")
76

Callers 1

__main__.pyFile · 0.90

Calls 11

add_block_countMethod · 0.95
add_uint64Method · 0.95
write_header_to_fileMethod · 0.95
write_kv_data_to_fileMethod · 0.95
write_tensors_to_fileMethod · 0.95
closeMethod · 0.95
GGUFWriterClass · 0.90
load_activation_weightsFunction · 0.85
append_gpu_idxFunction · 0.85
printFunction · 0.50
writeMethod · 0.45

Tested by

no test coverage detected