#!/usr/bin/env python3 """ Export PocketPal-compatible Qwen3.5 GGUFs (Q4_K_M, Q5_K_M, Q8_0) for Solace-2.5-2B using llama.cpp pinned to b12292 with `--no-mtp`. Using b12292 --no-mtp ensures `qwen35.block_count=24` with zero missing `blk.24.*` MTP tensors and clean split tensor packing matching unsloth/Qwen3.5-2B-GGUF for PocketPal AI (llama.rn 0.13.0-rc.11) and llama.cpp / Ollama runtimes. """ import argparse import glob import os import subprocess def sh(cmd, cwd=None): print(f"+ {cmd}", flush=True) subprocess.run(cmd, shell=True, check=True, cwd=cwd) def main(): ap = argparse.ArgumentParser() ap.add_argument("--hf-dir", default="/content/ckpt25/solace_25_2b_final") ap.add_argument("--out-dir", default="/content/gguf25") ap.add_argument("--llama-dir", default="/content/llama_b12292") ap.add_argument("--quants", nargs="+", default=["Q4_K_M", "Q5_K_M", "Q8_0"]) args = ap.parse_args() os.makedirs(args.out_dir, exist_ok=True) if not os.path.exists(args.llama_dir): sh(f"git clone --depth 1 --branch b12292 https://github.com/ggml-org/llama.cpp.git {args.llama_dir}") sh("cmake -B build -DGGML_CUDA=OFF", cwd=args.llama_dir) sh("cmake --build build --config Release -j2 --target llama-quantize llama-completion", cwd=args.llama_dir) sh("pip install -q gguf sentencepiece protobuf") bf16_gguf = os.path.join(args.out_dir, "Solace-2.5-2B-BF16.gguf") sh( f"python3 {args.llama_dir}/convert_hf_to_gguf.py " f"{args.hf_dir} --outfile {bf16_gguf} --outtype bf16 --no-mtp" ) # Verify GGUF metadata and tensor count before quantizing sh( "python3 - <<'PY'\n" "from gguf import GGUFReader\n" f"r = GGUFReader({bf16_gguf!r})\n" "print('GGUF tensor_count:', len(r.tensors))\n" "for key in ['general.architecture', 'qwen35.block_count', 'qwen35.nextn_predict_layers']:\n" " if key in r.fields:\n" " f = r.fields[key]\n" " print(key, '=', f.parts[-1] if f.parts else f)\n" "assert 'qwen35.nextn_predict_layers' not in r.fields, 'Unexpected MTP layer present'\n" "assert len(r.tensors) == 320, f'Expected 320 tensors, got {len(r.tensors)}'\n" "PY" ) qbin = os.path.join(args.llama_dir, "build/bin/llama-quantize") cli = os.path.join(args.llama_dir, "build/bin/llama-completion") for q in args.quants: out_file = os.path.join(args.out_dir, f"Solace-2.5-2B-{q}.gguf") sh(f"{qbin} {bf16_gguf} {out_file} {q}") print(f"Quantized {out_file} ({os.path.getsize(out_file)/1e9:.2f} GB)", flush=True) # Remove intermediate BF16 to save space before HF upload os.remove(bf16_gguf) # Smoke-test Q4_K_M using b12292 llama-completion q4 = os.path.join(args.out_dir, "Solace-2.5-2B-Q4_K_M.gguf") prompt = "<|im_start|>user\nWho are you and who created you?<|im_end|>\n<|im_start|>assistant\n\n\n\n\n" out = subprocess.check_output( f"{cli} -m {q4} -p {prompt!r} -n 120 --temp 0.0 --no-warmup", shell=True, text=True, stderr=subprocess.STDOUT, ) print("=== GGUF Q4_K_M Smoke Test (b12292) ===") print(out[-1200:]) if __name__ == "__main__": main()