@@ -376,13 +376,24 @@ bool Qwen35DFlashTarget::rollback_to_tree(
376376 (size_t )rollback_dfs * cap.ssm_intermediate_states ->nb [3 ];
377377 const void * ssm_src =
378378 (const char *)cap.ssm_intermediate_states ->data + ssm_src_offset;
379- const auto to_fp32 = ggml_get_to_fp32_cuda (cap.ssm_intermediate_states ->type );
380- if (!to_fp32) {
381- std::fprintf (stderr, " rollback_to_tree: no fp32 converter for type %d (layer %d)\n " ,
382- (int )cap.ssm_intermediate_states ->type , il);
383- return false ;
379+ if (cap.ssm_intermediate_states ->type == GGML_TYPE_F32 ) {
380+ const cudaError_t ce = cudaMemcpyAsync (cache_.ssm_state [il]->data , ssm_src,
381+ ssm_elems * sizeof (float ),
382+ cudaMemcpyDeviceToDevice, stream);
383+ if (ce != cudaSuccess) {
384+ std::fprintf (stderr, " rollback_to_tree: F32 SSM copy failed at layer %d: %s\n " ,
385+ il, cudaGetErrorString (ce));
386+ return false ;
387+ }
388+ } else {
389+ const auto to_fp32 = ggml_get_to_fp32_cuda (cap.ssm_intermediate_states ->type );
390+ if (!to_fp32) {
391+ std::fprintf (stderr, " rollback_to_tree: no fp32 converter for type %d (layer %d)\n " ,
392+ (int )cap.ssm_intermediate_states ->type , il);
393+ return false ;
394+ }
395+ to_fp32 (ssm_src, (float *)cache_.ssm_state [il]->data , (int64_t )ssm_elems, stream);
384396 }
385- to_fp32 (ssm_src, (float *)cache_.ssm_state [il]->data , (int64_t )ssm_elems, stream);
386397
387398 // Conv state ← the K-1 most recent inputs along rollback_dfs's ancestry.
388399 const int K_conv = 4 ;
@@ -551,7 +562,6 @@ bool Qwen35DFlashTarget::rollback_to(int base_pos, int commit_n) {
551562 cache_.cur_pos = base_pos + commit_n;
552563 return true ;
553564 }
554-
555565 const int rollback_idx = commit_n - 1 ; // index into per-step intermediates
556566 cudaStream_t stream = nullptr ;
557567
@@ -589,16 +599,30 @@ bool Qwen35DFlashTarget::rollback_to(int base_pos, int commit_n) {
589599 (size_t )rollback_idx * cap.ssm_intermediate_states ->nb [3 ];
590600 const void * ssm_src =
591601 (const char *)cap.ssm_intermediate_states ->data + ssm_src_offset;
592- const auto to_fp32 = ggml_get_to_fp32_cuda (cap.ssm_intermediate_states ->type );
593- if (!to_fp32) {
594- if (kFastRollbackDiag ) {
595- std::fprintf (stderr, " rollback_to: no fp32 converter type=%d layer=%d\n " ,
596- (int )cap.ssm_intermediate_states ->type , il);
602+ if (cap.ssm_intermediate_states ->type == GGML_TYPE_F32 ) {
603+ const size_t ssm_bytes = ssm_elems * sizeof (float );
604+ const cudaError_t ce = cudaMemcpyAsync (cache_.ssm_state [il]->data , ssm_src,
605+ ssm_bytes,
606+ cudaMemcpyDeviceToDevice, stream);
607+ if (ce != cudaSuccess) {
608+ if (kFastRollbackDiag ) {
609+ std::fprintf (stderr, " rollback_to: F32 SSM copy failed layer=%d: %s\n " ,
610+ il, cudaGetErrorString (ce));
611+ }
612+ return false ;
597613 }
598- return false ;
614+ } else {
615+ const auto to_fp32 = ggml_get_to_fp32_cuda (cap.ssm_intermediate_states ->type );
616+ if (!to_fp32) {
617+ if (kFastRollbackDiag ) {
618+ std::fprintf (stderr, " rollback_to: no fp32 converter type=%d layer=%d\n " ,
619+ (int )cap.ssm_intermediate_states ->type , il);
620+ }
621+ return false ;
622+ }
623+ to_fp32 (ssm_src, (float *)cache_.ssm_state [il]->data ,
624+ (int64_t )ssm_elems, stream);
599625 }
600- to_fp32 (ssm_src, (float *)cache_.ssm_state [il]->data ,
601- (int64_t )ssm_elems, stream);
602626
603627 // Conv rollback: copy conv_input[commit_n..commit_n+K-2, :, :]
604628 // into cache.conv_state[il].
0 commit comments