mirror of
https://github.com/ggerganov/llama.cpp
synced 2026-03-06 15:19:40 +01:00
This commit updates the causal model verification script to use the
CONVERTED_MODEL environment variable instead of using the MODEL_PATH
(the original model path) as the basis for the converted model file
name.
The motivation for this that currently if the converted model file name
differs from the original model directory/name the verification script
will look for the wrong .bin file that was generating when running
the converted model.
This similar to the change made for the embeddings models script in
Commit db81d5ec4b ("model-conversion :
use CONVERTED_EMBEDDING_MODEL for embedding_verify_logits (#18079)"),
but we also verify the embeddings of for causal models as well.
47 lines
1.2 KiB
Bash
Executable File
47 lines
1.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
MODEL_PATH="${1:-"$MODEL_PATH"}"
|
|
MODEL_NAME="${2:-$(basename "$MODEL_PATH")}"
|
|
|
|
CONVERTED_MODEL_PATH="${1:-"$CONVERTED_MODEL"}"
|
|
CONVERTED_MODEL_NAME="${2:-$(basename "$CONVERTED_MODEL_PATH" ".gguf")}"
|
|
|
|
if [ -t 0 ]; then
|
|
CPP_EMBEDDINGS="data/llamacpp-${CONVERTED_MODEL_NAME}-embeddings.bin"
|
|
else
|
|
# Process piped JSON data and convert to binary (matching logits.cpp format)
|
|
TEMP_FILE=$(mktemp /tmp/tmp.XXXXXX.binn)
|
|
python3 -c "
|
|
import json
|
|
import sys
|
|
import struct
|
|
|
|
data = json.load(sys.stdin)
|
|
|
|
# Flatten all embeddings completely
|
|
flattened = []
|
|
for item in data:
|
|
embedding = item['embedding']
|
|
for token_embedding in embedding:
|
|
flattened.extend(token_embedding)
|
|
|
|
print(f'Total embedding values: {len(flattened)}', file=sys.stderr)
|
|
|
|
# Write as binary floats - matches logitc.cpp fwrite format
|
|
with open('$TEMP_FILE', 'wb') as f:
|
|
for value in flattened:
|
|
f.write(struct.pack('f', value))
|
|
"
|
|
CPP_EMBEDDINGS="$TEMP_FILE"
|
|
trap "rm -f $TEMP_FILE" EXIT
|
|
fi
|
|
|
|
python scripts/utils/semantic_check.py --model-path $MODEL_PATH \
|
|
--python-embeddings data/pytorch-${MODEL_NAME}-embeddings.bin \
|
|
--cpp-embeddings $CPP_EMBEDDINGS \
|
|
--prompt "Hello world today" \
|
|
--causal
|
|
|