Felipe97/llama-cpp-compiled
01.1k
1#!/bin/bash2 3# MIT license4# Copyright (C) 2024 Intel Corporation5# SPDX-License-Identifier: MIT6 7Help() {8 cat << EOF9Usage: $(basename "$0") [OPTIONS]10 11This script processes files with specified options.12 13Options:14 -h, --help Display this help message and exit.15 -d, --device <value> Set SYCL devices (default: SYCL0).16 -c, --context <value> Set context length. Bigger need more memory.17 -p, --promote <value> Prompt to start generation with.18 -m, --model <value> Full model file path.19 -mg,--main-gpu <value> Set main GPU ID (0 - n) for single GPU mode.20 -sm,--split-mode <value> How to split the model across multiple GPUs, one of:21 - none: use one GPU only22 - layer (default): split layers and KV across GPUs23 - row: split rows across GPUs24 -ngl,--n-gpu-layers <value> Max. number of layers to store in VRAM (default: -1)25 -lv,--log-verbosity <value> Set the verbosity threshold. Messages with a higher verbosity will be26 ignored. Values:27 - 0: generic output28 - 1: error29 - 2: warning30 - 3: info31 - 4: debug32 33 34EOF35}36 37BIN_FILE=./build/bin/llama-completion38SEED=039GPUS_SETTING=""40 41INPUT_PROMPT="Building a website can be done in 10 simple steps:\nStep 1:"42MODEL_FILE=../models/llama-2-7b.Q4_0.gguf43NGL=9944CONTEXT=409645GGML_SYCL_DEVICE=-146SYCL_DEVICES="SYCL0"47SPLIT_MODE=layer48LOG_VERBOSE=349while [[ $# -gt 0 ]]; do50 case "$1" in51 -d|--device)52 SYCL_DEVICES="$2"53 shift54 shift55 ;;56 -c|--context)57 CONTEXT=$258 # Shift twice to consume both the option flag and its value59 shift60 shift61 ;;62 -p|--promote)63 # Option that is a simple flag (boolean)64 INPUT_PROMPT="$2"65 # Shift once to consume the option flag66 shift67 shift68 ;;69 -m|--model)70 MODEL_FILE="$2"71 # Shift twice to consume both the option flag and its value72 shift73 shift74 ;;75 -mg|--main-gpu)76 GGML_SYCL_DEVICE=$277 SPLIT_MODE=none78 # Shift twice to consume both the option flag and its value79 shift80 shift81 ;;82 -sm|--split-mode)83 SPLIT_MODE=$284 # Shift twice to consume both the option flag and its value85 shift86 shift87 ;;88 -ngl|--n-gpu-layers)89 NGL=$290 # Shift twice to consume both the option flag and its value91 shift92 shift93 ;;94 -lv|--log-verbosity)95 LOG_VERBOSE=$296 # Shift twice to consume both the option flag and its value97 shift98 shift99 ;;100 -h|--help)101 Help102 exit 0103 ;;104 *)105 # Handle unknown options or stop processing options106 echo "Invalid option: $1"107 # Optional: exit script or shift to treat remaining as positional args108 exit 1109 ;;110 esac111done112 113 114 115source /opt/intel/oneapi/setvars.sh116 117#export GGML_SYCL_DEBUG=1118 119#ZES_ENABLE_SYSMAN=1, Support to get free memory of GPU by sycl::aspect::ext_intel_free_memory. Recommended to use when --split-mode = layer.120 121#support malloc device memory more than 4GB.122export UR_L0_ENABLE_RELAXED_ALLOCATION_LIMITS=1123echo "UR_L0_ENABLE_RELAXED_ALLOCATION_LIMITS=${UR_L0_ENABLE_RELAXED_ALLOCATION_LIMITS}"124 125echo "ONEAPI_DEVICE_SELECTOR=${ONEAPI_DEVICE_SELECTOR}"126 127if [ $GGML_SYCL_DEVICE -ne -1 ]; then128 echo "Use $GGML_SYCL_DEVICE as main GPU"129 #use signle GPU only130 GPUS_SETTING="-mg $GGML_SYCL_DEVICE -sm ${SPLIT_MODE}"131else132 echo "Use Intel GPUs: ${SYCL_DEVICES}"133 GPUS_SETTING="-sm ${SPLIT_MODE}"134 fi135 136echo "run cmd: ZES_ENABLE_SYSMAN=1 ${BIN_FILE} -m ${MODEL_FILE} -no-cnv -p "${INPUT_PROMPT}" -n 200 -e -ngl ${NGL} -s ${SEED} -c ${CONTEXT} ${GPUS_SETTING} -lv ${LOG_VERBOSE} --device ${SYCL_DEVICES} --load-mode auto "137ZES_ENABLE_SYSMAN=1 ${BIN_FILE} -m ${MODEL_FILE} -no-cnv -p "${INPUT_PROMPT}" -n 200 -e -ngl ${NGL} -s ${SEED} -c ${CONTEXT} ${GPUS_SETTING} -lv ${LOG_VERBOSE} --device ${SYCL_DEVICES} --load-mode auto138 139 