(input_dir_or_checkpoint: str, output_file: str)
| 109 | |
| 110 | |
| 111 | def convert_weights(input_dir_or_checkpoint: str, output_file: str) -> None: |
| 112 | try: |
| 113 | sd = load_checkpoint_from_pytorch_model(input_dir_or_checkpoint) |
| 114 | print("Converting checkpoint...") |
| 115 | sd = phi_4_hf_to_meta(sd) |
| 116 | except FileNotFoundError: |
| 117 | checkpointer = FullModelHFCheckpointer( |
| 118 | checkpoint_dir=input_dir_or_checkpoint, |
| 119 | checkpoint_files=[ |
| 120 | "model-00001-of-00002.safetensors", |
| 121 | "model-00002-of-00002.safetensors", |
| 122 | ], |
| 123 | output_dir=".", |
| 124 | model_type="PHI4", |
| 125 | ) |
| 126 | print("Loading checkpoint from directory...") |
| 127 | sd = checkpointer.load_checkpoint() |
| 128 | sd = sd["model"] |
| 129 | print("Converting checkpoint...") |
| 130 | sd = phi_4_tune_to_meta(sd) |
| 131 | |
| 132 | print("Saving checkpoint...") |
| 133 | torch.save(sd, output_file) |
| 134 | print("Done.") |
| 135 | |
| 136 | |
| 137 | def main(): |
no test coverage detected