Datasets:
File size: 2,410 Bytes
d548d67 14690b9 d548d67 14690b9 d548d67 14690b9 d548d67 e6a8d26 d548d67 14690b9 d548d67 e6a8d26 14690b9 e6a8d26 d548d67 14690b9 d548d67 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | #!/usr/bin/env python3
"""Export joemaddalone/ffmpeg-nl2cmd-0.8B to GGUF Q8_0 WITHOUT the MTP tail
(--no-mtp), verify the tensor map, and upload to the model repo.
The previous export kept the MTP speculative-decode block as blk.24.*, which
ollama's llama.cpp rejects ('blk.24.attn_norm.weight not found').
"""
import os
import subprocess
import sys
REPO = "joemaddalone/ffmpeg-nl2cmd-0.8B"
WORK = "/workspace"
def sh(cmd, **kw):
print("+", cmd, flush=True)
return subprocess.run(cmd, shell=True, **kw)
sh("pip install -q --no-cache-dir gguf numpy 'torch<3' transformers sentencepiece protobuf || true")
sh("apt-get update -qq && apt-get install -y -qq git >/dev/null 2>&1 || true")
if not os.path.isdir(f"{WORK}/llama.cpp"):
sh(f"git clone --depth 1 https://github.com/ggml-org/llama.cpp {WORK}/llama.cpp")
from huggingface_hub import snapshot_download, HfApi # noqa: E402
local = snapshot_download(REPO)
print("model at", local, flush=True)
out = f"{WORK}/ffmpeg-nl2cmd-0.8B-q8_0.gguf"
ok = False
for extra in (["--no-mtp"], ["--no-mtp", "--disable-vision"]):
r = sh(f"python {WORK}/llama.cpp/convert_hf_to_gguf.py {local} --outfile {out} --outtype q8_0 " +
" ".join(extra))
if r.returncode == 0 and os.path.exists(out):
print("converted with extra args:", extra, flush=True)
ok = True
break
print("conversion failed with extra args:", extra, flush=True)
if not ok:
print("CONVERT_FAILED (all fallbacks)", flush=True)
sys.exit(1)
# --- verify tensor map: no MTP block (blk.24), last real block complete ---
from gguf import GGUFReader # noqa: E402
reader = GGUFReader(out)
names = [t.name for t in reader.tensors]
blocks = sorted({int(n.split(".")[1]) for n in names if n.startswith("blk.")})
mtp = [n for n in names if n.startswith("blk.24.")]
print(f"tensors: {len(names)} | blocks: {blocks[0]}..{blocks[-1]}", flush=True)
if mtp:
print("MTP tensors still present:", mtp[:5], flush=True)
sys.exit(1)
if f"blk.{blocks[-1]}.attn_norm.weight" not in names:
print("last block incomplete!", flush=True)
sys.exit(1)
print(f"VERIFIED: no MTP block, blk.{blocks[-1]} complete", flush=True)
print("gguf size:", os.path.getsize(out), flush=True)
api = HfApi()
api.upload_file(path_or_fileobj=out, path_in_repo="ffmpeg-nl2cmd-0.8B-q8_0.gguf",
repo_id=REPO, repo_type="model")
print("UPLOADED", flush=True)
|