RND1 is a Qwen3Moe AR model converted to diffusion model.
| 2 | |
| 3 | // RND1 is a Qwen3Moe AR model converted to diffusion model. |
| 4 | llm_build_rnd1::llm_build_rnd1(const llama_model & model, const llm_graph_params & params) : llm_graph_context(params) { |
| 5 | const int64_t n_embd_head = hparams.n_embd_head_v; |
| 6 | |
| 7 | GGML_ASSERT(n_embd_head == hparams.n_embd_head_k); |
| 8 | GGML_ASSERT(n_embd_head == hparams.n_rot); |
| 9 | |
| 10 | ggml_tensor * cur; |
| 11 | ggml_tensor * inpL; |
| 12 | |
| 13 | inpL = build_inp_embd(model.tok_embd); |
| 14 | |
| 15 | // inp_pos - contains the positions |
| 16 | ggml_tensor * inp_pos = build_inp_pos(); |
| 17 | |
| 18 | // Non-causal attention for diffusion |
| 19 | auto * inp_attn = build_attn_inp_no_cache(); |
| 20 | |
| 21 | ggml_tensor * inp_out_ids = build_inp_out_ids(); |
| 22 | |
| 23 | for (int il = 0; il < n_layer; ++il) { |
| 24 | ggml_tensor * inpSA = inpL; |
| 25 | |
| 26 | // norm |
| 27 | cur = build_norm(inpL, |
| 28 | model.layers[il].attn_norm, NULL, |
| 29 | LLM_NORM_RMS, il); |
| 30 | cb(cur, "attn_norm", il); |
| 31 | |
| 32 | // self_attention |
| 33 | { |
| 34 | // compute Q and K and RoPE them |
| 35 | ggml_tensor * Qcur = build_lora_mm(model.layers[il].wq, cur); |
| 36 | cb(Qcur, "Qcur", il); |
| 37 | |
| 38 | ggml_tensor * Kcur = build_lora_mm(model.layers[il].wk, cur); |
| 39 | cb(Kcur, "Kcur", il); |
| 40 | |
| 41 | ggml_tensor * Vcur = build_lora_mm(model.layers[il].wv, cur); |
| 42 | cb(Vcur, "Vcur", il); |
| 43 | |
| 44 | Qcur = ggml_reshape_3d(ctx0, Qcur, n_embd_head, n_head, n_tokens); |
| 45 | Kcur = ggml_reshape_3d(ctx0, Kcur, n_embd_head, n_head_kv, n_tokens); |
| 46 | Vcur = ggml_reshape_3d(ctx0, Vcur, n_embd_head, n_head_kv, n_tokens); |
| 47 | |
| 48 | Qcur = build_norm(Qcur, model.layers[il].attn_q_norm, NULL, LLM_NORM_RMS, il); |
| 49 | cb(Qcur, "Qcur_normed", il); |
| 50 | |
| 51 | Qcur = ggml_rope_ext( |
| 52 | ctx0, Qcur, inp_pos, nullptr, |
| 53 | n_rot, rope_type, n_ctx_orig, freq_base, freq_scale, |
| 54 | ext_factor, attn_factor, beta_fast, beta_slow |
| 55 | ); |
| 56 | |
| 57 | Kcur = build_norm(Kcur, model.layers[il].attn_k_norm, NULL, LLM_NORM_RMS, il); |
| 58 | cb(Kcur, "Kcur_normed", il); |
| 59 | |
| 60 | Kcur = ggml_rope_ext( |
| 61 | ctx0, Kcur, inp_pos, nullptr, |
nothing calls this directly
no test coverage detected