Skip to content

Commit

Permalink
convert : auto-determine model name based on dir + scripts update
Browse files Browse the repository at this point in the history
  • Loading branch information
ggerganov committed Aug 24, 2023
1 parent 7694add commit 8f8c28e
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 135 deletions.
13 changes: 10 additions & 3 deletions convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ class Params:

ftype: Optional[GGMLFileType] = None

# path to the directory containing the model files
path_model: Optional['Path'] = None

@staticmethod
def find_n_mult(n_ff: int, n_embd: int) -> int:
# hardcoded magic range
Expand Down Expand Up @@ -231,6 +234,8 @@ def load(model_plus: 'ModelPlus') -> 'Params':
else:
params = Params.guessed(model_plus.model)

params.path_model = model_plus.paths[0].parent

return params


Expand Down Expand Up @@ -733,11 +738,13 @@ def __init__(self, fname_out: Path) -> None:
self.gguf = gguf.GGUFWriter(fname_out, gguf.MODEL_ARCH_NAMES[ARCH])

def add_meta_arch(self, params: Params) -> None:
ver = None
name = "LLaMA"
if (params.n_ctx == 4096):
ver = "v2"
name = "LLaMA v2"
if params.path_model:
name = str(params.path_model.parent).split('/')[-1]

self.gguf.add_name ("LLaMA" if ver == None else "LLaMA " + ver)
self.gguf.add_name (name)
self.gguf.add_context_length (params.n_ctx)
self.gguf.add_embedding_length (params.n_embd)
self.gguf.add_block_count (params.n_layer)
Expand Down
93 changes: 0 additions & 93 deletions scripts/perf-run-all.sh

This file was deleted.

39 changes: 0 additions & 39 deletions scripts/ppl-run-all.sh

This file was deleted.

27 changes: 27 additions & 0 deletions scripts/qnt-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

qnt=(q8_0 q6_k q5_k q5_1 q5_0 q4_k q4_1 q4_0 q3_k q2_k)
args=""

if [ -z "$1" ]; then
echo "usage: $0 <model> [qnt] [args]"
echo "default: $0 <model> \"${qnt[@]}\" \"${args}\""
exit 1
fi

if [ ! -z "$2" ]; then
qnt=($2)
fi

if [ ! -z "$3" ]; then
args="$3"
fi

model="$1"
out="../tmp/results-${model}"

mkdir -p ${out}

for q in ${qnt[@]}; do
time ./bin/quantize ../models/${model}/ggml-model-f16.gguf ../models/${model}/ggml-model-${q}.gguf ${q} 2>&1 ${args} | tee ${out}/qnt-${q}.txt
done
31 changes: 31 additions & 0 deletions scripts/run-all-perf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

qnt=(f16 q8_0 q6_k q5_k q5_1 q5_0 q4_k q4_1 q4_0 q3_k q2_k)
args="-ngl 999 -n 64 -p 512"

if [ -z "$1" ]; then
echo "usage: $0 <model> [qnt] [args]"
echo "default: $0 <model> \"${qnt[@]}\" \"${args}\""
exit 1
fi

if [ ! -z "$2" ]; then
qnt=($2)
fi

if [ ! -z "$3" ]; then
args="$3"
fi

model="$1"
out="../tmp/results-${model}"

mkdir -p ${out}

mstr=""

for q in ${qnt[@]}; do
mstr="${mstr} -m ../models/${model}/ggml-model-${q}.gguf"
done

./bin/llama-bench ${mstr} ${args} 2> /dev/null
27 changes: 27 additions & 0 deletions scripts/run-all-ppl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

qnt=(f16 q8_0 q6_k q5_k q5_1 q5_0 q4_k q4_1 q4_0 q3_k q2_k)
args="--no-mmap -ngl 999 -t 8"

if [ -z "$1" ]; then
echo "usage: $0 <model> [qnt] [args]"
echo "default: $0 <model> \"${qnt[@]}\" \"${args}\""
exit 1
fi

if [ ! -z "$2" ]; then
qnt=($2)
fi

if [ ! -z "$3" ]; then
args="$3"
fi

model="$1"
out="../tmp/results-${model}"

mkdir -p ${out}

for q in ${qnt[@]}; do
time ./bin/perplexity -m ../models/${model}/ggml-model-f16.gguf -f ./wiki.test.raw ${args} 2>&1 | tee ${out}/ppl-${q}.txt
done

0 comments on commit 8f8c28e

Please sign in to comment.