ggml-debug: better tensor type support
This commit is contained in:
parent
3f8a93fb7b
commit
cfb820b343
1 changed files with 22 additions and 7 deletions
|
@ -13,7 +13,7 @@
|
|||
* Later on we can for example add operation or tensor name filter from the CLI arg, or a file descriptor to dump the tensor.
|
||||
*/
|
||||
struct callback_data {
|
||||
std::vector<int8_t> data;
|
||||
std::vector<uint8_t> data;
|
||||
};
|
||||
|
||||
static std::string ggml_ne_string(const ggml_tensor * t) {
|
||||
|
@ -27,7 +27,9 @@ static std::string ggml_ne_string(const ggml_tensor * t) {
|
|||
return str;
|
||||
}
|
||||
|
||||
static void ggml_print_tensor(int8_t * data, const int64_t * ne, const size_t * nb, int64_t n) {
|
||||
static void ggml_print_tensor(uint8_t * data, ggml_type type, const int64_t * ne, const size_t * nb, int64_t n) {
|
||||
size_t bs = ggml_blck_size(type);
|
||||
|
||||
for (int64_t i3 = 0; i3 < ne[3]; i3++) {
|
||||
printf(" [\n");
|
||||
for (int64_t i2 = 0; i2 < ne[2] && i2 < n; i2++) {
|
||||
|
@ -35,8 +37,21 @@ static void ggml_print_tensor(int8_t * data, const int64_t * ne, const size_t *
|
|||
for (int64_t i1 = 0; i1 < ne[1] && i1 < n; i1++) {
|
||||
printf(" [");
|
||||
for (int64_t i0 = 0; i0 < ne[0] && i0 < n; i0++) {
|
||||
size_t i = i3 * nb[3] + i2 * nb[2] + i1 * nb[1] + i0 * nb[0];
|
||||
float v = *(float *)(data + i);
|
||||
size_t i = i3 * nb[3] + i2 * nb[2] + i1 * nb[1] + i0 / bs * nb[0];
|
||||
float v;
|
||||
if (type == GGML_TYPE_F16) {
|
||||
v = ggml_fp16_to_fp32(*(ggml_fp16_t *) data + i);
|
||||
} else if (type == GGML_TYPE_F32) {
|
||||
v = *(float *) data + i;
|
||||
} else if (type == GGML_TYPE_I32) {
|
||||
v = (float) *(int32_t *) data + i;
|
||||
} else if (type == GGML_TYPE_I16) {
|
||||
v = (float) *(int16_t *) data + i;
|
||||
} else if (type == GGML_TYPE_I8) {
|
||||
v = (float) *(int8_t *) data + i;
|
||||
} else {
|
||||
GGML_ASSERT(false);
|
||||
}
|
||||
printf("%8.4f", v);
|
||||
if (i0 < ne[0] - 1 && i0 < n - 1) printf(", ");
|
||||
}
|
||||
|
@ -92,9 +107,9 @@ static bool ggml_debug(struct ggml_tensor * t, bool ask, void * user_data) {
|
|||
ggml_backend_tensor_get(t, cb_data->data.data(), 0, n_bytes);
|
||||
}
|
||||
|
||||
if (t->type == GGML_TYPE_F32 || t->type == GGML_TYPE_F16) {
|
||||
int8_t * data = is_host ? (int8_t *) t->data : cb_data->data.data();
|
||||
ggml_print_tensor(data, t->ne, t->nb, 3);
|
||||
if (!ggml_is_quantized(t->type)) {
|
||||
uint8_t * data = is_host ? (uint8_t *) t->data : cb_data->data.data();
|
||||
ggml_print_tensor(data, t->type, t->ne, t->nb, 3);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue