char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

Fathi Boudracommon: migrate the deprecated --mmap/--no-mmap to --load-mode (#26934)0177dcc73

char/aliceai-t5-moe
4.4 KiB138 linesraw
1#!/bin/bash
2
3#  MIT license
4#  Copyright (C) 2024 Intel Corporation
5#  SPDX-License-Identifier: MIT
6
7Help() {
8  cat << EOF
9Usage: $(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 only
22                            - layer (default): split layers and KV across GPUs
23                            - row: split rows across GPUs
24  -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 be
26                               ignored. Values:
27                                - 0: generic output
28                                - 1: error
29                                - 2: warning
30                                - 3: info
31                                - 4: debug
32
33
34EOF
35}
36
37BIN_FILE=./build/bin/llama-completion
38SEED=0
39GPUS_SETTING=""
40
41INPUT_PROMPT="Building a website can be done in 10 simple steps:\nStep 1:"
42MODEL_FILE=../models/llama-2-7b.Q4_0.gguf
43NGL=99
44CONTEXT=4096
45GGML_SYCL_DEVICE=-1
46SYCL_DEVICES="SYCL0"
47SPLIT_MODE=layer
48LOG_VERBOSE=3
49while [[ $# -gt 0 ]]; do
50    case "$1" in
51        -d|--device)
52            SYCL_DEVICES="$2"
53            shift
54            shift
55            ;;
56        -c|--context)
57            CONTEXT=$2
58            # Shift twice to consume both the option flag and its value
59            shift
60            shift
61            ;;
62        -p|--promote)
63            # Option that is a simple flag (boolean)
64            INPUT_PROMPT="$2"
65            # Shift once to consume the option flag
66            shift
67            shift
68            ;;
69        -m|--model)
70            MODEL_FILE="$2"
71            # Shift twice to consume both the option flag and its value
72            shift
73            shift
74            ;;
75        -mg|--main-gpu)
76            GGML_SYCL_DEVICE=$2
77            SPLIT_MODE=none
78            # Shift twice to consume both the option flag and its value
79            shift
80            shift
81            ;;
82        -sm|--split-mode)
83            SPLIT_MODE=$2
84            # Shift twice to consume both the option flag and its value
85            shift
86            shift
87            ;;
88        -ngl|--n-gpu-layers)
89            NGL=$2
90            # Shift twice to consume both the option flag and its value
91            shift
92            shift
93            ;;
94        -lv|--log-verbosity)
95            LOG_VERBOSE=$2
96            # Shift twice to consume both the option flag and its value
97            shift
98            shift
99            ;;
100        -h|--help)
101            Help
102            exit 0
103            ;;
104        *)
105            # Handle unknown options or stop processing options
106            echo "Invalid option: $1"
107            # Optional: exit script or shift to treat remaining as positional args
108            exit 1
109            ;;
110    esac
111done
112
113
114
115source /opt/intel/oneapi/setvars.sh
116
117#export GGML_SYCL_DEBUG=1
118
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=1
123echo "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 ]; then
128    echo "Use $GGML_SYCL_DEVICE as main GPU"
129    #use signle GPU only
130    GPUS_SETTING="-mg $GGML_SYCL_DEVICE -sm ${SPLIT_MODE}"
131else
132    echo "Use Intel GPUs: ${SYCL_DEVICES}"
133    GPUS_SETTING="-sm ${SPLIT_MODE}"
134 fi
135
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 auto
138