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

Function metal_graph_encode_layer_batch

ds4.c:19261–19284  ·  view source on GitHub ↗

Encode one complete layer for prefill by chaining attention and FFN batches. */

Source from the content-addressed store, hash-verified

19259 (uint64_t)DS4_N_HC * sizeof(float));
19260 g->hc_post_by_tier[t] = ds4_gpu_tensor_view(g->hc_split_by_tier[t],
19261 (uint64_t)DS4_N_HC * sizeof(float),
19262 (uint64_t)DS4_N_HC * sizeof(float));
19263 g->hc_comb_by_tier[t] = ds4_gpu_tensor_view(g->hc_split_by_tier[t],
19264 2ull * DS4_N_HC * sizeof(float),
19265 (uint64_t)DS4_N_HC * DS4_N_HC * sizeof(float));
19266 g->attn_cur_by_tier[t] = ds4_gpu_tensor_alloc_ptr_on(t, (uint64_t)DS4_N_EMBD * sizeof(float));
19267 g->attn_norm_by_tier[t] = ds4_gpu_tensor_alloc_ptr_on(t, (uint64_t)DS4_N_EMBD * sizeof(float));
19268 g->qr_by_tier[t] = ds4_gpu_tensor_alloc_ptr_on(t, q_rank * sizeof(float));
19269 g->qr_norm_by_tier[t] = ds4_gpu_tensor_alloc_ptr_on(t, q_rank * sizeof(float));
19270 g->q_by_tier[t] = ds4_gpu_tensor_alloc_ptr_on(t, q_dim * sizeof(float));
19271 g->kv_raw_by_tier[t] = ds4_gpu_tensor_alloc_ptr_on(t, (uint64_t)DS4_N_HEAD_DIM * sizeof(float));
19272 g->kv_by_tier[t] = ds4_gpu_tensor_alloc_ptr_on(t, (uint64_t)DS4_N_HEAD_DIM * sizeof(float));
19273 }
19274 bool state_init_ok = true;
19275 for (uint32_t il = 0; il < DS4_N_LAYER; il++) {
19276 /* A distributed process owns only its bound layer slice. Persistent
19277 * KV state must follow that ownership just like the model tensors;
19278 * allocating every model layer here defeats split-model residency. */
19279 if (!weights_layer_has_required(&weights->layer[il], il)) continue;
19280 /* per-layer Class L allocations land on the layer's
19281 * home tier. placement is NULL on single-tier / diagnostic paths
19282 * (all-tier-0); non-NULL on the engine path that opted into
19283 * multi-tier. layer_tier == 0 in single-tier mode is the
19284 * byte-equivalent path through metal_graph_alloc_kv_cache_tensor_on
19285 * and ds4_gpu_tensor_alloc_ptr_on. */
19286 const int layer_tier = placement ? placement[il + 1] : 0;
19287 g->layer_raw_cache[il] = metal_graph_alloc_kv_cache_tensor_on(

Tested by

no test coverage detected