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
C55.4/100
Duplication88
1.4% in c, python, c-header, bash, makefile, cmakeDead 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
Most complex files
- src/cli/k3_run.c576 cx
- src/io/k3_st.c329 cx
- src/chat/k3_chat.c307 cx
- src/core/k3_ops.c296 cx
- tests/unit/test_ops.c220 cx
- src/io/k3_trunk.c207 cx
- tests/unit/test_st_faults.c163 cx
- tests/unit/k3_model.c129 cx
- src/cache/k3_cache.c128 cx
- src/model/k3_bind.c117 cx
Dead code 24.68% unused · 8 findings
- docs/images/_plots.pyunused-file
- docs/images/_gen.pyunused-file
- docs/images/_eq.pyunused-file
- tools/_paths.py:hf_dirunused-export
- tools/_paths.py:ensureunused-export
- tools/_paths.py:FIX_GOLDENunused-export
- tools/_paths.py:REF_K3_JSONunused-export
- tools/_paths.py:TINY_K3_BINunused-export
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
- 8 lines in 2 placesc116 tokens
- 7 lines in 2 placesc113 tokens
- 16 lines in 2 placespython103 tokens
- 7 lines in 2 placesc92 tokens
- 10 lines in 2 placesc90 tokens
- 8 lines in 2 placespython85 tokens
- 9 lines in 2 placespython85 tokens
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
| Format | Files | Lines | Clones | Duplicated lines | Duplication |
|---|---|---|---|---|---|
| c | 10 | 7,251 | 10 | 72 | 0.99% |
| python | 24 | 4,597 | 5 | 50 | 1.09% |
| bash | 6 | 1,039 | 4 | 36 | 3.46% |
| c-header | 15 | 2,553 | 0 | 0 | 0% |
By format, all files
| Format | Files | Lines | Clones | Duplicated lines | Duplication |
|---|---|---|---|---|---|
| c | 32 | 14,370 | 68 | 620 | 4.31% |
| json | 21 | 162,442 | 20 | 46,401 | 28.56% |
| python | 29 | 6,330 | 6 | 56 | 0.88% |
| bash | 13 | 1,211 | 6 | 48 | 3.96% |
| txt | 6 | 646 | 5 | 43 | 6.66% |
| text | 4 | 458 | 2 | 12 | 2.62% |
| yaml | 3 | 418 | 1 | 7 | 1.67% |
| cmake | 5 | 381 | 1 | 24 | 6.3% |
| markdown | 21 | 5,647 | 0 | 0 | 0% |
| c-header | 15 | 2,553 | 0 | 0 | 0% |
Trending appearances
| Day | Rank | Stars | Files | Lines | Clones | All files | Code | Health | Commit |
|---|---|---|---|---|---|---|---|---|---|
| Nov 5, 2026 | #7 | 10,453 (+351) | 187 | 195,635 | 109 | 24.13% | 1.02% | C 55.4 | 81bb6c2 |
Want this for your own project? Install jscpd and run jscpd ., or measure it the way the baselines were measured.