Skip to content

Commit 8dea587

Browse files
Merge pull request #315 from janhq/update-dev-from-master-2025-11-06-00-35
Sync master with upstream release b6962
2 parents b00dc38 + 230d116 commit 8dea587

File tree

26 files changed

+2534
-404
lines changed

26 files changed

+2534
-404
lines changed

common/common.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,10 @@ struct common_params {
507507
// return false from callback to abort model loading or true to continue
508508
llama_progress_callback load_progress_callback = NULL;
509509
void * load_progress_callback_user_data = NULL;
510+
511+
bool has_speculative() const {
512+
return !speculative.model.path.empty() || !speculative.model.hf_repo.empty();
513+
}
510514
};
511515

512516
// call once at the start of a program if it uses libcommon

convert_hf_to_gguf.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7187,6 +7187,42 @@ def modify_tensors(self, data_torch: Tensor, name: str, bid: int | None):
71877187
return super().modify_tensors(data_torch, name, bid)
71887188

71897189

7190+
@ModelBase.register("PanguEmbeddedForCausalLM")
7191+
class PanguEmbeddedModel(TextModel):
7192+
model_arch = gguf.MODEL_ARCH.PANGU_EMBED
7193+
7194+
def set_vocab(self):
7195+
self._set_vocab_sentencepiece()
7196+
7197+
tokenizer_config_file = self.dir_model / 'tokenizer_config.json'
7198+
if tokenizer_config_file.is_file():
7199+
with open(tokenizer_config_file, "r", encoding="utf-8") as f:
7200+
tokenizer_config_json = json.load(f)
7201+
if "add_prefix_space" in tokenizer_config_json:
7202+
self.gguf_writer.add_add_space_prefix(tokenizer_config_json["add_prefix_space"])
7203+
7204+
def set_gguf_parameters(self):
7205+
super().set_gguf_parameters()
7206+
hparams = self.hparams
7207+
self.gguf_writer.add_vocab_size(hparams["vocab_size"])
7208+
7209+
# PanguEmbedded's hparam loaded from config.json without head_dim
7210+
if (rope_dim := hparams.get("head_dim")) is None:
7211+
rope_dim = hparams["hidden_size"] // hparams["num_attention_heads"]
7212+
self.gguf_writer.add_rope_dimension_count(rope_dim)
7213+
7214+
if hparams.get("head_dim") is None:
7215+
self.gguf_writer.add_key_length(rope_dim)
7216+
self.gguf_writer.add_value_length(rope_dim)
7217+
7218+
def modify_tensors(self, data_torch: Tensor, name: str, bid: int | None) -> Iterable[tuple[str, Tensor]]:
7219+
if name == "lm_head.weight":
7220+
if self.hparams.get("tie_word_embeddings", False):
7221+
logger.info("Skipping tied output layer 'lm_head.weight'")
7222+
return []
7223+
return [(self.map_tensor_name(name), data_torch)]
7224+
7225+
71907226
@ModelBase.register("Dots1ForCausalLM")
71917227
class Dots1Model(Qwen2MoeModel):
71927228
model_arch = gguf.MODEL_ARCH.DOTS1

docs/backend/OPENCL.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,41 @@ The llama.cpp OpenCL backend is designed to enable llama.cpp on **Qualcomm Adren
3939
| Adreno 830 (Snapdragon 8 Elite) | Support |
4040
| Adreno X85 (Snapdragon X Elite) | Support |
4141

42+
> A6x GPUs with a recent driver and compiler are supported; they are usually found in IoT platforms.
43+
However, A6x GPUs in phones are likely not supported due to the outdated driver and compiler.
44+
4245
## DataType Supports
4346

4447
| DataType | Status |
4548
|:----------------------:|:--------------------------:|
4649
| Q4_0 | Support |
4750
| Q6_K | Support, but not optimized |
51+
| Q8_0 | Support |
52+
| MXFP4 | Support |
4853

4954
## Model Preparation
5055

51-
You can refer to the general [*Prepare and Quantize*](README.md#prepare-and-quantize) guide for model prepration.
56+
You can refer to the general [llama-quantize tool](/tools/quantize/README.md) for steps to convert a model in Hugging Face safetensor format to GGUF with quantization.
5257

53-
Currently we support `Q4_0` quantization and have optimize for it. To achieve best performance on Adreno GPU, add `--pure` to `llama-quantize`. For example,
58+
Currently we support `Q4_0` quantization and have optimized for it. To achieve best performance on Adreno GPU, add `--pure` to `llama-quantize` (i.e., make all weights in `Q4_0`). For example,
5459

5560
```sh
5661
./llama-quantize --pure ggml-model-qwen2.5-3b-f16.gguf ggml-model-qwen-3b-Q4_0.gguf Q4_0
5762
```
5863

5964
Since `Q6_K` is also supported, `Q4_0` quantization without `--pure` will also work. However, the performance will be worse compared to pure `Q4_0` quantization.
6065

66+
### `MXFP4` MoE Models
67+
68+
OpenAI gpt-oss models are MoE models in `MXFP4`. The quantized model will be in `MXFP4_MOE`, a mixture of `MXFP4` and `Q8_0`.
69+
For this quantization, there is no need to specify `--pure`.
70+
For gpt-oss-20b model, you can directly [download](https://huggingface.co/ggml-org/gpt-oss-20b-GGUF) the quantized GGUF file in `MXFP4_MOE` from Hugging Face.
71+
72+
Although it is possible to quantize gpt-oss-20b model in pure `Q4_0` (all weights in `Q4_0`), it is not recommended since `MXFP4` has been optimized for MoE while `Q4_0` is not. In addition, accuracy should degrade with such pure `Q4_0` quantization.
73+
Hence, using the default `MXFP4_MOE` quantization (see the link above) is recommended for this model.
74+
75+
> Note that the `Q4_0` model found [here](https://huggingface.co/unsloth/gpt-oss-20b-GGUF/blob/main/gpt-oss-20b-Q4_0.gguf) is a mixture of `Q4_0`, `Q8_0` and `MXFP4` and gives better performance than `MXFP4_MOE` quantization.
76+
6177
## CMake Options
6278

6379
The OpenCL backend has the following CMake options that control the behavior of the backend.
@@ -146,10 +162,13 @@ A Snapdragon X Elite device with Windows 11 Arm64 is used. Make sure the followi
146162
* Ninja
147163
* Visual Studio 2022
148164
* Powershell 7
165+
* Python
149166

150167
Visual Studio provides necessary headers and libraries although it is not directly used for building.
151168
Alternatively, Visual Studio Build Tools can be installed instead of the full Visual Studio.
152169

170+
> Note that building using Visual Studio's cl compiler is not supported. Clang must be used. Clang depends on libraries provided by Visual Studio to work. Therefore, Visual Studio must be installed. Alternatively, Visual Studio Build Tools can be installed instead of the full Visual Studio.
171+
153172
Powershell 7 is used for the following commands.
154173
If an older version of Powershell is used, these commands may not work as they are.
155174

@@ -201,9 +220,12 @@ ninja
201220

202221
## Known Issues
203222

204-
- Currently OpenCL backend does not work on Adreno 6xx GPUs.
223+
- Flash attention does not always improve performance.
224+
- Currently OpenCL backend works on A6xx GPUs with recent drivers and compilers (usually found in IoT platforms).
225+
However, it does not work on A6xx GPUs found in phones with old drivers and compilers.
205226

206227
## TODO
207228

208229
- Optimization for Q6_K
209230
- Support and optimization for Q4_K
231+
- Improve flash attention

docs/ops.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ Legend:
2222
| ARANGE ||||||||||
2323
| ARGMAX ||||||||||
2424
| ARGSORT ||||||||||
25-
| CEIL |||| ||||||
25+
| CEIL |||| 🟡 ||||||
2626
| CLAMP ||||| 🟡 | 🟡 || 🟡 ||
2727
| CONCAT |||| 🟡 || 🟡 | 🟡 |||
2828
| CONT || 🟡 |||| 🟡 | 🟡 | 🟡 ||
29-
| CONV_2D |||| ||||||
29+
| CONV_2D |||| 🟡 ||||||
3030
| CONV_2D_DW ||||||||||
3131
| CONV_3D ||||||||||
3232
| CONV_TRANSPOSE_1D ||||||||||
@@ -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 || 🟡 ||||||||
@@ -111,6 +111,6 @@ Legend:
111111
| TANH |||| 🟡 | 🟡 || 🟡 | 🟡 ||
112112
| TIMESTEP_EMBEDDING ||||||||||
113113
| TOPK_MOE ||||||||||
114-
| TRUNC |||| ||||||
114+
| TRUNC |||| 🟡 ||||||
115115
| UPSCALE || 🟡 ||| 🟡 || 🟡 |||
116116
| XIELU ||||||||||

0 commit comments

Comments
 (0)