MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / build_falcon

Method build_falcon

llama.cpp:5326–5468  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5324 }
5325
5326 struct ggml_cgraph * build_falcon() {
5327 struct ggml_cgraph * gf = ggml_new_graph_custom(ctx0, LLAMA_MAX_NODES, false);
5328
5329 struct ggml_tensor * cur;
5330 struct ggml_tensor * inpL;
5331
5332 inpL = llm_build_inp_embd(ctx0, hparams, batch, model.tok_embd, cb);
5333 cb(inpL, "inp_embd", -1);
5334
5335 // inp_pos - contains the positions
5336 struct ggml_tensor * inp_pos = ggml_new_tensor_1d(ctx0, GGML_TYPE_I32, n_tokens);
5337 cb(inp_pos, "inp_pos", -1);
5338
5339 // KQ_scale
5340 struct ggml_tensor * KQ_scale = ggml_new_tensor_1d(ctx0, GGML_TYPE_F32, 1);
5341 cb(KQ_scale, "KQ_scale", -1);
5342
5343 // KQ_mask (mask for 1 head, it will be broadcasted to all heads)
5344 struct ggml_tensor * KQ_mask = ggml_new_tensor_3d(ctx0, GGML_TYPE_F32, n_kv, n_tokens, 1);
5345 cb(KQ_mask, "KQ_mask", -1);
5346
5347 // shift the entire K-cache if needed
5348 if (do_rope_shift) {
5349 llm_build_k_shift(ctx0, hparams, cparams, kv_self, gf, LLM_ROPE_NEOX, n_ctx, n_embd_head, freq_base, freq_scale, cb);
5350 }
5351
5352 for (int il = 0; il < n_layer; ++il) {
5353 struct ggml_tensor * attn_norm;
5354
5355 attn_norm = llm_build_norm(ctx0, inpL, hparams,
5356 model.layers[il].attn_norm,
5357 model.layers[il].attn_norm_b,
5358 LLM_NORM, cb, il);
5359
5360 // self-attention
5361 {
5362 if (model.layers[il].attn_norm_2) {
5363 // Falcon-40B
5364 cur = llm_build_norm(ctx0, inpL, hparams,
5365 model.layers[il].attn_norm_2,
5366 model.layers[il].attn_norm_2_b,
5367 LLM_NORM, cb, il);
5368 cb(cur, "attn_norm_2", il);
5369 } else {
5370 cur = attn_norm;
5371 }
5372
5373 cur = ggml_mul_mat(ctx0, model.layers[il].wqkv, cur);
5374 cb(cur, "wqkv", il);
5375
5376 struct ggml_tensor * Qcur = ggml_cont(ctx0, ggml_view_2d(ctx0, cur, n_embd, n_tokens, cur->nb[1], 0*sizeof(float)*(n_embd)));
5377 struct ggml_tensor * Kcur = ggml_cont(ctx0, ggml_view_2d(ctx0, cur, n_embd_gqa, n_tokens, cur->nb[1], 1*sizeof(float)*(n_embd)));
5378 struct ggml_tensor * Vcur = ggml_cont(ctx0, ggml_view_2d(ctx0, cur, n_embd_gqa, n_tokens, cur->nb[1], 1*sizeof(float)*(n_embd + n_embd_gqa)));
5379
5380 cb(Qcur, "Qcur", il);
5381 cb(Kcur, "Kcur", il);
5382 cb(Vcur, "Vcur", il);
5383

Callers 1

llama_build_graphFunction · 0.80

Calls 15

llm_build_inp_embdFunction · 0.85
cbFunction · 0.85
llm_build_k_shiftFunction · 0.85
llm_build_normFunction · 0.85
llm_build_kv_storeFunction · 0.85
llm_build_kqvFunction · 0.85
llm_build_ffn_sparseFunction · 0.85
llm_build_ffnFunction · 0.85
ggml_new_graph_customFunction · 0.70
ggml_new_tensor_1dFunction · 0.70
ggml_new_tensor_3dFunction · 0.70

Tested by

no test coverage detected