Cosmos convert logic
This commit is contained in:
+29
-13
@@ -39,10 +39,10 @@ index b16c462f..6d1568f1 100644
|
||||
const int idx = gguf_find_tensor(ctx, name);
|
||||
if (idx < 0) {
|
||||
diff --git a/src/llama.cpp b/src/llama.cpp
|
||||
index 24e1f1f0..39045ca5 100644
|
||||
index 24e1f1f0..9957ea30 100644
|
||||
--- a/src/llama.cpp
|
||||
+++ b/src/llama.cpp
|
||||
@@ -205,6 +205,15 @@ enum llm_arch {
|
||||
@@ -205,6 +205,16 @@ enum llm_arch {
|
||||
LLM_ARCH_GRANITE,
|
||||
LLM_ARCH_GRANITE_MOE,
|
||||
LLM_ARCH_CHAMELEON,
|
||||
@@ -55,10 +55,11 @@ index 24e1f1f0..39045ca5 100644
|
||||
+ LLM_ARCH_HYVID,
|
||||
+ LLM_ARCH_WAN,
|
||||
+ LLM_ARCH_HIDREAM,
|
||||
+ LLM_ARCH_COSMOS,
|
||||
LLM_ARCH_UNKNOWN,
|
||||
};
|
||||
|
||||
@@ -258,6 +267,15 @@ static const std::map<llm_arch, const char *> LLM_ARCH_NAMES = {
|
||||
@@ -258,6 +268,16 @@ static const std::map<llm_arch, const char *> LLM_ARCH_NAMES = {
|
||||
{ LLM_ARCH_GRANITE, "granite" },
|
||||
{ LLM_ARCH_GRANITE_MOE, "granitemoe" },
|
||||
{ LLM_ARCH_CHAMELEON, "chameleon" },
|
||||
@@ -71,10 +72,11 @@ index 24e1f1f0..39045ca5 100644
|
||||
+ { LLM_ARCH_HYVID, "hyvid" },
|
||||
+ { LLM_ARCH_WAN, "wan" },
|
||||
+ { LLM_ARCH_HIDREAM, "hidream" },
|
||||
+ { LLM_ARCH_COSMOS, "cosmos" },
|
||||
{ LLM_ARCH_UNKNOWN, "(unknown)" },
|
||||
};
|
||||
|
||||
@@ -1531,6 +1549,15 @@ static const std::map<llm_arch, std::map<llm_tensor, const char *>> LLM_TENSOR_N
|
||||
@@ -1531,6 +1551,16 @@ static const std::map<llm_arch, std::map<llm_tensor, const char *>> LLM_TENSOR_N
|
||||
{ LLM_TENSOR_ATTN_K_NORM, "blk.%d.attn_k_norm" },
|
||||
},
|
||||
},
|
||||
@@ -87,10 +89,11 @@ index 24e1f1f0..39045ca5 100644
|
||||
+ { LLM_ARCH_HYVID, {}},
|
||||
+ { LLM_ARCH_WAN, {}},
|
||||
+ { LLM_ARCH_HIDREAM, {}},
|
||||
+ { LLM_ARCH_COSMOS, {}},
|
||||
{
|
||||
LLM_ARCH_UNKNOWN,
|
||||
{
|
||||
@@ -5403,6 +5430,23 @@ static void llm_load_hparams(
|
||||
@@ -5403,6 +5433,24 @@ static void llm_load_hparams(
|
||||
// get general kv
|
||||
ml.get_key(LLM_KV_GENERAL_NAME, model.name, false);
|
||||
|
||||
@@ -105,6 +108,7 @@ index 24e1f1f0..39045ca5 100644
|
||||
+ case LLM_ARCH_HYVID:
|
||||
+ case LLM_ARCH_WAN:
|
||||
+ case LLM_ARCH_HIDREAM:
|
||||
+ case LLM_ARCH_COSMOS:
|
||||
+ model.ftype = ml.ftype;
|
||||
+ return;
|
||||
+ default:
|
||||
@@ -114,7 +118,7 @@ index 24e1f1f0..39045ca5 100644
|
||||
// get hparams kv
|
||||
ml.get_key(LLM_KV_VOCAB_SIZE, hparams.n_vocab, false) || ml.get_arr_n(LLM_KV_TOKENIZER_LIST, hparams.n_vocab);
|
||||
|
||||
@@ -18016,6 +18060,129 @@ static void llama_tensor_dequantize_internal(
|
||||
@@ -18016,6 +18064,132 @@ static void llama_tensor_dequantize_internal(
|
||||
workers.clear();
|
||||
}
|
||||
|
||||
@@ -149,7 +153,8 @@ index 24e1f1f0..39045ca5 100644
|
||||
+ (name.find(".to_v.weight") != std::string::npos) ||
|
||||
+ (name.find(".v.weight") != std::string::npos) ||
|
||||
+ (name.find(".attn.w1v.weight") != std::string::npos) ||
|
||||
+ (name.find(".attn.w2v.weight") != std::string::npos)
|
||||
+ (name.find(".attn.w2v.weight") != std::string::npos) ||
|
||||
+ (name.find("_attn.v_proj.weight") != std::string::npos)
|
||||
+ ){
|
||||
+ if (ftype == LLAMA_FTYPE_MOSTLY_Q2_K) {
|
||||
+ new_type = GGML_TYPE_Q3_K;
|
||||
@@ -184,7 +189,9 @@ index 24e1f1f0..39045ca5 100644
|
||||
+ (name.find("ffn_down") != std::string::npos) ||
|
||||
+ ((name.find("experts.") != std::string::npos) && (name.find(".w2.weight") != std::string::npos)) ||
|
||||
+ (name.find(".ffn.2.weight") != std::string::npos) || // is this even the right way around?
|
||||
+ (name.find(".ff.net.2.weight") != std::string::npos)
|
||||
+ (name.find(".ff.net.2.weight") != std::string::npos) ||
|
||||
+ (name.find(".mlp.layer2.weight") != std::string::npos) ||
|
||||
+ (name.find(".adaln_modulation_mlp.2.weight") != std::string::npos)
|
||||
+ ) {
|
||||
+ // TODO: add back `layer_info` with some model specific logic + logic further down
|
||||
+ if (ftype == LLAMA_FTYPE_MOSTLY_Q3_K_M) {
|
||||
@@ -244,7 +251,7 @@ index 24e1f1f0..39045ca5 100644
|
||||
static ggml_type llama_tensor_get_type(quantize_state_internal & qs, ggml_type new_type, const ggml_tensor * tensor, llama_ftype ftype) {
|
||||
const std::string name = ggml_get_name(tensor);
|
||||
|
||||
@@ -18513,7 +18680,9 @@ static void llama_model_quantize_internal(const std::string & fname_inp, const s
|
||||
@@ -18513,7 +18687,9 @@ static void llama_model_quantize_internal(const std::string & fname_inp, const s
|
||||
if (llama_model_has_encoder(&model)) {
|
||||
n_attn_layer *= 3;
|
||||
}
|
||||
@@ -255,7 +262,7 @@ index 24e1f1f0..39045ca5 100644
|
||||
}
|
||||
|
||||
size_t total_size_org = 0;
|
||||
@@ -18547,6 +18716,51 @@ static void llama_model_quantize_internal(const std::string & fname_inp, const s
|
||||
@@ -18547,6 +18723,51 @@ static void llama_model_quantize_internal(const std::string & fname_inp, const s
|
||||
ctx_outs[i_split] = gguf_init_empty();
|
||||
}
|
||||
gguf_add_tensor(ctx_outs[i_split], tensor);
|
||||
@@ -307,7 +314,7 @@ index 24e1f1f0..39045ca5 100644
|
||||
}
|
||||
|
||||
// Set split info if needed
|
||||
@@ -18647,6 +18861,92 @@ static void llama_model_quantize_internal(const std::string & fname_inp, const s
|
||||
@@ -18647,6 +18868,101 @@ static void llama_model_quantize_internal(const std::string & fname_inp, const s
|
||||
// do not quantize relative position bias (T5)
|
||||
quantize &= name.find("attn_rel_b.weight") == std::string::npos;
|
||||
|
||||
@@ -392,6 +399,15 @@ index 24e1f1f0..39045ca5 100644
|
||||
+ quantize &= name.find(".ff_i.gate.weight") == std::string::npos;
|
||||
+ quantize &= name.find("caption_projection.") == std::string::npos;
|
||||
+ }
|
||||
+ if (model.arch == LLM_ARCH_COSMOS) {
|
||||
+ image_model = true;
|
||||
+ quantize &= name.find("p_embedder.") == std::string::npos;
|
||||
+ quantize &= name.find("t_embedder.") == std::string::npos;
|
||||
+ quantize &= name.find("t_embedding_norm.") == std::string::npos;
|
||||
+ quantize &= name.find("x_embedder.") == std::string::npos;
|
||||
+ quantize &= name.find("pos_embedder.") == std::string::npos;
|
||||
+ quantize &= name.find("final_layer.") == std::string::npos;
|
||||
+ }
|
||||
+ // ignore 3D/4D tensors for image models as the code was never meant to handle these
|
||||
+ if (image_model) {
|
||||
+ quantize &= ggml_n_dims(tensor) == 2;
|
||||
@@ -400,7 +416,7 @@ index 24e1f1f0..39045ca5 100644
|
||||
enum ggml_type new_type;
|
||||
void * new_data;
|
||||
size_t new_size;
|
||||
@@ -18655,6 +18955,9 @@ static void llama_model_quantize_internal(const std::string & fname_inp, const s
|
||||
@@ -18655,6 +18971,9 @@ static void llama_model_quantize_internal(const std::string & fname_inp, const s
|
||||
new_type = default_type;
|
||||
|
||||
// get more optimal quantization type based on the tensor shape, layer, etc.
|
||||
@@ -410,7 +426,7 @@ index 24e1f1f0..39045ca5 100644
|
||||
if (!params->pure && ggml_is_quantized(default_type)) {
|
||||
new_type = llama_tensor_get_type(qs, new_type, tensor, ftype);
|
||||
}
|
||||
@@ -18664,6 +18967,7 @@ static void llama_model_quantize_internal(const std::string & fname_inp, const s
|
||||
@@ -18664,6 +18983,7 @@ static void llama_model_quantize_internal(const std::string & fname_inp, const s
|
||||
if (params->output_tensor_type < GGML_TYPE_COUNT && strcmp(tensor->name, "output.weight") == 0) {
|
||||
new_type = params->output_tensor_type;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user