2
2
#define _USE_MATH_DEFINES // For M_PI on MSVC
3
3
4
4
#include "ggml-impl.h"
5
+
5
6
#include "ggml-quants.h"
6
7
7
8
@@ -2947,7 +2948,9 @@ float ggml_get_f32_1d(const struct ggml_tensor * tensor, int i) {
2947
2948
}
2948
2949
default:
2949
2950
{
2950
- GGML_ASSERT(false);
2951
+ //return ((float *)(tensor->data))[i];
2952
+ return 0;
2953
+ //GGML_ASSERT(false);
2951
2954
}
2952
2955
}
2953
2956
@@ -9414,6 +9417,44 @@ static bool ggml_compute_forward_mul_mat_use_blas(
9414
9417
}
9415
9418
#endif
9416
9419
9420
+ void ggml_tensor_checksum(const char * name,const struct ggml_tensor * tensor);
9421
+ void ggml_tensor_checksum(const char * name,const struct ggml_tensor * tensor) {
9422
+ const int64_t ne = ggml_nelements(tensor) ;
9423
+ float fmin=0;
9424
+ float ffirst=0;
9425
+ float fmax=0;
9426
+ float fsum=0;
9427
+
9428
+ for (int64_t j = 0; j < ne; ++j) {
9429
+ float f = ggml_get_f32_1d(tensor, j);
9430
+ if (j ==0) {
9431
+ ffirst = f;
9432
+ fmin = f;
9433
+ fmax = f;
9434
+ }
9435
+ fsum += f;
9436
+ if (f < fmin){
9437
+ fmin = f;
9438
+ }
9439
+ if (f >fmax){
9440
+ fmax = f;
9441
+ }
9442
+ }
9443
+
9444
+ auto type_name = ggml_type_name(tensor->type);
9445
+ // color_name
9446
+ fprintf(stderr, "JSON: { \"name1\" :\"%s\", \"cnt\":\"%ld\", \"first\":\"%f\",\"max\":\"%f\",\"min\":\"%f\",\"sum\":\"%f\", \"name\":\"%s\", \"type\":\"%s\"}\n",
9447
+ name,
9448
+ ne,
9449
+ ffirst,
9450
+ fmax,
9451
+ fmin,
9452
+ fsum,
9453
+ tensor->name,
9454
+ std::string(type_name).c_str()
9455
+ );
9456
+ }
9457
+
9417
9458
static void ggml_compute_forward_mul_mat(
9418
9459
const struct ggml_compute_params * params,
9419
9460
const struct ggml_tensor * src0,
@@ -9423,6 +9464,9 @@ static void ggml_compute_forward_mul_mat(
9423
9464
print_fields(*src0);
9424
9465
print_fields(*src1);
9425
9466
print_fields(*dst);
9467
+ ggml_tensor_checksum("src0",src0);
9468
+ ggml_tensor_checksum("src1",src1);
9469
+ ggml_tensor_checksum("dst_pre",dst);
9426
9470
int64_t t0 = ggml_perf_time_us();
9427
9471
UNUSED(t0);
9428
9472
@@ -9466,7 +9510,10 @@ static void ggml_compute_forward_mul_mat(
9466
9510
if (params->ith == 0 && params->type == GGML_TASK_COMPUTE) {
9467
9511
ggml_cl_mul_mat(src0, src1, dst, params->wdata, params->wsize);
9468
9512
}
9513
+
9514
+
9469
9515
print_fields(*dst);
9516
+ ggml_tensor_checksum("after1",dst);
9470
9517
return;
9471
9518
}
9472
9519
#endif
@@ -9475,6 +9522,7 @@ static void ggml_compute_forward_mul_mat(
9475
9522
if (ggml_compute_forward_mul_mat_use_blas(src0, src1, dst)) {
9476
9523
if (params->ith != 0) {
9477
9524
print_fields(*dst);
9525
+ ggml_tensor_checksum("after_accel",dst);
9478
9526
return;
9479
9527
}
9480
9528
@@ -9522,6 +9570,7 @@ static void ggml_compute_forward_mul_mat(
9522
9570
9523
9571
//printf("CBLAS = %f ms, %d x %d x %d x %d\n", (ggml_perf_time_us() - t0)/1000.0, ne0, ne1, ne2, ne3);
9524
9572
print_fields(*dst);
9573
+ ggml_tensor_checksum("after_blas",dst);
9525
9574
return;
9526
9575
}
9527
9576
#endif
@@ -9541,11 +9590,13 @@ static void ggml_compute_forward_mul_mat(
9541
9590
}
9542
9591
}
9543
9592
print_fields(*dst);
9593
+ ggml_tensor_checksum("after3",dst);
9544
9594
return;
9545
9595
}
9546
9596
9547
9597
if (params->type == GGML_TASK_FINALIZE) {
9548
9598
print_fields(*dst);
9599
+ ggml_tensor_checksum("after_final",dst);
9549
9600
return;
9550
9601
}
9551
9602
@@ -9633,6 +9684,7 @@ static void ggml_compute_forward_mul_mat(
9633
9684
}
9634
9685
}
9635
9686
print_fields(*dst);
9687
+ ggml_tensor_checksum("last",dst);
9636
9688
}
9637
9689
9638
9690
// ggml_compute_forward_out_prod
@@ -13741,6 +13793,8 @@ static void ggml_compute_forward(struct ggml_compute_params * params, struct ggm
13741
13793
if (tensor->op == GGML_OP_NONE) {
13742
13794
return;
13743
13795
}
13796
+ print_fields(*params);
13797
+ print_fields(*tensor);
13744
13798
13745
13799
#ifdef GGML_USE_CUBLAS
13746
13800
bool skip_cpu = ggml_cuda_compute_forward(params, tensor);
0 commit comments