(activations_path: str, output_path: str, solved_list: list[int], vram_capacity: int)
| 51 | ) |
| 52 | |
| 53 | def 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 |
no test coverage detected