|
|
|
@ -17,6 +17,68 @@
|
|
|
|
|
#include <regex>
|
|
|
|
|
#include <random>
|
|
|
|
|
|
|
|
|
|
#if defined(GGML_BIG_ENDIAN)
|
|
|
|
|
#include <bit>
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
static T byteswap(T value) {
|
|
|
|
|
return std::byteswap(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<>
|
|
|
|
|
float byteswap(float value) {
|
|
|
|
|
return std::bit_cast<float>(byteswap(std::bit_cast<std::uint32_t>(value)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
static void byteswap_tensor_data(ggml_tensor * tensor) {
|
|
|
|
|
T * datum = reinterpret_cast<T *>(tensor->data);
|
|
|
|
|
for (int i = 0; i < ggml_nelements(tensor); i++) {
|
|
|
|
|
datum[i] = byteswap(datum[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void byteswap_tensor(ggml_tensor * tensor) {
|
|
|
|
|
switch (tensor->type) {
|
|
|
|
|
case GGML_TYPE_I16: {
|
|
|
|
|
byteswap_tensor_data<int16_t>(tensor);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case GGML_TYPE_F16: {
|
|
|
|
|
byteswap_tensor_data<ggml_fp16_t>(tensor);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case GGML_TYPE_I32: {
|
|
|
|
|
byteswap_tensor_data<int32_t>(tensor);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case GGML_TYPE_F32: {
|
|
|
|
|
byteswap_tensor_data<float>(tensor);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: { // GML_TYPE_I8
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define BYTESWAP_VALUE(d) d = byteswap(d)
|
|
|
|
|
#define BYTESWAP_FILTERS(f) \
|
|
|
|
|
do { \
|
|
|
|
|
for (auto & datum : f.data) { \
|
|
|
|
|
datum = byteswap(datum); \
|
|
|
|
|
} \
|
|
|
|
|
} while (0)
|
|
|
|
|
#define BYTESWAP_TENSOR(t) \
|
|
|
|
|
do { \
|
|
|
|
|
byteswap_tensor(tensor); \
|
|
|
|
|
} while (0)
|
|
|
|
|
#else
|
|
|
|
|
#define BYTESWAP_VALUE(d) do {} while (0)
|
|
|
|
|
#define BYTESWAP_FILTERS(f) do {} while (0)
|
|
|
|
|
#define BYTESWAP_TENSOR(t) do {} while (0)
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#define WHISPER_ASSERT(x) \
|
|
|
|
|
do { \
|
|
|
|
|
if (!(x)) { \
|
|
|
|
@ -521,6 +583,7 @@ struct whisper_context {
|
|
|
|
|
template<typename T>
|
|
|
|
|
static void read_safe(whisper_model_loader * loader, T & dest) {
|
|
|
|
|
loader->read(loader->context, &dest, sizeof(T));
|
|
|
|
|
BYTESWAP_VALUE(dest);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool kv_cache_init(
|
|
|
|
@ -733,6 +796,7 @@ static bool whisper_model_load(struct whisper_model_loader * loader, whisper_con
|
|
|
|
|
|
|
|
|
|
filters.data.resize(filters.n_mel * filters.n_fft);
|
|
|
|
|
loader->read(loader->context, filters.data.data(), filters.data.size() * sizeof(float));
|
|
|
|
|
BYTESWAP_FILTERS(filters);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// load vocab
|
|
|
|
@ -1196,6 +1260,7 @@ static bool whisper_model_load(struct whisper_model_loader * loader, whisper_con
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loader->read(loader->context, tensor->data, ggml_nbytes(tensor));
|
|
|
|
|
BYTESWAP_TENSOR(tensor);
|
|
|
|
|
|
|
|
|
|
//printf("%48s - [%5d, %5d, %5d], type = %6s, %6.2f MB\n", name.data(), ne[0], ne[1], ne[2], ftype == 0 ? "float" : "f16", ggml_nbytes(tensor)/1024.0/1024.0);
|
|
|
|
|
total_size += ggml_nbytes(tensor);
|
|
|
|
|