Skip to content

Commit 9a1d2c7

Browse files
committed
resolve conflicts
2 parents 07d2da0 + 70f01cb commit 9a1d2c7

19 files changed

+777
-137
lines changed

.devops/full.Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
ARG UBUNTU_VERSION=22.04
2+
3+
FROM ubuntu:$UBUNTU_VERSION as build
4+
5+
RUN apt-get update && \
6+
apt-get install -y build-essential python3 python3-pip
7+
8+
RUN pip install --upgrade pip setuptools wheel \
9+
&& pip install torch torchvision torchaudio sentencepiece numpy
10+
11+
WORKDIR /app
12+
13+
COPY . .
14+
15+
RUN make
16+
17+
ENTRYPOINT ["/app/.devops/tools.sh"]

.devops/main.Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
ARG UBUNTU_VERSION=22.04
2+
3+
FROM ubuntu:$UBUNTU_VERSION as build
4+
5+
RUN apt-get update && \
6+
apt-get install -y build-essential
7+
8+
WORKDIR /app
9+
10+
COPY . .
11+
12+
RUN make
13+
14+
FROM ubuntu:$UBUNTU_VERSION as runtime
15+
16+
COPY --from=build /app/main /main
17+
18+
ENTRYPOINT [ "/main" ]

.devops/tools.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Read the first argument into a variable
5+
arg1="$1"
6+
7+
# Shift the arguments to remove the first one
8+
shift
9+
10+
# Join the remaining arguments into a single string
11+
arg2="$@"
12+
13+
if [[ $arg1 == '--convert' || $arg1 == '-c' ]]; then
14+
python3 ./convert-pth-to-ggml.py $arg2
15+
elif [[ $arg1 == '--quantize' || $arg1 == '-q' ]]; then
16+
./quantize $arg2
17+
elif [[ $arg1 == '--run' || $arg1 == '-r' ]]; then
18+
./main $arg2
19+
elif [[ $arg1 == '--download' || $arg1 == '-d' ]]; then
20+
python3 ./download-pth.py $arg2
21+
elif [[ $arg1 == '--all-in-one' || $arg1 == '-a' ]]; then
22+
echo "Downloading model..."
23+
python3 ./download-pth.py "$1" "$2"
24+
echo "Converting PTH to GGML..."
25+
for i in `ls $1/$2/ggml-model-f16.bin*`; do
26+
if [ -f "${i/f16/q4_0}" ]; then
27+
echo "Skip model quantization, it already exists: ${i/f16/q4_0}"
28+
else
29+
echo "Converting PTH to GGML: $i into ${i/f16/q4_0}..."
30+
./quantize "$i" "${i/f16/q4_0}" 2
31+
fi
32+
done
33+
else
34+
echo "Unknown command: $arg1"
35+
echo "Available commands: "
36+
echo " --run (-r): Run a model previously converted into ggml"
37+
echo " ex: -m /models/7B/ggml-model-q4_0.bin -p \"Building a website can be done in 10 simple steps:\" -n 512"
38+
echo " --convert (-c): Convert a llama model into ggml"
39+
echo " ex: \"/models/7B/\" 1"
40+
echo " --quantize (-q): Optimize with quantization process ggml"
41+
echo " ex: \"/models/7B/ggml-model-f16.bin\" \"/models/7B/ggml-model-q4_0.bin\" 2"
42+
echo " --download (-d): Download original llama model from CDN: https://agi.gpt4.org/llama/"
43+
echo " ex: \"/models/\" 7B"
44+
echo " --all-in-one (-a): Execute --download, --convert & --quantize"
45+
echo " ex: \"/models/\" 7B"
46+
fi

.dockerignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
*.o
2+
*.a
3+
.cache/
4+
.vs/
5+
.vscode/
6+
.DS_Store
7+
8+
build/
9+
build-em/
10+
build-debug/
11+
build-release/
12+
build-static/
13+
build-no-accel/
14+
build-sanitize-addr/
15+
build-sanitize-thread/
16+
17+
models/*
18+
19+
/main
20+
/quantize
21+
22+
arm_neon.h
23+
compile_commands.json
24+
Dockerfile

.github/workflows/build.yml

Lines changed: 97 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,144 @@
11
name: CI
2-
on: [push, pull_request]
2+
3+
on:
4+
workflow_dispatch: # allows manual triggering
5+
inputs:
6+
create_release:
7+
description: 'Create new release'
8+
required: true
9+
type: boolean
10+
push:
11+
paths: ['.github/workflows/**', 'CMakeLists.txt', 'Makefile', '**.h', '*.c', '**.cpp']
12+
pull_request:
13+
types: [opened, synchronize, edited, reopened, review_requested, ready_for_review]
14+
paths: ['CMakeLists.txt', 'Makefile', '**.h', '*.c', '**.cpp']
15+
16+
env:
17+
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
318

419
jobs:
5-
ubuntu-latest:
20+
ubuntu-latest-make:
621
runs-on: ubuntu-latest
722

823
steps:
924
- name: Clone
25+
id: checkout
1026
uses: actions/checkout@v1
1127

1228
- name: Dependencies
29+
id: depends
1330
run: |
1431
sudo apt-get update
1532
sudo apt-get install build-essential
1633
1734
- name: Build
35+
id: make_build
1836
run: |
1937
make
2038
21-
macOS-latest:
22-
runs-on: macOS-latest
39+
ubuntu-latest-cmake:
40+
runs-on: ubuntu-latest
41+
42+
steps:
43+
- name: Clone
44+
uses: actions/checkout@v1
45+
46+
- name: Dependencies
47+
run: |
48+
sudo apt-get update
49+
sudo apt-get install build-essential
50+
51+
- name: Build
52+
run: |
53+
mkdir build
54+
cd build
55+
cmake ..
56+
cmake --build . --config Release
57+
58+
macOS-latest-make:
59+
runs-on: macos-latest
2360

2461
steps:
2562
- name: Clone
63+
id: checkout
2664
uses: actions/checkout@v1
2765

2866
- name: Dependencies
67+
id: depends
2968
run: |
3069
brew update
3170
3271
- name: Build
72+
id: make_build
3373
run: |
3474
make
3575
36-
windows-latest:
76+
macOS-latest-cmake:
77+
runs-on: macOS-latest
78+
79+
steps:
80+
- name: Clone
81+
uses: actions/checkout@v1
82+
83+
- name: Dependencies
84+
run: |
85+
brew update
86+
87+
- name: Build
88+
run: |
89+
mkdir build
90+
cd build
91+
cmake ..
92+
cmake --build . --config Release
93+
94+
windows-latest-cmake:
3795
runs-on: windows-latest
3896

3997
steps:
4098
- name: Clone
99+
id: checkout
41100
uses: actions/checkout@v1
42101

43102
- name: Build
103+
id: cmake_build
44104
run: |
45105
mkdir build
46106
cd build
47107
cmake ..
48108
cmake --build . --config Release
49109
110+
- name: Get commit hash
111+
id: commit
112+
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
113+
uses: pr-mpt/actions-commit-hash@v2
114+
115+
- name: Pack artifacts
116+
id: pack_artifacts
117+
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
118+
run: |
119+
7z a llama-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-x64.zip .\build\Release\*
120+
121+
- name: Create release
122+
id: create_release
123+
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
124+
uses: zendesk/action-create-release@v1
125+
env:
126+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
127+
with:
128+
tag_name: ${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}
129+
130+
- name: Upload release
131+
id: upload_release
132+
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
133+
uses: actions/upload-release-asset@v1
134+
env:
135+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
136+
with:
137+
upload_url: ${{ steps.create_release.outputs.upload_url }}
138+
asset_path: .\llama-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-x64.zip
139+
asset_name: llama-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-x64.zip
140+
asset_content_type: application/octet-stream
141+
50142
# ubuntu-latest-gcc:
51143
# runs-on: ubuntu-latest
52144
#

.github/workflows/docker.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
6+
# GitHub recommends pinning actions to a commit SHA.
7+
# To get a newer version, you will need to update the SHA.
8+
# You can also reference a tag or branch, but the action may change without warning.
9+
10+
name: Publish Docker image
11+
12+
on:
13+
pull_request:
14+
push:
15+
branches:
16+
- master
17+
18+
jobs:
19+
push_to_registry:
20+
name: Push Docker image to Docker Hub
21+
runs-on: ubuntu-latest
22+
env:
23+
COMMIT_SHA: ${{ github.sha }}
24+
strategy:
25+
matrix:
26+
config:
27+
- { tag: "light", dockerfile: ".devops/main.Dockerfile" }
28+
- { tag: "full", dockerfile: ".devops/full.Dockerfile" }
29+
steps:
30+
- name: Check out the repo
31+
uses: actions/checkout@v3
32+
33+
- name: Set up QEMU
34+
uses: docker/setup-qemu-action@v2
35+
36+
- name: Set up Docker Buildx
37+
uses: docker/setup-buildx-action@v2
38+
39+
- name: Log in to Docker Hub
40+
uses: docker/login-action@v2
41+
with:
42+
registry: ghcr.io
43+
username: ${{ github.actor }}
44+
password: ${{ secrets.GITHUB_TOKEN }}
45+
46+
- name: Build and push Docker image (versioned)
47+
if: github.event_name == 'push'
48+
uses: docker/build-push-action@v4
49+
with:
50+
context: .
51+
push: true
52+
tags: "ghcr.io/ggerganov/llama.cpp:${{ matrix.config.tag }}-${{ env.COMMIT_SHA }}"
53+
file: ${{ matrix.config.dockerfile }}
54+
55+
- name: Build and push Docker image (tagged)
56+
uses: docker/build-push-action@v4
57+
with:
58+
context: .
59+
push: ${{ github.event_name == 'push' }}
60+
tags: "ghcr.io/ggerganov/llama.cpp:${{ matrix.config.tag }}"
61+
file: ${{ matrix.config.dockerfile }}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ models/*
1818

1919
/main
2020
/quantize
21+
/result
2122

2223
arm_neon.h
2324
compile_commands.json
25+
26+
.envrc
27+
.direnv/

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ project("llama.cpp")
44
set(CMAKE_CXX_STANDARD 20)
55
set(CMAKE_CXX_STANDARD_REQUIRED true)
66
set(CMAKE_C_STANDARD 11)
7+
set(THREADS_PREFER_PTHREAD_FLAG ON)
8+
find_package(Threads REQUIRED)
79

810
if (NOT XCODE AND NOT MSVC AND NOT CMAKE_BUILD_TYPE)
911
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
@@ -126,3 +128,4 @@ target_link_libraries(ggml PRIVATE ${LLAMA_EXTRA_LIBS})
126128
target_include_directories(ggml PUBLIC .)
127129
target_link_libraries(quantize PRIVATE ggml)
128130
target_link_libraries(llama PRIVATE ggml)
131+
target_link_libraries(ggml PRIVATE Threads::Threads)

0 commit comments

Comments
 (0)