Skip to content

refresh code and readme to be more inline with ampere-inferencing-benchmarking repo #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 22 additions & 29 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,32 @@
# Running benchmark
![Ampere AI](https://ampereaimodelzoo.s3.eu-central-1.amazonaws.com/ampere_logo_®_primary_stacked_rgb.png "Ampere AI")
# Wrapper for multi-process / batched benchmark of llama.cpp

This benchmarking tool runs multi-process, throughput-oriented benchmark of Ampere optimized llama.cpp using arbitrary model(s) provided by the user.
The benchmarking script spawns multiple parallel streams of token generation using llama.cpp and provides user with aggregate metrics of both prompt eval and token generation stages.
Underneath, the _batched-bench_ script from upstream llama.cpp project is being used in an unaltered form.
The script orchestrates the benchmark inside Docker container from the outside environment, **therefore this script should not be run inside Docker container.**

## Setup
Few dependencies need to be installed first. On Debian-based systems you can use the setup script.
## ARM
Instructions assume you have a debian based OS
```bash
cd benchmarks
sudo bash setup_deb.sh
# vim download_models.sh # uncomment / add models you want to download
bash download_models.sh
# vim run.sh # modify run.sh (provide the name of the docker image, threads, batch sizes etc.)
nohup sudo bash run.sh
```

## Downloading models
Any GGUF model is expected to work, if you experience troubles running your network of choice please raise an [issue](https://github.com/AmpereComputingAI/llama.cpp/issues/new/choose).
Benchmarking script expects models to be placed under _**llama.cpp/benchmarks/models**_ dir.
## x86
Instructions assume you have a debian based OS
```bash
mkdir -p models
huggingface-cli download QuantFactory/Meta-Llama-3-8B-Instruct-GGUF Meta-Llama-3-8B-Instruct.Q8_0.gguf --local-dir models --local-dir-use-symlinks False
```
cd benchmarks
sudo bash setup_deb.sh
# vim download_models.sh # uncomment / add models you want to download
bash download_models.sh

## Benchmark
Provide run.py Python script with following arguments:
- -m, filename(s) of model(s) that should be available under _**llama.cpp/benchmarks/models**_ directory, multiple models can be provided
- -t, threadpool(s) per single process, e.g., if there are 20 threads available on the system, if -t 10 is provided, 2 parallel processes will be spawned, each using 10 threads;
multiple threadpools can be provided and they will be treated as separate cases to benchmark
- -b, batch size(s) to benchmark, meaning separate token generation streams handled as a single batch; multiple batch sizes can be provided and they will be treated as separate cases to benchmark
- -p, prompt size(s) to benchmark, size of an input prompt; multiple prompt sizes can be provided and they will be treated as separate cases to benchmark
- -r, thread-range, e.g., on an 80-thread system, it should be input as 0-79, unless user wants to use just a subset of available threads, say 16-63 (48 threads indexed 16<>63)
```bash
python3 run.py -m Meta-Llama-3-8B-Instruct.Q8_0.gguf -t 10 16 32 40 64 80 -b 1 2 4 8 16 32 64 -p 512 -r 0-79
cd utils
sudo docker build -t llama_x86 .
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think user has to specify dockerfile with -f arg?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is only one Dockerfile in the directory, so it will build only that one without -f.

cd ..
# vim run.sh # modify run.sh (provide the name of the docker image, threads, batch sizes etc.)
nohup sudo bash run.sh
```

## Quick run on 80t OCI A1 system
```bash
bash setup_deb.sh # works on Debian-based systems
bash download_models.sh # uncomment preferred models in the file, by default llama3 q8_0 will be downloaded
bash run.sh # modify to adjust number of threads available and other parameters
```
Benchmarks will take few hours in default setting, going over various combinations of n_proc x n_threads x batch_size x prompt_size x model_size 😵‍💫
After they complete you will find .csv files with results in the benchmarks directory of this repo.
27 changes: 15 additions & 12 deletions benchmarks/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,18 @@ def get_file_dir():
return os.path.dirname(os.path.realpath(__file__))


def docker_init():
tag = "amperecomputingai/llama.cpp:1.2.3"
if subprocess.run(
["docker", "pull", tag]).returncode != 0:
print("Docker pull process failed!")
sys.exit(1)
def docker_init(docker_image):
# if subprocess.run(
# ["docker", "pull", docker_image]).returncode != 0:
# print("Docker pull process failed!")
# sys.exit(1)
container_name = "llama_benchmark"
subprocess.run(["docker", "rm", "-f", container_name])
memory = (psutil.virtual_memory().total >> 30) - 30 # leave 30GB for OS
assert memory > 10, "less than 10GB of memory available on the system for llama.cpp"
if subprocess.run(
["docker", "run", "--privileged=true", "--name", container_name, "-d", "-m", f"{str(memory)}g", "-v",
f"{get_file_dir()}:/runner", "--entrypoint", "/bin/bash", "-it", tag]).returncode != 0:
f"{get_file_dir()}:/runner", "--entrypoint", "/bin/bash", "-it", docker_image]).returncode != 0:
print("Docker run process failed!")
sys.exit(1)
return container_name
Expand Down Expand Up @@ -52,7 +51,8 @@ def docker_start():
def benchmark(docker_container_name, args):
num_available_threads = len(parse_threads_range(args.threads_range))
if num_available_threads < max(args.num_threads):
print(f"Requested number of threads ({max(args.num_threads)}) exceeds threads available ({num_available_threads})")
print(
f"Requested number of threads ({max(args.num_threads)}) exceeds threads available ({num_available_threads})")
sys.exit(1)

docker_restart(docker_container_name)
Expand All @@ -63,11 +63,11 @@ def benchmark(docker_container_name, args):
num_processes = int(num_available_threads / num_threads)
case = f"{num_processes} x {num_threads} [proc x threads], bs = {batch_size}"
print(f"\nRunning {case}")

cmd = (f"cd /runner; python3 utils/benchmark.py -m models/{model} -n {str(num_processes)} "
f"-t {str(num_threads)} -b {str(batch_size)} -p {str(prompt_size)} -r {args.threads_range}")
cmd = ["docker", "exec", "-i", docker_container_name, "bash", "-c", cmd]

print(f"Executing: {' '.join(cmd)}")
success = False
start = time.time()
Expand All @@ -90,6 +90,9 @@ def parse_args():
parser.add_argument("-m", "--model_names",
type=str, required=True, nargs="+",
help="model names, e.g. 'Meta-Llama-3-8B-Instruct.Q8_0.gguf'")
parser.add_argument("-d", "--docker_image",
type=str, required=True,
help="Docker image to use for benchmarking")
parser.add_argument("-t", "--num_threads",
type=int, required=True, nargs="+",
help="number of threads per process to use")
Expand All @@ -111,8 +114,8 @@ def parse_args():

def main():
args = parse_args()
benchmark(docker_init(), args)
benchmark(docker_init(args.docker_image), args)


if __name__ == "__main__":
main()
main()
2 changes: 1 addition & 1 deletion benchmarks/run.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set -e

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets remove run.sh and instead describe args of run.py for user to set

python3 run.py -m Meta-Llama-3-8B-Instruct.Q8_0.gguf -t 10 16 32 40 64 80 -b 1 2 4 8 16 32 64 -p 512 -r 0-79
python3 run.py -m Meta-Llama-3-8B-Instruct.Q8_0.gguf -t 8 12 16 24 48 -b 1 2 4 8 16 32 -p 128 -r 0-47 -d amperecomputingai/llama.cpp:latest
rm -f /tmp/log_power
7 changes: 7 additions & 0 deletions benchmarks/utils/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM ubuntu:22.04
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update -y && apt-get install -y build-essential cmake vim wget git numactl libopenblas-dev pkg-config python3 python3-pip libnuma-dev clang
RUN mkdir /workspace
RUN mkdir /llm
RUN cd /workspace && git clone -b b3615 https://github.com/ggerganov/llama.cpp.git && cd llama.cpp && make -j && mv /workspace/llama.cpp/llama-batched-bench /llm/
RUN rm -R /workspace
6 changes: 3 additions & 3 deletions benchmarks/utils/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ def main():
for n in range(args.num_processes):
logfile = f"{logs_dir}/log_{n}"
cmd = ["numactl", f"--physcpubind={gen_threads_config(args.num_threads, n)}",
"/llm/batched-bench", args.model, str(args.kv_cache), "2048", "512", "0", "0", "0", str(args.prompt_size), str(TOKENS),
str(args.batch_size), str(args.num_threads)]
"/llm/llama-batched-bench", "-m", args.model, "-c", str(args.kv_cache), "-b", "2048", "-ub", "512", "-npp", str(args.prompt_size), "-ntg", str(TOKENS),
"-npl", str(args.batch_size), "-t", str(args.num_threads), "-tb", str(args.num_threads), "-td", str(args.num_threads)]
current_subprocesses.append(
subprocess.Popen(cmd, stdout=open(logfile, 'wb'), stderr=open(logfile, 'wb')))
start = time.time()
Expand All @@ -130,4 +130,4 @@ def main():


if __name__ == "__main__":
main()
main()