mirror of
https://github.com/ggml-org/llama.cpp.git
synced 2026-10-28 17:56:13 +08:00
llama : move the Engram pad id to llama_hparams and the token map to llama_model
The saver no longer needs the deepseek41 model class.
This commit is contained in:
1 parent
1fa6c20223
commit
c07230fa91
5 files changed
+11
-13
No files matched your search
@@ -358,6 +358,8 @@ struct llama_hparams {
|
||||
llama_token ple_embd_token = LLAMA_TOKEN_NULL;
|
||||
// hash constant sets, stored back to back: 1 shared by all PLE layers (qwen4exp), or 1 per PLE layer in layer order (deepseek41)
|
||||
uint32_t ple_n_modules = 1;
|
||||
// deepseek41 Engram: the token that pads the n-gram history, an index into llama_model::engram_token_map
|
||||
uint32_t engram_pad_id = 0;
|
||||
// the file lists PLE layer indices, so this is never a per-layer gguf array and can hold one bit per layer
|
||||
std::bitset<LLAMA_MAX_LAYERS> is_ple_impl;
|
||||
// the hash multipliers reach ~2e13 and have to stay 64-bit
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include "llama-hparams.h"
|
||||
#include "llama-model.h"
|
||||
#include "llama-vocab.h"
|
||||
#include "models/models.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
@@ -342,8 +341,6 @@ void llama_model_saver::add_kv_from_model() {
|
||||
add_kv(LLM_KV_HYPER_CONNECTION_LOW_RANK, hparams.hc_low_rank);
|
||||
|
||||
if (model->arch == LLM_ARCH_DEEPSEEK41) {
|
||||
const auto * m41 = dynamic_cast<const llama_model_deepseek41 *>(model);
|
||||
GGML_ASSERT(m41 != nullptr);
|
||||
std::vector<uint32_t> kv_src;
|
||||
std::vector<uint32_t> idx_src;
|
||||
for (uint32_t il = 0; il < hparams.n_layer(); ++il) {
|
||||
@@ -362,8 +359,8 @@ void llama_model_saver::add_kv_from_model() {
|
||||
add_kv(LLM_KV_ATTENTION_INDEXER_CANDIDATE_BLOCK_SIZE, hparams.dsv41_cand_block_size);
|
||||
}
|
||||
if (hparams.ple_n_heads > 0) {
|
||||
add_kv(LLM_KV_ENGRAM_PAD_TOKEN_ID, m41->engram_pad_id);
|
||||
add_kv(LLM_KV_ENGRAM_TOKEN_MAP, m41->engram_token_map);
|
||||
add_kv(LLM_KV_ENGRAM_PAD_TOKEN_ID, hparams.engram_pad_id);
|
||||
add_kv(LLM_KV_ENGRAM_TOKEN_MAP, model->engram_token_map);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -730,6 +730,9 @@ struct llama_model {
|
||||
std::vector<std::string> classifier_labels;
|
||||
std::vector<std::string> decision_labels;
|
||||
|
||||
// deepseek41 Engram: token id -> id of its normalized form, hashed into the n-grams
|
||||
std::vector<int32_t> engram_token_map;
|
||||
|
||||
struct ggml_tensor * tok_embd = nullptr;
|
||||
struct ggml_tensor * type_embd = nullptr;
|
||||
struct ggml_tensor * pos_embd = nullptr;
|
||||
|
||||
@@ -96,7 +96,7 @@ void llama_model_deepseek41::load_arch_hparams(llama_model_loader & ml) {
|
||||
ml.get_arr(LLM_KV_PLE_LAYER_MULTIPLIERS, mult);
|
||||
ml.get_arr(LLM_KV_PLE_HEAD_OFFSETS, offsets);
|
||||
ml.get_arr(LLM_KV_PLE_HEAD_VOCAB_SIZES, primes);
|
||||
ml.get_key(LLM_KV_ENGRAM_PAD_TOKEN_ID, engram_pad_id);
|
||||
ml.get_key(LLM_KV_ENGRAM_PAD_TOKEN_ID, hparams.engram_pad_id);
|
||||
ml.get_arr(LLM_KV_ENGRAM_TOKEN_MAP, engram_token_map);
|
||||
|
||||
const size_t n_e = e_layers.size();
|
||||
@@ -105,7 +105,7 @@ void llama_model_deepseek41::load_arch_hparams(llama_model_loader & ml) {
|
||||
if (n_cols == 0 || hparams.ple_head_dim == 0 ||
|
||||
mult.size() != n_e*n_gram || primes.size() != n_e*n_cols || offsets.size() != n_e*n_cols ||
|
||||
mult.size() > LLAMA_MAX_PLE_NGRAM || primes.size() > LLAMA_MAX_PLE_HEADS ||
|
||||
engram_pad_id >= engram_token_map.size()) {
|
||||
hparams.engram_pad_id >= engram_token_map.size()) {
|
||||
throw std::runtime_error("DeepSeek-V4.1 engram metadata is inconsistent");
|
||||
}
|
||||
for (size_t e = 0; e < n_e; ++e) {
|
||||
@@ -247,7 +247,7 @@ void llama_model_deepseek41::engram_hash(int e, const llama_ubatch & ubatch, con
|
||||
|
||||
const uint64_t * mult = hparams.ple_layer_multipliers.data() + (size_t) e*n_gram;
|
||||
const uint32_t * primes = hparams.ple_head_vocab_sizes.data() + (size_t) e*n_cols;
|
||||
const int64_t pad = engram_token_map[engram_pad_id];
|
||||
const int64_t pad = engram_token_map[hparams.engram_pad_id];
|
||||
const uint32_t * offs = hparams.ple_head_offsets.data() + (size_t) e*n_cols;
|
||||
|
||||
const auto cid = [&](llama_token t) -> int64_t {
|
||||
|
||||
+1
-5
@@ -1498,11 +1498,7 @@ struct llama_model_deepseek41 : public llama_model_deepseek4 {
|
||||
void load_arch_hparams(llama_model_loader & ml) override;
|
||||
void load_arch_tensors(llama_model_loader & ml) override;
|
||||
|
||||
// Engram: the hash constants are hparams.ple_* (one module per Engram layer), hashed on the host (ggml has no
|
||||
// int64 mul/xor/mod); the token map and its pad id are V4.1 only
|
||||
uint32_t engram_pad_id = 0;
|
||||
std::vector<int32_t> engram_token_map;
|
||||
|
||||
// Engram: the hash constants are hparams.ple_* (one module per Engram layer), hashed on the host (ggml has no int64 mul/xor/mod)
|
||||
int engram_index(int il) const;
|
||||
|
||||
void engram_hash(int e, const llama_ubatch & ubatch, const std::vector<llama_token> & prev, std::vector<int32_t> & out) const;
|
||||
|
||||
Reference in new issue
Block a user