Skip to content

Commit 90402c0

Browse files
committed
Merge branch 'master' into quantize
2 parents fa1df81 + 84bf3c6 commit 90402c0

File tree

88 files changed

+4437
-556
lines changed

Some content is hidden

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

88 files changed

+4437
-556
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ jobs:
134134
include:
135135
- build: 'x64'
136136
os: ubuntu-22.04
137+
- build: 's390x-z15' # z15 because our CI runners are on z15
138+
os: ubuntu-22.04-s390x
137139
# GGML_BACKEND_DL and GGML_CPU_ALL_VARIANTS are not currently supported on arm
138140
# - build: 'arm64'
139141
# os: ubuntu-22.04-arm

.github/workflows/update-ops-docs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ name: Update Operations Documentation
33
on:
44
push:
55
paths:
6+
- 'docs/ops.md'
67
- 'docs/ops/**'
78
- 'scripts/create_ops_docs.py'
89
pull_request:
910
paths:
11+
- 'docs/ops.md'
1012
- 'docs/ops/**'
1113
- 'scripts/create_ops_docs.py'
1214

CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
/ggml/src/ggml-cuda/common.cuh @slaren
5656
/ggml/src/ggml-cuda/fattn* @JohannesGaessler
5757
/ggml/src/ggml-cuda/ggml-cuda.cu @slaren
58-
/ggml/src/ggml-cuda/mmf.* @JohannesGaessler
58+
/ggml/src/ggml-cuda/mmf.* @JohannesGaessler @am17an
5959
/ggml/src/ggml-cuda/mmq.* @JohannesGaessler
6060
/ggml/src/ggml-cuda/mmvf.* @JohannesGaessler
6161
/ggml/src/ggml-cuda/mmvq.* @JohannesGaessler

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ Instructions for adding support for new models: [HOWTO-add-model.md](docs/develo
138138
- [x] [Ling models](https://huggingface.co/collections/inclusionAI/ling-67c51c85b34a7ea0aba94c32)
139139
- [x] [LFM2 models](https://huggingface.co/collections/LiquidAI/lfm2-686d721927015b2ad73eaa38)
140140
- [x] [Hunyuan models](https://huggingface.co/collections/tencent/hunyuan-dense-model-6890632cda26b19119c9c5e7)
141+
- [x] [BailingMoeV2 (Ring/Ling 2.0) models](https://huggingface.co/collections/inclusionAI/ling-v2-68bf1dd2fc34c306c1fa6f86)
141142

142143
#### Multimodal
143144

@@ -187,6 +188,7 @@ Instructions for adding support for new models: [HOWTO-add-model.md](docs/develo
187188
- Swift [srgtuszy/llama-cpp-swift](https://github.com/srgtuszy/llama-cpp-swift)
188189
- Swift [ShenghaiWang/SwiftLlama](https://github.com/ShenghaiWang/SwiftLlama)
189190
- Delphi [Embarcadero/llama-cpp-delphi](https://github.com/Embarcadero/llama-cpp-delphi)
191+
- Go (no CGo needed): [hybridgroup/yzma](https://github.com/hybridgroup/yzma)
190192

191193
</details>
192194

ci/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ if [ ! -z ${GG_BUILD_ROCM} ]; then
7575
exit 1
7676
fi
7777

78-
CMAKE_EXTRA="${CMAKE_EXTRA} -DAMDGPU_TARGETS=${GG_BUILD_AMDGPU_TARGETS}"
78+
CMAKE_EXTRA="${CMAKE_EXTRA} -DGPU_TARGETS=${GG_BUILD_AMDGPU_TARGETS}"
7979
fi
8080

8181
if [ ! -z ${GG_BUILD_SYCL} ]; then

common/json-schema-to-grammar.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ static std::string build_repetition(const std::string & item_rule, int min_items
4141
return result;
4242
}
4343

44-
static void _build_min_max_int(int min_value, int max_value, std::stringstream & out, int decimals_left = 16, bool top_level = true) {
45-
auto has_min = min_value != std::numeric_limits<int>::min();
46-
auto has_max = max_value != std::numeric_limits<int>::max();
44+
static void _build_min_max_int(int64_t min_value, int64_t max_value, std::stringstream & out, int decimals_left = 16, bool top_level = true) {
45+
auto has_min = min_value != std::numeric_limits<int64_t>::min();
46+
auto has_max = max_value != std::numeric_limits<int64_t>::max();
4747

4848
auto digit_range = [&](char from, char to) {
4949
out << "[";
@@ -159,7 +159,7 @@ static void _build_min_max_int(int min_value, int max_value, std::stringstream &
159159
if (has_min) {
160160
if (min_value < 0) {
161161
out << "\"-\" (";
162-
_build_min_max_int(std::numeric_limits<int>::min(), -min_value, out, decimals_left, /* top_level= */ false);
162+
_build_min_max_int(std::numeric_limits<int64_t>::min(), -min_value, out, decimals_left, /* top_level= */ false);
163163
out << ") | [0] | [1-9] ";
164164
more_digits(0, decimals_left - 1);
165165
} else if (min_value == 0) {
@@ -194,7 +194,7 @@ static void _build_min_max_int(int min_value, int max_value, std::stringstream &
194194
}
195195
digit_range(c, c);
196196
out << " (";
197-
_build_min_max_int(std::stoi(min_s.substr(1)), std::numeric_limits<int>::max(), out, less_decimals, /* top_level= */ false);
197+
_build_min_max_int(std::stoll(min_s.substr(1)), std::numeric_limits<int64_t>::max(), out, less_decimals, /* top_level= */ false);
198198
out << ")";
199199
if (c < '9') {
200200
out << " | ";
@@ -216,7 +216,7 @@ static void _build_min_max_int(int min_value, int max_value, std::stringstream &
216216
_build_min_max_int(0, max_value, out, decimals_left, /* top_level= */ true);
217217
} else {
218218
out << "\"-\" (";
219-
_build_min_max_int(-max_value, std::numeric_limits<int>::max(), out, decimals_left, /* top_level= */ false);
219+
_build_min_max_int(-max_value, std::numeric_limits<int64_t>::max(), out, decimals_left, /* top_level= */ false);
220220
out << ")";
221221
}
222222
return;
@@ -925,17 +925,17 @@ class SchemaConverter {
925925
int max_len = schema.contains("maxLength") ? schema["maxLength"].get<int>() : std::numeric_limits<int>::max();
926926
return _add_rule(rule_name, "\"\\\"\" " + build_repetition(char_rule, min_len, max_len) + " \"\\\"\" space");
927927
} else if (schema_type == "integer" && (schema.contains("minimum") || schema.contains("exclusiveMinimum") || schema.contains("maximum") || schema.contains("exclusiveMaximum"))) {
928-
int min_value = std::numeric_limits<int>::min();
929-
int max_value = std::numeric_limits<int>::max();
928+
int64_t min_value = std::numeric_limits<int64_t>::min();
929+
int64_t max_value = std::numeric_limits<int64_t>::max();
930930
if (schema.contains("minimum")) {
931-
min_value = schema["minimum"].get<int>();
931+
min_value = schema["minimum"].get<int64_t>();
932932
} else if (schema.contains("exclusiveMinimum")) {
933-
min_value = schema["exclusiveMinimum"].get<int>() + 1;
933+
min_value = schema["exclusiveMinimum"].get<int64_t>() + 1;
934934
}
935935
if (schema.contains("maximum")) {
936-
max_value = schema["maximum"].get<int>();
936+
max_value = schema["maximum"].get<int64_t>();
937937
} else if (schema.contains("exclusiveMaximum")) {
938-
max_value = schema["exclusiveMaximum"].get<int>() - 1;
938+
max_value = schema["exclusiveMaximum"].get<int64_t>() - 1;
939939
}
940940
std::stringstream out;
941941
out << "(";

convert_hf_to_gguf.py

Lines changed: 99 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -892,8 +892,8 @@ def get_vocab_base_pre(self, tokenizer) -> str:
892892
# ref: https://huggingface.co/JetBrains/Mellum-4b-base
893893
res = "mellum"
894894
if chkhsh == "9b1be57e70d20d9501b2b3186e792d81181ae36ada3903c26f9fea418cf87206":
895-
# ref: https://huggingface.co/inclusionAI/LLaDA-MoE-7B-A1B-Base
896-
res = "llada-moe"
895+
# ref: https://huggingface.co/inclusionAI/Ling-mini-base-2.0
896+
res = "bailingmoe2"
897897
if chkhsh == "53e325976a6e142379c19b09afcae354f2f496f147afa8f9e189a33fe4e3024e":
898898
# ref: https://huggingface.co/ibm-granite/granite-docling-258M
899899
res = "granite-docling"
@@ -8055,6 +8055,103 @@ def prepare_tensors(self):
80558055
raise ValueError(f"Unprocessed experts: {experts}")
80568056

80578057

8058+
@ModelBase.register("BailingMoeV2ForCausalLM")
8059+
class BailingMoeV2Model(TextModel):
8060+
model_arch = gguf.MODEL_ARCH.BAILINGMOE2
8061+
8062+
def __init__(self, *args, **kwargs):
8063+
super().__init__(*args, **kwargs)
8064+
if nextn_layers := self.hparams.get("num_nextn_predict_layers", 0):
8065+
self.block_count = self.hparams["num_hidden_layers"] + nextn_layers
8066+
self.tensor_map = gguf.get_tensor_name_map(self.model_arch, self.block_count)
8067+
8068+
def set_vocab(self):
8069+
self._set_vocab_gpt2()
8070+
8071+
def set_gguf_parameters(self):
8072+
super().set_gguf_parameters()
8073+
hparams = self.hparams
8074+
if (rope_dim := hparams.get("head_dim")) is None:
8075+
rope_dim = hparams["hidden_size"] // hparams["num_attention_heads"]
8076+
8077+
self.gguf_writer.add_rope_dimension_count(int(rope_dim * self.hparams.get("partial_rotary_factor", 0.5)))
8078+
rope_scaling = self.hparams.get("rope_scaling") or {}
8079+
if rope_scaling.get("rope_type", rope_scaling.get("type")) == "yarn" and "factor" in rope_scaling:
8080+
self.gguf_writer.add_rope_scaling_type(gguf.RopeScalingType.YARN)
8081+
self.gguf_writer.add_rope_scaling_factor(rope_scaling["factor"])
8082+
self.gguf_writer.add_rope_scaling_orig_ctx_len(rope_scaling["original_max_position_embeddings"])
8083+
else:
8084+
self.gguf_writer.add_rope_scaling_type(gguf.RopeScalingType.NONE)
8085+
self.gguf_writer.add_leading_dense_block_count(hparams["first_k_dense_replace"])
8086+
self.gguf_writer.add_vocab_size(hparams["vocab_size"])
8087+
self.gguf_writer.add_expert_feed_forward_length(hparams["moe_intermediate_size"])
8088+
self.gguf_writer.add_expert_shared_feed_forward_length(hparams.get("moe_shared_expert_intermediate_size", hparams["moe_intermediate_size"] * hparams["num_shared_experts"]))
8089+
self.gguf_writer.add_expert_weights_scale(hparams["routed_scaling_factor"])
8090+
self.gguf_writer.add_expert_count(hparams["num_experts"])
8091+
self.gguf_writer.add_expert_shared_count(hparams["num_shared_experts"])
8092+
self.gguf_writer.add_expert_group_count(hparams["n_group"])
8093+
self.gguf_writer.add_expert_group_used_count(hparams["topk_group"])
8094+
self.gguf_writer.add_expert_weights_norm(hparams["norm_topk_prob"])
8095+
8096+
if hparams["score_function"] == "sigmoid":
8097+
self.gguf_writer.add_expert_gating_func(gguf.ExpertGatingFuncType.SIGMOID)
8098+
elif hparams["score_function"] == "softmax":
8099+
self.gguf_writer.add_expert_gating_func(gguf.ExpertGatingFuncType.SOFTMAX)
8100+
else:
8101+
raise ValueError(f"Unsupported score_function value: {hparams['score_function']}")
8102+
8103+
if (nextn_layers := self.hparams.get("num_nextn_predict_layers")) is not None:
8104+
self.gguf_writer.add_nextn_predict_layers(nextn_layers)
8105+
8106+
_experts: list[dict[str, Tensor]] | None = None
8107+
8108+
def modify_tensors(self, data_torch: Tensor, name: str, bid: int | None) -> Iterable[tuple[str, Tensor]]:
8109+
if "mlp.experts" in name:
8110+
n_experts = self.hparams["num_experts"]
8111+
assert bid is not None
8112+
8113+
tensors: list[tuple[str, Tensor]] = []
8114+
8115+
if self._experts is None:
8116+
self._experts = [{} for _ in range(self.block_count)]
8117+
8118+
self._experts[bid][name] = data_torch
8119+
8120+
if len(self._experts[bid]) >= n_experts * 3:
8121+
# merge the experts into a single 3d tensor
8122+
for w_name in ["down_proj", "gate_proj", "up_proj"]:
8123+
datas: list[Tensor] = []
8124+
8125+
for xid in range(n_experts):
8126+
ename = f"model.layers.{bid}.mlp.experts.{xid}.{w_name}.weight"
8127+
datas.append(self._experts[bid][ename])
8128+
del self._experts[bid][ename]
8129+
8130+
data_torch = torch.stack(datas, dim=0)
8131+
8132+
merged_name = f"model.layers.{bid}.mlp.experts.{w_name}.weight"
8133+
8134+
new_name = self.map_tensor_name(merged_name)
8135+
8136+
tensors.append((new_name, data_torch))
8137+
8138+
return tensors
8139+
8140+
if name.endswith(".expert_bias"):
8141+
name = name.replace(".expert_bias", ".expert_bias.bias")
8142+
8143+
return [(self.map_tensor_name(name), data_torch)]
8144+
8145+
def prepare_tensors(self):
8146+
super().prepare_tensors()
8147+
8148+
if self._experts is not None:
8149+
# flatten `list[dict[str, Tensor]]` into `list[str]`
8150+
experts = [k for d in self._experts for k in d.keys()]
8151+
if len(experts) > 0:
8152+
raise ValueError(f"Unprocessed experts: {experts}")
8153+
8154+
80588155
@ModelBase.register("GroveMoeForCausalLM", "modeling_grove_moe.GroveMoeForCausalLM")
80598156
class GroveMoeModel(TextModel):
80608157
model_arch = gguf.MODEL_ARCH.GROVEMOE

convert_hf_to_gguf_update.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class TOKENIZER_TYPE(IntEnum):
139139
{"name": "lfm2", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/LiquidAI/LFM2-Tokenizer"},
140140
{"name": "exaone4", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/LGAI-EXAONE/EXAONE-4.0-32B", },
141141
{"name": "mellum", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/JetBrains/Mellum-4b-base", },
142-
{"name": "llada-moe", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/inclusionAI/LLaDA-MoE-7B-A1B-Base", },
142+
{"name": "bailingmoe2", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/inclusionAI/Ling-mini-base-2.0", },
143143
{"name": "granite-docling", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/ibm-granite/granite-docling-258M", },
144144
]
145145

docs/ops.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Legend:
2222
| ARANGE ||||||||||
2323
| ARGMAX ||||||||||
2424
| ARGSORT ||||||||||
25-
| CEIL ||||||| |||
25+
| CEIL ||||||| |||
2626
| CLAMP ||||| 🟡 | 🟡 || 🟡 ||
2727
| CONCAT |||| 🟡 || 🟡 | 🟡 |||
2828
| CONT || 🟡 |||| 🟡 | 🟡 | 🟡 ||
@@ -42,7 +42,7 @@ Legend:
4242
| ELU |||| 🟡 | 🟡 || 🟡 |||
4343
| EXP |||| 🟡 | 🟡 || 🟡 |||
4444
| FLASH_ATTN_EXT || 🟡 || 🟡 | 🟡 ||| 🟡 ||
45-
| FLOOR ||||||| |||
45+
| FLOOR ||||||| |||
4646
| GATED_LINEAR_ATTN ||||||||||
4747
| GEGLU ||||| 🟡 ||| 🟡 ||
4848
| GEGLU_ERF ||||| 🟡 ||| 🟡 ||
@@ -84,7 +84,7 @@ Legend:
8484
| ROLL ||||||||||
8585
| ROPE || 🟡 ||||||||
8686
| ROPE_BACK ||||||||||
87-
| ROUND ||||||| |||
87+
| ROUND ||||||| |||
8888
| RWKV_WKV6 ||||||||||
8989
| RWKV_WKV7 ||||||||||
9090
| SCALE || 🟡 ||||||||
@@ -100,8 +100,8 @@ Legend:
100100
| SOFT_MAX_BACK ||| 🟡 | 🟡 ||| 🟡 |||
101101
| SQR ||||| 🟡 ||| 🟡 ||
102102
| SQRT ||||| 🟡 |||||
103-
| SSM_CONV |||||||| ||
104-
| SSM_SCAN |||||||| ||
103+
| SSM_CONV |||||||| ||
104+
| SSM_SCAN |||||||| ||
105105
| STEP |||| 🟡 | 🟡 || 🟡 |||
106106
| SUB ||||| 🟡 | 🟡 ||||
107107
| SUM ||||||||||
@@ -111,6 +111,6 @@ Legend:
111111
| TANH |||| 🟡 | 🟡 || 🟡 | 🟡 ||
112112
| TIMESTEP_EMBEDDING ||||||||||
113113
| TOPK_MOE ||||||||||
114-
| TRUNC ||||||| |||
114+
| TRUNC ||||||| |||
115115
| UPSCALE || 🟡 ||| 🟡 || 🟡 |||
116116
| XIELU ||||||||||

docs/ops/SYCL.csv

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@
3131
"SYCL0","GELU_ERF","type=f16,ne_a=[5,7,11,13],v=0","support","1","yes","SYCL"
3232
"SYCL0","XIELU","type=f16,ne_a=[128,2,2,2],v=0","support","0","no","SYCL"
3333
"SYCL0","XIELU","type=f16,ne_a=[5,7,11,13],v=0","support","0","no","SYCL"
34+
"SYCL0","FLOOR","type=f16,ne_a=[128,2,2,2],v=0","support","1","yes","SYCL"
35+
"SYCL0","FLOOR","type=f16,ne_a=[5,7,11,13],v=0","support","1","yes","SYCL"
36+
"SYCL0","CEIL","type=f16,ne_a=[128,2,2,2],v=0","support","1","yes","SYCL"
37+
"SYCL0","CEIL","type=f16,ne_a=[5,7,11,13],v=0","support","1","yes","SYCL"
38+
"SYCL0","ROUND","type=f16,ne_a=[128,2,2,2],v=0","support","1","yes","SYCL"
39+
"SYCL0","ROUND","type=f16,ne_a=[5,7,11,13],v=0","support","1","yes","SYCL"
40+
"SYCL0","TRUNC","type=f16,ne_a=[128,2,2,2],v=0","support","1","yes","SYCL"
41+
"SYCL0","TRUNC","type=f16,ne_a=[5,7,11,13],v=0","support","1","yes","SYCL"
3442
"SYCL0","ABS","type=f16,ne_a=[128,2,2,2],v=1","support","0","no","SYCL"
3543
"SYCL0","ABS","type=f16,ne_a=[5,7,11,13],v=1","support","0","no","SYCL"
3644
"SYCL0","SGN","type=f16,ne_a=[128,2,2,2],v=1","support","0","no","SYCL"
@@ -95,6 +103,14 @@
95103
"SYCL0","GELU_ERF","type=f32,ne_a=[5,7,11,13],v=0","support","1","yes","SYCL"
96104
"SYCL0","XIELU","type=f32,ne_a=[128,2,2,2],v=0","support","0","no","SYCL"
97105
"SYCL0","XIELU","type=f32,ne_a=[5,7,11,13],v=0","support","0","no","SYCL"
106+
"SYCL0","FLOOR","type=f32,ne_a=[128,2,2,2],v=0","support","1","yes","SYCL"
107+
"SYCL0","FLOOR","type=f32,ne_a=[5,7,11,13],v=0","support","1","yes","SYCL"
108+
"SYCL0","CEIL","type=f32,ne_a=[128,2,2,2],v=0","support","1","yes","SYCL"
109+
"SYCL0","CEIL","type=f32,ne_a=[5,7,11,13],v=0","support","1","yes","SYCL"
110+
"SYCL0","ROUND","type=f32,ne_a=[128,2,2,2],v=0","support","1","yes","SYCL"
111+
"SYCL0","ROUND","type=f32,ne_a=[5,7,11,13],v=0","support","1","yes","SYCL"
112+
"SYCL0","TRUNC","type=f32,ne_a=[128,2,2,2],v=0","support","1","yes","SYCL"
113+
"SYCL0","TRUNC","type=f32,ne_a=[5,7,11,13],v=0","support","1","yes","SYCL"
98114
"SYCL0","ABS","type=f32,ne_a=[128,2,2,2],v=1","support","0","no","SYCL"
99115
"SYCL0","ABS","type=f32,ne_a=[5,7,11,13],v=1","support","0","no","SYCL"
100116
"SYCL0","SGN","type=f32,ne_a=[128,2,2,2],v=1","support","0","no","SYCL"

0 commit comments

Comments
 (0)