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

Method build_starcoder

llama.cpp:5474–5571  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5472
5473
5474 struct ggml_cgraph * build_starcoder() {
5475 struct ggml_cgraph * gf = ggml_new_graph_custom(ctx0, LLAMA_MAX_NODES, false);
5476
5477 struct ggml_tensor * cur;
5478 struct ggml_tensor * pos;
5479 struct ggml_tensor * inpL;
5480
5481 inpL = llm_build_inp_embd(ctx0, hparams, batch, model.tok_embd, cb);
5482 cb(inpL, "inp_embd", -1);
5483
5484 // inp_pos - contains the positions
5485 struct ggml_tensor * inp_pos = ggml_new_tensor_1d(ctx0, GGML_TYPE_I32, n_tokens);
5486 cb(inp_pos, "inp_pos", -1);
5487
5488 // KQ_scale
5489 struct ggml_tensor * KQ_scale = ggml_new_tensor_1d(ctx0, GGML_TYPE_F32, 1);
5490 cb(KQ_scale, "KQ_scale", -1);
5491
5492 // KQ_mask (mask for 1 head, it will be broadcasted to all heads)
5493 struct ggml_tensor * KQ_mask = ggml_new_tensor_3d(ctx0, GGML_TYPE_F32, n_kv, n_tokens, 1);
5494 cb(KQ_mask, "KQ_mask", -1);
5495
5496 pos = ggml_get_rows(ctx0, model.pos_embd, inp_pos);
5497 cb(pos, "pos_embd", -1);
5498
5499 inpL = ggml_add(ctx0, inpL, pos);
5500 cb(inpL, "inpL", -1);
5501
5502 for (int il = 0; il < n_layer; ++il) {
5503 cur = llm_build_norm(ctx0, inpL, hparams,
5504 model.layers[il].attn_norm,
5505 model.layers[il].attn_norm_b,
5506 LLM_NORM, cb, il);
5507 cb(cur, "attn_norm", il);
5508
5509 // self-attention
5510 {
5511 cur = ggml_mul_mat(ctx0, model.layers[il].wqkv, cur);
5512 cb(cur, "wqkv", il);
5513
5514 cur = ggml_add(ctx0, cur, model.layers[il].bqkv);
5515 cb(cur, "bqkv", il);
5516
5517 struct ggml_tensor * Qcur = ggml_cont(ctx0, ggml_view_2d(ctx0, cur, n_embd, n_tokens, cur->nb[1], 0*sizeof(float)*(n_embd)));
5518 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)));
5519 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)));
5520
5521 cb(Qcur, "Qcur", il);
5522 cb(Kcur, "Kcur", il);
5523 cb(Vcur, "Vcur", il);
5524
5525 Qcur = ggml_reshape_3d(ctx0, Qcur, n_embd_head, n_head, n_tokens);
5526
5527 llm_build_kv_store(ctx0, hparams, kv_self, gf, Kcur, Vcur, n_ctx, n_tokens, kv_head, cb, il);
5528
5529 cur = llm_build_kqv(ctx0, hparams, kv_self,
5530 model.layers[il].wo, model.layers[il].bo,
5531 Qcur, KQ_scale, KQ_mask, n_ctx, n_tokens, n_kv, -1.0f, cb, il);

Callers 1

llama_build_graphFunction · 0.80

Calls 15

llm_build_inp_embdFunction · 0.85
cbFunction · 0.85
llm_build_normFunction · 0.85
llm_build_kv_storeFunction · 0.85
llm_build_kqvFunction · 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
ggml_get_rowsFunction · 0.70
ggml_addFunction · 0.70
ggml_mul_matFunction · 0.70

Tested by

no test coverage detected