freetoken 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (357) hide show
  1. freetoken-0.1.1/LICENSE +201 -0
  2. freetoken-0.1.1/PKG-INFO +88 -0
  3. freetoken-0.1.1/README.md +47 -0
  4. freetoken-0.1.1/pyproject.toml +110 -0
  5. freetoken-0.1.1/python/freetoken/__init__.py +5 -0
  6. freetoken-0.1.1/python/freetoken/__main__.py +5 -0
  7. freetoken-0.1.1/python/freetoken/attention/__init__.py +183 -0
  8. freetoken-0.1.1/python/freetoken/attention/base.py +121 -0
  9. freetoken-0.1.1/python/freetoken/attention/dsa.py +325 -0
  10. freetoken-0.1.1/python/freetoken/attention/dsa_indexer.py +60 -0
  11. freetoken-0.1.1/python/freetoken/attention/dsv4_compress.py +154 -0
  12. freetoken-0.1.1/python/freetoken/attention/dsv4_indexer.py +87 -0
  13. freetoken-0.1.1/python/freetoken/attention/dsv4_sparse.py +291 -0
  14. freetoken-0.1.1/python/freetoken/attention/fa.py +198 -0
  15. freetoken-0.1.1/python/freetoken/attention/fi.py +313 -0
  16. freetoken-0.1.1/python/freetoken/attention/linear.py +129 -0
  17. freetoken-0.1.1/python/freetoken/attention/m3_sparse.py +443 -0
  18. freetoken-0.1.1/python/freetoken/attention/triton.py +351 -0
  19. freetoken-0.1.1/python/freetoken/attention/trtllm.py +172 -0
  20. freetoken-0.1.1/python/freetoken/attention/utils.py +23 -0
  21. freetoken-0.1.1/python/freetoken/benchmark/client.py +501 -0
  22. freetoken-0.1.1/python/freetoken/benchmark/perf.py +74 -0
  23. freetoken-0.1.1/python/freetoken/cache_report.py +218 -0
  24. freetoken-0.1.1/python/freetoken/checkpoint/__init__.py +19 -0
  25. freetoken-0.1.1/python/freetoken/checkpoint/__main__.py +53 -0
  26. freetoken-0.1.1/python/freetoken/checkpoint/convert.py +304 -0
  27. freetoken-0.1.1/python/freetoken/checkpoint/ftw.py +577 -0
  28. freetoken-0.1.1/python/freetoken/cli.py +130 -0
  29. freetoken-0.1.1/python/freetoken/control_cli.py +480 -0
  30. freetoken-0.1.1/python/freetoken/core.py +207 -0
  31. freetoken-0.1.1/python/freetoken/daemon/__init__.py +31 -0
  32. freetoken-0.1.1/python/freetoken/daemon/__main__.py +5 -0
  33. freetoken-0.1.1/python/freetoken/daemon/accounting.py +160 -0
  34. freetoken-0.1.1/python/freetoken/daemon/app.py +464 -0
  35. freetoken-0.1.1/python/freetoken/daemon/checkpoint.py +174 -0
  36. freetoken-0.1.1/python/freetoken/daemon/client.py +198 -0
  37. freetoken-0.1.1/python/freetoken/daemon/logfmt.py +76 -0
  38. freetoken-0.1.1/python/freetoken/daemon/logring.py +67 -0
  39. freetoken-0.1.1/python/freetoken/daemon/metrics.py +134 -0
  40. freetoken-0.1.1/python/freetoken/daemon/osproc.py +198 -0
  41. freetoken-0.1.1/python/freetoken/daemon/pidfile.py +107 -0
  42. freetoken-0.1.1/python/freetoken/daemon/proxy.py +129 -0
  43. freetoken-0.1.1/python/freetoken/daemon/serve_manager.py +908 -0
  44. freetoken-0.1.1/python/freetoken/daemon/server.py +231 -0
  45. freetoken-0.1.1/python/freetoken/daemon/tailer.py +117 -0
  46. freetoken-0.1.1/python/freetoken/daemon/version.py +8 -0
  47. freetoken-0.1.1/python/freetoken/distributed/__init__.py +12 -0
  48. freetoken-0.1.1/python/freetoken/distributed/impl.py +97 -0
  49. freetoken-0.1.1/python/freetoken/distributed/info.py +38 -0
  50. freetoken-0.1.1/python/freetoken/engine/__init__.py +5 -0
  51. freetoken-0.1.1/python/freetoken/engine/cache_budget.py +131 -0
  52. freetoken-0.1.1/python/freetoken/engine/config.py +106 -0
  53. freetoken-0.1.1/python/freetoken/engine/engine.py +1394 -0
  54. freetoken-0.1.1/python/freetoken/engine/graph.py +217 -0
  55. freetoken-0.1.1/python/freetoken/engine/sample.py +80 -0
  56. freetoken-0.1.1/python/freetoken/env.py +94 -0
  57. freetoken-0.1.1/python/freetoken/kernel/__init__.py +40 -0
  58. freetoken-0.1.1/python/freetoken/kernel/__main__.py +47 -0
  59. freetoken-0.1.1/python/freetoken/kernel/_toolchain.py +71 -0
  60. freetoken-0.1.1/python/freetoken/kernel/aot.py +285 -0
  61. freetoken-0.1.1/python/freetoken/kernel/aot_models.py +411 -0
  62. freetoken-0.1.1/python/freetoken/kernel/backend.py +59 -0
  63. freetoken-0.1.1/python/freetoken/kernel/batch_memcpy.py +69 -0
  64. freetoken-0.1.1/python/freetoken/kernel/causal_conv1d.py +75 -0
  65. freetoken-0.1.1/python/freetoken/kernel/csrc/cpu_moe/cpu_moe_ext.cpp +2150 -0
  66. freetoken-0.1.1/python/freetoken/kernel/csrc/gguf/dequantize.cuh +583 -0
  67. freetoken-0.1.1/python/freetoken/kernel/csrc/gguf/dispatch.h +28 -0
  68. freetoken-0.1.1/python/freetoken/kernel/csrc/gguf/ggml-common.h +1029 -0
  69. freetoken-0.1.1/python/freetoken/kernel/csrc/gguf/gguf_kernel.cu +848 -0
  70. freetoken-0.1.1/python/freetoken/kernel/csrc/gguf/mmq.cuh +881 -0
  71. freetoken-0.1.1/python/freetoken/kernel/csrc/gguf/mmvq.cuh +352 -0
  72. freetoken-0.1.1/python/freetoken/kernel/csrc/gguf/moe.cuh +1379 -0
  73. freetoken-0.1.1/python/freetoken/kernel/csrc/gguf/moe_vec.cuh +413 -0
  74. freetoken-0.1.1/python/freetoken/kernel/csrc/gguf/vecdotq.cuh +2037 -0
  75. freetoken-0.1.1/python/freetoken/kernel/csrc/include/freetoken/nccl227.h +571 -0
  76. freetoken-0.1.1/python/freetoken/kernel/csrc/include/freetoken/tensor.h +496 -0
  77. freetoken-0.1.1/python/freetoken/kernel/csrc/include/freetoken/utils.cuh +144 -0
  78. freetoken-0.1.1/python/freetoken/kernel/csrc/include/freetoken/utils.h +122 -0
  79. freetoken-0.1.1/python/freetoken/kernel/csrc/include/freetoken/warp.cuh +80 -0
  80. freetoken-0.1.1/python/freetoken/kernel/csrc/jit/batch_memcpy.cuh +58 -0
  81. freetoken-0.1.1/python/freetoken/kernel/csrc/jit/fast_index_copy.cuh +562 -0
  82. freetoken-0.1.1/python/freetoken/kernel/csrc/jit/index.cu +172 -0
  83. freetoken-0.1.1/python/freetoken/kernel/csrc/jit/store.cu +123 -0
  84. freetoken-0.1.1/python/freetoken/kernel/csrc/pinned_tensor.cpp +128 -0
  85. freetoken-0.1.1/python/freetoken/kernel/csrc/src/pynccl.cu +188 -0
  86. freetoken-0.1.1/python/freetoken/kernel/csrc/src/radix.cpp +44 -0
  87. freetoken-0.1.1/python/freetoken/kernel/csrc/src/tensor.cpp +31 -0
  88. freetoken-0.1.1/python/freetoken/kernel/fast_index_copy.py +192 -0
  89. freetoken-0.1.1/python/freetoken/kernel/fla/__init__.py +35 -0
  90. freetoken-0.1.1/python/freetoken/kernel/fla/chunk.py +257 -0
  91. freetoken-0.1.1/python/freetoken/kernel/fla/chunk_delta_h.py +357 -0
  92. freetoken-0.1.1/python/freetoken/kernel/fla/chunk_fwd.py +416 -0
  93. freetoken-0.1.1/python/freetoken/kernel/fla/chunk_o.py +174 -0
  94. freetoken-0.1.1/python/freetoken/kernel/fla/cumsum.py +299 -0
  95. freetoken-0.1.1/python/freetoken/kernel/fla/fused_sigmoid_gating_recurrent.py +372 -0
  96. freetoken-0.1.1/python/freetoken/kernel/fla/index.py +35 -0
  97. freetoken-0.1.1/python/freetoken/kernel/fla/l2norm.py +150 -0
  98. freetoken-0.1.1/python/freetoken/kernel/fla/layernorm_gated.py +264 -0
  99. freetoken-0.1.1/python/freetoken/kernel/fla/op.py +66 -0
  100. freetoken-0.1.1/python/freetoken/kernel/fla/utils.py +340 -0
  101. freetoken-0.1.1/python/freetoken/kernel/fla/wy_fast.py +156 -0
  102. freetoken-0.1.1/python/freetoken/kernel/gguf.py +142 -0
  103. freetoken-0.1.1/python/freetoken/kernel/index.py +54 -0
  104. freetoken-0.1.1/python/freetoken/kernel/moe_impl.py +504 -0
  105. freetoken-0.1.1/python/freetoken/kernel/pinned.py +68 -0
  106. freetoken-0.1.1/python/freetoken/kernel/pynccl.py +78 -0
  107. freetoken-0.1.1/python/freetoken/kernel/radix.py +20 -0
  108. freetoken-0.1.1/python/freetoken/kernel/store.py +42 -0
  109. freetoken-0.1.1/python/freetoken/kernel/tensor.py +19 -0
  110. freetoken-0.1.1/python/freetoken/kernel/triton/activation.py +169 -0
  111. freetoken-0.1.1/python/freetoken/kernel/triton/attention.py +949 -0
  112. freetoken-0.1.1/python/freetoken/kernel/triton/autotune_cache.py +37 -0
  113. freetoken-0.1.1/python/freetoken/kernel/triton/causal_conv1d_triton.py +681 -0
  114. freetoken-0.1.1/python/freetoken/kernel/triton/decode_moe.py +75 -0
  115. freetoken-0.1.1/python/freetoken/kernel/triton/df11.py +318 -0
  116. freetoken-0.1.1/python/freetoken/kernel/triton/df11_decode.py +171 -0
  117. freetoken-0.1.1/python/freetoken/kernel/triton/dsv4/bf16_linear.py +70 -0
  118. freetoken-0.1.1/python/freetoken/kernel/triton/dsv4/compress.py +67 -0
  119. freetoken-0.1.1/python/freetoken/kernel/triton/dsv4/fp8_linear.py +402 -0
  120. freetoken-0.1.1/python/freetoken/kernel/triton/dsv4/fused_moe.py +301 -0
  121. freetoken-0.1.1/python/freetoken/kernel/triton/dsv4/hadamard.py +44 -0
  122. freetoken-0.1.1/python/freetoken/kernel/triton/dsv4/hc.py +94 -0
  123. freetoken-0.1.1/python/freetoken/kernel/triton/dsv4/indexer.py +226 -0
  124. freetoken-0.1.1/python/freetoken/kernel/triton/dsv4/norm.py +55 -0
  125. freetoken-0.1.1/python/freetoken/kernel/triton/dsv4/rope.py +87 -0
  126. freetoken-0.1.1/python/freetoken/kernel/triton/dsv4/sinkhorn.py +77 -0
  127. freetoken-0.1.1/python/freetoken/kernel/triton/dsv4/sparse_attn.py +393 -0
  128. freetoken-0.1.1/python/freetoken/kernel/triton/dsv4/swiglu.py +46 -0
  129. freetoken-0.1.1/python/freetoken/kernel/triton/e4m3_compat.py +128 -0
  130. freetoken-0.1.1/python/freetoken/kernel/triton/fp8_block_linear.py +318 -0
  131. freetoken-0.1.1/python/freetoken/kernel/triton/fp8_blockscale_moe.py +264 -0
  132. freetoken-0.1.1/python/freetoken/kernel/triton/fp8_pertensor_linear.py +230 -0
  133. freetoken-0.1.1/python/freetoken/kernel/triton/fused_moe.py +302 -0
  134. freetoken-0.1.1/python/freetoken/kernel/triton/gemma4_fused.py +191 -0
  135. freetoken-0.1.1/python/freetoken/kernel/triton/glm_dsa_sparse.py +419 -0
  136. freetoken-0.1.1/python/freetoken/kernel/triton/minimax_m3_sparse.py +1118 -0
  137. freetoken-0.1.1/python/freetoken/kernel/triton/moe_align.py +328 -0
  138. freetoken-0.1.1/python/freetoken/kernel/triton/mxfp4_moe.py +332 -0
  139. freetoken-0.1.1/python/freetoken/kernel/triton/mxfp8_linear.py +292 -0
  140. freetoken-0.1.1/python/freetoken/kernel/triton/norm.py +190 -0
  141. freetoken-0.1.1/python/freetoken/kernel/triton/nvfp4_dequant.py +133 -0
  142. freetoken-0.1.1/python/freetoken/kernel/triton/nvfp4_fused_moe.py +333 -0
  143. freetoken-0.1.1/python/freetoken/kernel/triton/nvfp4_linear.py +941 -0
  144. freetoken-0.1.1/python/freetoken/kernel/triton/rope.py +143 -0
  145. freetoken-0.1.1/python/freetoken/kernel/triton/sampling.py +619 -0
  146. freetoken-0.1.1/python/freetoken/kernel/utils.py +284 -0
  147. freetoken-0.1.1/python/freetoken/kvcache/__init__.py +250 -0
  148. freetoken-0.1.1/python/freetoken/kvcache/base.py +265 -0
  149. freetoken-0.1.1/python/freetoken/kvcache/bsa_pool.py +126 -0
  150. freetoken-0.1.1/python/freetoken/kvcache/cache_status.py +215 -0
  151. freetoken-0.1.1/python/freetoken/kvcache/dsa_pool.py +183 -0
  152. freetoken-0.1.1/python/freetoken/kvcache/dsv4_cost_model.py +366 -0
  153. freetoken-0.1.1/python/freetoken/kvcache/dsv4_paged_pool.py +614 -0
  154. freetoken-0.1.1/python/freetoken/kvcache/hybrid_radix_cache.py +294 -0
  155. freetoken-0.1.1/python/freetoken/kvcache/hybrid_swa_pool.py +408 -0
  156. freetoken-0.1.1/python/freetoken/kvcache/linear_state_pool.py +236 -0
  157. freetoken-0.1.1/python/freetoken/kvcache/mha_pool.py +148 -0
  158. freetoken-0.1.1/python/freetoken/kvcache/naive_cache.py +45 -0
  159. freetoken-0.1.1/python/freetoken/kvcache/radix_cache.py +265 -0
  160. freetoken-0.1.1/python/freetoken/kvcache/swa_radix_cache.py +454 -0
  161. freetoken-0.1.1/python/freetoken/launch.py +937 -0
  162. freetoken-0.1.1/python/freetoken/layers/__init__.py +46 -0
  163. freetoken-0.1.1/python/freetoken/layers/activation.py +59 -0
  164. freetoken-0.1.1/python/freetoken/layers/base.py +99 -0
  165. freetoken-0.1.1/python/freetoken/layers/embedding.py +125 -0
  166. freetoken-0.1.1/python/freetoken/layers/gguf.py +128 -0
  167. freetoken-0.1.1/python/freetoken/layers/linear.py +127 -0
  168. freetoken-0.1.1/python/freetoken/layers/moe.py +636 -0
  169. freetoken-0.1.1/python/freetoken/layers/norm.py +170 -0
  170. freetoken-0.1.1/python/freetoken/layers/rotary.py +234 -0
  171. freetoken-0.1.1/python/freetoken/llm/__init__.py +3 -0
  172. freetoken-0.1.1/python/freetoken/llm/llm.py +142 -0
  173. freetoken-0.1.1/python/freetoken/message/__init__.py +42 -0
  174. freetoken-0.1.1/python/freetoken/message/backend.py +55 -0
  175. freetoken-0.1.1/python/freetoken/message/frontend.py +70 -0
  176. freetoken-0.1.1/python/freetoken/message/tokenizer.py +116 -0
  177. freetoken-0.1.1/python/freetoken/message/utils.py +84 -0
  178. freetoken-0.1.1/python/freetoken/models/__init__.py +35 -0
  179. freetoken-0.1.1/python/freetoken/models/blocks.py +55 -0
  180. freetoken-0.1.1/python/freetoken/models/config.py +406 -0
  181. freetoken-0.1.1/python/freetoken/models/deepseek_v4/__init__.py +28 -0
  182. freetoken-0.1.1/python/freetoken/models/deepseek_v4/args.py +111 -0
  183. freetoken-0.1.1/python/freetoken/models/deepseek_v4/attention.py +324 -0
  184. freetoken-0.1.1/python/freetoken/models/deepseek_v4/compress.py +482 -0
  185. freetoken-0.1.1/python/freetoken/models/deepseek_v4/config.py +96 -0
  186. freetoken-0.1.1/python/freetoken/models/deepseek_v4/layers.py +79 -0
  187. freetoken-0.1.1/python/freetoken/models/deepseek_v4/model.py +296 -0
  188. freetoken-0.1.1/python/freetoken/models/deepseek_v4/moe.py +146 -0
  189. freetoken-0.1.1/python/freetoken/models/deepseek_v4/ops.py +127 -0
  190. freetoken-0.1.1/python/freetoken/models/deepseek_v4/weight.py +346 -0
  191. freetoken-0.1.1/python/freetoken/models/gemma4/__init__.py +34 -0
  192. freetoken-0.1.1/python/freetoken/models/gemma4/attention.py +111 -0
  193. freetoken-0.1.1/python/freetoken/models/gemma4/config.py +204 -0
  194. freetoken-0.1.1/python/freetoken/models/gemma4/gguf.py +474 -0
  195. freetoken-0.1.1/python/freetoken/models/gemma4/model.py +139 -0
  196. freetoken-0.1.1/python/freetoken/models/gemma4/moe.py +138 -0
  197. freetoken-0.1.1/python/freetoken/models/gemma4/vision.py +236 -0
  198. freetoken-0.1.1/python/freetoken/models/gemma4/weight.py +315 -0
  199. freetoken-0.1.1/python/freetoken/models/gguf/__init__.py +26 -0
  200. freetoken-0.1.1/python/freetoken/models/gguf/config.py +96 -0
  201. freetoken-0.1.1/python/freetoken/models/gguf/dequant.py +153 -0
  202. freetoken-0.1.1/python/freetoken/models/gguf/reader.py +189 -0
  203. freetoken-0.1.1/python/freetoken/models/gguf/tokenizer.py +75 -0
  204. freetoken-0.1.1/python/freetoken/models/glm4_moe/__init__.py +11 -0
  205. freetoken-0.1.1/python/freetoken/models/glm4_moe/attention.py +82 -0
  206. freetoken-0.1.1/python/freetoken/models/glm4_moe/config.py +93 -0
  207. freetoken-0.1.1/python/freetoken/models/glm4_moe/df11_embedding.py +59 -0
  208. freetoken-0.1.1/python/freetoken/models/glm4_moe/df11_linear.py +81 -0
  209. freetoken-0.1.1/python/freetoken/models/glm4_moe/mlp.py +38 -0
  210. freetoken-0.1.1/python/freetoken/models/glm4_moe/model.py +79 -0
  211. freetoken-0.1.1/python/freetoken/models/glm4_moe/moe.py +86 -0
  212. freetoken-0.1.1/python/freetoken/models/glm4_moe/nvfp4_linear.py +114 -0
  213. freetoken-0.1.1/python/freetoken/models/glm4_moe/weight.py +229 -0
  214. freetoken-0.1.1/python/freetoken/models/glm_moe_dsa/__init__.py +15 -0
  215. freetoken-0.1.1/python/freetoken/models/glm_moe_dsa/args.py +77 -0
  216. freetoken-0.1.1/python/freetoken/models/glm_moe_dsa/attention.py +234 -0
  217. freetoken-0.1.1/python/freetoken/models/glm_moe_dsa/config.py +137 -0
  218. freetoken-0.1.1/python/freetoken/models/glm_moe_dsa/mlp.py +39 -0
  219. freetoken-0.1.1/python/freetoken/models/glm_moe_dsa/model.py +121 -0
  220. freetoken-0.1.1/python/freetoken/models/glm_moe_dsa/moe.py +87 -0
  221. freetoken-0.1.1/python/freetoken/models/glm_moe_dsa/weight.py +182 -0
  222. freetoken-0.1.1/python/freetoken/models/gpt_oss/__init__.py +5 -0
  223. freetoken-0.1.1/python/freetoken/models/gpt_oss/attention.py +93 -0
  224. freetoken-0.1.1/python/freetoken/models/gpt_oss/config.py +113 -0
  225. freetoken-0.1.1/python/freetoken/models/gpt_oss/model.py +95 -0
  226. freetoken-0.1.1/python/freetoken/models/gpt_oss/moe.py +231 -0
  227. freetoken-0.1.1/python/freetoken/models/gpt_oss/weight.py +613 -0
  228. freetoken-0.1.1/python/freetoken/models/llama/__init__.py +5 -0
  229. freetoken-0.1.1/python/freetoken/models/llama/attention.py +80 -0
  230. freetoken-0.1.1/python/freetoken/models/llama/config.py +48 -0
  231. freetoken-0.1.1/python/freetoken/models/llama/model.py +85 -0
  232. freetoken-0.1.1/python/freetoken/models/llama/weight.py +62 -0
  233. freetoken-0.1.1/python/freetoken/models/loader.py +321 -0
  234. freetoken-0.1.1/python/freetoken/models/minimax_m2/__init__.py +11 -0
  235. freetoken-0.1.1/python/freetoken/models/minimax_m2/attention.py +87 -0
  236. freetoken-0.1.1/python/freetoken/models/minimax_m2/config.py +72 -0
  237. freetoken-0.1.1/python/freetoken/models/minimax_m2/model.py +74 -0
  238. freetoken-0.1.1/python/freetoken/models/minimax_m2/moe.py +50 -0
  239. freetoken-0.1.1/python/freetoken/models/minimax_m2/weight.py +126 -0
  240. freetoken-0.1.1/python/freetoken/models/minimax_m3/__init__.py +15 -0
  241. freetoken-0.1.1/python/freetoken/models/minimax_m3/args.py +257 -0
  242. freetoken-0.1.1/python/freetoken/models/minimax_m3/attention.py +122 -0
  243. freetoken-0.1.1/python/freetoken/models/minimax_m3/config.py +201 -0
  244. freetoken-0.1.1/python/freetoken/models/minimax_m3/mlp.py +62 -0
  245. freetoken-0.1.1/python/freetoken/models/minimax_m3/model.py +100 -0
  246. freetoken-0.1.1/python/freetoken/models/minimax_m3/moe.py +92 -0
  247. freetoken-0.1.1/python/freetoken/models/minimax_m3/weight.py +283 -0
  248. freetoken-0.1.1/python/freetoken/models/mistral/__init__.py +5 -0
  249. freetoken-0.1.1/python/freetoken/models/mistral/attention.py +80 -0
  250. freetoken-0.1.1/python/freetoken/models/mistral/config.py +48 -0
  251. freetoken-0.1.1/python/freetoken/models/mistral/model.py +86 -0
  252. freetoken-0.1.1/python/freetoken/models/mistral/weight.py +62 -0
  253. freetoken-0.1.1/python/freetoken/models/nvfp4_banks.py +327 -0
  254. freetoken-0.1.1/python/freetoken/models/qwen2/__init__.py +5 -0
  255. freetoken-0.1.1/python/freetoken/models/qwen2/attention.py +80 -0
  256. freetoken-0.1.1/python/freetoken/models/qwen2/config.py +48 -0
  257. freetoken-0.1.1/python/freetoken/models/qwen2/model.py +83 -0
  258. freetoken-0.1.1/python/freetoken/models/qwen2/weight.py +62 -0
  259. freetoken-0.1.1/python/freetoken/models/qwen3/__init__.py +5 -0
  260. freetoken-0.1.1/python/freetoken/models/qwen3/attention.py +80 -0
  261. freetoken-0.1.1/python/freetoken/models/qwen3/config.py +48 -0
  262. freetoken-0.1.1/python/freetoken/models/qwen3/model.py +83 -0
  263. freetoken-0.1.1/python/freetoken/models/qwen3/weight.py +62 -0
  264. freetoken-0.1.1/python/freetoken/models/qwen3_5_moe/__init__.py +19 -0
  265. freetoken-0.1.1/python/freetoken/models/qwen3_5_moe/attention.py +91 -0
  266. freetoken-0.1.1/python/freetoken/models/qwen3_5_moe/config.py +278 -0
  267. freetoken-0.1.1/python/freetoken/models/qwen3_5_moe/gdn.py +224 -0
  268. freetoken-0.1.1/python/freetoken/models/qwen3_5_moe/gdn_kernels.py +76 -0
  269. freetoken-0.1.1/python/freetoken/models/qwen3_5_moe/gdn_reference.py +176 -0
  270. freetoken-0.1.1/python/freetoken/models/qwen3_5_moe/model.py +117 -0
  271. freetoken-0.1.1/python/freetoken/models/qwen3_5_moe/moe.py +93 -0
  272. freetoken-0.1.1/python/freetoken/models/qwen3_5_moe/quant_linear.py +77 -0
  273. freetoken-0.1.1/python/freetoken/models/qwen3_5_moe/weight.py +1107 -0
  274. freetoken-0.1.1/python/freetoken/models/qwen3_moe/__init__.py +10 -0
  275. freetoken-0.1.1/python/freetoken/models/qwen3_moe/attention.py +80 -0
  276. freetoken-0.1.1/python/freetoken/models/qwen3_moe/config.py +54 -0
  277. freetoken-0.1.1/python/freetoken/models/qwen3_moe/model.py +84 -0
  278. freetoken-0.1.1/python/freetoken/models/qwen3_moe/moe.py +34 -0
  279. freetoken-0.1.1/python/freetoken/models/qwen3_moe/weight.py +120 -0
  280. freetoken-0.1.1/python/freetoken/models/register.py +137 -0
  281. freetoken-0.1.1/python/freetoken/models/weight.py +413 -0
  282. freetoken-0.1.1/python/freetoken/moe/__init__.py +74 -0
  283. freetoken-0.1.1/python/freetoken/moe/base.py +18 -0
  284. freetoken-0.1.1/python/freetoken/moe/bench_profile.py +139 -0
  285. freetoken-0.1.1/python/freetoken/moe/benchbw.py +968 -0
  286. freetoken-0.1.1/python/freetoken/moe/configs/triton_3_5_1/E=128,N=704,device_name=NVIDIA_H100_80GB_HBM3.json +154 -0
  287. freetoken-0.1.1/python/freetoken/moe/cpu_executor.py +670 -0
  288. freetoken-0.1.1/python/freetoken/moe/cpu_offload.py +58 -0
  289. freetoken-0.1.1/python/freetoken/moe/expert_banks.py +443 -0
  290. freetoken-0.1.1/python/freetoken/moe/fused.py +452 -0
  291. freetoken-0.1.1/python/freetoken/moe/fused_ds_fp4.py +238 -0
  292. freetoken-0.1.1/python/freetoken/moe/fused_fp8_block.py +47 -0
  293. freetoken-0.1.1/python/freetoken/moe/fused_mxfp4.py +282 -0
  294. freetoken-0.1.1/python/freetoken/moe/fused_nvfp4.py +351 -0
  295. freetoken-0.1.1/python/freetoken/moe/fused_q4_0.py +53 -0
  296. freetoken-0.1.1/python/freetoken/moe/host_banks.py +268 -0
  297. freetoken-0.1.1/python/freetoken/moe/nvfp4_backends.py +790 -0
  298. freetoken-0.1.1/python/freetoken/moe/offload.py +20 -0
  299. freetoken-0.1.1/python/freetoken/moe/offload_cache.py +988 -0
  300. freetoken-0.1.1/python/freetoken/moe/offload_kernels.py +431 -0
  301. freetoken-0.1.1/python/freetoken/scheduler/__init__.py +4 -0
  302. freetoken-0.1.1/python/freetoken/scheduler/cache.py +667 -0
  303. freetoken-0.1.1/python/freetoken/scheduler/config.py +43 -0
  304. freetoken-0.1.1/python/freetoken/scheduler/decode.py +39 -0
  305. freetoken-0.1.1/python/freetoken/scheduler/io.py +133 -0
  306. freetoken-0.1.1/python/freetoken/scheduler/prefill.py +301 -0
  307. freetoken-0.1.1/python/freetoken/scheduler/scheduler.py +905 -0
  308. freetoken-0.1.1/python/freetoken/scheduler/status.py +144 -0
  309. freetoken-0.1.1/python/freetoken/scheduler/table.py +30 -0
  310. freetoken-0.1.1/python/freetoken/scheduler/utils.py +34 -0
  311. freetoken-0.1.1/python/freetoken/server/__init__.py +3 -0
  312. freetoken-0.1.1/python/freetoken/server/access_log_filter.py +89 -0
  313. freetoken-0.1.1/python/freetoken/server/accounting.py +157 -0
  314. freetoken-0.1.1/python/freetoken/server/anthropic_api.py +622 -0
  315. freetoken-0.1.1/python/freetoken/server/anthropic_models.py +178 -0
  316. freetoken-0.1.1/python/freetoken/server/api_models.py +140 -0
  317. freetoken-0.1.1/python/freetoken/server/api_server.py +990 -0
  318. freetoken-0.1.1/python/freetoken/server/args.py +681 -0
  319. freetoken-0.1.1/python/freetoken/server/control_api.py +78 -0
  320. freetoken-0.1.1/python/freetoken/server/function_call_parser.py +3248 -0
  321. freetoken-0.1.1/python/freetoken/server/generation.py +730 -0
  322. freetoken-0.1.1/python/freetoken/server/launch.py +203 -0
  323. freetoken-0.1.1/python/freetoken/server/model_meta.py +123 -0
  324. freetoken-0.1.1/python/freetoken/server/openai_api.py +624 -0
  325. freetoken-0.1.1/python/freetoken/server/reasoning_parser.py +604 -0
  326. freetoken-0.1.1/python/freetoken/server/request_logger.py +177 -0
  327. freetoken-0.1.1/python/freetoken/server/request_ring.py +89 -0
  328. freetoken-0.1.1/python/freetoken/server/responses_api.py +754 -0
  329. freetoken-0.1.1/python/freetoken/server/stats.py +172 -0
  330. freetoken-0.1.1/python/freetoken/server/supervisor.py +186 -0
  331. freetoken-0.1.1/python/freetoken/shell/__init__.py +82 -0
  332. freetoken-0.1.1/python/freetoken/shell/__main__.py +4 -0
  333. freetoken-0.1.1/python/freetoken/shell/client.py +327 -0
  334. freetoken-0.1.1/python/freetoken/shell/render.py +350 -0
  335. freetoken-0.1.1/python/freetoken/shell/tui.py +752 -0
  336. freetoken-0.1.1/python/freetoken/tokenizer/__init__.py +3 -0
  337. freetoken-0.1.1/python/freetoken/tokenizer/detokenize.py +147 -0
  338. freetoken-0.1.1/python/freetoken/tokenizer/server.py +269 -0
  339. freetoken-0.1.1/python/freetoken/tokenizer/tokenize.py +165 -0
  340. freetoken-0.1.1/python/freetoken/utils/__init__.py +59 -0
  341. freetoken-0.1.1/python/freetoken/utils/arch.py +48 -0
  342. freetoken-0.1.1/python/freetoken/utils/hf.py +166 -0
  343. freetoken-0.1.1/python/freetoken/utils/logger.py +129 -0
  344. freetoken-0.1.1/python/freetoken/utils/misc.py +53 -0
  345. freetoken-0.1.1/python/freetoken/utils/mp.py +151 -0
  346. freetoken-0.1.1/python/freetoken/utils/progress.py +90 -0
  347. freetoken-0.1.1/python/freetoken/utils/registry.py +45 -0
  348. freetoken-0.1.1/python/freetoken/utils/torch_utils.py +37 -0
  349. freetoken-0.1.1/python/freetoken/version.py +1 -0
  350. freetoken-0.1.1/python/freetoken.egg-info/PKG-INFO +88 -0
  351. freetoken-0.1.1/python/freetoken.egg-info/SOURCES.txt +355 -0
  352. freetoken-0.1.1/python/freetoken.egg-info/dependency_links.txt +1 -0
  353. freetoken-0.1.1/python/freetoken.egg-info/entry_points.txt +2 -0
  354. freetoken-0.1.1/python/freetoken.egg-info/requires.txt +32 -0
  355. freetoken-0.1.1/python/freetoken.egg-info/top_level.txt +1 -0
  356. freetoken-0.1.1/setup.cfg +4 -0
  357. freetoken-0.1.1/setup.py +79 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 FreeToken Authors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,88 @@
1
+ Metadata-Version: 2.4
2
+ Name: freetoken
3
+ Version: 0.1.1
4
+ Summary: FreeToken inference runtime
5
+ License-Expression: Apache-2.0
6
+ Project-URL: Homepage, https://github.com/FlashML-org/FreeToken
7
+ Project-URL: Repository, https://github.com/FlashML-org/FreeToken
8
+ Project-URL: Issues, https://github.com/FlashML-org/FreeToken/issues
9
+ Requires-Python: >=3.10
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: apache-tvm-ffi==0.1.13.post3
13
+ Requires-Dist: einops<1,>=0.8
14
+ Requires-Dist: fastapi<1,>=0.115
15
+ Requires-Dist: flashlib==0.3.0
16
+ Requires-Dist: gguf<1,>=0.19
17
+ Requires-Dist: huggingface_hub<2,>=1.5
18
+ Requires-Dist: msgpack<2,>=1.1
19
+ Requires-Dist: modelscope<2,>=1.37
20
+ Requires-Dist: numpy<2.5,>=2.0
21
+ Requires-Dist: openai<3,>=2.0
22
+ Requires-Dist: partial-json-parser<1,>=0.2
23
+ Requires-Dist: prompt_toolkit<4,>=3.0
24
+ Requires-Dist: pydantic<3,>=2.9
25
+ Requires-Dist: pyzmq<28,>=27
26
+ Requires-Dist: safetensors<1,>=0.6
27
+ Requires-Dist: torch<2.12,>=2.11
28
+ Requires-Dist: tqdm<5,>=4.66
29
+ Requires-Dist: transformers<6,>=5.5
30
+ Requires-Dist: triton==3.6.0
31
+ Requires-Dist: uvicorn<1,>=0.30
32
+ Provides-Extra: dev
33
+ Requires-Dist: pytest>=6.0; extra == "dev"
34
+ Provides-Extra: fi
35
+ Requires-Dist: flashinfer-python[cu13]<0.7,>=0.6; extra == "fi"
36
+ Provides-Extra: sgl
37
+ Requires-Dist: sglang-kernel==0.4.5; extra == "sgl"
38
+ Provides-Extra: accel
39
+ Requires-Dist: freetoken[fi,sgl]; extra == "accel"
40
+ Dynamic: license-file
41
+
42
+ <div align="center">
43
+ <picture>
44
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/FlashML-org/FreeToken/main/assets/freetoken-logo-dark.svg">
45
+ <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/FlashML-org/FreeToken/main/assets/freetoken-logo-light.svg">
46
+ <img alt="FreeToken" src="https://raw.githubusercontent.com/FlashML-org/FreeToken/main/assets/freetoken-logo.svg" width=55%>
47
+ </picture>
48
+
49
+ [![Slack](https://img.shields.io/badge/Slack-join%20the%20community-4A154B?logo=slack&logoColor=white)](https://join.slack.com/t/flashml/shared_invite/zt-3zpdh5j10-9dwTXrgLiqpVxizhA9KVbA)
50
+ [![Discord](https://img.shields.io/badge/Discord-join%20the%20community-5865F2?logo=discord&logoColor=white)](https://discord.gg/xzwSnMdsX)
51
+ </div>
52
+
53
+
54
+
55
+ A local, MoE-offload inference runtime with an OpenAI- and Anthropic-compatible
56
+ HTTP API — Run DeepSeek-V4-Flash on your 5090 with 20+ TPS.
57
+
58
+
59
+
60
+ ## Quick start
61
+
62
+ See [docs/install.md](https://github.com/FlashML-org/FreeToken/blob/main/docs/install.md) for requirements and installation.
63
+
64
+ ```bash
65
+ ft serve --model ~/models/Qwen3.6-35B-A3B # API server on http://127.0.0.1:1919
66
+ ft launch claude # point an agent at it (codex / opencode / openclaw)
67
+ ft shell # or chat in the terminal
68
+ ```
69
+
70
+ ## Documentation
71
+
72
+ - [Install](https://github.com/FlashML-org/FreeToken/blob/main/docs/install.md) — requirements and setup
73
+ - [Supported models](https://github.com/FlashML-org/FreeToken/blob/main/docs/models.md) — model × quantization
74
+ - [CLI reference](https://github.com/FlashML-org/FreeToken/blob/main/docs/cli.md) — `ft` commands and environment variables
75
+
76
+ ## Acknowledgment
77
+
78
+ FreeToken was deeply inspired by [mini-sglang](https://github.com/sgl-project/mini-sglang), and
79
+ learned the design and reused code from the following projects:
80
+ [SGLang](https://github.com/sgl-project/sglang),
81
+ [vLLM](https://github.com/vllm-project/vllm),
82
+ [FlashInfer](https://github.com/flashinfer-ai/flashinfer),
83
+ [flash-linear-attention](https://github.com/fla-org/flash-linear-attention),
84
+ [LightLLM](https://github.com/ModelTC/lightllm) and [llama.cpp](https://github.com/ggml-org/llama.cpp).
85
+
86
+ ## License
87
+
88
+ [Apache License 2.0](https://github.com/FlashML-org/FreeToken/blob/main/LICENSE).
@@ -0,0 +1,47 @@
1
+ <div align="center">
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/FlashML-org/FreeToken/main/assets/freetoken-logo-dark.svg">
4
+ <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/FlashML-org/FreeToken/main/assets/freetoken-logo-light.svg">
5
+ <img alt="FreeToken" src="https://raw.githubusercontent.com/FlashML-org/FreeToken/main/assets/freetoken-logo.svg" width=55%>
6
+ </picture>
7
+
8
+ [![Slack](https://img.shields.io/badge/Slack-join%20the%20community-4A154B?logo=slack&logoColor=white)](https://join.slack.com/t/flashml/shared_invite/zt-3zpdh5j10-9dwTXrgLiqpVxizhA9KVbA)
9
+ [![Discord](https://img.shields.io/badge/Discord-join%20the%20community-5865F2?logo=discord&logoColor=white)](https://discord.gg/xzwSnMdsX)
10
+ </div>
11
+
12
+
13
+
14
+ A local, MoE-offload inference runtime with an OpenAI- and Anthropic-compatible
15
+ HTTP API — Run DeepSeek-V4-Flash on your 5090 with 20+ TPS.
16
+
17
+
18
+
19
+ ## Quick start
20
+
21
+ See [docs/install.md](https://github.com/FlashML-org/FreeToken/blob/main/docs/install.md) for requirements and installation.
22
+
23
+ ```bash
24
+ ft serve --model ~/models/Qwen3.6-35B-A3B # API server on http://127.0.0.1:1919
25
+ ft launch claude # point an agent at it (codex / opencode / openclaw)
26
+ ft shell # or chat in the terminal
27
+ ```
28
+
29
+ ## Documentation
30
+
31
+ - [Install](https://github.com/FlashML-org/FreeToken/blob/main/docs/install.md) — requirements and setup
32
+ - [Supported models](https://github.com/FlashML-org/FreeToken/blob/main/docs/models.md) — model × quantization
33
+ - [CLI reference](https://github.com/FlashML-org/FreeToken/blob/main/docs/cli.md) — `ft` commands and environment variables
34
+
35
+ ## Acknowledgment
36
+
37
+ FreeToken was deeply inspired by [mini-sglang](https://github.com/sgl-project/mini-sglang), and
38
+ learned the design and reused code from the following projects:
39
+ [SGLang](https://github.com/sgl-project/sglang),
40
+ [vLLM](https://github.com/vllm-project/vllm),
41
+ [FlashInfer](https://github.com/flashinfer-ai/flashinfer),
42
+ [flash-linear-attention](https://github.com/fla-org/flash-linear-attention),
43
+ [LightLLM](https://github.com/ModelTC/lightllm) and [llama.cpp](https://github.com/ggml-org/llama.cpp).
44
+
45
+ ## License
46
+
47
+ [Apache License 2.0](https://github.com/FlashML-org/FreeToken/blob/main/LICENSE).
@@ -0,0 +1,110 @@
1
+ [build-system]
2
+ # torch must match the runtime range below: build isolation resolves this list on its
3
+ # own, and a mismatch links the C++ extensions against the wrong libtorch.
4
+ # setuptools floor: 77 is the first release that understands the PEP 639 `license`
5
+ # SPDX string and `license-files` below.
6
+ requires = ["setuptools>=77", "torch>=2.11,<2.12", "wheel"]
7
+ build-backend = "setuptools.build_meta"
8
+
9
+ [project]
10
+ name = "freetoken"
11
+ # Single source of truth: python/freetoken/version.py (read via the attr directive below).
12
+ dynamic = ["version"]
13
+ description = "FreeToken inference runtime"
14
+ readme = "README.md"
15
+ requires-python = ">=3.10"
16
+ license = "Apache-2.0"
17
+ license-files = ["LICENSE"]
18
+ # Version ranges are floor=last-verified, ceiling=next-major (kept loose enough to
19
+ # resolve, tight enough to bar a silent breaking bump). These ranges are the contract;
20
+ # there is no lockfile.
21
+ dependencies = [
22
+ "apache-tvm-ffi==0.1.13.post3", # pin it
23
+ "einops>=0.8,<1",
24
+ "fastapi>=0.115,<1",
25
+ # slot_cache: the device-side LRU admission kernel behind the MoE expert cache.
26
+ "flashlib==0.3.0", # pin it
27
+ "gguf>=0.19,<1",
28
+ "huggingface_hub>=1.5,<2",
29
+ "msgpack>=1.1,<2",
30
+ "modelscope>=1.37,<2",
31
+ # ceiling: numba (via flashlib) needs numpy<2.5
32
+ "numpy>=2.0,<2.5",
33
+ "openai>=2.0,<3",
34
+ "partial-json-parser>=0.2,<1",
35
+ "prompt_toolkit>=3.0,<4",
36
+ "pydantic>=2.9,<3",
37
+ "pyzmq>=27,<28",
38
+ "safetensors>=0.6,<1",
39
+ # floor+ceiling: sglang-kernel 0.4.5 links libtorch symbols only 2.11 has.
40
+ # PyPI's torch 2.11.0 wheel is itself the cu130 build, so plain pip resolves
41
+ # correctly from PyPI alone; uv additionally pins the index below.
42
+ "torch>=2.11,<2.12",
43
+ "tqdm>=4.66,<5",
44
+ "transformers>=5.5,<6",
45
+ "triton==3.6.0",
46
+ "uvicorn>=0.30,<1",
47
+ ]
48
+
49
+ [project.urls]
50
+ Homepage = "https://github.com/FlashML-org/FreeToken"
51
+ Repository = "https://github.com/FlashML-org/FreeToken"
52
+ Issues = "https://github.com/FlashML-org/FreeToken/issues"
53
+
54
+ [project.scripts]
55
+ ft = "freetoken.cli:main"
56
+
57
+ [project.optional-dependencies]
58
+ dev = ["pytest>=6.0"]
59
+ # Native fused-kernel packages. Without them the runtime falls back to the pure-Triton
60
+ # kernels in freetoken.kernel.triton (and the 'triton' attention backend). Install
61
+ # `freetoken[accel]` for the full native fast path.
62
+ fi = ["flashinfer-python[cu13]>=0.6,<0.7"]
63
+ # renamed from sgl-kernel at 0.4; still imports as `sgl_kernel`, so never co-install both
64
+ sgl = ["sglang-kernel==0.4.5"]
65
+ accel = ["freetoken[fi,sgl]"]
66
+ # NOTE: the Marlin W4A16 NVFP4 expert-GEMM path (sm_80-99) borrows vLLM's AOT wheel
67
+ # (vllm>=0.14,<0.15), which pins transformers>=4.56,<5 and so is INCOMPATIBLE with the
68
+ # core transformers>=5.5 requirement. It is therefore not a lockable extra and is left
69
+ # out of the default resolution — install it separately (`pip install 'vllm>=0.14,<0.15'`)
70
+ # in a dedicated environment when you specifically need the Marlin path.
71
+
72
+ # uv-only provenance pins — pip ignores this section and resolves from PyPI, which
73
+ # works: PyPI's torch 2.11.0 and sglang-kernel 0.4.5 are the same cu130 builds these
74
+ # indexes serve. `explicit = true` scopes each index to the one package that needs it
75
+ # (the torch index also mirrors stale copies of common deps, e.g. packaging<=24.1,
76
+ # which would otherwise shadow PyPI under uv's first-index strategy).
77
+ [tool.uv.sources]
78
+ torch = { index = "pytorch-cu130" }
79
+ sglang-kernel = { index = "sglang-cu130" }
80
+
81
+ [[tool.uv.index]]
82
+ name = "pytorch-cu130"
83
+ url = "https://download.pytorch.org/whl/cu130"
84
+ explicit = true
85
+
86
+ [[tool.uv.index]]
87
+ name = "sglang-cu130"
88
+ url = "https://docs.sglang.io/whl/cu130"
89
+ explicit = true
90
+
91
+ [tool.setuptools]
92
+ include-package-data = true
93
+ package-dir = {"" = "python"}
94
+
95
+ [tool.setuptools.dynamic]
96
+ version = {attr = "freetoken.version.__version__"}
97
+
98
+ [tool.setuptools.packages.find]
99
+ where = ["python"]
100
+
101
+ [tool.setuptools.package-data]
102
+ "*" = ["csrc/**/*", "moe/configs/**/*.json"]
103
+
104
+ [tool.pytest.ini_options]
105
+ testpaths = ["tests"]
106
+ python_files = ["test_*.py"]
107
+ markers = [
108
+ "slow: takes tens of seconds (big kernel sweeps, real-checkpoint reads); deselect with -m 'not slow'",
109
+ "needs_weights: needs a real local checkpoint, gated behind an env var (see tests/README.md)",
110
+ ]
@@ -0,0 +1,5 @@
1
+ """FreeToken inference runtime."""
2
+
3
+ from freetoken.version import __version__
4
+
5
+ __all__ = ["__version__"]
@@ -0,0 +1,5 @@
1
+ from .server import launch_server
2
+
3
+ assert __name__ == "__main__"
4
+
5
+ launch_server(prog="python -m freetoken")
@@ -0,0 +1,183 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+ from typing import TYPE_CHECKING, Protocol
5
+
6
+ from freetoken.utils import Registry, init_logger
7
+
8
+ from .base import AttentionSpec, AttnType, BaseAttnBackend, BaseAttnMetadata, HybridBackend
9
+
10
+ if TYPE_CHECKING:
11
+ from freetoken.models import ModelConfig
12
+
13
+ logger = init_logger(__name__)
14
+
15
+
16
+ class BackendCreator(Protocol):
17
+ def __call__(self, config: ModelConfig) -> BaseAttnBackend: ...
18
+
19
+
20
+ @dataclass(frozen=True)
21
+ class BackendInfo:
22
+ """Declarative capability matrix entry for one backend. The engine's config-time
23
+ validation interprets the requirement flags through its own (monkeypatch-able)
24
+ availability probes; this stays pure data so registration never imports kernels."""
25
+
26
+ supported_types: frozenset[AttnType]
27
+ requires_flashinfer: bool = False
28
+ requires_sgl_kernel: bool = False
29
+ requires_sm100: bool = False
30
+ # Allowed page sizes (None -> any). Config-time resolution coerces to the last
31
+ # entry when the resolved page_size is not in the list.
32
+ page_sizes: tuple[int, ...] | None = None
33
+ # Whether forward() honors a per-call AttentionSpec (window/sm_scale/sinks).
34
+ # Non-consumers raise on a non-None spec instead of silently dropping it.
35
+ consumes_attn_spec: bool = False
36
+ # Whether this backend coexists with hybrid-linear (GDN/mamba) models. The
37
+ # linear layers bypass the backend entirely, but a backend whose metadata or
38
+ # graph machinery assumes layer 0 is an attention layer can opt out here.
39
+ hybrid_linear_ok: bool = True
40
+
41
+
42
+ SUPPORTED_ATTENTION_BACKENDS = Registry[BackendCreator]("Attention Backend")
43
+
44
+
45
+ @SUPPORTED_ATTENTION_BACKENDS.register(
46
+ "trtllm",
47
+ BackendInfo(
48
+ supported_types=frozenset({AttnType.FULL}),
49
+ requires_flashinfer=True,
50
+ requires_sm100=True,
51
+ page_sizes=(16, 32, 64),
52
+ ),
53
+ )
54
+ def create_trtllm_backend(config: ModelConfig):
55
+ from .trtllm import TensorRTLLMBackend
56
+
57
+ return TensorRTLLMBackend(config)
58
+
59
+
60
+ @SUPPORTED_ATTENTION_BACKENDS.register(
61
+ "fi",
62
+ BackendInfo(
63
+ supported_types=frozenset({AttnType.FULL}),
64
+ requires_flashinfer=True,
65
+ ),
66
+ )
67
+ def create_fi_backend(config: ModelConfig):
68
+ from .fi import FlashInferBackend
69
+
70
+ return FlashInferBackend(config)
71
+
72
+
73
+ @SUPPORTED_ATTENTION_BACKENDS.register(
74
+ "fa",
75
+ BackendInfo(
76
+ supported_types=frozenset({AttnType.FULL}),
77
+ requires_sgl_kernel=True,
78
+ ),
79
+ )
80
+ def create_fa_backend(config: ModelConfig):
81
+ from .fa import FlashAttentionBackend
82
+
83
+ return FlashAttentionBackend(config)
84
+
85
+
86
+ @SUPPORTED_ATTENTION_BACKENDS.register(
87
+ "triton",
88
+ BackendInfo(
89
+ supported_types=frozenset({AttnType.FULL, AttnType.SWA}),
90
+ consumes_attn_spec=True,
91
+ ),
92
+ )
93
+ def create_triton_backend(config: ModelConfig):
94
+ from .triton import TritonAttentionBackend
95
+
96
+ return TritonAttentionBackend(config)
97
+
98
+
99
+ @SUPPORTED_ATTENTION_BACKENDS.register(
100
+ "dsv4_sparse",
101
+ BackendInfo(supported_types=frozenset({AttnType.DSV4})),
102
+ )
103
+ def create_dsv4_sparse_backend(config: ModelConfig):
104
+ from .dsv4_sparse import DSV4SparseAttnBackend
105
+
106
+ return DSV4SparseAttnBackend(config)
107
+
108
+
109
+ @SUPPORTED_ATTENTION_BACKENDS.register(
110
+ "dsa",
111
+ BackendInfo(supported_types=frozenset({AttnType.MLA, AttnType.DSA})),
112
+ )
113
+ def create_dsa_backend(config: ModelConfig):
114
+ from .dsa import DSAAttnBackend
115
+
116
+ return DSAAttnBackend(config)
117
+
118
+
119
+ @SUPPORTED_ATTENTION_BACKENDS.register(
120
+ "m3_sparse",
121
+ BackendInfo(
122
+ supported_types=frozenset({AttnType.BSA}),
123
+ # One KV page == one 128-token sparse block: the top-k block ids ARE page
124
+ # indices and the block-base-row addressing needs page-aligned 128-row runs.
125
+ # Config-time resolution coerces any other page size here.
126
+ page_sizes=(128,),
127
+ ),
128
+ )
129
+ def create_m3_sparse_backend(config: ModelConfig):
130
+ from .m3_sparse import M3SparseAttnBackend
131
+
132
+ return M3SparseAttnBackend(config)
133
+
134
+
135
+ def attention_backend_info(name: str) -> BackendInfo:
136
+ return SUPPORTED_ATTENTION_BACKENDS.info(name)
137
+
138
+
139
+ def validate_attn_backend(backend: str, allow_auto: bool = True):
140
+ if backend != "auto":
141
+ parts = backend.split(",")
142
+ if len(parts) > 2:
143
+ from argparse import ArgumentTypeError
144
+
145
+ raise ArgumentTypeError(
146
+ f"At most two comma-separated attention backends are allowed "
147
+ f"(prefill,decode), got {backend!r}"
148
+ )
149
+ SUPPORTED_ATTENTION_BACKENDS.assert_supported(parts)
150
+ else:
151
+ assert allow_auto, "auto is not allowed here"
152
+ return backend
153
+
154
+
155
+ def create_attention_backend(
156
+ backend: str,
157
+ config: ModelConfig,
158
+ ) -> BaseAttnBackend:
159
+ validate_attn_backend(backend, allow_auto=False)
160
+ if "," in backend:
161
+ p_backend, d_backend = backend.split(",", 1)
162
+ if p_backend != d_backend:
163
+ logger.info(f"Using hybrid attention backend: prefill={p_backend}, decode={d_backend}")
164
+ p_backend = create_attention_backend(p_backend, config)
165
+ d_backend = create_attention_backend(d_backend, config)
166
+ return HybridBackend(p_backend, d_backend)
167
+ backend = p_backend # both are the same, fall through to single backend
168
+ logger.warning(f"P/D attention backends are the same: {backend}, using single backend.")
169
+
170
+ return SUPPORTED_ATTENTION_BACKENDS[backend](config)
171
+
172
+
173
+ __all__ = [
174
+ "AttnType",
175
+ "BackendInfo",
176
+ "BaseAttnMetadata",
177
+ "BaseAttnBackend",
178
+ "AttentionSpec",
179
+ "attention_backend_info",
180
+ "create_attention_backend",
181
+ "SUPPORTED_ATTENTION_BACKENDS",
182
+ "validate_attn_backend",
183
+ ]