MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / build_rs

Method build_rs

subprojects/llama.cpp/src/llama-graph.cpp:2141–2174  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2139}
2140
2141ggml_tensor * llm_graph_context::build_rs(
2142 ggml_tensor * s,
2143 ggml_tensor * state_copy_main,
2144 ggml_tensor * state_copy_extra,
2145 int32_t state_size,
2146 int32_t n_seqs,
2147 uint32_t n_rs,
2148 uint32_t rs_head,
2149 uint32_t rs_size,
2150 int32_t rs_zero,
2151 const llm_graph_get_rows_fn & get_state_rows) const {
2152
2153 ggml_tensor * states = ggml_reshape_2d(ctx0, s, state_size, rs_size);
2154
2155 // Clear a single state which will then be copied to the other cleared states.
2156 // Note that this is a no-op when the view is zero-sized.
2157 ggml_tensor * state_zero = ggml_view_1d(ctx0, states, state_size*(rs_zero >= 0), rs_zero*states->nb[1]*(rs_zero >= 0));
2158 ggml_build_forward_expand(gf, ggml_scale_inplace(ctx0, state_zero, 0));
2159
2160 // copy states
2161 // NOTE: assuming the copy destinations are ALL contained between rs_head and rs_head + n_rs
2162 // {state_size, rs_size} -> {state_size, n_seqs}
2163 ggml_tensor * output_states = get_state_rows(ctx0, states, state_copy_main);
2164 ggml_build_forward_expand(gf, output_states);
2165
2166 // copy extra states which won't be changed further (between n_seqs and n_rs)
2167 ggml_tensor * states_extra = ggml_get_rows(ctx0, states, state_copy_extra);
2168 ggml_build_forward_expand(gf,
2169 ggml_cpy(ctx0,
2170 states_extra,
2171 ggml_view_1d(ctx0, s, state_size*(n_rs - n_seqs), (rs_head + n_seqs)*state_size*ggml_element_size(s))));
2172
2173 return output_states;
2174}
2175
2176static std::unique_ptr<llm_graph_input_rs> build_rs_inp_impl(
2177 ggml_context * ctx0,

Callers

nothing calls this directly

Calls 11

ggml_reshape_2dFunction · 0.85
ggml_view_1dFunction · 0.85
ggml_scale_inplaceFunction · 0.85
ggml_get_rowsFunction · 0.85
ggml_cpyFunction · 0.85
ggml_element_sizeFunction · 0.85
get_n_rsMethod · 0.80
get_headMethod · 0.80
get_rs_zMethod · 0.80
get_sizeMethod · 0.45

Tested by

no test coverage detected