Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦
C
fix(cuda): stop coli_cuda_tensor_bytes from overcounting fmt=8/fmt=6 scale bytes
monotophic5823580994ef
diff --git a/c/backend_cuda.cu b/c/backend_cuda.cuindex 2af3f329..017c9db4 100644--- a/c/backend_cuda.cu+++ b/c/backend_cuda.cu@@ -2311,13 +2311,19 @@ extern "C" void coli_cuda_tensor_free(ColiCudaTensor *tensor) {extern "C" size_t coli_cuda_tensor_bytes(const ColiCudaTensor *tensor) {if (!tensor) return 0;- int ng = tensor->ng > 0 ? tensor->ng : 1;+ /* Must mirror upload's and free's accounting exactly -- literally the same+ * expression they use (scale_count * sizeof(float), gated on fmt=6 never+ * having a separate scale buffer) -- so all three can no longer drift+ * independently. The prior `O * ng` shape over-reported for fmt=8 (real+ * footprint is (O+127)/128 * ng block scales, not O * ng) and for fmt=6+ * (which has no separate scale buffer at all). */size_t storage_bytes =#ifdef COLI_ANStensor->compressed ? tensor->archive_bytes :#endiftensor->weight_bytes;- return storage_bytes + (tensor->fmt ? (size_t)tensor->O * ng * sizeof(float) : 0);+ return storage_bytes ++ ((tensor->fmt && tensor->fmt != 6) ? tensor->scale_count * sizeof(float) : 0);}extern "C" int coli_cuda_tensor_device(const ColiCudaTensor *tensor) {diff --git a/c/tests/test_fp8_cuda.cu b/c/tests/test_fp8_cuda.cuindex 7b1bb0c7..8547624f 100644--- a/c/tests/test_fp8_cuda.cu+++ b/c/tests/test_fp8_cuda.cu@@ -261,6 +261,66 @@ int main(void){free(gw);free(gsc);printf("byte accounting: fmt=8 dense + fmt=4 grouped free() restores stats exactly\n");}++ /* ---- coli_cuda_tensor_bytes() regression: the live-tensor byte report+ * must equal weight_bytes + scale_count*sizeof(float) exactly (fmt=6+ * excepted: no separate scale buffer, so weight_bytes alone). The old+ * `O * ng` shape over-reported fmt=8 (real footprint is (O+127)/128 * ng+ * block scales, not O*ng) and charged fmt=6 a phantom O*ng*4 scale+ * buffer it never allocates -- this is the same shape bug F4 fixed in+ * tensor_free(), here in the sibling accessor most callers actually use+ * for GPU-tier budget bookkeeping (c/colibri.c). */+ {+ ColiCudaTensor *bt=nullptr;+ uint8_t *bw=(uint8_t*)malloc((size_t)I*D); float *bs=(float*)malloc(hs_n*4);+ for(size_t i=0;i<(size_t)I*D;i++) bw[i]=rnd_e4m3();+ for(int i=0;i<hs_n;i++) bs[i]=ldexpf(1.f+rand()/(float)RAND_MAX,-12);+ if(!coli_cuda_tensor_upload(&bt,bw,bs,8,D,I,0)){ printf("FAIL bytes-check fmt8 upload\n"); return 1; }+ size_t want=bt->weight_bytes+bt->scale_count*sizeof(float);+ size_t got=coli_cuda_tensor_bytes(bt);+ if(got!=want){+ printf("FAIL bytes-check fmt8: got %zu want %zu (weight_bytes %zu + scale_count %zu*4)\n",+ got,want,bt->weight_bytes,bt->scale_count);+ return 1;+ }+ coli_cuda_tensor_free(bt);+ free(bw);free(bs);++ const int SI=256,SO=32; /* fmt=6: one exact 256-wide in-block, no tail */+ size_t srb=row_bytes(6,SI);+ ColiCudaTensor *st=nullptr;+ uint8_t *sw=(uint8_t*)malloc(srb*SO);+ for(size_t i=0;i<srb*(size_t)SO;i++) sw[i]=(uint8_t)rand();+ if(!coli_cuda_tensor_upload(&st,sw,nullptr,6,SI,SO,0)){ printf("FAIL bytes-check fmt6 upload\n"); return 1; }+ want=st->weight_bytes;+ got=coli_cuda_tensor_bytes(st);+ if(got!=want||st->scale_count!=0){+ printf("FAIL bytes-check fmt6: got %zu want %zu scale_count %zu (want 0)\n",+ got,want,st->scale_count);+ return 1;+ }+ coli_cuda_tensor_free(st);+ free(sw);++ const int GI=64,GO=32,GS=32; /* fmt=4 grouped: unchanged regression */+ int gng=(GI+GS-1)/GS;+ ColiCudaTensor *gt=nullptr;+ uint8_t *gw=(uint8_t*)malloc((size_t)((GI+1)/2)*GO);+ float *gsc=(float*)malloc((size_t)GO*gng*4);+ for(size_t i=0;i<(size_t)((GI+1)/2)*GO;i++) gw[i]=(uint8_t)rand();+ for(int i=0;i<GO*gng;i++) gsc[i]=ldexpf(1.f+rand()/(float)RAND_MAX,-4);+ if(!coli_cuda_tensor_upload_g(>,gw,gsc,4,GI,GO,0,GS)){ printf("FAIL bytes-check fmt4g upload\n"); return 1; }+ want=gt->weight_bytes+gt->scale_count*sizeof(float);+ got=coli_cuda_tensor_bytes(gt);+ if(got!=want||gt->scale_count!=(size_t)GO*gng){+ printf("FAIL bytes-check fmt4g: got %zu want %zu scale_count %zu (want %d)\n",+ got,want,gt->scale_count,GO*gng);+ return 1;+ }+ coli_cuda_tensor_free(gt);+ free(gw);free(gsc);+ printf("tensor_bytes: fmt=8 dense + fmt=6 + fmt=4 grouped report exact footprint\n");+ }coli_cuda_shutdown();}printf("OK\n"); return 0;