report-review

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

quantize_gguf.py (1439B)


      1 import os
      2 import subprocess
      3 
      4 # --- 設定 ---
      5 INPUT_GGUF = "mistral_typst_merged.f16.gguf"
      6 OUTPUT_GGUF = "mistral_typst_quantized.gguf"
      7 # ⚠️ quantize.exe をプロジェクトルートまたはパスの通った場所にあると仮定
      8 QUANTIZE_TOOL = "llama-b7247-bin-win-cuda-12.4-x64/llama-quantize.exe"
      9 
     10 
     11 def run_quantization():
     12     if not os.path.exists(QUANTIZE_TOOL):
     13         print(f"Error: 量子化ツール '{QUANTIZE_TOOL}' が見つかりません。")
     14         print("llama.cpp リポジトリから一度だけビルドして取得してください。")
     15         return
     16 
     17     if not os.path.exists(INPUT_GGUF):
     18         print(
     19             f"Error: 入力ファイル '{INPUT_GGUF}' が見つかりません。F16変換を先に実行してください。"
     20         )
     21         return
     22 
     23     print(f"\n⚛️ GGUF (F16) を Q4_K_M に量子化中...")
     24 
     25     try:
     26         subprocess.run(
     27             [
     28                 QUANTIZE_TOOL,
     29                 INPUT_GGUF,
     30                 OUTPUT_GGUF,
     31                 "q4_k_m",  # 推奨される量子化手法
     32             ],
     33             check=True,
     34         )
     35         print(f"✅ 量子化成功: {OUTPUT_GGUF}")
     36 
     37     except subprocess.CalledProcessError as e:
     38         print(f"❌ 量子化失敗: {e}")
     39 
     40 
     41 if __name__ == "__main__":
     42     # 最初に convert_merge.py を実行し、F16 GGUF を作成してからこれを実行
     43     run_quantization()