FareedKhan-dev/kimi-k3-in-c

A 2.78-trillion-parameter Kimi K3 running inference on a single CPU in 8.24 GB of RAM. Portable C99: no BLAS, no framework, no GPU.

C★ 10,453+351 that day#7 on trending

Analyzed November 5, 2026 at 81bb6c2 (main) with jscpd v5 in 1.8s.

C55.4/100
Project health24,277 lines of code (M)
Duplication88
1.4% in c, python, c-header, bash, makefile, cmake
Dead code17
24.7%
Complexity48
56.1%

The score is jscpd's own --health model: markup, data and text left out, tests kept. The numbers below are the trending scan's.

1.02%duplicated code · 158 of 15,440 lines
19clones in code
55code files of 187 scanned
24.13%duplicated over all files · 109 clones

The code number leaves out tests, fixtures, docs, examples, data files, styles, translations and vendored code, and 1 generated file: src/io/k3_st.c.

Largest clones in the code

  • 7 lines in 2 placesc141 tokens
    1/* k3_cache.c - see k3_cache.h. */
    2#define _POSIX_C_SOURCE 200809L
    3
    4#include "k3_portable_io.h"   /* first: sets _DARWIN_C_SOURCE before any libc header;
    5                                * on Windows, supplies posix_memalign */
    6
    7#include <stdio.h>
    
    1/* k3_bind.c - see k3_bind.h. */
    2#define _POSIX_C_SOURCE 200809L
    3
    4#include "k3_portable_io.h"   /* first: sets _DARWIN_C_SOURCE before any libc header;
    5                                * on Windows, supplies posix_memalign */
    6
    7#include <stdarg.h>
    
  • 6 lines in 2 placesc125 tokens
    282        a[l] = fma((double)row[i + l], (double)x[i + l], a[l]);
    283double b0 = (a[0] + a[4]) + (a[8]  + a[12]);
    284double b1 = (a[1] + a[5]) + (a[9]  + a[13]);
    285double b2 = (a[2] + a[6]) + (a[10] + a[14]);
    286double b3 = (a[3] + a[7]) + (a[11] + a[15]);
    287double acc = (b0 + b1) + (b2 + b3);
    
    1202        a[l] = fma((double)k3_bf16f(row[i + l]), (double)x[i + l], a[l]);
    1203double b0 = (a[0] + a[4]) + (a[8]  + a[12]);
    1204double b1 = (a[1] + a[5]) + (a[9]  + a[13]);
    1205double b2 = (a[2] + a[6]) + (a[10] + a[14]);
    1206double b3 = (a[3] + a[7]) + (a[11] + a[15]);
    1207acc = (b0 + b1) + (b2 + b3);
    
  • 8 lines in 2 placespython123 tokens
    96        if hasattr(layer.self_attn, "A_log"):
    97            h = layer.self_attn.A_log.numel()
    98            layer.self_attn.A_log.copy_(torch.linspace(-0.4, 1.2, h))
    99            torch.nn.init.normal_(layer.self_attn.dt_bias, std=0.5)
    100            torch.nn.init.normal_(layer.self_attn.q_conv1d.weight, std=0.4)
    101            torch.nn.init.normal_(layer.self_attn.k_conv1d.weight, std=0.4)
    102            torch.nn.init.normal_(layer.self_attn.v_conv1d.weight, std=0.4)
    103return cfg, model
    
7 more
Largest clones over all files, tests and data included
  • 45511 lines in 2 placesjsontests113,771 tokens
    1314 ]
    1315},
    1316"q_proj": {
    1317 "shape": [
    1318  64,
    1319  128
    1320 ],
    1321 "data": [
    1322  0.1663753,
    1323  -0.5625148,
    

    First 10 of 45511 lines.

  • 27 lines in 2 placescdocs and examples570 tokens
    1739    k3_mmw(z + (size_t)t * P, fa, w->f_b, w->wdt, D, P);
    1740}
    1741
    1742/* 2. ShortConv with fused SiLU, carrying state across calls */
    1743float *cs = state ? state + (size_t)H * D * D : NULL;
    1744k3_shortconv(q, q, w->q_conv, cs ? cs : NULL, P, K, T);
    1745k3_shortconv(k, k, w->k_conv, cs ? cs + (size_t)P * hist : NULL, P, K, T);
    1746k3_shortconv(v, v, w->v_conv, cs ? cs + (size_t)2 * P * hist : NULL, P, K, T);
    1747
    1748/* 3. L2Norm on q and k ONLY, per head. v is deliberately left alone. */
    

    First 10 of 27 lines.

  • 32 lines in 2 placescdocs and examples473 tokens
    2012/* norm gain and scoring projection collapse into one vector */
    2013for (int i = 0; i < E; i++) {
    2014    foldA[i] = w->attn_res_norm[i] * w->attn_res_proj[i];
    2015    foldM[i] = w->mlp_res_norm[i]  * w->mlp_res_proj[i];
    2016}
    2017
    2018memcpy(pref, h, (size_t)T * E * sizeof(float));
    2019int have_prefix = 1;                        /* mirrors "prefix_sum is not None" */
    2020
    2021/* aggregation before attention, only when snapshots already exist */
    

    First 10 of 32 lines.

  • 16 lines in 2 placescdocs and examples404 tokens
  • 30 lines in 2 placescdocs and examples352 tokens
By format, code only
FormatFilesLinesClonesDuplicated linesDuplication
c107,25110720.99%
python244,5975501.09%
bash61,0394363.46%
c-header152,553000%
By format, all files
FormatFilesLinesClonesDuplicated linesDuplication
c3214,370686204.31%
json21162,4422046,40128.56%
python296,3306560.88%
bash131,2116483.96%
txt66465436.66%
text44582122.62%
yaml3418171.67%
cmake53811246.3%
markdown215,647000%
c-header152,553000%

Trending appearances

DayRankStarsFilesLinesClonesAll filesCodeHealthCommit
Nov 5, 2026#710,453 (+351)187195,63510924.13%1.02%C 55.481bb6c2

Want this for your own project? Install jscpd and run jscpd ., or measure it the way the baselines were measured.