10 size_t n = fread(dst,
sizeof(
float), count, f);
13 fprintf(stderr,
"ck_model_load_weights_flat: fread error: %s\n",
16 fprintf(stderr,
"ck_model_load_weights_flat: unexpected EOF (wanted %zu floats, got %zu)\n",
27 fprintf(stderr,
"ck_model_load_weights_flat: invalid arguments\n");
31 FILE *f = fopen(path,
"rb");
33 fprintf(stderr,
"ck_model_load_weights_flat: failed to open %s: %s\n",
34 path, strerror(errno));
38 if (fread(magic, 1, 8, f) == 8) {
39 if (memcmp(magic,
"BUMPWGT2", 8) == 0) {
40 if (fseek(f, 128, SEEK_SET) != 0) {
44 }
else if (memcmp(magic,
"BUMPWGT3", 8) == 0) {
45 if (fseek(f, 128, SEEK_SET) != 0) {
49 uint32_t dtype_len = 0;
50 if (fread(&dtype_len,
sizeof(uint32_t), 1, f) != 1) {
54 if (fseek(f, (
long)dtype_len, SEEK_CUR) != 0) {
58 }
else if (fseek(f, 0, SEEK_SET) != 0) {
62 }
else if (fseek(f, 0, SEEK_SET) != 0) {
73 if (L <= 0 || H <= 0 || Hff <= 0 || V <= 0 || T <= 0) {
74 fprintf(stderr,
"ck_model_load_weights_flat: invalid model cfg (L=%d, H=%d, Hff=%d, V=%d, T=%d)\n",
84 (
size_t)V * (
size_t)H) != 0) {
91 (
size_t)T * (
size_t)H) != 0) {
97 for (
int layer = 0; layer < L; ++layer) {
114 (
size_t)H * (
size_t)(3 * H)) != 0) {
127 (
size_t)H * (
size_t)H) != 0) {
140 (
size_t)H * (
size_t)Hff) != 0) {
153 (
size_t)Hff * (
size_t)H) != 0) {
179 (
size_t)V * (
size_t)H) != 0) {
int ck_model_load_weights_flat(TransformerModel *m, const char *path)
static int read_floats(FILE *f, float *dst, size_t count)
size_t attn_proj_bias_offset
size_t attn_proj_weight_offset