MCPcopy Create free account
hub / github.com/antirez/ds4 / layer_ffn_shared_batch

Function layer_ffn_shared_batch

ds4.c:8117–8231  ·  view source on GitHub ↗

Default prefill FFN path. HC and shared expert are batched, while routed * experts can run either token-parallel or expert-grouped depending on size. */

Source from the content-addressed store, hash-verified

8115 /*
8116 * PRO Q4 routed expert tensors are too large to hide inside broad
8117 * layer spans. Isolate them so the default selected-expert path does
8118 * not stack large aliases on top of layer-sized model views. Optional
8119 * group splits are enabled by DS4_METAL_Q4_PRO_MAP_GROUPS for Metal
8120 * experiments that bind stable grouped views.
8121 */
8122 const uint64_t group_bytes = t->bytes / q4_pro_group_views;
8123 if (group_bytes > spans->max_tensor_bytes) spans->max_tensor_bytes = group_bytes;
8124 for (uint32_t i = 0; i < q4_pro_group_views; i++) {
8125 const uint64_t lo = t->abs_offset + (uint64_t)i * group_bytes;
8126 model_map_span_vec_append(spans, lo, lo + group_bytes, true);
8127 }
8128 return;
8129 }
8130
8131 uint64_t lo = UINT64_MAX, hi = 0;
8132 model_map_span_include_tensor(t, &lo, &hi, &spans->max_tensor_bytes);
8133 const bool isolate = (t->type == DS4_TENSOR_Q4_K ||
8134 t->type == DS4_TENSOR_MXFP4) &&
8135 t->bytes >= q4_isolated_min_bytes;
8136 model_map_span_vec_append(spans, lo, hi, isolate);
8137}
8138
8139static void model_map_span_vec_include_layer(ds4_model_map_span_vec *spans, const ds4_layer_weights *l) {
8140#define DS4_INCLUDE_TENSOR(t_) model_map_span_vec_include_one(spans, (t_))
8141 DS4_INCLUDE_TENSOR(l->hc_attn_fn);
8142 DS4_INCLUDE_TENSOR(l->hc_attn_scale);
8143 DS4_INCLUDE_TENSOR(l->hc_attn_base);
8144 DS4_INCLUDE_TENSOR(l->attn_norm);
8145 DS4_INCLUDE_TENSOR(l->attn_q_a);
8146 DS4_INCLUDE_TENSOR(l->attn_q_a_norm);
8147 DS4_INCLUDE_TENSOR(l->attn_q_b);
8148 DS4_INCLUDE_TENSOR(l->attn_kv);
8149 DS4_INCLUDE_TENSOR(l->attn_kv_a_mqa);
8150 DS4_INCLUDE_TENSOR(l->attn_kv_a_norm);
8151 DS4_INCLUDE_TENSOR(l->attn_k_b);
8152 DS4_INCLUDE_TENSOR(l->attn_v_b);
8153 DS4_INCLUDE_TENSOR(l->attn_sinks);
8154 DS4_INCLUDE_TENSOR(l->attn_output);
8155 DS4_INCLUDE_TENSOR(l->attn_output_a);
8156 DS4_INCLUDE_TENSOR(l->attn_output_b);
8157 DS4_INCLUDE_TENSOR(l->kda_q);
8158 DS4_INCLUDE_TENSOR(l->kda_k);
8159 DS4_INCLUDE_TENSOR(l->kda_v);
8160 DS4_INCLUDE_TENSOR(l->kda_q_conv);
8161 DS4_INCLUDE_TENSOR(l->kda_k_conv);
8162 DS4_INCLUDE_TENSOR(l->kda_v_conv);
8163 DS4_INCLUDE_TENSOR(l->kda_f_a);
8164 DS4_INCLUDE_TENSOR(l->kda_f_b);
8165 DS4_INCLUDE_TENSOR(l->kda_dt_bias);
8166 DS4_INCLUDE_TENSOR(l->kda_a_log);
8167 DS4_INCLUDE_TENSOR(l->kda_beta);
8168 DS4_INCLUDE_TENSOR(l->kda_g_a);
8169 DS4_INCLUDE_TENSOR(l->kda_g_b);
8170 DS4_INCLUDE_TENSOR(l->kda_o_norm);
8171 DS4_INCLUDE_TENSOR(l->kda_output);
8172 DS4_INCLUDE_TENSOR(l->attn_compressor_ape);
8173 DS4_INCLUDE_TENSOR(l->attn_compressor_kv);
8174 DS4_INCLUDE_TENSOR(l->attn_compressor_gate);

Callers 1

prefill_layer_major_cpuFunction · 0.85

Calls 10

hc_pre_norm_batchFunction · 0.85
layer_shared_ffn_batchFunction · 0.85
hc_post_batchFunction · 0.85
hc_post_sum_batchFunction · 0.85
now_secFunction · 0.70
xmallocFunction · 0.70

Tested by

no test coverage detected