From 55d323507de290f5baacf56082b087a6bccfc7d9 Mon Sep 17 00:00:00 2001 From: nicholas-mainardi-domyn Date: Fri, 20 Nov 2026 08:51:41 +0100 Subject: [PATCH] model: add Domyn Edge 4B Model (#32559) * feat: add domyn-edge model * Generate tokenizer hash for conversion + fix tests * Address changes according to code-review skill * catch ValueError in convert_hf_to_gguf_update.py * renegerate fusion test baseline + fix model naming style --- conversion/__init__.py | 1 + conversion/base.py | 3 + conversion/domynedge.py | 53 +++++++++++ convert_hf_to_gguf_update.py | 6 +- gguf-py/gguf/constants.py | 18 ++++ gguf-py/gguf/tensor_mapping.py | 8 ++ src/llama-arch.cpp | 1 + src/llama-arch.h | 1 + src/llama-model.cpp | 3 + src/llama-vocab.cpp | 3 +- src/models/domyn-edge.cpp | 164 +++++++++++++++++++++++++++++++++ src/models/models.h | 13 +++ tests/fusion/MTL.csv | 2 + tests/test-llama-archs.cpp | 10 +- tests/test-tokenizer-random.py | 9 +- 15 files changed, 285 insertions(+), 10 deletions(-) create mode 100644 conversion/domynedge.py create mode 100644 src/models/domyn-edge.cpp diff --git a/conversion/__init__.py b/conversion/__init__.py index 1182c06be..253a18fd4 100644 --- a/conversion/__init__.py +++ b/conversion/__init__.py @@ -78,6 +78,7 @@ TEXT_MODEL_MAP: dict[str, str] = { "DistilBertForMaskedLM": "bert", "DistilBertForSequenceClassification": "bert", "DistilBertModel": "bert", + "DomynEdgeForCausalLM": "domynedge", "Dots1ForCausalLM": "dots1", "Dots3NoteForCausalLM": "dots3", "Dots3NoteForConditionalGeneration": "dots3", diff --git a/conversion/base.py b/conversion/base.py index 7cfbff321..540a66ba5 100644 --- a/conversion/base.py +++ b/conversion/base.py @@ -2470,6 +2470,9 @@ class TextModel(ModelBase): if chkhsh == "5635e1c8d621dff7b4825f41f2f97b6ceb39bcf2d5c541db28577080d6efd5e5": # ref: https://huggingface.co/thinkingmachines/Inkling-2-Small res = "inkling2" + if chkhsh == "32d85c31273f8019248f2559fed492d929ea28b17e51d81d3bb36fff23ca72b3": + # ref: https://huggingface.co/domyn/Domyn-Edge-Teacher-IF + res = "domyn-edge" if res is None: logger.warning("\n") diff --git a/conversion/domynedge.py b/conversion/domynedge.py new file mode 100644 index 000000000..df07add83 --- /dev/null +++ b/conversion/domynedge.py @@ -0,0 +1,53 @@ +from .base import TextModel, ModelBase +import gguf + + +@ModelBase.register("DomynEdgeForCausalLM") +@ModelBase.example("domyn/Domyn-Edge-Teacher-IF") +class DomynEdgeModel(TextModel): + model_arch = gguf.MODEL_ARCH.DOMYN_EDGE + + def set_gguf_parameters(self): + super().set_gguf_parameters() + hparams = self.hparams + self.gguf_writer.add_vocab_size(hparams["vocab_size"]) + + position_layers = hparams["position_layers"] # list of "rope"/"nope" strings per layer + head_sizes = hparams["head_sizes"] # list of int head dims per layer + + # Per-layer rope/SWA pattern: True="rope", False="nope" + rope_pattern = [v == "rope" for v in position_layers] + self.gguf_writer.add_rope_pattern(rope_pattern) + self.gguf_writer.add_sliding_window_pattern(rope_pattern) # SWA <-> RoPE in domyn-edge + + # window_sizes entries are flash-attn style [left, right] (current token excluded; -1 = full attention), + # while llama.cpp's n_swa counts the current token, hence the +1 (matches HF's sliding_window=1025) + swa_window = hparams.get("sliding_window") + if swa_window is None: + window_sizes = hparams.get("window_sizes") # list of [size, offset] pairs per layer + if window_sizes is None: + raise KeyError("Neither `sliding_window` nor `window_sizes` found among domyn edge hyperparameters") + left = next((ws[0] for v, ws in zip(position_layers, window_sizes) if v == "rope"), None) + swa_window = left + 1 if left is not None and left > 0 else None + if swa_window is None: + raise ValueError("No sliding window size found among domyn edge hyperparameters") + self.gguf_writer.add_sliding_window(swa_window) + + # Head dims differ between full-attention ("nope") and SWA ("rope") layers + full_head_dims = {h for v, h in zip(position_layers, head_sizes) if v == "nope"} + swa_head_dims = {h for v, h in zip(position_layers, head_sizes) if v == "rope"} + + if len(full_head_dims) != 1: + raise ValueError(f"Expected one head dimension for full attention layers, found {len(full_head_dims)}") + full_head_dim = full_head_dims.pop() + + self.gguf_writer.add_key_length(full_head_dim) + self.gguf_writer.add_value_length(full_head_dim) + + if len(swa_head_dims) != 1: + raise ValueError(f"Expected one head dimension for SWA attention layers, found {len(swa_head_dims)}") + swa_head_dim = swa_head_dims.pop() + + self.gguf_writer.add_key_length_swa(swa_head_dim) + self.gguf_writer.add_value_length_swa(swa_head_dim) + self.gguf_writer.add_rope_dimension_count_swa(swa_head_dim) diff --git a/convert_hf_to_gguf_update.py b/convert_hf_to_gguf_update.py index ff5fca4ff..91fb418a5 100755 --- a/convert_hf_to_gguf_update.py +++ b/convert_hf_to_gguf_update.py @@ -168,6 +168,7 @@ models = [ {"name": "mmbert", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/jhu-clsp/mmBERT-base", }, {"name": "k2-horizon", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/IFM/K2-Horizon-36B", }, {"name": "inkling2", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/thinkingmachines/Inkling-2-Small", }, + {"name": "domyn-edge", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/domyn/Domyn-Edge-Teacher-IF", }, ] # some models are known to be broken upstream, so we will skip them as exceptions @@ -227,8 +228,6 @@ def download_model(model): repo = model["repo"] tokt = model["tokt"] - os.makedirs(f"models/tokenizers/{name}", exist_ok=True) - files = ["config.json", "tokenizer.json", "tokenizer_config.json"] if name == "gpt-4o": @@ -243,6 +242,7 @@ def download_model(model): if os.path.isdir(repo): # If repo is a path on the file system, copy the directory + os.makedirs(f"models/tokenizers/{name}", exist_ok=True) for file in files: src_path = os.path.join(repo, file) dst_path = f"models/tokenizers/{name}/{file}" @@ -484,7 +484,7 @@ for model in models: tokenizer = AutoTokenizer.from_pretrained(f"models/tokenizers/{name}", use_fast=False) else: tokenizer = AutoTokenizer.from_pretrained(f"models/tokenizers/{name}") - except (OSError, TypeError) as e: + except (OSError, TypeError, ValueError) as e: logger.error(f"Failed to load tokenizer for model {name}. Error: {e}") continue # Skip this model and continue with the next one in the loop diff --git a/gguf-py/gguf/constants.py b/gguf-py/gguf/constants.py index e07ea2f4b..f36566a81 100644 --- a/gguf-py/gguf/constants.py +++ b/gguf-py/gguf/constants.py @@ -778,6 +778,7 @@ class MODEL_ARCH(IntEnum): KOLIBRI1 = auto() LIMITE = auto() INKLING2 = auto() + DOMYN_EDGE = auto() class VISION_PROJECTOR_TYPE(IntEnum): @@ -1778,6 +1779,7 @@ MODEL_ARCH_NAMES: dict[MODEL_ARCH, str] = { MODEL_ARCH.KOLIBRI1: "kolibri1", MODEL_ARCH.LIMITE: "limite", MODEL_ARCH.INKLING2: "inkling2", + MODEL_ARCH.DOMYN_EDGE: "domynedge", } VISION_PROJECTOR_TYPE_NAMES: dict[VISION_PROJECTOR_TYPE, str] = { @@ -7085,6 +7087,22 @@ MODEL_TENSORS: dict[MODEL_ARCH, list[MODEL_TENSOR]] = { MODEL_TENSOR.FFN_POST_CONV, MODEL_TENSOR.FFN_RES_QUERY, ], + MODEL_ARCH.DOMYN_EDGE: [ + MODEL_TENSOR.TOKEN_EMBD, + MODEL_TENSOR.ATTN_Q, + MODEL_TENSOR.ATTN_K, + MODEL_TENSOR.ATTN_V, + MODEL_TENSOR.ATTN_OUT, + MODEL_TENSOR.ATTN_K_NORM, + MODEL_TENSOR.ATTN_NORM, + MODEL_TENSOR.ATTN_POST_NORM, + MODEL_TENSOR.FFN_PRE_NORM, + MODEL_TENSOR.FFN_POST_NORM, + MODEL_TENSOR.FFN_DOWN, + MODEL_TENSOR.FFN_UP, + MODEL_TENSOR.FFN_GATE, + MODEL_TENSOR.OUTPUT_NORM, + ], } # tensors that will not be serialized diff --git a/gguf-py/gguf/tensor_mapping.py b/gguf-py/gguf/tensor_mapping.py index c844a9322..d48d46b9a 100644 --- a/gguf-py/gguf/tensor_mapping.py +++ b/gguf-py/gguf/tensor_mapping.py @@ -272,6 +272,7 @@ class TensorNameMap: "model.layers.{bid}.pre_attention_layernorm", # kormo "head.layers.{bid}.norm1", # laya "model.layers.{bid}.attn_norm", # inkling2 + "model.layers.{bid}.pre_attention_norm", # domynedge ), # Attention norm 2 @@ -440,6 +441,7 @@ class TensorNameMap: "model.layers.{bid}.post_attn_norm", # kolibri1 "model.layers.layers.{bid}.post_mixer_norm.weight", # plamo2 "model.layers.{bid}.post_operator_norm", # lfm3 + "model.layers.{bid}.post_attention_norm", # domynedge ), # Rotary embeddings @@ -579,6 +581,7 @@ class TensorNameMap: "layers.{bid}.pre_feedforward_layernorm", # embeddinggemma "model.layers.{bid}.pre_ff_layernorm.weight", "model.layers.{bid}.pre_mlp_layernorm", # afmoe + "model.layers.{bid}.pre_feedforward_norm", # domynedge ), MODEL_TENSOR.FFN_PRE_NORM_2: ( @@ -603,6 +606,7 @@ class TensorNameMap: "model.layers.{bid}.feed_forward.up_proj", "model.layers.{bid}.post_moe_norm", # grok-2 "model.layers.{bid}.post_ffn_norm", # lfm3 + "model.layers.{bid}.post_feedforward_norm", # domynedge ), MODEL_TENSOR.FFN_POST_NORM_1: ( @@ -692,6 +696,7 @@ class TensorNameMap: "encoder.layers.{bid}.mlp.dense_h_to_4h", # chatglm "transformer.h.{bid}.mlp.c_fc_1", # exaone "model.layers.{bid}.feed_forward.up_proj", # llama4 jamba granite-hybrid + "model.layers.{bid}.feedforward.up_proj", # domynedge "transformer_encoder.{bid}.ffn.w12", # neobert "model.layers.{bid}.block_sparse_moe.up", # smallthinker "model.transformer.blocks.{bid}.up_proj", # llada @@ -755,6 +760,7 @@ class TensorNameMap: "layers.{bid}.mlp.gate_proj", # qwen3-embedding "model.layers.{bid}.mlp.language_mlp.gate_proj", # cogvlm "model.blocks.{bid}.mlp.mlp_gate", # talkie + "model.layers.{bid}.feedforward.gate_proj", # domynedge ), MODEL_TENSOR.FFN_GATE_EXP: ( @@ -923,6 +929,7 @@ class TensorNameMap: "encoder.layers.{bid}.mlp.dense_4h_to_h", # chatglm "model.layers.h.{bid}.mlp.c_proj", # exaone "model.layers.{bid}.feed_forward.down_proj", # llama4 jamba granite-hybrid + "model.layers.{bid}.feedforward.down_proj", # domynedge "transformer_encoder.{bid}.ffn.w3", # neobert "model.layers.{bid}.block_sparse_moe.down", # smallthinker "model.transformer.blocks.{bid}.ff_out", # llada @@ -997,6 +1004,7 @@ class TensorNameMap: "layers.{bid}.self_attn.k_norm", # qwen3-embedding "model.layers.{bid}.self_attn.k_rope_only_layernorm", # dots3note "model.layers.{bid}.attention.key_layernorm", # apertus + "model.layers.{bid}.attention.k_norm", # domynedge ), MODEL_TENSOR.ROPE_FREQS: ( diff --git a/src/llama-arch.cpp b/src/llama-arch.cpp index c50e9f98a..1c90b2180 100644 --- a/src/llama-arch.cpp +++ b/src/llama-arch.cpp @@ -184,6 +184,7 @@ static const std::map LLM_ARCH_NAMES = { { LLM_ARCH_KOLIBRI1, "kolibri1" }, { LLM_ARCH_RICURSIVE, "ricursive" }, { LLM_ARCH_INKLING2, "inkling2" }, + { LLM_ARCH_DOMYN_EDGE, "domynedge" }, { LLM_ARCH_UNKNOWN, "(unknown)" }, }; diff --git a/src/llama-arch.h b/src/llama-arch.h index 9c517a9fe..a8c0fdf09 100644 --- a/src/llama-arch.h +++ b/src/llama-arch.h @@ -188,6 +188,7 @@ enum llm_arch { LLM_ARCH_LIMITE, LLM_ARCH_RICURSIVE, LLM_ARCH_INKLING2, + LLM_ARCH_DOMYN_EDGE, LLM_ARCH_UNKNOWN, }; diff --git a/src/llama-model.cpp b/src/llama-model.cpp index ac5266a42..629b3a7a6 100644 --- a/src/llama-model.cpp +++ b/src/llama-model.cpp @@ -394,6 +394,8 @@ static llama_model * llama_model_mapping(llm_arch arch, const llama_model_params return new llama_model_k2_horizon(params); case LLM_ARCH_KOLIBRI1: return new llama_model_kolibri1(params); + case LLM_ARCH_DOMYN_EDGE: + return new llama_model_domyn_edge(params); default: throw std::runtime_error(std::string("unsupported model architecture: '") + llm_arch_name(arch) + "'"); } @@ -3873,6 +3875,7 @@ llama_rope_type llama_model_rope_type(const llama_model * model) { case LLM_ARCH_HRM_TEXT: case LLM_ARCH_BEAM: case LLM_ARCH_KOLIBRI1: + case LLM_ARCH_DOMYN_EDGE: return LLAMA_ROPE_TYPE_NEOX; case LLM_ARCH_DFLASH: diff --git a/src/llama-vocab.cpp b/src/llama-vocab.cpp index 3aecacb51..f3e1d0192 100644 --- a/src/llama-vocab.cpp +++ b/src/llama-vocab.cpp @@ -2566,7 +2566,8 @@ void llama_vocab::impl::load(llama_model_loader & ml, const LLM_KV & kv) { tokenizer_pre == "qwen2" || tokenizer_pre == "deepseek-r1-qwen" || tokenizer_pre == "kormo" || - tokenizer_pre == "f2llmv2") { + tokenizer_pre == "f2llmv2" || + tokenizer_pre == "domyn-edge") { pre_type = LLAMA_VOCAB_PRE_TYPE_QWEN2; clean_spaces = false; } else if ( diff --git a/src/models/domyn-edge.cpp b/src/models/domyn-edge.cpp new file mode 100644 index 000000000..6452894d3 --- /dev/null +++ b/src/models/domyn-edge.cpp @@ -0,0 +1,164 @@ +#include "models.h" + +void llama_model_domyn_edge::load_arch_hparams(llama_model_loader & ml) { + ml.get_key(LLM_KV_ATTENTION_LAYERNORM_RMS_EPS, hparams.f_norm_rms_eps); + ml.get_key(LLM_KV_ATTENTION_SLIDING_WINDOW, hparams.n_swa); + // required: the base loader defaults it to n_rot_full if the key is not found + ml.get_key(LLM_KV_ROPE_DIMENSION_COUNT_SWA, hparams.n_rot_swa); + // RoPE cannot rotate more dims than the SWA head has: CPU aborts, GPU backends read past the row + if (hparams.n_rot_swa > hparams.n_embd_head_k_swa) { + throw std::runtime_error(format("invalid n_rot_swa: %u, max %u", hparams.n_rot_swa, hparams.n_embd_head_k_swa)); + } + + hparams.swa_type = LLAMA_SWA_TYPE_STANDARD; + + ml.get_arr(LLM_KV_ATTENTION_SLIDING_WINDOW_PATTERN, hparams.is_swa_impl); + ml.get_arr(LLM_KV_ATTENTION_ROPE_PATTERN, hparams.rope_pattern); + + // only for print_info / saver; get_rope_params uses cparams + hparams.rope_freq_base_train_swa = hparams.rope_freq_base_train; + hparams.rope_freq_scale_train_swa = hparams.rope_freq_scale_train; + + switch (hparams.n_layer()) { + case 36: type = LLM_TYPE_4B; break; + default: type = LLM_TYPE_UNKNOWN; + } +} + +void llama_model_domyn_edge::load_arch_tensors(llama_model_loader &) { + LLAMA_LOAD_LOCALS; + + tok_embd = create_tensor(tn(LLM_TENSOR_TOKEN_EMBD, "weight"), {n_embd, n_vocab}, 0); + output_norm = create_tensor(tn(LLM_TENSOR_OUTPUT_NORM, "weight"), {n_embd}, 0); + output = create_tensor(tn(LLM_TENSOR_OUTPUT, "weight"), {n_embd, n_vocab}, TENSOR_NOT_REQUIRED); + + // if output is NULL, init from the input tok embed + if (output == NULL) { + output = create_tensor(tn(LLM_TENSOR_TOKEN_EMBD, "weight"), {n_embd, n_vocab}, TENSOR_DUPLICATED); + } + + for (int i = 0; i < n_layer; ++i) { + auto & layer = layers[i]; + const int64_t n_embd_head_i = hparams.n_embd_head_k(i); + const int64_t n_embd_k_i = hparams.n_embd_k_gqa(i); + const int64_t n_embd_v_i = hparams.n_embd_v_gqa(i); + + layer.attn_norm = create_tensor(tn(LLM_TENSOR_ATTN_NORM, "weight", i), {n_embd}, 0); + layer.attn_post_norm = create_tensor(tn(LLM_TENSOR_ATTN_POST_NORM, "weight", i), {n_embd}, 0); + + const int64_t n_embd_q_i = n_embd_head_i * n_head; + create_tensor_qkv(layer, i, n_embd, n_embd_q_i, n_embd_k_i, n_embd_v_i, 0); + layer.wo = create_tensor(tn(LLM_TENSOR_ATTN_OUT, "weight", i), {n_embd_head_i * n_head, n_embd}, 0); + + // K-norm has a learnable weight; Q-norm does not + layer.attn_k_norm = create_tensor(tn(LLM_TENSOR_ATTN_K_NORM, "weight", i), {n_embd_head_i}, 0); + + layer.ffn_norm = create_tensor(tn(LLM_TENSOR_FFN_NORM, "weight", i), {n_embd}, 0); + layer.ffn_post_norm = create_tensor(tn(LLM_TENSOR_FFN_POST_NORM, "weight", i), {n_embd}, 0); + + layer.ffn_gate = create_tensor(tn(LLM_TENSOR_FFN_GATE, "weight", i), {n_embd, n_ff}, 0); + layer.ffn_up = create_tensor(tn(LLM_TENSOR_FFN_UP, "weight", i), {n_embd, n_ff}, 0); + layer.ffn_down = create_tensor(tn(LLM_TENSOR_FFN_DOWN, "weight", i), {n_ff, n_embd}, 0); + } +} + +llama_rope_params llama_model_domyn_edge::get_rope_params(const llama_cparams & cparams, int il) const { + auto res = llama_model::get_rope_params(cparams, il); + + // the SWA layers use the global base and scale + res.freq_base = cparams.rope_freq_base; + res.freq_scale = cparams.rope_freq_scale; + + return res; +} + +llama_model_domyn_edge::graph::graph(const llm_graph_params & params) + : llm_graph_context(params) { + ggml_tensor * cur; + ggml_tensor * inpL = build_inp_embd(model.tok_embd); + ggml_tensor * inp_pos = build_inp_pos(); + + auto * inp_attn = build_attn_inp_kv_iswa(); + + ggml_tensor * inp_out_ids = build_inp_out_ids(); + + for (int il = 0; il < n_layer; ++il) { + const auto & layer = model.layers[il]; + const int64_t n_embd_head = hparams.n_embd_head_k(il); + const int64_t n_head_il = hparams.n_head(il); + const int64_t n_head_kv_il = hparams.n_head_kv(il); + const float kq_scale = 1.0f / sqrtf((float)n_embd_head); + + ggml_tensor * residual = inpL; + + // pre-attention norm + cur = build_norm(inpL, layer.attn_norm, NULL, LLM_NORM_RMS, il); + cb(cur, "attn_norm", il); + + auto [Qcur, Kcur, Vcur] = build_qkv(layer, cur, n_embd_head, n_head_il, n_head_kv_il, il); + + // Q-norm: RMSNorm without learnable weight (elementwise_affine=False) + Qcur = build_norm(Qcur, NULL, NULL, LLM_NORM_RMS, il); + cb(Qcur, "Qcur_normed", il); + + // K-norm: RMSNorm with learnable weight + Kcur = build_norm(Kcur, layer.attn_k_norm, NULL, LLM_NORM_RMS, il); + cb(Kcur, "Kcur_normed", il); + + // build_rope already applies RoPE only if the current layer is a RoPE layer + Qcur = build_rope(Qcur, inp_pos, il); + cb(Qcur, "Qcur_rope", il); + + Kcur = build_rope(Kcur, inp_pos, il); + cb(Kcur, "Kcur_rope", il); + + cur = build_attn(inp_attn, + layer.wo, NULL, layer.wo_s, + Qcur, Kcur, Vcur, nullptr, nullptr, nullptr, kq_scale, il); + cb(cur, "attn_out", il); + + // post-attention norm applied to attn output before residual add + cur = build_norm(cur, layer.attn_post_norm, NULL, LLM_NORM_RMS, il); + cb(cur, "attn_post_norm", il); + + if (il == n_layer - 1 && inp_out_ids) { + cur = ggml_get_rows(ctx0, cur, inp_out_ids); + residual = ggml_get_rows(ctx0, residual, inp_out_ids); + } + + ggml_tensor * ffn_inp = ggml_add(ctx0, cur, residual); + cb(ffn_inp, "ffn_inp", il); + + // pre-FFN norm + cur = build_norm(ffn_inp, layer.ffn_norm, NULL, LLM_NORM_RMS, il); + cb(cur, "ffn_norm", il); + + // SwiGLU FFN + cur = build_ffn(cur, + layer.ffn_up, NULL, NULL, + layer.ffn_gate, NULL, NULL, + layer.ffn_down, NULL, NULL, NULL, + LLM_FFN_SILU, LLM_FFN_PAR, il); + cb(cur, "ffn_out", il); + + // post-FFN norm applied to ffn output before residual add + cur = build_norm(cur, layer.ffn_post_norm, NULL, LLM_NORM_RMS, il); + cb(cur, "ffn_post_norm", il); + + cur = ggml_add(ctx0, cur, ffn_inp); + inpL = build_cvec(cur, il); + cb(inpL, "l_out", il); + } + + cur = build_norm(inpL, model.output_norm, NULL, LLM_NORM_RMS, -1); + cb(cur, "result_norm", -1); + res->t_embd = cur; + + cur = build_lora_mm(model.output, cur, model.output_s); + cb(cur, "result_output", -1); + res->t_logits = cur; +} + +std::unique_ptr llama_model_domyn_edge::build_arch_graph(const llm_graph_params & params) const { + return std::make_unique(params); +} diff --git a/src/models/models.h b/src/models/models.h index e7849e07d..e0a4db5f7 100644 --- a/src/models/models.h +++ b/src/models/models.h @@ -3308,3 +3308,16 @@ struct llama_model_kolibri1 : public llama_model_base { std::unique_ptr build_arch_graph(const llm_graph_params & params) const override; }; + +struct llama_model_domyn_edge : public llama_model_base { + llama_model_domyn_edge(const struct llama_model_params & params) : llama_model_base(params) {} + void load_arch_hparams(llama_model_loader & ml) override; + void load_arch_tensors(llama_model_loader & ml) override; + llama_rope_params get_rope_params(const llama_cparams & cparams, int il) const override; + + struct graph : public llm_graph_context { + graph(const llm_graph_params & params); + }; + + std::unique_ptr build_arch_graph(const llm_graph_params & params) const override; +}; diff --git a/tests/fusion/MTL.csv b/tests/fusion/MTL.csv index 310934e31..295740c7c 100644 --- a/tests/fusion/MTL.csv +++ b/tests/fusion/MTL.csv @@ -65,6 +65,8 @@ deepseek4 ,0 ,any ,UNARY+SQRT+ADD+ARGSORT+GET_ROWS+SUM_ROWS+CLAM deepseek41 ,0 ,any ,MUL+ADD , 12 deepseek41 ,0 ,any ,RMS_NORM+MUL , 29 deepseek41 ,0 ,any ,UNARY+SQRT+ADD+ARGSORT+GET_ROWS+SUM_ROWS+SCALE+DIV, 6 +domynedge ,0 ,any ,RMS_NORM+MUL , 8 +domynedge ,0 ,any ,RMS_NORM+MUL+ADD , 3 dots1 ,0 ,any ,ADD+ADD , 1 dots1 ,0 ,any ,MUL+ADD , 2 dots1 ,0 ,any ,RMS_NORM+MUL , 9 diff --git a/tests/test-llama-archs.cpp b/tests/test-llama-archs.cpp index f10404e8c..90a32abc7 100644 --- a/tests/test-llama-archs.cpp +++ b/tests/test-llama-archs.cpp @@ -496,16 +496,22 @@ static gguf_context_ptr get_gguf_ctx(const llm_arch arch, const bool moe, const ms.add_kv(LLM_KV_ATTENTION_SLIDING_WINDOW_PATTERN, pattern); } else if (arch == LLM_ARCH_COHERE2MOE || arch == LLM_ARCH_MIMO2 || arch == LLM_ARCH_STEP35 || arch == LLM_ARCH_SPARK2_5 || arch == LLM_ARCH_MUSE_GLIMMER || arch == LLM_ARCH_MUSE_SPARK || arch == LLM_ARCH_GRANITE_SWA || arch == LLM_ARCH_DOTS3NOTE || - arch == LLM_ARCH_KOLIBRI1 || arch == LLM_ARCH_MAPLE || arch == LLM_ARCH_FLINT || arch == LLM_ARCH_BEAM || arch == LLM_ARCH_RICURSIVE) { + arch == LLM_ARCH_KOLIBRI1 || arch == LLM_ARCH_MAPLE || arch == LLM_ARCH_FLINT || arch == LLM_ARCH_BEAM || arch == LLM_ARCH_RICURSIVE || arch == LLM_ARCH_DOMYN_EDGE) { std::vector pattern; pattern.reserve(n_layer); for (uint32_t il = 0; il < n_layer; il++) { pattern.push_back(il % 2); } ms.add_kv(LLM_KV_ATTENTION_SLIDING_WINDOW_PATTERN, pattern); - if (arch == LLM_ARCH_FLINT) { + if (arch == LLM_ARCH_FLINT || arch == LLM_ARCH_DOMYN_EDGE) { ms.add_kv(LLM_KV_ATTENTION_ROPE_PATTERN, pattern); } + if (arch == LLM_ARCH_DOMYN_EDGE) { + // SWA (rope) layers use a smaller head dim than the full-attention (nope) layers + ms.add_kv(LLM_KV_ATTENTION_KEY_LENGTH_SWA, n_embd_head/2); + ms.add_kv(LLM_KV_ATTENTION_VALUE_LENGTH_SWA, n_embd_head/2); + ms.add_kv(LLM_KV_ROPE_DIMENSION_COUNT_SWA, n_embd_head/2); + } } else if (arch == LLM_ARCH_LFM3) { ms.add_kv(LLM_KV_ATTENTION_SLIDING_WINDOW_PATTERN, std::vector({0, 0, 1})); ms.add_kv(LLM_KV_ROPE_FREQ_BASE_SWA, 10000.0f); diff --git a/tests/test-tokenizer-random.py b/tests/test-tokenizer-random.py index 7f5ea3f45..4b4fbdf75 100644 --- a/tests/test-tokenizer-random.py +++ b/tests/test-tokenizer-random.py @@ -80,6 +80,7 @@ class LibLlamaModel: raise RuntimeError("error: failed to load model '%s'" % path_model) if isinstance(cparams, dict): cparams = libllama.context_default_params(**cparams) + self.vocab = self.lib.llama_model_get_vocab(self.model) self.ctx = self.lib.llama_init_from_model(self.model, cparams) if not self.ctx: raise RuntimeError("error: failed to create context for model '%s'" % path_model) @@ -98,10 +99,10 @@ class LibLlamaModel: def tokenize(self, text: str, add_special: bool = False, parse_special: bool = False) -> list[int]: encoded_text: bytes = text.encode("utf-8") - num = self.lib.llama_tokenize(self.model, encoded_text, len(encoded_text), self.token_ids, len(self.token_ids), add_special, parse_special) + num = self.lib.llama_tokenize(self.vocab, encoded_text, len(encoded_text), self.token_ids, len(self.token_ids), add_special, parse_special) while num < 0 and len(self.token_ids) < (16 << 20): self.token_ids = self.ffi.new("llama_token[]", -2 * num) - num = self.lib.llama_tokenize(self.model, encoded_text, len(encoded_text), self.token_ids, len(self.token_ids), add_special, parse_special) + num = self.lib.llama_tokenize(self.vocab, encoded_text, len(encoded_text), self.token_ids, len(self.token_ids), add_special, parse_special) return list(self.token_ids[0:num]) def detokenize(self, ids: list[int], remove_special: bool = False, unparse_special: bool = False) -> str: @@ -109,10 +110,10 @@ class LibLlamaModel: self.token_ids = self.ffi.new("llama_token[]", 2 * len(ids)) for i, id in enumerate(ids): self.token_ids[i] = id - num = self.lib.llama_detokenize(self.model, self.token_ids, len(ids), self.text_buff, len(self.text_buff), remove_special, unparse_special) + num = self.lib.llama_detokenize(self.vocab, self.token_ids, len(ids), self.text_buff, len(self.text_buff), remove_special, unparse_special) while num < 0 and len(self.text_buff) < (16 << 20): self.text_buff = self.ffi.new("uint8_t[]", -2 * num) - num = self.lib.llama_detokenize(self.model, self.token_ids, len(ids), self.text_buff, len(self.text_buff), remove_special, unparse_special) + num = self.lib.llama_detokenize(self.vocab, self.token_ids, len(ids), self.text_buff, len(self.text_buff), remove_special, unparse_special) return str(self.ffi.buffer(self.text_buff, num), encoding="utf-8", errors="replace") # replace errors with '\uFFFD' # pyright: ignore[reportArgumentType]