MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / altup_correct

Method altup_correct

subprojects/llama.cpp/src/models/gemma3n-iswa.cpp:364–384  ·  view source on GitHub ↗

input predictions shape: [n_embd, n_tokens, n_altup] input activated shape: [n_embd, n_tokens] output shape: [n_embd, n_tokens, n_altup]

Source from the content-addressed store, hash-verified

362// input activated shape: [n_embd, n_tokens]
363// output shape: [n_embd, n_tokens, n_altup]
364ggml_tensor * llm_build_gemma3n_iswa::altup_correct(ggml_tensor * predictions, ggml_tensor * activated, int il) {
365 ggml_tensor * modalities = altup_compute_router_modalities(activated, il); // [n_altup, n_tokens]
366 cb(modalities, "modalities", il);
367
368 ggml_tensor * active_prediction = view_2d_slice(predictions, i_altup_act);
369 ggml_tensor * innovation = ggml_sub(ctx0, activated, active_prediction); // [n_embd, n_tokens]
370 cb(innovation, "innovation", il);
371
372 ggml_tensor * all_coefs = build_lora_mm(model.layers[il].altup_correct_coef, modalities); // [n_altup, n_tokens]
373 all_coefs = ggml_scale_bias(ctx0, all_coefs, 1.0f, 1.0f); // + 1.0
374 cb(all_coefs, "all_coefs", il);
375 all_coefs = ggml_transpose(ctx0, all_coefs); // [n_tokens, n_altup]
376 all_coefs = ggml_cont_3d(ctx0, all_coefs, 1, n_tokens, n_altup); // [1, n_tokens, n_altup]
377
378 innovation = ggml_repeat_4d(ctx0, innovation, n_embd, n_tokens, n_altup, 1);
379 ggml_tensor * corrected = ggml_mul(ctx0, innovation, all_coefs); // [n_embd, n_tokens, n_altup]
380 corrected = ggml_add(ctx0, corrected, predictions); // [n_embd, n_tokens, n_altup]
381 cb(corrected, "corrected", il);
382
383 return corrected;
384}

Callers

nothing calls this directly

Calls 7

ggml_subFunction · 0.85
ggml_scale_biasFunction · 0.85
ggml_transposeFunction · 0.85
ggml_cont_3dFunction · 0.85
ggml_repeat_4dFunction · 0.85
ggml_mulFunction · 0.85
ggml_addFunction · 0.85

Tested by

no test coverage detected