Skip to content

Commit 03c2d46

Browse files
Merge branch 'ggml-org:master' into master
2 parents 72ce718 + 2be60cb commit 03c2d46

38 files changed

+3074
-965
lines changed

.clang-format

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ AllowShortIfStatementsOnASingleLine: Never
2222
AllowShortLambdasOnASingleLine: Inline
2323
AllowShortLoopsOnASingleLine: false
2424
AlwaysBreakBeforeMultilineStrings: true
25-
BinPackArguments: true
26-
BinPackParameters: true # OnePerLine
25+
BinPackArguments: false
26+
BinPackParameters: false # OnePerLine
2727
BitFieldColonSpacing: Both
2828
BreakBeforeBraces: Custom # Attach
2929
BraceWrapping:
@@ -70,15 +70,18 @@ ExperimentalAutoDetectBinPacking: false
7070
FixNamespaceComments: true
7171
IncludeBlocks: Regroup
7272
IncludeCategories:
73-
- Regex: '^<.*\.h>'
73+
- Regex: '".*"'
7474
Priority: 1
7575
SortPriority: 0
76-
- Regex: '^<.*'
76+
- Regex: '^<.*\.h>'
7777
Priority: 2
7878
SortPriority: 0
79-
- Regex: '.*'
79+
- Regex: '^<.*'
8080
Priority: 3
8181
SortPriority: 0
82+
- Regex: '.*'
83+
Priority: 4
84+
SortPriority: 0
8285
IncludeIsMainRegex: '([-_](test|unittest))?$'
8386
IncludeIsMainSourceRegex: ''
8487
IndentAccessModifiers: false

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
/ggml/src/ggml-cuda/mmvq.* @JohannesGaessler
1010
/ggml/src/ggml-opt.cpp @JohannesGaessler
1111
/ggml/src/gguf.cpp @JohannesGaessler
12+
/ggml/src/ggml-vulkan/ @0cc4m

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ To learn more about model quantization, [read this documentation](tools/quantize
436436

437437
## [`llama-perplexity`](tools/perplexity)
438438

439-
#### A tool for measuring the perplexity [^1][^2] (and other quality metrics) of a model over a given text.
439+
#### A tool for measuring the [perplexity](tools/perplexity/README.md) [^1] (and other quality metrics) of a model over a given text.
440440

441441
- <details open>
442442
<summary>Measure the perplexity over a text file</summary>
@@ -459,8 +459,7 @@ To learn more about model quantization, [read this documentation](tools/quantize
459459

460460
</details>
461461

462-
[^1]: [tools/perplexity/README.md](./tools/perplexity/README.md)
463-
[^2]: [https://huggingface.co/docs/transformers/perplexity](https://huggingface.co/docs/transformers/perplexity)
462+
[^1]: [https://huggingface.co/docs/transformers/perplexity](https://huggingface.co/docs/transformers/perplexity)
464463

465464
## [`llama-bench`](tools/llama-bench)
466465

common/common.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,15 @@ void string_replace_all(std::string & s, const std::string & search, const std::
448448
bool string_ends_with(const std::string_view & str, const std::string_view & suffix) {
449449
return str.size() >= suffix.size() && str.compare(str.size()-suffix.size(), suffix.size(), suffix) == 0;
450450
}
451+
452+
bool string_remove_suffix(std::string & str, const std::string_view & suffix) {
453+
bool has_suffix = string_ends_with(str, suffix);
454+
if (has_suffix) {
455+
str = str.substr(0, str.size() - suffix.size());
456+
}
457+
return has_suffix;
458+
}
459+
451460
size_t string_find_partial_stop(const std::string_view & str, const std::string_view & stop) {
452461
if (!str.empty() && !stop.empty()) {
453462
const char text_last_char = str.back();

common/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ static bool string_starts_with(const std::string & str,
534534

535535
// While we wait for C++20's std::string::ends_with...
536536
bool string_ends_with(const std::string_view & str, const std::string_view & suffix);
537+
bool string_remove_suffix(std::string & str, const std::string_view & suffix);
537538
size_t string_find_partial_stop(const std::string_view & str, const std::string_view & stop);
538539

539540
bool string_parse_kv_override(const char * data, std::vector<llama_model_kv_override> & overrides);

convert_hf_to_gguf.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,9 @@ def get_vocab_base_pre(self, tokenizer) -> str:
843843
if chkhsh == "169bf0296a13c4d9b7672313f749eb36501d931022de052aad6e36f2bf34dd51":
844844
# ref: https://huggingface.co/LiquidAI/LFM2-Tokenizer
845845
res = "lfm2"
846+
if chkhsh == "2085e1638f6c377a0aa4ead21b27bb4cb941bf800df86ed391011769c1758dfb":
847+
# ref: https://huggingface.co/LGAI-EXAONE/EXAONE-4.0-32B
848+
res = "exaone4"
846849

847850
if res is None:
848851
logger.warning("\n")
@@ -6780,6 +6783,75 @@ def generate_extra_tensors(self) -> Iterable[tuple[str, Tensor]]:
67806783
yield (self.format_tensor_name(gguf.MODEL_TENSOR.ROPE_FREQS), torch.tensor(rope_factors, dtype=torch.float32))
67816784

67826785

6786+
@ModelBase.register("Exaone4ForCausalLM")
6787+
class Exaone4Model(TextModel):
6788+
model_arch = gguf.MODEL_ARCH.EXAONE4
6789+
6790+
def set_vocab(self):
6791+
tokens, toktypes, tokpre = self.get_vocab_base()
6792+
self.gguf_writer.add_tokenizer_model("gpt2")
6793+
self.gguf_writer.add_tokenizer_pre(tokpre)
6794+
self.gguf_writer.add_token_list(tokens)
6795+
self.gguf_writer.add_token_types(toktypes)
6796+
6797+
special_vocab = gguf.SpecialVocab(self.dir_model, load_merges=True)
6798+
special_vocab.add_to_gguf(self.gguf_writer)
6799+
6800+
def set_gguf_parameters(self):
6801+
super().set_gguf_parameters()
6802+
hparams = self.hparams
6803+
self.gguf_writer.add_vocab_size(hparams["vocab_size"])
6804+
6805+
if hparams.get("sliding_window") is not None:
6806+
self.gguf_writer.add_sliding_window(hparams["sliding_window"])
6807+
if "layer_types" in hparams:
6808+
self.gguf_writer.add_sliding_window_pattern([t == "sliding_attention" for t in hparams["layer_types"]])
6809+
elif "sliding_window_pattern" in hparams:
6810+
sliding_window_pattern = []
6811+
if isinstance(hparams["sliding_window_pattern"], str): # e.g. LLLG
6812+
for i in range(hparams["num_hidden_layers"]):
6813+
sliding_window_pattern.append(hparams["sliding_window_pattern"][i % len(hparams["sliding_window_pattern"])] == "L")
6814+
if isinstance(hparams["sliding_window_pattern"], int): # e.g. 4
6815+
for i in range(hparams["num_hidden_layers"]):
6816+
sliding_window_pattern.append((i + 1) % hparams["sliding_window_pattern"] != 0)
6817+
if len(sliding_window_pattern) == hparams["num_hidden_layers"]:
6818+
self.gguf_writer.add_sliding_window_pattern(sliding_window_pattern)
6819+
6820+
rope_scaling = self.hparams.get("rope_scaling") or {}
6821+
if rope_scaling.get("rope_type", rope_scaling.get("type")) == "linear" and "factor" in rope_scaling:
6822+
self.gguf_writer.add_rope_scaling_type(gguf.RopeScalingType.LINEAR)
6823+
self.gguf_writer.add_rope_scaling_factor(rope_scaling["factor"])
6824+
6825+
def generate_extra_tensors(self) -> Iterable[tuple[str, Tensor]]:
6826+
if rope_scaling := self.find_hparam(["rope_scaling"], optional=True):
6827+
if rope_scaling.get("rope_type", '').lower() == "llama3":
6828+
base = self.hparams.get("rope_theta", 10_000.0)
6829+
if (dim := self.hparams.get("head_dim")) is None:
6830+
dim = self.hparams["hidden_size"] // self.hparams["num_attention_heads"]
6831+
freqs = 1.0 / (base ** (torch.arange(0, dim, 2, dtype=torch.float32) / dim))
6832+
6833+
factor = rope_scaling.get("factor", 16.0)
6834+
low_freq_factor = rope_scaling.get("low_freq_factor", 1.0)
6835+
high_freq_factor = rope_scaling.get("high_freq_factor", 4.0)
6836+
old_context_len = self.hparams.get("original_max_position_embeddings", 8192)
6837+
6838+
low_freq_wavelen = old_context_len / low_freq_factor
6839+
high_freq_wavelen = old_context_len / high_freq_factor
6840+
6841+
rope_factors = []
6842+
for freq in freqs:
6843+
wavelen = 2 * math.pi / freq
6844+
if wavelen < high_freq_wavelen:
6845+
rope_factors.append(1)
6846+
elif wavelen > low_freq_wavelen:
6847+
rope_factors.append(factor)
6848+
else:
6849+
smooth = (old_context_len / wavelen - low_freq_factor) / (high_freq_factor - low_freq_factor)
6850+
rope_factors.append(1 / ((1 - smooth) / factor + smooth))
6851+
6852+
yield (self.format_tensor_name(gguf.MODEL_TENSOR.ROPE_FREQS), torch.tensor(rope_factors, dtype=torch.float32))
6853+
6854+
67836855
@ModelBase.register("GraniteForCausalLM")
67846856
class GraniteModel(LlamaModel):
67856857
"""Conversion for IBM's GraniteForCausalLM"""

convert_hf_to_gguf_update.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ class TOKENIZER_TYPE(IntEnum):
129129
{"name": "a.x-4.0", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/skt/A.X-4.0", },
130130
{"name": "midm-2.0", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/K-intelligence/Midm-2.0-Base-Instruct", },
131131
{"name": "lfm2", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/LiquidAI/LFM2-Tokenizer"},
132+
{"name": "exaone4", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/LGAI-EXAONE/EXAONE-4.0-32B", },
132133
]
133134

134135
# some models are known to be broken upstream, so we will skip them as exceptions

docs/build.md

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,8 @@ On Linux it is possible to use unified memory architecture (UMA) to share main m
305305

306306
## Vulkan
307307

308-
**Windows**
309-
310-
### w64devkit
308+
### For Windows Users:
309+
**w64devkit**
311310

312311
Download and extract [`w64devkit`](https://github.com/skeeto/w64devkit/releases).
313312

@@ -334,7 +333,7 @@ cmake -B build -DGGML_VULKAN=ON
334333
cmake --build build --config Release
335334
```
336335

337-
### Git Bash MINGW64
336+
**Git Bash MINGW64**
338337

339338
Download and install [`Git-SCM`](https://git-scm.com/downloads/win) with the default settings
340339

@@ -357,7 +356,8 @@ Now you can load the model in conversation mode using `Vulkan`
357356
build/bin/Release/llama-cli -m "[PATH TO MODEL]" -ngl 100 -c 16384 -t 10 -n -2 -cnv
358357
```
359358

360-
### MSYS2
359+
**MSYS2**
360+
361361
Install [MSYS2](https://www.msys2.org/) and then run the following commands in a UCRT terminal to install dependencies.
362362
```sh
363363
pacman -S git \
@@ -373,9 +373,9 @@ cmake -B build -DGGML_VULKAN=ON
373373
cmake --build build --config Release
374374
```
375375

376-
**With docker**:
376+
### For Docker users:
377377

378-
You don't need to install Vulkan SDK. It will be installed inside the container.
378+
You don't need to install the Vulkan SDK. It will be installed inside the container.
379379

380380
```sh
381381
# Build the image
@@ -385,32 +385,29 @@ docker build -t llama-cpp-vulkan --target light -f .devops/vulkan.Dockerfile .
385385
docker run -it --rm -v "$(pwd):/app:Z" --device /dev/dri/renderD128:/dev/dri/renderD128 --device /dev/dri/card1:/dev/dri/card1 llama-cpp-vulkan -m "/app/models/YOUR_MODEL_FILE" -p "Building a website can be done in 10 simple steps:" -n 400 -e -ngl 33
386386
```
387387

388-
**Without docker**:
388+
### For Linux users:
389389

390-
Firstly, you need to make sure you have installed [Vulkan SDK](https://vulkan.lunarg.com/doc/view/latest/linux/getting_started_ubuntu.html)
390+
First, follow the official LunarG instructions for the installation and setup of the Vulkan SDK in the [Getting Started with the Linux Tarball Vulkan SDK](https://vulkan.lunarg.com/doc/sdk/latest/linux/getting_started.html) guide.
391391

392-
For example, on Ubuntu 22.04 (jammy), use the command below:
392+
> [!IMPORTANT]
393+
> After completing the first step, ensure that you have used the `source` command on the `setup_env.sh` file inside of the Vulkan SDK in your current terminal session. Otherwise, the build won't work. Additionally, if you close out of your terminal, you must perform this step again if you intend to perform a build. However, there are ways to make this persistent. Refer to the Vulkan SDK guide linked in the first step for more information about any of this.
393394
395+
Second, after verifying that you have followed all of the SDK installation/setup steps, use this command to make sure before proceeding:
394396
```bash
395-
wget -qO - https://packages.lunarg.com/lunarg-signing-key-pub.asc | apt-key add -
396-
wget -qO /etc/apt/sources.list.d/lunarg-vulkan-jammy.list https://packages.lunarg.com/vulkan/lunarg-vulkan-jammy.list
397-
apt update -y
398-
apt-get install -y vulkan-sdk
399-
# To verify the installation, use the command below:
400397
vulkaninfo
401398
```
402399

403-
Alternatively your package manager might be able to provide the appropriate libraries.
404-
For example for Ubuntu 22.04 you can install `libvulkan-dev` instead.
405-
For Fedora 40, you can install `vulkan-devel`, `glslc` and `glslang` packages.
406-
407-
Then, build llama.cpp using the cmake command below:
408-
400+
Then, assuming you have `cd` into your llama.cpp folder and there are no errors with running `vulkaninfo`, you can proceed to build llama.cpp using the CMake commands below:
409401
```bash
410402
cmake -B build -DGGML_VULKAN=1
411403
cmake --build build --config Release
412-
# Test the output binary (with "-ngl 33" to offload all layers to GPU)
413-
./bin/llama-cli -m "PATH_TO_MODEL" -p "Hi you how are you" -n 50 -e -ngl 33 -t 4
404+
```
405+
406+
Finally, after finishing your build, you should be able to do something like this:
407+
```bash
408+
# Test the output binary
409+
# "-ngl 99" should offload all of the layers to GPU for most (if not all) models.
410+
./build/bin/llama-cli -m "PATH_TO_MODEL" -p "Hi you how are you" -ngl 99
414411

415412
# You should see in the output, ggml_vulkan detected your GPU. For example:
416413
# ggml_vulkan: Using Intel(R) Graphics (ADL GT2) | uma: 1 | fp16: 1 | warp size: 32

examples/parallel/parallel.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ int main(int argc, char ** argv) {
184184
// extra text to insert in each client's prompt in order to make it larger
185185
const int32_t n_junk = std::max(1, params.n_junk);
186186

187+
// signed seed, use negative values to indicate different seeds for the different clients
188+
const int32_t & sseed = params.sampling.seed;
189+
187190
// init llama.cpp
188191
llama_backend_init();
189192
llama_numa_init(params.numa);
@@ -219,12 +222,21 @@ int main(int argc, char ** argv) {
219222

220223
const int n_ctx = llama_n_ctx(ctx);
221224

225+
if (sseed >= 0) {
226+
LOG_INF("%s: initializing all samplers with the same RNG seed: %d (use a negative seed to have different seeds)\n", __func__, sseed);
227+
} else {
228+
LOG_INF("%s: initializing samplers with different RNG seeds, starting from %d\n", __func__, sseed);
229+
}
230+
222231
std::vector<client> clients(n_clients);
223232
for (size_t i = 0; i < clients.size(); ++i) {
224233
auto & client = clients[i];
225234
client.id = i;
226235
client.smpl = common_sampler_init(model, params.sampling);
227-
//params.sampling.seed++;
236+
237+
if (sseed < 0) {
238+
params.sampling.seed--;
239+
}
228240
}
229241

230242
std::vector<llama_token> tokens_system;

ggml/src/ggml-alloc.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,6 @@ static bool ggml_is_view(const struct ggml_tensor * t) {
2222
return t->view_src != NULL;
2323
}
2424

25-
static bool ggml_are_same_layout(const struct ggml_tensor * a, const struct ggml_tensor * b) {
26-
if (a->type != b->type) {
27-
return false;
28-
}
29-
for (int i = 0; i < GGML_MAX_DIMS; i++) {
30-
if (a->ne[i] != b->ne[i]) {
31-
return false;
32-
}
33-
if (a->nb[i] != b->nb[i]) {
34-
return false;
35-
}
36-
}
37-
return true;
38-
}
39-
4025
// ops that return true for this function must not use restrict pointers for their backend implementations
4126
static bool ggml_op_can_inplace(enum ggml_op op) {
4227
switch (op) {

0 commit comments

Comments
 (0)