Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions tools/mtmd/mtmd-ios.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ void mtmd_ios_free(mtmd_ios_context* ctx) {
}

int mtmd_ios_prefill_image(mtmd_ios_context* ctx, const std::string& image_path) {

if (!ctx || image_path.empty()) {
return -1;
}
Expand Down Expand Up @@ -292,3 +293,18 @@ mtmd_ios_token mtmd_ios_loop(mtmd_ios_context* ctx) {
const char* mtmd_ios_get_last_error(mtmd_ios_context* ctx) {
return ctx ? ctx->last_error.c_str() : nullptr;
}

bool mtmd_ios_clean_kv_cache(mtmd_ios_context* ctx) {
if (!ctx) {
return false;
}

// 清理 kv-cache 并重置序列位置
ctx->n_past = 0;
llama_kv_self_seq_rm(ctx->lctx, 0, 0, -1);

// 清理batch状态
common_batch_clear(ctx->batch);

return true;
}
27 changes: 16 additions & 11 deletions tools/mtmd/mtmd-ios.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@
#include "mtmd-helper.h"
#include "mtmd.h"

#ifdef __cplusplus
extern "C" {
#endif

// Context structure
typedef struct mtmd_ios_context mtmd_ios_context;

// Parameters structure
// Parameters structure (C++ only)
typedef struct mtmd_ios_params {
std::string model_path;
std::string mmproj_path;
Expand All @@ -28,6 +24,16 @@ typedef struct mtmd_ios_params {
bool warmup;
} mtmd_ios_params;

// Loop return value structure (C++ only)
typedef struct {
char * token;
bool is_end;
} mtmd_ios_token;

#ifdef __cplusplus
extern "C" {
#endif

// Initialize, returns 0 on success, -1 on failure
// Parameters:
// params: parameters
Expand All @@ -54,12 +60,6 @@ int mtmd_ios_prefill_image(mtmd_ios_context * ctx, const std::string & image_pat
// role: role
int mtmd_ios_prefill_text(mtmd_ios_context * ctx, const std::string & text, const std::string & role);

// Loop return value structure
typedef struct {
char * token;
bool is_end;
} mtmd_ios_token;

// Loop, returns 0 on success, -1 on failure
// Parameters:
// ctx: context
Expand All @@ -75,6 +75,11 @@ const char * mtmd_ios_get_last_error(mtmd_ios_context * ctx);
// str: string
void mtmd_ios_string_free(char * str);

// Clean kv-cache
// Parameters:
// ctx: context
bool mtmd_ios_clean_kv_cache(mtmd_ios_context * ctx);

#ifdef __cplusplus
}
#endif
Expand Down
Loading