@@ -2032,6 +2032,10 @@ llm_graph_result * llama_context::process_ubatch(const llama_ubatch & ubatch, ll
20322032 phase2_gf = model.build_graph (gparams, nullptr , nullptr , &moe_weight_cache);
20332033 if (!phase2_gf) { ret = GGML_STATUS_FAILED ; return nullptr ; }
20342034 ggml_backend_sched_reset (sched.get ());
2035+ for (int i = 0 ; i < ggml_graph_n_nodes (phase2_gf); i++)
2036+ ggml_backend_sched_set_tensor_backend (sched.get (), ggml_graph_node (phase2_gf, i), gpu);
2037+ for (int i = 0 ; i < ggml_graph_n_leafs (phase2_gf); i++)
2038+ ggml_backend_sched_set_tensor_backend (sched.get (), ggml_graph_leaf (phase2_gf, i), gpu);
20352039 force_idxs_to_cpu ();
20362040 if (!ggml_backend_sched_alloc_graph (sched.get (), phase2_gf)) { ret = GGML_STATUS_ALLOC_FAILED ; return nullptr ; }
20372041
@@ -2048,17 +2052,18 @@ llm_graph_result * llama_context::process_ubatch(const llama_ubatch & ubatch, ll
20482052 // 3. Copy scratch data to hijacked static addresses
20492053 void * st = ggml_backend_cuda_get_stream_ptr (gpu, 0 );
20502054 h2_hijack.copy_data_to_static (st);
2051-
2052- // 4. Record barrier
2053- h2_guard.record (st);
2054-
2055- // 5. Launch CUDA Graph
2056- ggml_backend_sched_synchronize (sched.get ());
2057- int cu = cudaGraphLaunch (h2_hijack.cuda_graph_exec , st);
2058- if (cu != cudaSuccess) fprintf (stderr, " cuda_replay: %s\n " , cudaGetErrorString (cu));
20592055 ggml_backend_sched_synchronize (sched.get ());
20602056
2061- // 6. Save logits data pointer for direct readback
2057+ // 4. Normal graph compute (CUDA graph replay disabled:
2058+ // non-hijacked tensors get different allocator addresses
2059+ // on replay, causing illegal memory access on capture-time
2060+ // addresses recorded in the graph)
2061+ {
2062+ auto s = graph_compute (phase2_gf, ubatch.n_tokens > 1 );
2063+ if (s != GGML_STATUS_SUCCESS ) { ret = s; return nullptr ; }
2064+ }
2065+
2066+ // 5. Save logits data pointer for direct readback
20622067 if (res->t_logits )
20632068 moe_weight_cache.phase2_logits_data = res->t_logits ->data ;
20642069 } else {
0 commit comments