diff --git a/ggml/src/ggml.c b/ggml/src/ggml.c index f3b59e9e..19ba0436 100644 --- a/ggml/src/ggml.c +++ b/ggml/src/ggml.c @@ -19007,6 +19007,11 @@ static void ggml_compute_forward_set_rows_f32( const int64_t ir1 = MIN(ir0 + dr, nr); ggml_from_float_t const from_float = type_traits[dst->type].from_float; + // F32 has no from_float entry in type_traits (it is NULL), so set_rows into an F32 + // destination would call a NULL function pointer and crash. Handle F32 dst with a + // direct float copy. Hit by graphs that scatter F32 rows into an F32 base. + const bool dst_is_f32 = (dst->type == GGML_TYPE_F32); + GGML_ASSERT(dst_is_f32 || from_float); if (src1->type == GGML_TYPE_I64) { for (int64_t i03 = 0; i03 < ne03; ++i03) { @@ -19020,8 +19025,10 @@ static void ggml_compute_forward_set_rows_f32( GGML_ASSERT(i1 >= 0 && i1 < ne1); - from_float((const float *) ((char *) src0->data + i*nb01 + i02*nb02 + i03*nb03), - ((char *) dst->data + i1*nb1 + i02*nb2 + i03*nb3), nc); + const float * src_row = (const float *) ((char *) src0->data + i*nb01 + i02*nb02 + i03*nb03); + char * dst_row = (char *) dst->data + i1*nb1 + i02*nb2 + i03*nb3; + if (dst_is_f32) memcpy(dst_row, src_row, nc*sizeof(float)); + else from_float(src_row, dst_row, nc); } } } @@ -19038,8 +19045,10 @@ static void ggml_compute_forward_set_rows_f32( GGML_ASSERT(i1 >= 0 && i1 < ne1); - from_float((const float *) ((char *) src0->data + i*nb01 + i02*nb02 + i03*nb03), - ((char *) dst->data + i1*nb1 + i02*nb2 + i03*nb3), nc); + const float * src_row = (const float *) ((char *) src0->data + i*nb01 + i02*nb02 + i03*nb03); + char * dst_row = (char *) dst->data + i1*nb1 + i02*nb2 + i03*nb3; + if (dst_is_f32) memcpy(dst_row, src_row, nc*sizeof(float)); + else from_float(src_row, dst_row, nc); } } }