| 47 | return half_to_float(val); |
| 48 | } |
| 49 | [[maybe_unused]] inline f8e5m2_t float_to_float8e5m2(float x) { |
| 50 | f16_t val = float_to_half(x); |
| 51 | f8e5m2_t out; |
| 52 | #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ |
| 53 | memcpy(&out, (char*)&val, sizeof(f8e5m2_t)); // TODO: round instead of truncate? |
| 54 | #else |
| 55 | memcpy(&out, (char*)&val + sizeof(f8e5m2_t), sizeof(f8e5m2_t)); // TODO: round instead of truncate? |
| 56 | #endif |
| 57 | return out; |
| 58 | } |
| 59 | |
| 60 | // Quant of tensors saved in the file. |
| 61 | // This corresponds to PyTorch tensor dtypes. |