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

Method build_bloom

llama.cpp:5874–5966  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5872 }
5873
5874 struct ggml_cgraph * build_bloom() {
5875 struct ggml_cgraph * gf = ggml_new_graph_custom(ctx0, LLAMA_MAX_NODES, false);
5876
5877 struct ggml_tensor * cur;
5878 struct ggml_tensor * inpL;
5879
5880 inpL = llm_build_inp_embd(ctx0, hparams, batch, model.tok_embd, cb);
5881 cb(inpL, "inp_embd", -1);
5882
5883 // KQ_scale
5884 struct ggml_tensor * KQ_scale = ggml_new_tensor_1d(ctx0, GGML_TYPE_F32, 1);
5885 cb(KQ_scale, "KQ_scale", -1);
5886
5887 // KQ_mask (mask for 1 head, it will be broadcasted to all heads)
5888 struct ggml_tensor * KQ_mask = ggml_new_tensor_3d(ctx0, GGML_TYPE_F32, n_kv, n_tokens, 1);
5889 cb(KQ_mask, "KQ_mask", -1);
5890
5891 inpL = llm_build_norm(ctx0, inpL, hparams,
5892 model.tok_norm,
5893 model.tok_norm_b,
5894 LLM_NORM, cb, -1);
5895 cb(inpL, "inp_norm", -1);
5896
5897 for (int il = 0; il < n_layer; ++il) {
5898 cur = llm_build_norm(ctx0, inpL, hparams,
5899 model.layers[il].attn_norm,
5900 model.layers[il].attn_norm_b,
5901 LLM_NORM, cb, il);
5902 cb(cur, "attn_norm", il);
5903
5904 // self-attention
5905 {
5906 cur = ggml_mul_mat(ctx0, model.layers[il].wqkv, cur);
5907 cb(cur, "wqkv", il);
5908
5909 cur = ggml_add(ctx0, cur, model.layers[il].bqkv);
5910 cb(cur, "bqkv", il);
5911
5912 struct ggml_tensor * Qcur = ggml_cont(ctx0, ggml_view_2d(ctx0, cur, n_embd, n_tokens, cur->nb[1], 0*sizeof(float)*(n_embd)));
5913 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)));
5914 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)));
5915
5916 cb(Qcur, "Qcur", il);
5917 cb(Kcur, "Kcur", il);
5918 cb(Vcur, "Vcur", il);
5919
5920 Qcur = ggml_reshape_3d(ctx0, Qcur, n_embd_head, n_head, n_tokens);
5921
5922 llm_build_kv_store(ctx0, hparams, kv_self, gf, Kcur, Vcur, n_ctx, n_tokens, kv_head, cb, il);
5923
5924 cur = llm_build_kqv(ctx0, hparams, kv_self,
5925 model.layers[il].wo, model.layers[il].bo,
5926 Qcur, KQ_scale, KQ_mask, n_ctx, n_tokens, n_kv, 8.0f, cb, il);
5927 cb(cur, "kqv_out", il);
5928 }
5929
5930 // Add the input
5931 struct ggml_tensor * ffn_inp = ggml_add(ctx0, cur, inpL);

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_mul_matFunction · 0.70
ggml_addFunction · 0.70
ggml_contFunction · 0.70

Tested by

no test coverage detected