Skip to content

Commit 2c57726

Browse files
Neha AbbasNeha Abbas
authored andcommitted
Merge branch 'master' of https://github.com/reeselevine/llama.cpp into addition
merging with addition
2 parents 39aa11d + ae8edbf commit 2c57726

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+5601
-542
lines changed

.devops/cann.Dockerfile

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# ==============================================================================
2+
# ARGUMENTS
3+
# ==============================================================================
4+
5+
# Define the CANN base image for easier version updates later
6+
ARG CANN_BASE_IMAGE=quay.io/ascend/cann:8.1.rc1-910b-openeuler22.03-py3.10
7+
8+
# ==============================================================================
9+
# BUILD STAGE
10+
# Compile all binary files and libraries
11+
# ==============================================================================
12+
FROM ${CANN_BASE_IMAGE} AS build
13+
14+
# Define the Ascend chip model for compilation. Default is Ascend910B3
15+
ARG ASCEND_SOC_TYPE=Ascend910B3
16+
17+
# -- Install build dependencies --
18+
RUN yum install -y gcc g++ cmake make git libcurl-devel python3 python3-pip && \
19+
yum clean all && \
20+
rm -rf /var/cache/yum
21+
22+
# -- Set the working directory --
23+
WORKDIR /app
24+
25+
# -- Copy project files --
26+
COPY . .
27+
28+
# -- Set CANN environment variables (required for compilation) --
29+
# Using ENV instead of `source` allows environment variables to persist across the entire image layer
30+
ENV ASCEND_TOOLKIT_HOME=/usr/local/Ascend/ascend-toolkit/latest
31+
ENV LD_LIBRARY_PATH=${ASCEND_TOOLKIT_HOME}/lib64:${LD_LIBRARY_PATH}
32+
ENV PATH=${ASCEND_TOOLKIT_HOME}/bin:${PATH}
33+
ENV ASCEND_OPP_PATH=${ASCEND_TOOLKIT_HOME}/opp
34+
ENV LD_LIBRARY_PATH=${ASCEND_TOOLKIT_HOME}/runtime/lib64/stub:$LD_LIBRARY_PATH
35+
# ... You can add other environment variables from the original file as needed ...
36+
# For brevity, only core variables are listed here. You can paste the original ENV list here.
37+
38+
# -- Build llama.cpp --
39+
# Use the passed ASCEND_SOC_TYPE argument and add general build options
40+
RUN source /usr/local/Ascend/ascend-toolkit/set_env.sh --force \
41+
&& \
42+
cmake -B build \
43+
-DGGML_CANN=ON \
44+
-DCMAKE_BUILD_TYPE=Release \
45+
-DSOC_TYPE=${ASCEND_SOC_TYPE} \
46+
. && \
47+
cmake --build build --config Release -j$(nproc)
48+
49+
# -- Organize build artifacts for copying in later stages --
50+
# Create a lib directory to store all .so files
51+
RUN mkdir -p /app/lib && \
52+
find build -name "*.so" -exec cp {} /app/lib \;
53+
54+
# Create a full directory to store all executables and Python scripts
55+
RUN mkdir -p /app/full && \
56+
cp build/bin/* /app/full/ && \
57+
cp *.py /app/full/ && \
58+
cp -r gguf-py /app/full/ && \
59+
cp -r requirements /app/full/ && \
60+
cp requirements.txt /app/full/
61+
# If you have a tools.sh script, make sure it is copied here
62+
# cp .devops/tools.sh /app/full/tools.sh
63+
64+
# ==============================================================================
65+
# BASE STAGE
66+
# Create a minimal base image with CANN runtime and common libraries
67+
# ==============================================================================
68+
FROM ${CANN_BASE_IMAGE} AS base
69+
70+
# -- Install runtime dependencies --
71+
RUN yum install -y libgomp curl && \
72+
yum clean all && \
73+
rm -rf /var/cache/yum
74+
75+
# -- Set CANN environment variables (required for runtime) --
76+
ENV ASCEND_TOOLKIT_HOME=/usr/local/Ascend/ascend-toolkit/latest
77+
ENV LD_LIBRARY_PATH=/app:${ASCEND_TOOLKIT_HOME}/lib64:${LD_LIBRARY_PATH}
78+
ENV PATH=${ASCEND_TOOLKIT_HOME}/bin:${PATH}
79+
ENV ASCEND_OPP_PATH=${ASCEND_TOOLKIT_HOME}/opp
80+
# ... You can add other environment variables from the original file as needed ...
81+
82+
WORKDIR /app
83+
84+
# Copy compiled .so files from the build stage
85+
COPY --from=build /app/lib/ /app
86+
87+
# ==============================================================================
88+
# FINAL STAGES (TARGETS)
89+
# ==============================================================================
90+
91+
### Target: full
92+
# Complete image with all tools, Python bindings, and dependencies
93+
# ==============================================================================
94+
FROM base AS full
95+
96+
COPY --from=build /app/full /app
97+
98+
# Install Python dependencies
99+
RUN yum install -y git python3 python3-pip && \
100+
pip3 install --no-cache-dir --upgrade pip setuptools wheel && \
101+
pip3 install --no-cache-dir -r requirements.txt && \
102+
yum clean all && \
103+
rm -rf /var/cache/yum
104+
105+
# You need to provide a tools.sh script as the entrypoint
106+
ENTRYPOINT ["/app/tools.sh"]
107+
# If there is no tools.sh, you can set the default to start the server
108+
# ENTRYPOINT ["/app/llama-server"]
109+
110+
### Target: light
111+
# Lightweight image containing only llama-cli
112+
# ==============================================================================
113+
FROM base AS light
114+
115+
COPY --from=build /app/full/llama-cli /app
116+
117+
ENTRYPOINT [ "/app/llama-cli" ]
118+
119+
### Target: server
120+
# Dedicated server image containing only llama-server
121+
# ==============================================================================
122+
FROM base AS server
123+
124+
ENV LLAMA_ARG_HOST=0.0.0.0
125+
126+
COPY --from=build /app/full/llama-server /app
127+
128+
HEALTHCHECK --interval=5m CMD [ "curl", "-f", "http://localhost:8080/health" ]
129+
130+
ENTRYPOINT [ "/app/llama-server" ]

.github/workflows/build.yml

Lines changed: 18 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -159,31 +159,15 @@ jobs:
159159
- name: Dawn Dependency
160160
id: dawn-depends
161161
run: |
162-
ARTIFACTS_JSON=$(curl -s -L \
163-
-H "Accept: application/vnd.github+json" \
164-
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
165-
-H "X-GitHub-Api-Version: 2022-11-28" \
166-
"https://api.github.com/repos/google/dawn/actions/artifacts")
167-
echo "Finding latest macos-latest-Release artifact..."
168-
DOWNLOAD_URL=$(echo "$ARTIFACTS_JSON" | jq -r '.artifacts
169-
| sort_by(.created_at)
170-
| reverse
171-
| map(select(.name | test("macos-latest-Release$")))
172-
| .[0].archive_download_url')
173-
if [ "$DOWNLOAD_URL" = "null" ] || [ -z "$DOWNLOAD_URL" ]; then
174-
echo "No suitable Dawn artifact found!"
175-
exit 1
176-
fi
177-
echo "Downloading from: $DOWNLOAD_URL"
178-
curl -L \
179-
-H "Accept: application/vnd.github+json" \
180-
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
181-
-o artifact.zip "$DOWNLOAD_URL"
182-
unzip artifact.zip
162+
DAWN_VERSION="v1.0.0"
163+
DAWN_OWNER="reeselevine"
164+
DAWN_REPO="dawn"
165+
DAWN_ASSET_NAME="Dawn-a1a6b45cced25a3b7f4fb491e0ae70796cc7f22b-macos-latest-Release.tar.gz"
166+
echo "Fetching release asset from https://github.com/${DAWN_OWNER}/${DAWN_REPO}/releases/download/${DAWN_VERSION}/${DAWN_ASSET_NAME}"
167+
curl -L -o artifact.tar.gz \
168+
"https://github.com/${DAWN_OWNER}/${DAWN_REPO}/releases/download/${DAWN_VERSION}/${DAWN_ASSET_NAME}"
183169
mkdir dawn
184-
tar_file=$(find . -name '*.tar.gz' | head -n 1)
185-
echo "Extracting: $tar_file"
186-
tar -xvf "$tar_file" -C dawn --strip-components=1
170+
tar -xvf artifact.tar.gz -C dawn --strip-components=1
187171
188172
- name: Build
189173
id: cmake_build
@@ -195,6 +179,7 @@ jobs:
195179
- name: Test
196180
id: cmake_test
197181
run: |
182+
export LLAMA_SET_ROWS=0
198183
cd build
199184
ctest -L main --verbose --timeout 900
200185
@@ -433,31 +418,15 @@ jobs:
433418
id: dawn-depends
434419
run: |
435420
sudo apt-get install -y libxrandr-dev libxinerama-dev libxcursor-dev mesa-common-dev libx11-xcb-dev libxi-dev
436-
ARTIFACTS_JSON=$(curl -s -L \
437-
-H "Accept: application/vnd.github+json" \
438-
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
439-
-H "X-GitHub-Api-Version: 2022-11-28" \
440-
"https://api.github.com/repos/google/dawn/actions/artifacts")
441-
echo "Finding latest ubuntu-latest-Release artifact..."
442-
DOWNLOAD_URL=$(echo "$ARTIFACTS_JSON" | jq -r '.artifacts
443-
| sort_by(.created_at)
444-
| reverse
445-
| map(select(.name | test("ubuntu-latest-Release$")))
446-
| .[0].archive_download_url')
447-
if [ "$DOWNLOAD_URL" = "null" ] || [ -z "$DOWNLOAD_URL" ]; then
448-
echo "No suitable Dawn artifact found!"
449-
exit 1
450-
fi
451-
echo "Downloading from: $DOWNLOAD_URL"
452-
curl -L \
453-
-H "Accept: application/vnd.github+json" \
454-
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
455-
-o artifact.zip "$DOWNLOAD_URL"
456-
unzip artifact.zip
421+
DAWN_VERSION="v1.0.0"
422+
DAWN_OWNER="reeselevine"
423+
DAWN_REPO="dawn"
424+
DAWN_ASSET_NAME="Dawn-a1a6b45cced25a3b7f4fb491e0ae70796cc7f22b-ubuntu-latest-Release.tar.gz"
425+
echo "Fetching release asset from https://github.com/${DAWN_OWNER}/${DAWN_REPO}/releases/download/${DAWN_VERSION}/${DAWN_ASSET_NAME}"
426+
curl -L -o artifact.tar.gz \
427+
"https://github.com/${DAWN_OWNER}/${DAWN_REPO}/releases/download/${DAWN_VERSION}/${DAWN_ASSET_NAME}"
457428
mkdir dawn
458-
tar_file=$(find . -name '*.tar.gz' | head -n 1)
459-
echo "Extracting: $tar_file"
460-
tar -xvf "$tar_file" -C dawn --strip-components=1
429+
tar -xvf artifact.tar.gz -C dawn --strip-components=1
461430
462431
- name: Build
463432
id: cmake_build
@@ -469,6 +438,7 @@ jobs:
469438
- name: Test
470439
id: cmake_test
471440
run: |
441+
export LLAMA_SET_ROWS=0
472442
cd build
473443
# This is using llvmpipe and runs slower than other backends
474444
ctest -L main --verbose --timeout 3600
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Check Pre-Tokenizer Hashes
2+
3+
on:
4+
push:
5+
paths:
6+
- 'convert_hf_to_gguf.py'
7+
- 'convert_hf_to_gguf_update.py'
8+
pull_request:
9+
paths:
10+
- 'convert_hf_to_gguf.py'
11+
- 'convert_hf_to_gguf_update.py'
12+
13+
jobs:
14+
pre-tokenizer-hashes:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
21+
- name: Set up Python
22+
uses: actions/setup-python@v5
23+
with:
24+
python-version: '3.11'
25+
26+
- name: Install Python dependencies
27+
run: |
28+
python3 -m venv .venv
29+
.venv/bin/pip install -r requirements/requirements-convert_hf_to_gguf_update.txt
30+
31+
- name: Update pre-tokenizer hashes
32+
run: |
33+
cp convert_hf_to_gguf.py /tmp
34+
.venv/bin/python convert_hf_to_gguf_update.py --check-missing
35+
36+
- name: Check if committed pre-tokenizer hashes matches generated version
37+
run: |
38+
if ! diff -q convert_hf_to_gguf.py /tmp/convert_hf_to_gguf.py; then
39+
echo "Model pre-tokenizer hashes (in convert_hf_to_gguf.py) do not match generated hashes (from convert_hf_to_gguf_update.py)."
40+
echo "To fix: run ./convert_hf_to_gguf_update.py and commit the updated convert_hf_to_gguf.py along with your changes"
41+
echo "Differences found:"
42+
diff convert_hf_to_gguf.py /tmp/convert_hf_to_gguf.py || true
43+
exit 1
44+
fi
45+
echo "Model pre-tokenizer hashes are up to date."

common/arg.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2647,6 +2647,15 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
26472647
params.n_out_freq = value;
26482648
}
26492649
).set_examples({LLAMA_EXAMPLE_IMATRIX}));
2650+
add_opt(common_arg(
2651+
{"--output-format"}, "{gguf,dat}",
2652+
string_format("output format for imatrix file (default: %s)", params.imat_dat ? "dat" : "gguf"),
2653+
[](common_params & params, const std::string & value) {
2654+
/**/ if (value == "gguf") { params.imat_dat = false; }
2655+
else if (value == "dat") { params.imat_dat = true; }
2656+
else { throw std::invalid_argument("invalid output format"); }
2657+
}
2658+
).set_examples({LLAMA_EXAMPLE_IMATRIX}));
26502659
add_opt(common_arg(
26512660
{"--save-frequency"}, "N",
26522661
string_format("save an imatrix copy every N iterations (default: %d)", params.n_save_freq),

common/chat.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,7 +1646,7 @@ static void common_chat_parse_hermes_2_pro(common_chat_msg_parser & builder) {
16461646
"|<function name=\"([^\"]+)\">" // match 5 (function name again)
16471647
);
16481648

1649-
if (auto res = builder.try_find_regex(open_regex)) {
1649+
while (auto res = builder.try_find_regex(open_regex)) {
16501650
const auto & block_start = res->groups[1];
16511651
std::string block_end = block_start.empty() ? "" : "```";
16521652

@@ -1668,7 +1668,6 @@ static void common_chat_parse_hermes_2_pro(common_chat_msg_parser & builder) {
16681668
builder.consume_literal(block_end);
16691669
builder.consume_spaces();
16701670
}
1671-
builder.add_content(builder.consume_rest());
16721671
} else {
16731672
throw common_chat_msg_partial_exception("failed to parse tool call");
16741673
}
@@ -1693,11 +1692,10 @@ static void common_chat_parse_hermes_2_pro(common_chat_msg_parser & builder) {
16931692
builder.consume_spaces();
16941693
}
16951694
}
1696-
builder.add_content(builder.consume_rest());
16971695
}
1698-
} else {
1699-
builder.add_content(builder.consume_rest());
17001696
}
1697+
1698+
builder.add_content(builder.consume_rest());
17011699
}
17021700

17031701
static common_chat_params common_chat_params_init_without_tools(const common_chat_template & tmpl, const struct templates_params & inputs) {

common/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ struct common_params {
439439
int32_t n_out_freq = 10; // output the imatrix every n_out_freq iterations
440440
int32_t n_save_freq = 0; // save the imatrix every n_save_freq iterations
441441
int32_t i_chunk = 0; // start processing from this chunk
442+
bool imat_dat = false; // whether the legacy imatrix.dat format should be output
442443

443444
bool process_output = false; // collect data for the output tensor
444445
bool compute_ppl = true; // whether to compute perplexity

0 commit comments

Comments
 (0)