Datasets:
Download scripts/gguf_export.py from joemaddalone/ffmpeg-nl2cmd-clean: direct link, hf CLI and curl.
- Browser
- Download file 2.41 kB
-
https://huggingface.co/datasets/joemaddalone/ffmpeg-nl2cmd-clean/resolve/main/scripts/gguf_export.py
- Command line
-
hf download hf://datasets/joemaddalone/ffmpeg-nl2cmd-clean/scripts/gguf_export.py
-
curl -L -o gguf_export.py https://huggingface.co/datasets/joemaddalone/ffmpeg-nl2cmd-clean/resolve/main/scripts/gguf_export.py
2.41 kB
| #!/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) | |