()
| 17 | raise |
| 18 | |
| 19 | def main(): |
| 20 | if len(sys.argv) < 2: |
| 21 | script_name = Path(sys.argv[0]).name |
| 22 | print(f"Usage: python {script_name} <model-directory>") |
| 23 | sys.exit(1) |
| 24 | |
| 25 | model_dir_arg = sys.argv[1] |
| 26 | model_dir = Path(model_dir_arg).resolve() |
| 27 | |
| 28 | if not model_dir.is_dir(): |
| 29 | print(f"Error: Model directory '{model_dir}' not found or is not a directory.") |
| 30 | sys.exit(1) |
| 31 | |
| 32 | utils_dir = Path(__file__).parent.resolve() |
| 33 | project_root_dir = utils_dir.parent |
| 34 | |
| 35 | preprocess_script = utils_dir / "preprocess-huggingface-bitnet.py" |
| 36 | convert_script = utils_dir / "convert-ms-to-gguf-bitnet.py" |
| 37 | |
| 38 | llama_quantize_binary = project_root_dir / "build" / "bin" / "llama-quantize" |
| 39 | |
| 40 | input_file = model_dir / "model.safetensors" |
| 41 | input_backup_file = model_dir / "model.safetensors.backup" |
| 42 | preprocessed_output_file = model_dir / "model.safetensors" |
| 43 | |
| 44 | gguf_f32_output = model_dir / "ggml-model-f32-bitnet.gguf" |
| 45 | gguf_i2s_output = model_dir / "ggml-model-i2s-bitnet.gguf" |
| 46 | |
| 47 | if not preprocess_script.is_file(): |
| 48 | print(f"Error: Preprocess script not found at '{preprocess_script}'") |
| 49 | sys.exit(1) |
| 50 | if not convert_script.is_file(): |
| 51 | print(f"Error: Convert script not found at '{convert_script}'") |
| 52 | sys.exit(1) |
| 53 | if not llama_quantize_binary.is_file(): |
| 54 | print(f"Error: llama-quantize binary not found at '{llama_quantize_binary}'") |
| 55 | sys.exit(1) |
| 56 | |
| 57 | if not input_file.is_file(): |
| 58 | print(f"Error: Input safetensors file not found at '{input_file}'") |
| 59 | sys.exit(1) |
| 60 | |
| 61 | try: |
| 62 | print(f"Backing up '{input_file}' to '{input_backup_file}'") |
| 63 | if input_backup_file.exists(): |
| 64 | print(f"Warning: Removing existing backup file '{input_backup_file}'") |
| 65 | input_backup_file.unlink() |
| 66 | shutil.move(input_file, input_backup_file) |
| 67 | |
| 68 | print("Preprocessing huggingface checkpoint...") |
| 69 | cmd_preprocess = [ |
| 70 | sys.executable, |
| 71 | str(preprocess_script), |
| 72 | "--input", str(input_backup_file), |
| 73 | "--output", str(preprocessed_output_file) |
| 74 | ] |
| 75 | run_command(cmd_preprocess) |
| 76 |
no test coverage detected