input predictions shape: [n_embd, n_tokens, n_altup] input activated shape: [n_embd, n_tokens] output shape: [n_embd, n_tokens, n_altup]
| 362 | // input activated shape: [n_embd, n_tokens] |
| 363 | // output shape: [n_embd, n_tokens, n_altup] |
| 364 | ggml_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 | } |
nothing calls this directly
no test coverage detected