Skip to content

Commit 0b55d8b

Browse files
committed
Merge branch 'master' into xsn/csm_tts
2 parents d178099 + 0364178 commit 0b55d8b

39 files changed

+2164
-2138
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
name: Build on Linux using cross-compiler
2+
on:
3+
workflow_dispatch:
4+
workflow_call:
5+
6+
jobs:
7+
ubuntu-latest-riscv64-cpu-cross:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v4
12+
- name: Setup Riscv
13+
run: |
14+
sudo dpkg --add-architecture riscv64
15+
sudo sed -i 's|http://azure.archive.ubuntu.com/ubuntu|http://ports.ubuntu.com/ubuntu-ports|g' \
16+
/etc/apt/sources.list /etc/apt/apt-mirrors.txt
17+
sudo apt-get clean
18+
sudo apt-get update
19+
sudo apt-get install -y --no-install-recommends \
20+
build-essential \
21+
gcc-14-riscv64-linux-gnu \
22+
g++-14-riscv64-linux-gnu
23+
24+
- name: Build
25+
run: |
26+
cmake -B build -DCMAKE_BUILD_TYPE=Release \
27+
-DGGML_OPENMP=OFF \
28+
-DLLAMA_BUILD_EXAMPLES=ON \
29+
-DLLAMA_BUILD_TESTS=OFF \
30+
-DCMAKE_SYSTEM_NAME=Linux \
31+
-DCMAKE_SYSTEM_PROCESSOR=riscv64 \
32+
-DCMAKE_C_COMPILER=riscv64-linux-gnu-gcc-14 \
33+
-DCMAKE_CXX_COMPILER=riscv64-linux-gnu-g++-14 \
34+
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
35+
-DCMAKE_FIND_ROOT_PATH=/usr/lib/riscv64-linux-gnu \
36+
-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER \
37+
-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
38+
-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=BOTH
39+
40+
cmake --build build --config Release -j $(nproc)
41+
42+
ubuntu-latest-riscv64-vulkan-cross:
43+
runs-on: ubuntu-latest
44+
45+
steps:
46+
- uses: actions/checkout@v4
47+
with:
48+
fetch-depth: 0
49+
50+
- name: Setup Riscv
51+
run: |
52+
sudo dpkg --add-architecture riscv64
53+
sudo sed -i 's|http://azure.archive.ubuntu.com/ubuntu|http://ports.ubuntu.com/ubuntu-ports|g' \
54+
/etc/apt/sources.list /etc/apt/apt-mirrors.txt
55+
sudo apt-get clean
56+
sudo apt-get update
57+
sudo apt-get install -y --no-install-recommends \
58+
build-essential \
59+
glslc \
60+
gcc-14-riscv64-linux-gnu \
61+
g++-14-riscv64-linux-gnu \
62+
libvulkan-dev:riscv64
63+
64+
- name: Build
65+
run: |
66+
cmake -B build -DCMAKE_BUILD_TYPE=Release \
67+
-DGGML_VULKAN=ON \
68+
-DGGML_OPENMP=OFF \
69+
-DLLAMA_BUILD_EXAMPLES=ON \
70+
-DLLAMA_BUILD_TESTS=OFF \
71+
-DCMAKE_SYSTEM_NAME=Linux \
72+
-DCMAKE_SYSTEM_PROCESSOR=riscv64 \
73+
-DCMAKE_C_COMPILER=riscv64-linux-gnu-gcc-14 \
74+
-DCMAKE_CXX_COMPILER=riscv64-linux-gnu-g++-14 \
75+
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
76+
-DCMAKE_FIND_ROOT_PATH=/usr/lib/riscv64-linux-gnu \
77+
-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER \
78+
-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
79+
-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=BOTH
80+
81+
cmake --build build --config Release -j $(nproc)
82+
83+
ubuntu-latest-arm64-vulkan-cross:
84+
runs-on: ubuntu-latest
85+
86+
steps:
87+
- uses: actions/checkout@v4
88+
with:
89+
fetch-depth: 0
90+
91+
- name: Setup Arm64
92+
run: |
93+
sudo dpkg --add-architecture arm64
94+
sudo sed -i 's|http://azure.archive.ubuntu.com/ubuntu|http://ports.ubuntu.com/ubuntu-ports|g' \
95+
/etc/apt/sources.list /etc/apt/apt-mirrors.txt
96+
sudo apt-get clean
97+
sudo apt-get update
98+
sudo apt-get install -y --no-install-recommends \
99+
build-essential \
100+
glslc \
101+
crossbuild-essential-arm64 \
102+
libvulkan-dev:arm64
103+
104+
- name: Build
105+
run: |
106+
cmake -B build -DCMAKE_BUILD_TYPE=Release \
107+
-DGGML_VULKAN=ON \
108+
-DGGML_OPENMP=OFF \
109+
-DLLAMA_BUILD_EXAMPLES=ON \
110+
-DLLAMA_BUILD_TESTS=OFF \
111+
-DCMAKE_SYSTEM_NAME=Linux \
112+
-DCMAKE_SYSTEM_PROCESSOR=aarch64 \
113+
-DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc \
114+
-DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ \
115+
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
116+
-DCMAKE_FIND_ROOT_PATH=/usr/lib/aarch64-linux-gnu \
117+
-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER \
118+
-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
119+
-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=BOTH
120+
121+
cmake --build build --config Release -j $(nproc)

.github/workflows/build.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
push:
1111
branches:
1212
- master
13-
paths: ['.github/workflows/build.yml', '**/CMakeLists.txt', '**/Makefile', '**/*.h', '**/*.hpp', '**/*.c', '**/*.cpp', '**/*.cu', '**/*.cuh', '**/*.swift', '**/*.m', '**/*.metal', '**/*.comp']
13+
paths: ['.github/workflows/build.yml', '.github/workflows/build-linux-cross.yml', '**/CMakeLists.txt', '**/Makefile', '**/*.h', '**/*.hpp', '**/*.c', '**/*.cpp', '**/*.cu', '**/*.cuh', '**/*.swift', '**/*.m', '**/*.metal', '**/*.comp']
1414
pull_request:
1515
types: [opened, synchronize, reopened]
1616
paths: ['.github/workflows/build.yml', '**/CMakeLists.txt', '**/Makefile', '**/*.h', '**/*.hpp', '**/*.c', '**/*.cpp', '**/*.cu', '**/*.cuh', '**/*.swift', '**/*.m', '**/*.metal', '**/*.comp']
@@ -606,6 +606,9 @@ jobs:
606606
-DGGML_SYCL_F16=ON
607607
cmake --build build --config Release -j $(nproc)
608608
609+
build-linux-cross:
610+
uses: ./.github/workflows/build-linux-cross.yml
611+
609612
macOS-latest-cmake-ios:
610613
runs-on: macos-latest
611614

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,35 @@ If your issue is with model generation quality, then please at least scan the fo
530530
- [Aligning language models to follow instructions](https://openai.com/research/instruction-following)
531531
- [Training language models to follow instructions with human feedback](https://arxiv.org/abs/2203.02155)
532532
533+
## XCFramework
534+
The XCFramework is a precompiled version of the library for iOS, visionOS, tvOS,
535+
and macOS. It can be used in Swift projects without the need to compile the
536+
library from source. For example:
537+
```swift
538+
// swift-tools-version: 5.10
539+
// The swift-tools-version declares the minimum version of Swift required to build this package.
540+
541+
import PackageDescription
542+
543+
let package = Package(
544+
name: "MyLlamaPackage",
545+
targets: [
546+
.executableTarget(
547+
name: "MyLlamaPackage",
548+
dependencies: [
549+
"LlamaFramework"
550+
]),
551+
.binaryTarget(
552+
name: "LlamaFramework",
553+
url: "https://github.com/ggml-org/llama.cpp/releases/download/b5046/llama-b5046-xcframework.zip",
554+
checksum: "c19be78b5f00d8d29a25da41042cb7afa094cbf6280a225abe614b03b20029ab"
555+
)
556+
]
557+
)
558+
```
559+
The above example is using an intermediate build `b5046` of the library. This can be modified
560+
to use a different version by changing the URL and checksum.
561+
533562
## Completions
534563
Command-line completion is available for some environments.
535564

ci/run.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ if [ ! -z ${GG_BUILD_SYCL} ]; then
5959
export ONEAPI_DEVICE_SELECTOR="level_zero:0"
6060
# Enable sysman for correct memory reporting
6161
export ZES_ENABLE_SYSMAN=1
62+
# to circumvent precision issues on CPY operations
63+
export SYCL_PROGRAM_COMPILE_OPTIONS="-cl-fp32-correctly-rounded-divide-sqrt"
6264
CMAKE_EXTRA="${CMAKE_EXTRA} -DGGML_SYCL=1 -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DGGML_SYCL_F16=ON"
6365
fi
6466

common/arg.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -656,9 +656,13 @@ static void common_params_handle_model(
656656
}
657657
}
658658

659-
// TODO: allow custom host
660-
model.url = "https://huggingface.co/" + model.hf_repo + "/resolve/main/" + model.hf_file;
661-
659+
std::string hf_endpoint = "https://huggingface.co/";
660+
const char * hf_endpoint_env = getenv("HF_ENDPOINT");
661+
if (hf_endpoint_env) {
662+
hf_endpoint = hf_endpoint_env;
663+
if (hf_endpoint.back() != '/') hf_endpoint += '/';
664+
}
665+
model.url = hf_endpoint + model.hf_repo + "/resolve/main/" + model.hf_file;
662666
// make sure model path is present (for caching purposes)
663667
if (model.path.empty()) {
664668
// this is to avoid different repo having same file name, or same file name in different subdirs

common/minja/chat-template.hpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,19 @@
99
#pragma once
1010

1111
#include "minja.hpp"
12-
#include <json.hpp>
12+
13+
#include <chrono>
14+
#include <cstddef>
15+
#include <cstdio>
16+
#include <exception>
17+
#include <iomanip>
18+
#include <memory>
19+
#include <sstream>
1320
#include <string>
1421
#include <vector>
1522

23+
#include <json.hpp>
24+
1625
using json = nlohmann::ordered_json;
1726

1827
namespace minja {
@@ -425,7 +434,7 @@ class chat_template {
425434
auto obj = json {
426435
{"tool_calls", tool_calls},
427436
};
428-
if (!content.is_null() && content != "") {
437+
if (!content.is_null() && !content.empty()) {
429438
obj["content"] = content;
430439
}
431440
message["content"] = obj.dump(2);
@@ -435,13 +444,12 @@ class chat_template {
435444
if (polyfill_tool_responses && role == "tool") {
436445
message["role"] = "user";
437446
auto obj = json {
438-
{"tool_response", {
439-
{"content", message.at("content")},
440-
}},
447+
{"tool_response", json::object()},
441448
};
442449
if (message.contains("name")) {
443-
obj["tool_response"]["name"] = message.at("name");
450+
obj["tool_response"]["tool"] = message.at("name");
444451
}
452+
obj["tool_response"]["content"] = message.at("content");
445453
if (message.contains("tool_call_id")) {
446454
obj["tool_response"]["tool_call_id"] = message.at("tool_call_id");
447455
}
@@ -510,7 +518,7 @@ class chat_template {
510518
static nlohmann::ordered_json add_system(const nlohmann::ordered_json & messages, const std::string & system_prompt) {
511519
json messages_with_system = messages;
512520

513-
if (messages_with_system.size() > 0 && messages_with_system[0].at("role") == "system") {
521+
if (!messages_with_system.empty() && messages_with_system[0].at("role") == "system") {
514522
std::string existing_system = messages_with_system.at(0).at("content");
515523
messages_with_system[0] = json {
516524
{"role", "system"},

0 commit comments

Comments
 (0)