mirror of
https://github.com/ggml-org/llama.cpp.git
synced 2025-06-28 20:25:20 +00:00
clip : refactor clip_init, add tests (#12757)
* refactor clip_init * fix loading file * fix style * test ok * better test with report * add missing headers * clarify * add KEY_MM_PATCH_MERGE_TYPE * remove bool has_* pattern * Apply suggestions from code review Co-authored-by: Georgi Gerganov <ggerganov@gmail.com> * Update examples/llava/clip.cpp Co-authored-by: Georgi Gerganov <ggerganov@gmail.com> * use ggml_soft_max_ext * refactor logging system * add minicpm-v-o 2.6 for testing * use nullptr everywhere * fix Yi-VL model --------- Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
This commit is contained in:
273
examples/llava/clip-impl.h
Normal file
273
examples/llava/clip-impl.h
Normal file
@ -0,0 +1,273 @@
|
|||||||
|
#include "ggml.h"
|
||||||
|
#include "gguf.h"
|
||||||
|
|
||||||
|
#include <climits>
|
||||||
|
#include <cstdarg>
|
||||||
|
#include <string>
|
||||||
|
#include <map>
|
||||||
|
#include <sstream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
// Internal header for clip.cpp
|
||||||
|
|
||||||
|
#define KEY_FTYPE "general.file_type"
|
||||||
|
#define KEY_NAME "general.name"
|
||||||
|
#define KEY_DESCRIPTION "general.description"
|
||||||
|
#define KEY_HAS_TEXT_ENC "clip.has_text_encoder"
|
||||||
|
#define KEY_HAS_VIS_ENC "clip.has_vision_encoder"
|
||||||
|
#define KEY_HAS_LLAVA_PROJ "clip.has_llava_projector"
|
||||||
|
#define KEY_HAS_MINICPMV_PROJ "clip.has_minicpmv_projector"
|
||||||
|
#define KEY_HAS_GLM_PROJ "clip.has_glm_projector"
|
||||||
|
#define KEY_MINICPMV_VERSION "clip.minicpmv_version"
|
||||||
|
#define KEY_HAS_QWEN2VL_MERGER "clip.has_qwen2vl_merger"
|
||||||
|
#define KEY_USE_GELU "clip.use_gelu"
|
||||||
|
#define KEY_USE_SILU "clip.use_silu"
|
||||||
|
#define KEY_N_EMBD "clip.%s.embedding_length"
|
||||||
|
#define KEY_N_FF "clip.%s.feed_forward_length"
|
||||||
|
#define KEY_N_BLOCK "clip.%s.block_count"
|
||||||
|
#define KEY_N_HEAD "clip.%s.attention.head_count"
|
||||||
|
#define KEY_LAYER_NORM_EPS "clip.%s.attention.layer_norm_epsilon"
|
||||||
|
#define KEY_PROJ_DIM "clip.%s.projection_dim"
|
||||||
|
#define KEY_TOKENS "tokenizer.ggml.tokens"
|
||||||
|
#define KEY_N_POSITIONS "clip.text.context_length"
|
||||||
|
#define KEY_IMAGE_SIZE "clip.vision.image_size"
|
||||||
|
#define KEY_PATCH_SIZE "clip.vision.patch_size"
|
||||||
|
#define KEY_IMAGE_MEAN "clip.vision.image_mean"
|
||||||
|
#define KEY_IMAGE_STD "clip.vision.image_std"
|
||||||
|
#define KEY_PROJ_TYPE "clip.projector_type"
|
||||||
|
#define KEY_FEATURE_LAYER "clip.vision.feature_layer"
|
||||||
|
|
||||||
|
#define KEY_MM_PATCH_MERGE_TYPE "clip.vision.mm_patch_merge_type"
|
||||||
|
#define KEY_IMAGE_GRID_PINPOINTS "clip.vision.image_grid_pinpoints"
|
||||||
|
#define KEY_IMAGE_CROP_RESOLUTION "clip.vision.image_crop_resolution"
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// tensor name constants
|
||||||
|
//
|
||||||
|
|
||||||
|
#define TN_TOKEN_EMBD "%s.token_embd.weight"
|
||||||
|
#define TN_POS_EMBD "%s.position_embd.weight"
|
||||||
|
#define TN_CLASS_EMBD "v.class_embd"
|
||||||
|
#define TN_PATCH_EMBD "v.patch_embd.weight" // not rename tensor with ".0" postfix for backwrad compat
|
||||||
|
#define TN_PATCH_EMBD_1 "v.patch_embd.weight.1"
|
||||||
|
#define TN_PATCH_BIAS "v.patch_embd.bias"
|
||||||
|
#define TN_ATTN_K "%s.blk.%d.attn_k.%s"
|
||||||
|
#define TN_ATTN_Q "%s.blk.%d.attn_q.%s"
|
||||||
|
#define TN_ATTN_V "%s.blk.%d.attn_v.%s"
|
||||||
|
#define TN_ATTN_OUTPUT "%s.blk.%d.attn_out.%s"
|
||||||
|
#define TN_FFN_DOWN "%s.blk.%d.ffn_down.%s"
|
||||||
|
#define TN_FFN_UP "%s.blk.%d.ffn_up.%s"
|
||||||
|
#define TN_LN_1 "%s.blk.%d.ln1.%s"
|
||||||
|
#define TN_LN_2 "%s.blk.%d.ln2.%s"
|
||||||
|
#define TN_LN_PRE "%s.pre_ln.%s"
|
||||||
|
#define TN_LN_POST "%s.post_ln.%s"
|
||||||
|
#define TN_TEXT_PROJ "text_projection.weight"
|
||||||
|
#define TN_VIS_PROJ "visual_projection.weight"
|
||||||
|
#define TN_LLAVA_PROJ "mm.%d.%s"
|
||||||
|
#define TN_MVLM_PROJ_MLP "mm.model.mlp.%d.%s"
|
||||||
|
#define TN_MVLM_PROJ_BLOCK "mm.model.mb_block.%d.block.%d.%s"
|
||||||
|
#define TN_MVLM_PROJ_PEG "mm.model.peg.%d.%s"
|
||||||
|
#define TN_IMAGE_NEWLINE "model.image_newline"
|
||||||
|
#define TN_MM_INP_PROJ "mm.input_projection.weight" // gemma3
|
||||||
|
#define TN_MM_SOFT_EMB_N "mm.soft_emb_norm.weight" // gemma3
|
||||||
|
|
||||||
|
// mimicpmv
|
||||||
|
#define TN_MINICPMV_POS_EMBD_K "resampler.pos_embed_k"
|
||||||
|
#define TN_MINICPMV_QUERY "resampler.query"
|
||||||
|
#define TN_MINICPMV_PROJ "resampler.proj.weight"
|
||||||
|
#define TN_MINICPMV_KV_PROJ "resampler.kv.weight"
|
||||||
|
#define TN_MINICPMV_ATTN "resampler.attn.%s.%s"
|
||||||
|
#define TN_MINICPMV_LN "resampler.ln_%s.%s"
|
||||||
|
|
||||||
|
#define TN_GLM_ADAPER_CONV "adapter.conv.%s"
|
||||||
|
#define TN_GLM_ADAPTER_LINEAR "adapter.linear.linear.%s"
|
||||||
|
#define TN_GLM_ADAPTER_NORM_1 "adapter.linear.norm1.%s"
|
||||||
|
#define TN_GLM_ADAPTER_D_H_2_4H "adapter.linear.dense_h_to_4h.%s"
|
||||||
|
#define TN_GLM_ADAPTER_GATE "adapter.linear.gate.%s"
|
||||||
|
#define TN_GLM_ADAPTER_D_4H_2_H "adapter.linear.dense_4h_to_h.%s"
|
||||||
|
#define TN_GLM_BOI_W "adapter.boi"
|
||||||
|
#define TN_GLM_EOI_W "adapter.eoi"
|
||||||
|
|
||||||
|
enum projector_type {
|
||||||
|
PROJECTOR_TYPE_MLP,
|
||||||
|
PROJECTOR_TYPE_MLP_NORM,
|
||||||
|
PROJECTOR_TYPE_LDP,
|
||||||
|
PROJECTOR_TYPE_LDPV2,
|
||||||
|
PROJECTOR_TYPE_RESAMPLER,
|
||||||
|
PROJECTOR_TYPE_GLM_EDGE,
|
||||||
|
PROJECTOR_TYPE_MERGER,
|
||||||
|
PROJECTOR_TYPE_GEMMA3,
|
||||||
|
PROJECTOR_TYPE_UNKNOWN,
|
||||||
|
};
|
||||||
|
|
||||||
|
static std::map<projector_type, std::string> PROJECTOR_TYPE_NAMES = {
|
||||||
|
{ PROJECTOR_TYPE_MLP, "mlp" },
|
||||||
|
{ PROJECTOR_TYPE_LDP, "ldp" },
|
||||||
|
{ PROJECTOR_TYPE_LDPV2, "ldpv2"},
|
||||||
|
{ PROJECTOR_TYPE_RESAMPLER, "resampler"},
|
||||||
|
{ PROJECTOR_TYPE_GLM_EDGE, "adapter"},
|
||||||
|
{ PROJECTOR_TYPE_MERGER, "qwen2vl_merger"},
|
||||||
|
{ PROJECTOR_TYPE_GEMMA3, "gemma3"},
|
||||||
|
};
|
||||||
|
|
||||||
|
static projector_type clip_projector_type_from_string(const std::string & str) {
|
||||||
|
for (const auto & pair : PROJECTOR_TYPE_NAMES) {
|
||||||
|
if (pair.second == str) {
|
||||||
|
return pair.first;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return PROJECTOR_TYPE_UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// logging
|
||||||
|
//
|
||||||
|
|
||||||
|
static void clip_log_callback_default(enum ggml_log_level level, const char * text, void * user_data) {
|
||||||
|
(void) level;
|
||||||
|
(void) user_data;
|
||||||
|
fputs(text, stderr);
|
||||||
|
fflush(stderr);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct clip_logger_state {
|
||||||
|
ggml_log_level verbosity_thold;
|
||||||
|
ggml_log_callback log_callback;
|
||||||
|
void * log_callback_user_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern struct clip_logger_state g_logger_state;
|
||||||
|
|
||||||
|
static void clip_log_internal_v(enum ggml_log_level level, const char * format, va_list args) {
|
||||||
|
if (format == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
va_list args_copy;
|
||||||
|
va_copy(args_copy, args);
|
||||||
|
char buffer[128];
|
||||||
|
int len = vsnprintf(buffer, 128, format, args);
|
||||||
|
if (len < 128) {
|
||||||
|
g_logger_state.log_callback(level, buffer, g_logger_state.log_callback_user_data);
|
||||||
|
} else {
|
||||||
|
char * buffer2 = (char *) calloc(len + 1, sizeof(char));
|
||||||
|
vsnprintf(buffer2, len + 1, format, args_copy);
|
||||||
|
buffer2[len] = 0;
|
||||||
|
g_logger_state.log_callback(level, buffer2, g_logger_state.log_callback_user_data);
|
||||||
|
free(buffer2);
|
||||||
|
}
|
||||||
|
va_end(args_copy);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void clip_log_internal(enum ggml_log_level level, const char * format, ...) {
|
||||||
|
va_list args;
|
||||||
|
va_start(args, format);
|
||||||
|
clip_log_internal_v(level, format, args);
|
||||||
|
va_end(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define LOG_TMPL(level, ...) \
|
||||||
|
do { \
|
||||||
|
if ((level) >= g_logger_state.verbosity_thold) { \
|
||||||
|
clip_log_internal((level), __VA_ARGS__); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
#define LOG_INF(...) LOG_TMPL(GGML_LOG_LEVEL_INFO, __VA_ARGS__)
|
||||||
|
#define LOG_WRN(...) LOG_TMPL(GGML_LOG_LEVEL_WARN, __VA_ARGS__)
|
||||||
|
#define LOG_ERR(...) LOG_TMPL(GGML_LOG_LEVEL_ERROR, __VA_ARGS__)
|
||||||
|
#define LOG_DBG(...) LOG_TMPL(GGML_LOG_LEVEL_DEBUG, __VA_ARGS__)
|
||||||
|
#define LOG_CNT(...) LOG_TMPL(GGML_LOG_LEVEL_CONT, __VA_ARGS__)
|
||||||
|
|
||||||
|
//
|
||||||
|
// common utils
|
||||||
|
//
|
||||||
|
|
||||||
|
static std::string string_format(const char * fmt, ...) {
|
||||||
|
va_list ap;
|
||||||
|
va_list ap2;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
va_copy(ap2, ap);
|
||||||
|
int size = vsnprintf(NULL, 0, fmt, ap);
|
||||||
|
GGML_ASSERT(size >= 0 && size < INT_MAX); // NOLINT
|
||||||
|
std::vector<char> buf(size + 1);
|
||||||
|
int size2 = vsnprintf(buf.data(), size + 1, fmt, ap2);
|
||||||
|
GGML_ASSERT(size2 == size);
|
||||||
|
va_end(ap2);
|
||||||
|
va_end(ap);
|
||||||
|
return std::string(buf.data(), buf.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
static void string_replace_all(std::string & s, const std::string & search, const std::string & replace) {
|
||||||
|
if (search.empty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::string builder;
|
||||||
|
builder.reserve(s.length());
|
||||||
|
size_t pos = 0;
|
||||||
|
size_t last_pos = 0;
|
||||||
|
while ((pos = s.find(search, last_pos)) != std::string::npos) {
|
||||||
|
builder.append(s, last_pos, pos - last_pos);
|
||||||
|
builder.append(replace);
|
||||||
|
last_pos = pos + search.length();
|
||||||
|
}
|
||||||
|
builder.append(s, last_pos, std::string::npos);
|
||||||
|
s = std::move(builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// gguf utils
|
||||||
|
//
|
||||||
|
|
||||||
|
static std::string gguf_data_to_str(enum gguf_type type, const void * data, int i) {
|
||||||
|
switch (type) {
|
||||||
|
case GGUF_TYPE_UINT8: return std::to_string(((const uint8_t *)data)[i]);
|
||||||
|
case GGUF_TYPE_INT8: return std::to_string(((const int8_t *)data)[i]);
|
||||||
|
case GGUF_TYPE_UINT16: return std::to_string(((const uint16_t *)data)[i]);
|
||||||
|
case GGUF_TYPE_INT16: return std::to_string(((const int16_t *)data)[i]);
|
||||||
|
case GGUF_TYPE_UINT32: return std::to_string(((const uint32_t *)data)[i]);
|
||||||
|
case GGUF_TYPE_INT32: return std::to_string(((const int32_t *)data)[i]);
|
||||||
|
case GGUF_TYPE_UINT64: return std::to_string(((const uint64_t *)data)[i]);
|
||||||
|
case GGUF_TYPE_INT64: return std::to_string(((const int64_t *)data)[i]);
|
||||||
|
case GGUF_TYPE_FLOAT32: return std::to_string(((const float *)data)[i]);
|
||||||
|
case GGUF_TYPE_FLOAT64: return std::to_string(((const double *)data)[i]);
|
||||||
|
case GGUF_TYPE_BOOL: return ((const bool *)data)[i] ? "true" : "false";
|
||||||
|
default: return string_format("unknown type %d", type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string gguf_kv_to_str(const struct gguf_context * ctx_gguf, int i) {
|
||||||
|
const enum gguf_type type = gguf_get_kv_type(ctx_gguf, i);
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case GGUF_TYPE_STRING:
|
||||||
|
return gguf_get_val_str(ctx_gguf, i);
|
||||||
|
case GGUF_TYPE_ARRAY:
|
||||||
|
{
|
||||||
|
const enum gguf_type arr_type = gguf_get_arr_type(ctx_gguf, i);
|
||||||
|
int arr_n = gguf_get_arr_n(ctx_gguf, i);
|
||||||
|
const void * data = arr_type == GGUF_TYPE_STRING ? nullptr : gguf_get_arr_data(ctx_gguf, i);
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "[";
|
||||||
|
for (int j = 0; j < arr_n; j++) {
|
||||||
|
if (arr_type == GGUF_TYPE_STRING) {
|
||||||
|
std::string val = gguf_get_arr_str(ctx_gguf, i, j);
|
||||||
|
// escape quotes
|
||||||
|
string_replace_all(val, "\\", "\\\\");
|
||||||
|
string_replace_all(val, "\"", "\\\"");
|
||||||
|
ss << '"' << val << '"';
|
||||||
|
} else if (arr_type == GGUF_TYPE_ARRAY) {
|
||||||
|
ss << "???";
|
||||||
|
} else {
|
||||||
|
ss << gguf_data_to_str(arr_type, data, j);
|
||||||
|
}
|
||||||
|
if (j < arr_n - 1) {
|
||||||
|
ss << ", ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ss << "]";
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return gguf_data_to_str(type, gguf_get_val_data(ctx_gguf, i), 0);
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,7 @@
|
|||||||
#ifndef CLIP_H
|
#ifndef CLIP_H
|
||||||
#define CLIP_H
|
#define CLIP_H
|
||||||
|
|
||||||
|
#include "ggml.h"
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
@ -41,7 +42,7 @@ struct clip_image_f32_batch {
|
|||||||
|
|
||||||
struct clip_context_params {
|
struct clip_context_params {
|
||||||
bool use_gpu;
|
bool use_gpu;
|
||||||
int verbosity;
|
ggml_log_level verbosity;
|
||||||
};
|
};
|
||||||
|
|
||||||
// deprecated, use clip_init
|
// deprecated, use clip_init
|
||||||
|
@ -79,7 +79,11 @@ struct gemma3_context {
|
|||||||
|
|
||||||
void init_clip_model(common_params & params) {
|
void init_clip_model(common_params & params) {
|
||||||
const char * clip_path = params.mmproj.path.c_str();
|
const char * clip_path = params.mmproj.path.c_str();
|
||||||
ctx_clip = clip_model_load(clip_path, params.verbosity > 1);
|
ctx_clip = clip_model_load(clip_path, GGML_LOG_LEVEL_INFO);
|
||||||
|
if (!ctx_clip) {
|
||||||
|
LOG_ERR("Failed to load CLIP model from %s\n", clip_path);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
~gemma3_context() {
|
~gemma3_context() {
|
||||||
|
@ -241,7 +241,7 @@ static struct llava_context * llava_init_context(common_params * params, llama_m
|
|||||||
prompt = "describe the image in detail.";
|
prompt = "describe the image in detail.";
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ctx_clip = clip_model_load(clip_path, /*verbosity=*/ 1);
|
auto ctx_clip = clip_model_load(clip_path, GGML_LOG_LEVEL_INFO);
|
||||||
|
|
||||||
llama_context_params ctx_params = common_context_params_to_llama(*params);
|
llama_context_params ctx_params = common_context_params_to_llama(*params);
|
||||||
ctx_params.n_ctx = params->n_ctx < 2048 ? 2048 : params->n_ctx; // we need a longer context size to process image embeddings
|
ctx_params.n_ctx = params->n_ctx < 2048 ? 2048 : params->n_ctx; // we need a longer context size to process image embeddings
|
||||||
|
@ -88,7 +88,7 @@ static struct clip_ctx * clip_init_context(common_params * params) {
|
|||||||
}
|
}
|
||||||
struct clip_context_params clip_params = {
|
struct clip_context_params clip_params = {
|
||||||
/* use_gpu */ params->n_gpu_layers != 0,
|
/* use_gpu */ params->n_gpu_layers != 0,
|
||||||
/* verbosity */ params->verbosity,
|
/* verbosity */ GGML_LOG_LEVEL_INFO, // TODO: make this configurable
|
||||||
};
|
};
|
||||||
auto * ctx_clip = clip_init(clip_path, clip_params);
|
auto * ctx_clip = clip_init(clip_path, clip_params);
|
||||||
return ctx_clip;
|
return ctx_clip;
|
||||||
|
@ -330,7 +330,7 @@ static struct llava_context * llava_init_context(common_params * params, llama_m
|
|||||||
prompt = "describe the image in detail.";
|
prompt = "describe the image in detail.";
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ctx_clip = clip_model_load(clip_path, /*verbosity=*/ 1);
|
auto ctx_clip = clip_model_load(clip_path, GGML_LOG_LEVEL_INFO);
|
||||||
|
|
||||||
llama_context_params ctx_params = common_context_params_to_llama(*params);
|
llama_context_params ctx_params = common_context_params_to_llama(*params);
|
||||||
ctx_params.n_ctx = params->n_ctx < 2048 ? 2048 : params->n_ctx; // we need a longer context size to process image embeddings
|
ctx_params.n_ctx = params->n_ctx < 2048 ? 2048 : params->n_ctx; // we need a longer context size to process image embeddings
|
||||||
|
BIN
examples/llava/test-1.jpeg
Normal file
BIN
examples/llava/test-1.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 121 KiB |
81
examples/llava/tests.sh
Executable file
81
examples/llava/tests.sh
Executable file
@ -0,0 +1,81 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# make sure we are in the right directory
|
||||||
|
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
||||||
|
cd $SCRIPT_DIR
|
||||||
|
|
||||||
|
#export LLAMA_CACHE="$SCRIPT_DIR/tmp"
|
||||||
|
|
||||||
|
set -eux
|
||||||
|
|
||||||
|
mkdir -p $SCRIPT_DIR/output
|
||||||
|
|
||||||
|
PROJ_ROOT="$SCRIPT_DIR/../.."
|
||||||
|
cd $PROJ_ROOT
|
||||||
|
|
||||||
|
###############
|
||||||
|
|
||||||
|
arr_bin=()
|
||||||
|
arr_hf=()
|
||||||
|
|
||||||
|
add_test() {
|
||||||
|
local bin=$1
|
||||||
|
local hf=$2
|
||||||
|
arr_bin+=("$bin")
|
||||||
|
arr_hf+=("$hf")
|
||||||
|
}
|
||||||
|
|
||||||
|
add_test "llama-gemma3-cli" "ggml-org/gemma-3-4b-it-GGUF:Q4_K_M"
|
||||||
|
add_test "llama-llava-cli" "cmp-nct/Yi-VL-6B-GGUF:Q5_K"
|
||||||
|
add_test "llama-llava-cli" "guinmoon/MobileVLM-3B-GGUF:Q4_K_M"
|
||||||
|
add_test "llama-llava-cli" "THUDM/glm-edge-v-5b-gguf:Q4_K_M"
|
||||||
|
add_test "llama-llava-cli" "second-state/Llava-v1.5-7B-GGUF:Q2_K"
|
||||||
|
add_test "llama-llava-cli" "cjpais/llava-1.6-mistral-7b-gguf:Q3_K"
|
||||||
|
add_test "llama-llava-cli" "ibm-research/granite-vision-3.2-2b-GGUF:Q4_K_M"
|
||||||
|
add_test "llama-minicpmv-cli" "second-state/MiniCPM-Llama3-V-2_5-GGUF:Q2_K" # model from openbmb is corrupted
|
||||||
|
add_test "llama-minicpmv-cli" "openbmb/MiniCPM-V-2_6-gguf:Q2_K"
|
||||||
|
add_test "llama-minicpmv-cli" "openbmb/MiniCPM-o-2_6-gguf:Q4_0"
|
||||||
|
add_test "llama-qwen2vl-cli" "bartowski/Qwen2-VL-2B-Instruct-GGUF:Q4_K_M"
|
||||||
|
|
||||||
|
###############
|
||||||
|
|
||||||
|
cmake --build build -j --target "${arr_bin[@]}"
|
||||||
|
|
||||||
|
arr_res=()
|
||||||
|
|
||||||
|
for i in "${!arr_bin[@]}"; do
|
||||||
|
bin="${arr_bin[$i]}"
|
||||||
|
hf="${arr_hf[$i]}"
|
||||||
|
|
||||||
|
echo "Running test with binary: $bin and HF model: $hf"
|
||||||
|
echo ""
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
output=$("$PROJ_ROOT/build/bin/$bin" -hf "$hf" --image $SCRIPT_DIR/test-1.jpeg -p "what is the publisher name of the newspaper?" --temp 0 2>&1 | tee /dev/tty)
|
||||||
|
|
||||||
|
echo "$output" > $SCRIPT_DIR/output/$bin-$(echo "$hf" | tr '/' '-').log
|
||||||
|
|
||||||
|
if echo "$output" | grep -iq "new york"; then
|
||||||
|
result="\033[32mOK\033[0m: $bin $hf"
|
||||||
|
else
|
||||||
|
result="\033[31mFAIL\033[0m: $bin $hf"
|
||||||
|
fi
|
||||||
|
echo -e "$result"
|
||||||
|
arr_res+=("$result")
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo ""
|
||||||
|
echo ""
|
||||||
|
echo "#################################################"
|
||||||
|
echo "#################################################"
|
||||||
|
echo ""
|
||||||
|
echo ""
|
||||||
|
done
|
||||||
|
|
||||||
|
set +x
|
||||||
|
|
||||||
|
for i in "${!arr_res[@]}"; do
|
||||||
|
echo -e "${arr_res[$i]}"
|
||||||
|
done
|
||||||
|
echo ""
|
||||||
|
echo "Output logs are saved in $SCRIPT_DIR/output"
|
Reference in New Issue
Block a user