/* Loader-seam test for fmt=5: writes a real .safetensors file containing an * int3-g64 tensor (U8 payload + per-GROUP .qs) next to an int4 control tensor * (per-row .qs), indexes it with st_init, loads both through qt_from_disk, and * checks the byte-count/.qs-size format inference picks fmt=5 vs fmt=2 correctly * and the loaded weights dequantize identically to pack_int3_g64's output. */ #define main coli_glm_main_unused #include "../colibri.c" #undef main #include #include #include #include static int fails = 0; #define CHECK(c) do{ if(!(c)){ printf("FAIL %s:%d: %s\n", __FILE__, __LINE__, #c); fails++; } }while(0) static uint64_t rng = 0xA5A5A5A55A5A5A5Aull; static float rndf(void){ rng ^= rng << 13; rng ^= rng >> 7; rng ^= rng << 17; return ((int64_t)(rng & 0xFFFFF) - 0x80000) / (float)0x80000; } static void deq4(const QT *t, float *dq){ for(int o=0;oO;o++) for(int i=0;iI;i++){ if(t->fmt==5){ int64_t g=i/I3_GROUP; const uint8_t *lo=t->q4+(int64_t)o*i3_rowbytes(t->I)+g*I3_GBYTES, *hi=lo+16; int k=i%I3_GROUP; unsigned u=((lo[k>>2]>>((k&3)*2))&3)|(((hi[k>>3]>>(k&7))&1)<<2); dq[(int64_t)o*t->I+i]=(float)((int)u-4)*t->s[(int64_t)o*i3_groups(t->I)+g]; } else { /* fmt2 */ uint8_t b=t->q4[(int64_t)o*((t->I+1)/2)+(i>>1)]; int v=(i&1)?((int)(b>>4)-8):((int)(b&0xF)-8); dq[(int64_t)o*t->I+i]=(float)v*t->s[o]; } } } int main(void){ enum { O=5, I=320 }; /* 5 groups per row; I > 256 so the per-row int4 * control stays fmt=2 (detect_group_size probes * gs up to 256: any smaller I would make O row * scales match a legitimate 1-group layout) */ int64_t ng=i3_groups(I), rb=i3_rowbytes(I); static float w[O*I]; for(int i=0;i