model: Add support for SenseNova U1 model (#28919)
* model : add SenseNova U1 understanding support Add support for the dense SenseNova U1 understanding branch, including the U1.5-8B-MoT model. - Add HF-to-GGUF conversion for NEOChatModel, excluding MoT generation tensors and concatenating temporal and spatial Q/K normalization weights. - Register the sensenova_u1 GGUF architecture and custom spatial RoPE metadata. - Implement temporal/spatial Q/K normalization with 4-axis RoPE. - Keep U1-specific text position handling in the model implementation. - Add synthetic architecture coverage for sensenova_u1. Only the dense understanding branch is supported; generation branches are intentionally rejected during conversion. * conversion : treat one-expert SenseNova U1 configs as dense * mtmd : add SenseNova U1 vision support Add conversion support for the SenseNova U1 vision encoder and implement its CPU mtmd projector graph. The graph applies patch embedding, GELU, adjacent-pair 2D RoPE, spatial downsampling, and dense projection for dynamic-resolution image inputs. * mtmd : fix SenseNova U1 vision token layout * model : clean up SenseNova U1 RoPE metadata Replace the hard-coded spatial RoPE key with shared GGUF and LLM_KV definitions used by conversion, model loading, and architecture tests. Clarify why SenseNova U1 retains its custom text-position input: U1 uses [t, 0, 0, 0], while the generic M-RoPE input uses [t, t, t, 0]. * mtmd : simplify SenseNova U1 projector integration Map the SenseNova U1 dense projection to the standard mm.0 weight and bias tensors and reuse the shared projector fields in the loader and graph. Read vision parameters from the checkpoint configuration and remove the U1-specific tensor names and model fields while preserving its strided projection, bias, and row-major token layout. * mtmd : fix SenseNova U1 image positions and attention * fix spacing * mtmd : restore generic test input chunks * mtmd : restore SenseNova U1 integration after upstream merge * Update conversion/sensenova_u1.py Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co> * Update src/models/sensenova-u1.cpp Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co> * model : remove SenseNova U1 BF16 activation casts Use standard backend precision handling for QKV, FFN, and output projections instead of casting inputs based on the output tensor type. Assisted-by: Codex * Update src/models/sensenova-u1.cpp Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co> --------- Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co>
This commit is contained in:
1 parent
d454a204ef
commit
7775ffb7e4
18 files changed
+470
-2
No files matched your search
@@ -997,6 +997,10 @@ static std::unique_ptr<clip_graph> clip_get_graph_builder(clip_ctx * ctx, const
|
||||
{
|
||||
builder = std::make_unique<clip_graph_qwen3vl>(ctx, img);
|
||||
} break;
|
||||
case PROJECTOR_TYPE_SENSENOVA_U1:
|
||||
{
|
||||
builder = std::make_unique<clip_graph_sensenova_u1>(ctx, img);
|
||||
} break;
|
||||
case PROJECTOR_TYPE_LING3VL:
|
||||
{
|
||||
builder = std::make_unique<clip_graph_ling3vl>(ctx, img);
|
||||
@@ -1795,6 +1799,20 @@ struct clip_model_loader {
|
||||
LOG_WRN("%s: more info: https://github.com/ggml-org/llama.cpp/issues/16842\n\n", __func__);
|
||||
}
|
||||
} break;
|
||||
case PROJECTOR_TYPE_SENSENOVA_U1:
|
||||
{
|
||||
hparams.n_merge = 2;
|
||||
hparams.image_resize_algo = RESIZE_ALGO_BICUBIC;
|
||||
get_u32(KEY_SPATIAL_MERGE_SIZE, hparams.n_merge, false);
|
||||
get_u32(KEY_IMAGE_MIN_PIXELS, hparams.image_min_pixels);
|
||||
get_u32(KEY_IMAGE_MAX_PIXELS, hparams.image_max_pixels);
|
||||
hparams.rope_theta = 10000.0f;
|
||||
hparams.set_limit_image_tokens(16, 4096);
|
||||
if (hparams.n_merge != 2) {
|
||||
throw std::runtime_error(string_format("%s: SenseNova U1 requires spatial_merge_size=2, got %u", __func__, hparams.n_merge));
|
||||
}
|
||||
hparams.set_warmup_n_tokens(16*16);
|
||||
} break;
|
||||
case PROJECTOR_TYPE_MINIMAX_M3:
|
||||
{
|
||||
hparams.n_merge = 2; // spatial_merge_size
|
||||
@@ -3837,6 +3855,11 @@ struct clip_model_loader {
|
||||
}
|
||||
|
||||
} break;
|
||||
case PROJECTOR_TYPE_SENSENOVA_U1:
|
||||
{
|
||||
model.mm_0_w = get_tensor(string_format(TN_LLAVA_PROJ, 0, "weight"));
|
||||
model.mm_0_b = get_tensor(string_format(TN_LLAVA_PROJ, 0, "bias"));
|
||||
} break;
|
||||
default:
|
||||
GGML_ASSERT(false && "unknown projector type");
|
||||
}
|
||||
@@ -4311,6 +4334,7 @@ int clip_n_output_tokens_x(const clip_ctx * ctx, const clip_image_f32 * img) {
|
||||
case PROJECTOR_TYPE_QWEN2VL:
|
||||
case PROJECTOR_TYPE_QWEN25VL:
|
||||
case PROJECTOR_TYPE_QWEN3VL:
|
||||
case PROJECTOR_TYPE_SENSENOVA_U1:
|
||||
case PROJECTOR_TYPE_LING3VL:
|
||||
case PROJECTOR_TYPE_EXAONE4_5:
|
||||
case PROJECTOR_TYPE_MIMOVL:
|
||||
@@ -4341,6 +4365,7 @@ int clip_n_output_tokens_y(const clip_ctx * ctx, const clip_image_f32 * img) {
|
||||
case PROJECTOR_TYPE_QWEN2VL:
|
||||
case PROJECTOR_TYPE_QWEN25VL:
|
||||
case PROJECTOR_TYPE_QWEN3VL:
|
||||
case PROJECTOR_TYPE_SENSENOVA_U1:
|
||||
case PROJECTOR_TYPE_LING3VL:
|
||||
case PROJECTOR_TYPE_EXAONE4_5:
|
||||
case PROJECTOR_TYPE_MIMOVL:
|
||||
@@ -4426,6 +4451,7 @@ int clip_n_output_tokens(const clip_ctx * ctx, const clip_image_f32 * img) {
|
||||
case PROJECTOR_TYPE_QWEN2VL:
|
||||
case PROJECTOR_TYPE_QWEN25VL:
|
||||
case PROJECTOR_TYPE_QWEN3VL:
|
||||
case PROJECTOR_TYPE_SENSENOVA_U1:
|
||||
case PROJECTOR_TYPE_LING3VL:
|
||||
case PROJECTOR_TYPE_EXAONE4_5:
|
||||
case PROJECTOR_TYPE_MIMOVL:
|
||||
@@ -5525,6 +5551,19 @@ bool clip_encode(struct clip_ctx * ctx, struct clip_encode_params * params) {
|
||||
}
|
||||
set_input_i32("pos_w", pos_data);
|
||||
} break;
|
||||
case PROJECTOR_TYPE_SENSENOVA_U1:
|
||||
{
|
||||
const int n_patches_per_row = image_size_width / patch_size;
|
||||
std::vector<int> pos_data(n_pos);
|
||||
for (int i = 0; i < n_pos; i++) {
|
||||
pos_data[i] = i / n_patches_per_row;
|
||||
}
|
||||
set_input_i32("pos_y", pos_data);
|
||||
for (int i = 0; i < n_pos; i++) {
|
||||
pos_data[i] = i % n_patches_per_row;
|
||||
}
|
||||
set_input_i32("pos_x", pos_data);
|
||||
} break;
|
||||
case PROJECTOR_TYPE_DEEPSEEK4V:
|
||||
{
|
||||
// set the 2D positions (mrope layout, only the first 2 channels are used)
|
||||
@@ -6411,6 +6450,8 @@ int clip_n_mmproj_embd(const struct clip_ctx * ctx) {
|
||||
case PROJECTOR_TYPE_JANUS_PRO:
|
||||
case PROJECTOR_TYPE_YOUTUVL:
|
||||
return ctx->model.mm_1_b->ne[0];
|
||||
case PROJECTOR_TYPE_SENSENOVA_U1:
|
||||
return ctx->model.hparams.projection_dim;
|
||||
case PROJECTOR_TYPE_QWEN3VL:
|
||||
// main path + deepstack paths
|
||||
return ctx->model.mm_1_b->ne[0] * (1 + ctx->model.n_deepstack_layers);
|
||||
|
||||
Reference in new issue
Block a user