sedweave-7b / export_gguf.sh
asterbraid's picture
Sedweave 7B: 59.5% dev and 64.9% frozen correctness with GGUF, Ollama and CPU benchmarks
a55876e verified
Raw History Blame Contribute Delete
2.49 kB
#!/bin/bash
set -euo pipefail
MODEL_DIR=$1
OUTPUT_DIR=$2
BASENAME=${3:-sedweave-0.5b}
VENV=/tmp/sedweave-venv
python3 -m venv --system-site-packages "$VENV"
"$VENV/bin/pip" install -q --upgrade 'transformers>=4.46,<5' 'gguf>=0.14' 'sentencepiece'
if [ ! -d /tmp/llama.cpp ]; then
git clone --depth 1 https://github.com/ggml-org/llama.cpp.git /tmp/llama.cpp
fi
cmake -S /tmp/llama.cpp -B /tmp/llama.cpp/build -DGGML_NATIVE=OFF -DLLAMA_CURL=OFF -DCMAKE_BUILD_TYPE=Release
cmake --build /tmp/llama.cpp/build --target llama-quantize llama-completion -j 8
mkdir -p "$OUTPUT_DIR"
COMPAT_MODEL="$OUTPUT_DIR/hf-model"
cp -a "$MODEL_DIR" "$COMPAT_MODEL"
python3 - "$COMPAT_MODEL/tokenizer_config.json" <<'PY'
import json
import sys
from pathlib import Path
path = Path(sys.argv[1])
config = json.loads(path.read_text(encoding="utf-8"))
if isinstance(config.get("extra_special_tokens"), list):
config["extra_special_tokens"] = {}
path.write_text(json.dumps(config, indent=2) + "\n", encoding="utf-8")
PY
MODEL_DIR="$COMPAT_MODEL"
"$VENV/bin/python" /tmp/llama.cpp/convert_hf_to_gguf.py "$MODEL_DIR" --outtype f16 --outfile "$OUTPUT_DIR/${BASENAME}.f16.gguf"
/tmp/llama.cpp/build/bin/llama-quantize "$OUTPUT_DIR/${BASENAME}.f16.gguf" "$OUTPUT_DIR/${BASENAME}.Q8_0.gguf" Q8_0
/tmp/llama.cpp/build/bin/llama-quantize "$OUTPUT_DIR/${BASENAME}.f16.gguf" "$OUTPUT_DIR/${BASENAME}.Q4_K_M.gguf" Q4_K_M
rm "$OUTPUT_DIR/${BASENAME}.f16.gguf"
"$VENV/bin/python" - "$MODEL_DIR" <<'PY'
import sys
from pathlib import Path
from transformers import AutoTokenizer
from sedweave.prompts import messages
tokenizer = AutoTokenizer.from_pretrained(sys.argv[1])
prompt = tokenizer.apply_chat_template(messages("Replace every occurrence of amber with delta.", "amber birch\n"), tokenize=False, add_generation_prompt=True)
Path("/tmp/sedweave-gguf-prompt.txt").write_text(prompt, encoding="utf-8")
PY
/tmp/llama.cpp/build/bin/llama-completion -m "$OUTPUT_DIR/${BASENAME}.Q4_K_M.gguf" -f /tmp/sedweave-gguf-prompt.txt -n 64 --temp 0 -no-cnv > "$OUTPUT_DIR/gguf-smoke.txt" 2>&1
"$VENV/bin/python" - "$OUTPUT_DIR/gguf-smoke.txt" <<'PY'
import sys
from pathlib import Path
output = Path(sys.argv[1]).read_text(encoding="utf-8")
if "s/amber/delta/" not in output:
raise SystemExit("GGUF smoke generation did not contain the expected substitution")
PY
git -C /tmp/llama.cpp rev-parse HEAD > "$OUTPUT_DIR/llama-cpp-commit.txt"
rm -rf "$COMPAT_MODEL"
(cd "$OUTPUT_DIR" && sha256sum *.gguf > SHA256SUMS)
ls -lh "$OUTPUT_DIR"