File size: 1,986 Bytes
8262357
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/bin/bash
set -euo pipefail
MODEL_DIR=$1
OUTPUT_DIR=$2
VENV=/tmp/awkweave-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"
"$VENV/bin/python" /tmp/llama.cpp/convert_hf_to_gguf.py "$MODEL_DIR" --outtype f16 --outfile "$OUTPUT_DIR/awkweave-1.5b.f16.gguf"
/tmp/llama.cpp/build/bin/llama-quantize "$OUTPUT_DIR/awkweave-1.5b.f16.gguf" "$OUTPUT_DIR/awkweave-1.5b.Q8_0.gguf" Q8_0
/tmp/llama.cpp/build/bin/llama-quantize "$OUTPUT_DIR/awkweave-1.5b.f16.gguf" "$OUTPUT_DIR/awkweave-1.5b.Q4_K_M.gguf" Q4_K_M
rm "$OUTPUT_DIR/awkweave-1.5b.f16.gguf"
"$VENV/bin/python" - "$MODEL_DIR" <<'PY'
import sys
from pathlib import Path
from transformers import AutoTokenizer
from awkweave.prompts import messages
tokenizer = AutoTokenizer.from_pretrained(sys.argv[1])
prompt = tokenizer.apply_chat_template(messages("Print the last field of every input line.", "a 1\nb 2\n"), tokenize=False, add_generation_prompt=True)
Path("/tmp/awkweave-gguf-prompt.txt").write_text(prompt, encoding="utf-8")
PY
/tmp/llama.cpp/build/bin/llama-completion -m "$OUTPUT_DIR/awkweave-1.5b.Q4_K_M.gguf" -f /tmp/awkweave-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 "$NF" not in output:
    raise SystemExit("GGUF smoke generation did not contain the expected $NF program")
PY
git -C /tmp/llama.cpp rev-parse HEAD > "$OUTPUT_DIR/llama-cpp-commit.txt"
(cd "$OUTPUT_DIR" && sha256sum *.gguf > SHA256SUMS)
ls -lh "$OUTPUT_DIR"