Skip to content

Commit

Permalink
Add BF16 code for new ggml_validate_row_data() function
Browse files Browse the repository at this point in the history
  • Loading branch information
jart committed May 8, 2024
1 parent 2741a99 commit 632624e
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions ggml-quants.c
Original file line number Diff line number Diff line change
Expand Up @@ -12450,6 +12450,24 @@ bool ggml_validate_row_data(enum ggml_type type, const void * data, size_t nbyte
const size_t nb = nbytes/ggml_type_size(type);

switch (type) {
case GGML_TYPE_BF16:
{
int nans = 0;
int infs = 0;
const unsigned short * f = (const unsigned short *) data;
for (size_t i = 0; i < nb; ++i) {
nans += (f[i] & 0x7fff) > 0x7f80;
infs += (f[i] & 0x7fff) == 0x7f80;
}
if (nans) {
fprintf(stderr, "%s: found %d NaNs in row of %zu BF16 values\n", __func__, nans, nb);
return false;
}
if (infs) {
fprintf(stderr, "%s: found %d infinities in row of %zu BF16 values\n", __func__, infs, nb);
return false;
}
} break;
case GGML_TYPE_F16:
{
const ggml_fp16_t * f = (const ggml_fp16_t *) data;
Expand Down

0 comments on commit 632624e

Please sign in to comment.