turing-engine 2.0.0__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 (328) hide show
  1. turing_engine-2.0.0/LICENSE +31 -0
  2. turing_engine-2.0.0/MANIFEST.in +9 -0
  3. turing_engine-2.0.0/NOTICE +14 -0
  4. turing_engine-2.0.0/PKG-INFO +288 -0
  5. turing_engine-2.0.0/README.md +243 -0
  6. turing_engine-2.0.0/csrc/marlin/LICENSE +201 -0
  7. turing_engine-2.0.0/csrc/marlin/awq_marlin_repack.cu +271 -0
  8. turing_engine-2.0.0/csrc/marlin/core/scalar_type.hpp +368 -0
  9. turing_engine-2.0.0/csrc/marlin/dequant.h +612 -0
  10. turing_engine-2.0.0/csrc/marlin/kernel.h +45 -0
  11. turing_engine-2.0.0/csrc/marlin/kernel_bf16_g128.cu +9 -0
  12. turing_engine-2.0.0/csrc/marlin/kernel_bf16_g64.cu +9 -0
  13. turing_engine-2.0.0/csrc/marlin/kernel_configs.h +36 -0
  14. turing_engine-2.0.0/csrc/marlin/kernel_fp16_g128.cu +9 -0
  15. turing_engine-2.0.0/csrc/marlin/kernel_fp16_g64.cu +9 -0
  16. turing_engine-2.0.0/csrc/marlin/marlin.cu +557 -0
  17. turing_engine-2.0.0/csrc/marlin/marlin.cuh +155 -0
  18. turing_engine-2.0.0/csrc/marlin/marlin_dtypes.cuh +152 -0
  19. turing_engine-2.0.0/csrc/marlin/marlin_mma.h +272 -0
  20. turing_engine-2.0.0/csrc/marlin/marlin_template.h +1838 -0
  21. turing_engine-2.0.0/csrc/pybind_bindings.cpp +1716 -0
  22. turing_engine-2.0.0/csrc/turing_adam_kernel.hpp +49 -0
  23. turing_engine-2.0.0/csrc/turing_apc_hash.hpp +51 -0
  24. turing_engine-2.0.0/csrc/turing_asynch_scheduler.hpp +138 -0
  25. turing_engine-2.0.0/csrc/turing_birkhoff.hpp +69 -0
  26. turing_engine-2.0.0/csrc/turing_chunked_decay.hpp +102 -0
  27. turing_engine-2.0.0/csrc/turing_conv2d_shared.hpp +62 -0
  28. turing_engine-2.0.0/csrc/turing_convolution_shared.hpp +64 -0
  29. turing_engine-2.0.0/csrc/turing_cpu_moe_kernel.hpp +57 -0
  30. turing_engine-2.0.0/csrc/turing_cufile.hpp +186 -0
  31. turing_engine-2.0.0/csrc/turing_dag_tree_mask.hpp +39 -0
  32. turing_engine-2.0.0/csrc/turing_dilated_conv1d.hpp +82 -0
  33. turing_engine-2.0.0/csrc/turing_elastic_budget.hpp +125 -0
  34. turing_engine-2.0.0/csrc/turing_fast_hash.hpp +58 -0
  35. turing_engine-2.0.0/csrc/turing_fast_hash_tensor.hpp +70 -0
  36. turing_engine-2.0.0/csrc/turing_gated_zero_identity.hpp +69 -0
  37. turing_engine-2.0.0/csrc/turing_gguf_cpp.hpp +285 -0
  38. turing_engine-2.0.0/csrc/turing_gguf_simd.hpp +422 -0
  39. turing_engine-2.0.0/csrc/turing_halo_exchange.hpp +53 -0
  40. turing_engine-2.0.0/csrc/turing_hierarchical.hpp +56 -0
  41. turing_engine-2.0.0/csrc/turing_http_server.hpp +518 -0
  42. turing_engine-2.0.0/csrc/turing_json_fast_scan.hpp +157 -0
  43. turing_engine-2.0.0/csrc/turing_kda_simd.hpp +125 -0
  44. turing_engine-2.0.0/csrc/turing_laplacian_2d.hpp +44 -0
  45. turing_engine-2.0.0/csrc/turing_latent_decode.hpp +113 -0
  46. turing_engine-2.0.0/csrc/turing_linear_recurrence.hpp +91 -0
  47. turing_engine-2.0.0/csrc/turing_lora_gemv.hpp +104 -0
  48. turing_engine-2.0.0/csrc/turing_lru_cache.hpp +358 -0
  49. turing_engine-2.0.0/csrc/turing_main.cpp +223 -0
  50. turing_engine-2.0.0/csrc/turing_matrix_pow.hpp +80 -0
  51. turing_engine-2.0.0/csrc/turing_matryoshka_quadtree.hpp +138 -0
  52. turing_engine-2.0.0/csrc/turing_mhc_simd.hpp +128 -0
  53. turing_engine-2.0.0/csrc/turing_mmap.hpp +197 -0
  54. turing_engine-2.0.0/csrc/turing_model_cpp.hpp +321 -0
  55. turing_engine-2.0.0/csrc/turing_nbody_attention.hpp +83 -0
  56. turing_engine-2.0.0/csrc/turing_nbody_recirculator.hpp +49 -0
  57. turing_engine-2.0.0/csrc/turing_paged_attention.hpp +118 -0
  58. turing_engine-2.0.0/csrc/turing_paged_memory.hpp +97 -0
  59. turing_engine-2.0.0/csrc/turing_parallel_reader.hpp +250 -0
  60. turing_engine-2.0.0/csrc/turing_persistent_reducer.hpp +74 -0
  61. turing_engine-2.0.0/csrc/turing_prefix_match.hpp +56 -0
  62. turing_engine-2.0.0/csrc/turing_prefix_router.hpp +71 -0
  63. turing_engine-2.0.0/csrc/turing_pso.hpp +53 -0
  64. turing_engine-2.0.0/csrc/turing_pso_objectives.hpp +84 -0
  65. turing_engine-2.0.0/csrc/turing_pso_tuner.hpp +89 -0
  66. turing_engine-2.0.0/csrc/turing_radix_trie.hpp +142 -0
  67. turing_engine-2.0.0/csrc/turing_reasoning_scanner.hpp +100 -0
  68. turing_engine-2.0.0/csrc/turing_residual_outlier.hpp +78 -0
  69. turing_engine-2.0.0/csrc/turing_ridge_solver.hpp +61 -0
  70. turing_engine-2.0.0/csrc/turing_rope.hpp +56 -0
  71. turing_engine-2.0.0/csrc/turing_routing_history.hpp +130 -0
  72. turing_engine-2.0.0/csrc/turing_safetensors_fast_header.hpp +129 -0
  73. turing_engine-2.0.0/csrc/turing_sampler.hpp +118 -0
  74. turing_engine-2.0.0/csrc/turing_segment_pool.hpp +90 -0
  75. turing_engine-2.0.0/csrc/turing_serializer.hpp +90 -0
  76. turing_engine-2.0.0/csrc/turing_shannon_entropy.hpp +51 -0
  77. turing_engine-2.0.0/csrc/turing_simd.hpp +477 -0
  78. turing_engine-2.0.0/csrc/turing_sinkhorn_ot.hpp +131 -0
  79. turing_engine-2.0.0/csrc/turing_spec_verifier.hpp +55 -0
  80. turing_engine-2.0.0/csrc/turing_threadpool.hpp +123 -0
  81. turing_engine-2.0.0/csrc/turing_tokenizer_cpp.hpp +111 -0
  82. turing_engine-2.0.0/csrc/turing_traffic_manager.hpp +122 -0
  83. turing_engine-2.0.0/csrc/turing_unified_memory.hpp +61 -0
  84. turing_engine-2.0.0/csrc/turing_varlen_pack.hpp +52 -0
  85. turing_engine-2.0.0/csrc/turing_welford_anneal.hpp +56 -0
  86. turing_engine-2.0.0/pyproject.toml +93 -0
  87. turing_engine-2.0.0/setup.cfg +4 -0
  88. turing_engine-2.0.0/setup.py +167 -0
  89. turing_engine-2.0.0/tests/test_accuracy_eval.py +46 -0
  90. turing_engine-2.0.0/tests/test_activation_sparsity.py +71 -0
  91. turing_engine-2.0.0/tests/test_advanced_hpc.py +110 -0
  92. turing_engine-2.0.0/tests/test_attention_and_rope.py +54 -0
  93. turing_engine-2.0.0/tests/test_cca_and_enhanced_speculation.py +74 -0
  94. turing_engine-2.0.0/tests/test_chat_and_aliases.py +72 -0
  95. turing_engine-2.0.0/tests/test_colibri_enhancements.py +153 -0
  96. turing_engine-2.0.0/tests/test_completions_render.py +72 -0
  97. turing_engine-2.0.0/tests/test_cpp_engine_parity.py +122 -0
  98. turing_engine-2.0.0/tests/test_cpp_http_server.py +195 -0
  99. turing_engine-2.0.0/tests/test_cpp_standalone.py +65 -0
  100. turing_engine-2.0.0/tests/test_cross_model_kv_transfer.py +141 -0
  101. turing_engine-2.0.0/tests/test_csrc_and_simd.py +232 -0
  102. turing_engine-2.0.0/tests/test_demo.py +138 -0
  103. turing_engine-2.0.0/tests/test_distributed_inference.py +150 -0
  104. turing_engine-2.0.0/tests/test_doc_tables.py +10 -0
  105. turing_engine-2.0.0/tests/test_dsl_executor_load.py +17 -0
  106. turing_engine-2.0.0/tests/test_dsl_primitives.py +182 -0
  107. turing_engine-2.0.0/tests/test_ecosystem_integrations.py +34 -0
  108. turing_engine-2.0.0/tests/test_elastic_memory.py +98 -0
  109. turing_engine-2.0.0/tests/test_engine_generation.py +198 -0
  110. turing_engine-2.0.0/tests/test_entropy_kernel.py +46 -0
  111. turing_engine-2.0.0/tests/test_expert_cache_eviction.py +80 -0
  112. turing_engine-2.0.0/tests/test_fast_hash.py +46 -0
  113. turing_engine-2.0.0/tests/test_flashinfer_prefill.py +71 -0
  114. turing_engine-2.0.0/tests/test_fused_batched_sampler.py +59 -0
  115. turing_engine-2.0.0/tests/test_fused_fast_kernels.py +139 -0
  116. turing_engine-2.0.0/tests/test_fused_kernels_and_simd.py +126 -0
  117. turing_engine-2.0.0/tests/test_fused_kernels_parity.py +55 -0
  118. turing_engine-2.0.0/tests/test_fused_moe_block_gemm.py +80 -0
  119. turing_engine-2.0.0/tests/test_fused_ops.py +72 -0
  120. turing_engine-2.0.0/tests/test_generation_api.py +483 -0
  121. turing_engine-2.0.0/tests/test_gguf_loader.py +200 -0
  122. turing_engine-2.0.0/tests/test_gguf_parity.py +504 -0
  123. turing_engine-2.0.0/tests/test_gguf_simd_parity.py +57 -0
  124. turing_engine-2.0.0/tests/test_heterogeneous_moe_and_anthropic.py +185 -0
  125. turing_engine-2.0.0/tests/test_hf_parity.py +257 -0
  126. turing_engine-2.0.0/tests/test_hierarchical_compression_csa_hca.py +81 -0
  127. turing_engine-2.0.0/tests/test_hierarchical_paging.py +51 -0
  128. turing_engine-2.0.0/tests/test_hpc_integrations.py +182 -0
  129. turing_engine-2.0.0/tests/test_hybrid_attention.py +78 -0
  130. turing_engine-2.0.0/tests/test_hybrid_linear_decay.py +160 -0
  131. turing_engine-2.0.0/tests/test_hybrid_mesh.py +28 -0
  132. turing_engine-2.0.0/tests/test_kernel_fusions_and_simd_v8.py +145 -0
  133. turing_engine-2.0.0/tests/test_kernel_fusions_native.py +112 -0
  134. turing_engine-2.0.0/tests/test_kv_cache.py +356 -0
  135. turing_engine-2.0.0/tests/test_kv_events.py +171 -0
  136. turing_engine-2.0.0/tests/test_kv_transfer.py +142 -0
  137. turing_engine-2.0.0/tests/test_langchain_integration.py +103 -0
  138. turing_engine-2.0.0/tests/test_latent_decode.py +71 -0
  139. turing_engine-2.0.0/tests/test_lazy_imports.py +24 -0
  140. turing_engine-2.0.0/tests/test_lineage_and_pooling.py +150 -0
  141. turing_engine-2.0.0/tests/test_linear_recurrence_kernel.py +67 -0
  142. turing_engine-2.0.0/tests/test_llamaindex_integration.py +30 -0
  143. turing_engine-2.0.0/tests/test_llmd_metrics.py +87 -0
  144. turing_engine-2.0.0/tests/test_lora_adapters.py +93 -0
  145. turing_engine-2.0.0/tests/test_marlin.py +155 -0
  146. turing_engine-2.0.0/tests/test_matryoshka_draft.py +87 -0
  147. turing_engine-2.0.0/tests/test_measured_differentiators.py +95 -0
  148. turing_engine-2.0.0/tests/test_mhc_doubly_stochastic.py +92 -0
  149. turing_engine-2.0.0/tests/test_model_resolver.py +83 -0
  150. turing_engine-2.0.0/tests/test_models_and_tp.py +34 -0
  151. turing_engine-2.0.0/tests/test_moe_offload.py +104 -0
  152. turing_engine-2.0.0/tests/test_native_kernel_fusions.py +218 -0
  153. turing_engine-2.0.0/tests/test_native_lfru_cache.py +73 -0
  154. turing_engine-2.0.0/tests/test_niah.py +35 -0
  155. turing_engine-2.0.0/tests/test_no_private_identifiers.py +47 -0
  156. turing_engine-2.0.0/tests/test_ollama_api.py +163 -0
  157. turing_engine-2.0.0/tests/test_paged_decode_gemv.py +59 -0
  158. turing_engine-2.0.0/tests/test_parallel_reader_and_gds.py +80 -0
  159. turing_engine-2.0.0/tests/test_prefill_decode_scheduling.py +170 -0
  160. turing_engine-2.0.0/tests/test_radix_trie_cpp.py +38 -0
  161. turing_engine-2.0.0/tests/test_resolver_local_names.py +32 -0
  162. turing_engine-2.0.0/tests/test_segment_pool_and_batching.py +132 -0
  163. turing_engine-2.0.0/tests/test_serverless_integrations.py +75 -0
  164. turing_engine-2.0.0/tests/test_serving_and_api.py +111 -0
  165. turing_engine-2.0.0/tests/test_serving_headers.py +74 -0
  166. turing_engine-2.0.0/tests/test_side_endpoints.py +222 -0
  167. turing_engine-2.0.0/tests/test_simd_json_scanner.py +46 -0
  168. turing_engine-2.0.0/tests/test_simd_kernels_parity.py +70 -0
  169. turing_engine-2.0.0/tests/test_simd_reasoning_scanner.py +53 -0
  170. turing_engine-2.0.0/tests/test_sinkhorn_eviction_scores.py +64 -0
  171. turing_engine-2.0.0/tests/test_spec_gate_and_parity.py +90 -0
  172. turing_engine-2.0.0/tests/test_speculation_and_tree.py +106 -0
  173. turing_engine-2.0.0/tests/test_speculative_eagle_dspark.py +75 -0
  174. turing_engine-2.0.0/tests/test_split_k_and_prefix_bypass.py +171 -0
  175. turing_engine-2.0.0/tests/test_static_pool_and_streaming.py +68 -0
  176. turing_engine-2.0.0/tests/test_storage_ingest_ladder.py +124 -0
  177. turing_engine-2.0.0/tests/test_structured_output.py +57 -0
  178. turing_engine-2.0.0/tests/test_subspace_and_router.py +50 -0
  179. turing_engine-2.0.0/tests/test_tool_calling.py +88 -0
  180. turing_engine-2.0.0/tests/test_traffic_management.py +94 -0
  181. turing_engine-2.0.0/tests/test_triton_kv_decode.py +218 -0
  182. turing_engine-2.0.0/tests/test_triton_kv_prefill.py +91 -0
  183. turing_engine-2.0.0/tests/test_w4a16.py +247 -0
  184. turing_engine-2.0.0/tests/test_xkv_latent_transfer.py +94 -0
  185. turing_engine-2.0.0/turing/__init__.py +36 -0
  186. turing_engine-2.0.0/turing/cli.py +433 -0
  187. turing_engine-2.0.0/turing/config.py +298 -0
  188. turing_engine-2.0.0/turing/core/__init__.py +43 -0
  189. turing_engine-2.0.0/turing/core/asynch_scheduler.py +35 -0
  190. turing_engine-2.0.0/turing/core/attention_cache.py +135 -0
  191. turing_engine-2.0.0/turing/core/cca.py +139 -0
  192. turing_engine-2.0.0/turing/core/cca_fast.py +83 -0
  193. turing_engine-2.0.0/turing/core/cross_model_kv.py +673 -0
  194. turing_engine-2.0.0/turing/core/elastic_memory.py +157 -0
  195. turing_engine-2.0.0/turing/core/expert_cache.py +363 -0
  196. turing_engine-2.0.0/turing/core/expert_prefetch.py +126 -0
  197. turing_engine-2.0.0/turing/core/heterogeneous_moe.py +249 -0
  198. turing_engine-2.0.0/turing/core/hierarchical_compression.py +188 -0
  199. turing_engine-2.0.0/turing/core/hybrid_attention.py +251 -0
  200. turing_engine-2.0.0/turing/core/hybrid_memory.py +286 -0
  201. turing_engine-2.0.0/turing/core/hybrid_mesh.py +76 -0
  202. turing_engine-2.0.0/turing/core/kslot_pooling.py +159 -0
  203. turing_engine-2.0.0/turing/core/kv_cache.py +446 -0
  204. turing_engine-2.0.0/turing/core/lineage.py +204 -0
  205. turing_engine-2.0.0/turing/core/matrix_pow.py +76 -0
  206. turing_engine-2.0.0/turing/core/mhc.py +169 -0
  207. turing_engine-2.0.0/turing/core/optimal_transport.py +101 -0
  208. turing_engine-2.0.0/turing/core/paging.py +375 -0
  209. turing_engine-2.0.0/turing/core/persistent_gemv.py +38 -0
  210. turing_engine-2.0.0/turing/core/rope.py +190 -0
  211. turing_engine-2.0.0/turing/core/router.py +207 -0
  212. turing_engine-2.0.0/turing/core/router_annealer.py +66 -0
  213. turing_engine-2.0.0/turing/core/speculation.py +570 -0
  214. turing_engine-2.0.0/turing/core/subspace.py +65 -0
  215. turing_engine-2.0.0/turing/core/swarm_objectives.py +42 -0
  216. turing_engine-2.0.0/turing/core/swarm_opt.py +137 -0
  217. turing_engine-2.0.0/turing/core/unified_memory.py +60 -0
  218. turing_engine-2.0.0/turing/demo/__init__.py +17 -0
  219. turing_engine-2.0.0/turing/demo/agent_system.py +140 -0
  220. turing_engine-2.0.0/turing/demo/engine_wrapper.py +142 -0
  221. turing_engine-2.0.0/turing/demo/epistemic_gate.py +140 -0
  222. turing_engine-2.0.0/turing/demo/interactive_demo.py +72 -0
  223. turing_engine-2.0.0/turing/demo/world_model.py +101 -0
  224. turing_engine-2.0.0/turing/dsl/__init__.py +24 -0
  225. turing_engine-2.0.0/turing/dsl/context.py +188 -0
  226. turing_engine-2.0.0/turing/dsl/executor.py +374 -0
  227. turing_engine-2.0.0/turing/dsl/primitives.py +155 -0
  228. turing_engine-2.0.0/turing/integrations/__init__.py +7 -0
  229. turing_engine-2.0.0/turing/integrations/langchain.py +10 -0
  230. turing_engine-2.0.0/turing/kernels/__init__.py +17 -0
  231. turing_engine-2.0.0/turing/kernels/birkhoff_cuda.py +82 -0
  232. turing_engine-2.0.0/turing/kernels/cooperative_conv2d_cuda.py +27 -0
  233. turing_engine-2.0.0/turing/kernels/cooperative_conv_cuda.py +99 -0
  234. turing_engine-2.0.0/turing/kernels/dispatch.py +145 -0
  235. turing_engine-2.0.0/turing/kernels/flashinfer_prefill.py +66 -0
  236. turing_engine-2.0.0/turing/kernels/fused_adam_cuda.py +78 -0
  237. turing_engine-2.0.0/turing/kernels/fused_rope_cuda.py +45 -0
  238. turing_engine-2.0.0/turing/kernels/gds_loader.py +52 -0
  239. turing_engine-2.0.0/turing/kernels/laplacian_2d_cuda.py +39 -0
  240. turing_engine-2.0.0/turing/kernels/marlin.py +96 -0
  241. turing_engine-2.0.0/turing/kernels/rocm_heuristics.py +66 -0
  242. turing_engine-2.0.0/turing/kernels/shannon_entropy_cuda.py +95 -0
  243. turing_engine-2.0.0/turing/kernels/sinkhorn_ot_cuda.py +60 -0
  244. turing_engine-2.0.0/turing/kernels/softened_attention.py +54 -0
  245. turing_engine-2.0.0/turing/kernels/triton_cca.py +35 -0
  246. turing_engine-2.0.0/turing/kernels/triton_chunk_compression.py +101 -0
  247. turing_engine-2.0.0/turing/kernels/triton_chunk_filter.py +57 -0
  248. turing_engine-2.0.0/turing/kernels/triton_chunked_decay.py +207 -0
  249. turing_engine-2.0.0/turing/kernels/triton_dilated_conv.py +101 -0
  250. turing_engine-2.0.0/turing/kernels/triton_flash_tree.py +159 -0
  251. turing_engine-2.0.0/turing/kernels/triton_fused_kslot_gate.py +80 -0
  252. turing_engine-2.0.0/turing/kernels/triton_fused_lora.py +138 -0
  253. turing_engine-2.0.0/turing/kernels/triton_fused_moe_block_gemm.py +184 -0
  254. turing_engine-2.0.0/turing/kernels/triton_fused_ops.py +156 -0
  255. turing_engine-2.0.0/turing/kernels/triton_fused_qkv_rope.py +161 -0
  256. turing_engine-2.0.0/turing/kernels/triton_fused_router.py +93 -0
  257. turing_engine-2.0.0/turing/kernels/triton_fused_sample.py +182 -0
  258. turing_engine-2.0.0/turing/kernels/triton_gated_zero_identity.py +51 -0
  259. turing_engine-2.0.0/turing/kernels/triton_hybrid_anchor_fuse.py +225 -0
  260. turing_engine-2.0.0/turing/kernels/triton_kslot_pool.py +165 -0
  261. turing_engine-2.0.0/turing/kernels/triton_kv_decode.py +246 -0
  262. turing_engine-2.0.0/turing/kernels/triton_kv_prefill.py +133 -0
  263. turing_engine-2.0.0/turing/kernels/triton_latent_decode.py +198 -0
  264. turing_engine-2.0.0/turing/kernels/triton_linear_recurrence.py +131 -0
  265. turing_engine-2.0.0/turing/kernels/triton_linear_recurrence_step.py +185 -0
  266. turing_engine-2.0.0/turing/kernels/triton_matryoshka_gemv.py +102 -0
  267. turing_engine-2.0.0/turing/kernels/triton_matryoshka_spec.py +95 -0
  268. turing_engine-2.0.0/turing/kernels/triton_mhc_fuse.py +134 -0
  269. turing_engine-2.0.0/turing/kernels/triton_paged_decode_gemv.py +415 -0
  270. turing_engine-2.0.0/turing/kernels/triton_quadtree_mrp.py +111 -0
  271. turing_engine-2.0.0/turing/kernels/triton_recirculation.py +104 -0
  272. turing_engine-2.0.0/turing/kernels/triton_residual_outlier.py +87 -0
  273. turing_engine-2.0.0/turing/kernels/triton_segment_pool.py +202 -0
  274. turing_engine-2.0.0/turing/kernels/triton_select_gather.py +113 -0
  275. turing_engine-2.0.0/turing/kernels/triton_sparse_gemv.py +133 -0
  276. turing_engine-2.0.0/turing/kernels/triton_spec_entropy.py +161 -0
  277. turing_engine-2.0.0/turing/kernels/triton_spec_verify.py +128 -0
  278. turing_engine-2.0.0/turing/kernels/triton_subspace_compress.py +106 -0
  279. turing_engine-2.0.0/turing/kernels/triton_swiglu.py +112 -0
  280. turing_engine-2.0.0/turing/kernels/triton_vram_hash.py +119 -0
  281. turing_engine-2.0.0/turing/kernels/triton_w4a16.py +232 -0
  282. turing_engine-2.0.0/turing/kernels/vulkan_runtime.py +77 -0
  283. turing_engine-2.0.0/turing/models/__init__.py +35 -0
  284. turing_engine-2.0.0/turing/models/activation_sparsity.py +91 -0
  285. turing_engine-2.0.0/turing/models/adapters.py +146 -0
  286. turing_engine-2.0.0/turing/models/architecture_registry.py +83 -0
  287. turing_engine-2.0.0/turing/models/causal_lm.py +1050 -0
  288. turing_engine-2.0.0/turing/models/converter.py +19 -0
  289. turing_engine-2.0.0/turing/models/gguf_loader.py +865 -0
  290. turing_engine-2.0.0/turing/models/gguf_tokenizer.py +156 -0
  291. turing_engine-2.0.0/turing/models/hf_loader.py +416 -0
  292. turing_engine-2.0.0/turing/models/ingest.py +166 -0
  293. turing_engine-2.0.0/turing/models/mesh_2d.py +117 -0
  294. turing_engine-2.0.0/turing/models/quant.py +392 -0
  295. turing_engine-2.0.0/turing/models/registry.py +57 -0
  296. turing_engine-2.0.0/turing/models/resolver.py +201 -0
  297. turing_engine-2.0.0/turing/models/safetensors_mmap.py +111 -0
  298. turing_engine-2.0.0/turing/models/sizing_profiles.py +376 -0
  299. turing_engine-2.0.0/turing/models/streaming_loader.py +157 -0
  300. turing_engine-2.0.0/turing/models/tensor_parallel.py +249 -0
  301. turing_engine-2.0.0/turing/models/vllm_adapter.py +41 -0
  302. turing_engine-2.0.0/turing/serving/__init__.py +20 -0
  303. turing_engine-2.0.0/turing/serving/accuracy_eval.py +102 -0
  304. turing_engine-2.0.0/turing/serving/anthropic_api.py +232 -0
  305. turing_engine-2.0.0/turing/serving/disagg_sidecar.py +109 -0
  306. turing_engine-2.0.0/turing/serving/distributed.py +236 -0
  307. turing_engine-2.0.0/turing/serving/embeddings.py +168 -0
  308. turing_engine-2.0.0/turing/serving/engine.py +726 -0
  309. turing_engine-2.0.0/turing/serving/extract.py +82 -0
  310. turing_engine-2.0.0/turing/serving/generation.py +479 -0
  311. turing_engine-2.0.0/turing/serving/kv_events.py +226 -0
  312. turing_engine-2.0.0/turing/serving/kv_transfer.py +108 -0
  313. turing_engine-2.0.0/turing/serving/niah.py +54 -0
  314. turing_engine-2.0.0/turing/serving/ollama_api.py +316 -0
  315. turing_engine-2.0.0/turing/serving/prefix_cache.py +111 -0
  316. turing_engine-2.0.0/turing/serving/pull.py +54 -0
  317. turing_engine-2.0.0/turing/serving/reasoning.py +168 -0
  318. turing_engine-2.0.0/turing/serving/server.py +804 -0
  319. turing_engine-2.0.0/turing/serving/spec_gate.py +158 -0
  320. turing_engine-2.0.0/turing/serving/structured.py +230 -0
  321. turing_engine-2.0.0/turing/serving/tools.py +188 -0
  322. turing_engine-2.0.0/turing/serving/traffic.py +374 -0
  323. turing_engine-2.0.0/turing_engine.egg-info/PKG-INFO +288 -0
  324. turing_engine-2.0.0/turing_engine.egg-info/SOURCES.txt +326 -0
  325. turing_engine-2.0.0/turing_engine.egg-info/dependency_links.txt +1 -0
  326. turing_engine-2.0.0/turing_engine.egg-info/entry_points.txt +2 -0
  327. turing_engine-2.0.0/turing_engine.egg-info/requires.txt +36 -0
  328. turing_engine-2.0.0/turing_engine.egg-info/top_level.txt +1 -0
@@ -0,0 +1,31 @@
1
+ Business Source License 1.1
2
+
3
+ Parameters:
4
+
5
+ Licensor: Ishan Gupta
6
+ Licensed Work: Turing Engine Inference & Serving Stack
7
+ Additional Use: Use of the Licensed Work for all non-production purposes, local
8
+ developer testing, academic and scientific research, personal single-GPU
9
+ workstations, and performance benchmarking is permitted free of charge.
10
+ Change Date: August 24, 2030
11
+ Change License: Apache License, Version 2.0
12
+
13
+ --------------------------------------------------------------------------------
14
+
15
+ 1. Grant of License.
16
+ Licensor hereby grants you the right to copy, modify, create derivative works, redistribute,
17
+ and make non-production use of the Licensed Work in accordance with the Additional Use Grant.
18
+
19
+ 2. Commercial Production Use.
20
+ Any use of the Licensed Work in production multi-GPU clusters, commercial model hosting,
21
+ or serving revenue-generating API traffic is subject to the terms of a separate commercial
22
+ license agreement from Licensor.
23
+
24
+ 3. Change to Open Source License.
25
+ Effective on the Change Date, or the fourth anniversary of the first public release of the
26
+ Licensed Work, Licensor grants you the right to copy, modify, create derivative works,
27
+ redistribute, and use the Licensed Work under the Change License.
28
+
29
+ 4. Disclaimer of Warranty & Limitation of Liability.
30
+ THE LICENSED WORK IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.
31
+ IN NO EVENT SHALL LICENSOR BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY.
@@ -0,0 +1,9 @@
1
+ include csrc/*.hpp
2
+ include csrc/*.cpp
3
+ include LICENSE
4
+ include README.md
5
+ include pyproject.toml
6
+ include setup.py
7
+ recursive-include turing *.py
8
+ recursive-include csrc/marlin *
9
+ include NOTICE
@@ -0,0 +1,14 @@
1
+ Turing Engine
2
+ Licensed under the Business Source License 1.1 (see LICENSE), except the third-party code listed below, which keeps
3
+ its own license.
4
+
5
+ --------------------------------------------------------------------------------
6
+
7
+ csrc/marlin/ : Marlin mixed-precision (W4A16) GEMM kernel
8
+ Vendored from vLLM v0.31.0 (https://github.com/vllm-project/vllm): csrc/libtorch_stable/quantization/marlin/ and
9
+ csrc/core/scalar_type.hpp.
10
+ Copyright contributors to the vLLM project. Marlin: Copyright (C) 2024 Elias Frantar (IST-DASLab,
11
+ https://github.com/IST-DASLab/marlin), modified by Neural Magic and the vLLM project.
12
+ Licensed under the Apache License, Version 2.0 (csrc/marlin/LICENSE). Each file's header says whether Turing Engine
13
+ modified it and how. turing/kernels/marlin.py ports layout logic from vLLM's
14
+ vllm/model_executor/layers/quantization/utils/marlin_utils.py (Apache-2.0).
@@ -0,0 +1,288 @@
1
+ Metadata-Version: 2.4
2
+ Name: turing-engine
3
+ Version: 2.0.0
4
+ Summary: Turing Engine: Subspace-Compressed High-Performance LLM Inference & Serving Runtime for 70B+ LLMs on single consumer GPUs
5
+ Author: Ishan Gupta
6
+ Author-email: Ishan Gupta <support@intutic.ai>
7
+ Requires-Python: >=3.10
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ License-File: NOTICE
11
+ Requires-Dist: torch>=2.0.0
12
+ Requires-Dist: numpy>=1.22.0
13
+ Requires-Dist: fastapi>=0.100.0
14
+ Requires-Dist: uvicorn>=0.22.0
15
+ Requires-Dist: pydantic>=2.0.0
16
+ Requires-Dist: pybind11>=2.10.0
17
+ Requires-Dist: requests>=2.28.0
18
+ Requires-Dist: httpx>=0.24.0
19
+ Requires-Dist: transformers>=4.38.0
20
+ Requires-Dist: jinja2>=3.1.0
21
+ Requires-Dist: huggingface-hub>=0.20.0
22
+ Provides-Extra: dev
23
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
24
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
25
+ Requires-Dist: wheel; extra == "dev"
26
+ Requires-Dist: build; extra == "dev"
27
+ Requires-Dist: pyzmq>=24.0.0; extra == "dev"
28
+ Requires-Dist: msgpack>=1.0; extra == "dev"
29
+ Requires-Dist: prometheus-client>=0.17; extra == "dev"
30
+ Requires-Dist: httpx2>=2.0; python_version >= "3.10" and extra == "dev"
31
+ Requires-Dist: langchain-core>=0.3; extra == "dev"
32
+ Requires-Dist: gguf>=0.19.0; extra == "dev"
33
+ Requires-Dist: datasets>=2.18; extra == "dev"
34
+ Requires-Dist: llguidance>=1.9.0; extra == "dev"
35
+ Requires-Dist: jsonschema>=4.0; extra == "dev"
36
+ Provides-Extra: structured
37
+ Requires-Dist: llguidance>=1.9.0; extra == "structured"
38
+ Requires-Dist: jsonschema>=4.0; extra == "structured"
39
+ Provides-Extra: llmd
40
+ Requires-Dist: pyzmq>=24.0.0; extra == "llmd"
41
+ Requires-Dist: msgpack>=1.0; extra == "llmd"
42
+ Dynamic: author
43
+ Dynamic: license-file
44
+ Dynamic: requires-python
45
+
46
+ # ⚡ Turing Engine
47
+
48
+ **A small, readable LLM inference server for testing KV-cache and quantization ideas against real models, where every
49
+ number in the docs comes from a committed results file.**
50
+
51
+ [![Docs: Live](https://img.shields.io/badge/Documentation-intutic.github.io%2Fturing-blue.svg)](https://intutic.github.io/turing/)
52
+ [![Release: v2.0.0](https://img.shields.io/badge/Release-v2.0.0-blue.svg)](CHANGELOG.md)
53
+ [![License: BSL 1.1](https://img.shields.io/badge/License-BSL%201.1-green.svg)](LICENSE)
54
+ [![Tests: 1108](https://img.shields.io/badge/Tests-1108-brightgreen.svg)](https://github.com/intutic/turing/actions)
55
+
56
+ [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/intutic/turing/blob/master/demo/turing_quickstart_colab.ipynb)
57
+
58
+ ---
59
+
60
+ ## Is it faster than vLLM or llama.cpp?
61
+
62
+ Mostly no; in a few measured settings, yes. On one NVIDIA L4, same model and prompts (Qwen2.5-1.5B-Instruct,
63
+ 512-token prompts, 256 new tokens; `results_4bit_speed_cuda.json`, `results_4bit_quality_*_cuda.json`):
64
+
65
+ <!-- table:vs_4bit -->
66
+ | Setting | Batch 1, tok/s | Batch 8, tok/s | Batch 64, tok/s | GSM8K (n=500) |
67
+ | :--- | :---: | :---: | :---: | :---: |
68
+ | llama.cpp Q4_K_M | 180 | 752 | 2,157 | 52.4% ± 2.2% |
69
+ | vLLM GPTQ-Int4 (Qwen's checkpoint) | 171 | 1,093 | 3,065 | 50.2% ± 2.2% |
70
+ | Turing GPTQ | 155 | 1,035 | 2,739 | 50.4% ± 2.2% |
71
+ | Turing GPTQ + 4-bit LM head (opt-in) | 197 | 1,266 | 2,961 | 51.8% ± 2.2% |
72
+ | Turing GPTQ + TEAL 25% | 107 | 953 | 2,600 | 46.2% ± 2.2% |
73
+ | Turing GPTQ + TEAL 40% | 112 | 960 | 2,614 | 42.0% ± 2.2% |
74
+ | vLLM fp16 (reference) | 75 | 537 | 2,235 | — |
75
+ | Turing fp16 (reference) | 73 | 530 | 2,152 | — |
76
+ <!-- /table -->
77
+
78
+ * **fp16:** vLLM is 1.01–1.04× faster at batch 1–64. On SmolLM2 at 1,024-token prompts Turing reaches 88–103% of
79
+ vLLM's throughput, and its first token at batch 64 on SmolLM2-1.7B takes 2.3× as long (6.7 s against 2.9 s).
80
+ * **4 bits, fp16 LM head (default):** vLLM is 1.06–1.12× faster. llama.cpp is 1.17× faster at batch 1; Turing is
81
+ faster than llama.cpp at batch 8 and 64 (1.38× and 1.27×).
82
+ * **4 bits with the opt-in 4-bit LM head** (`--quantize-lm-head`): Turing is 1.15–1.16× vLLM at batch 1 and 8 and 1.09×
83
+ llama.cpp at batch 1; vLLM stays 1.04× faster at batch 64. This quantizes one more matrix than vLLM's GPTQ
84
+ checkpoint does; GSM8K 51.8% against vLLM's 50.2% (each ± 2.2%).
85
+ * **16K-token prompts, fp16 KV at equal memory:** Turing is 1.0–1.22× faster per request than vLLM, more at larger
86
+ batches. vLLM's fp8 cache with layer 0 kept in fp16 (the setting that is correct on this model) is 1.3–1.4×
87
+ faster than Turing's int8 at equal quality.
88
+ * **Cold start:** from process start to first token Turing takes 25.4 s from a cold page cache and 10.0 s warm,
89
+ against vLLM's 51.7 s and 34.2 s. vLLM was measured in an earlier session, where Turing's code at the time took
90
+ 27.4 s and 12.1 s (1.9–2.8× sooner); llama.cpp with its 4-bit GGUF takes 7.1 s and 1.3 s
91
+ (`results_cold_start_*_cuda.json`).
92
+
93
+ Details and every other setting are in the [comparison](docs/comparison.md). For production serving use vLLM, SGLang
94
+ or TensorRT-LLM; on a laptop, llama.cpp or Ollama.
95
+
96
+ ## What it is good for
97
+
98
+ * **Low-bit KV caches that do not silently break the model.** When a pool stores KV in int8 or int4, Turing measures
99
+ at startup which layers that format damages (each layer's K and V are round-tripped alone and the change in the
100
+ next-token distribution is measured on random tokens, in a few seconds) and keeps those layers in the model's
101
+ dtype; outlier key channels are scaled down for int4. On Qwen2.5-1.5B-Instruct vLLM's default fp8, per-token fp8
102
+ and per-token int4 caches collapse (GSM8K 0.6–2.4%); Turing's int8 and int4 keep it working with no setting:
103
+
104
+ <!-- table:vs_kv -->
105
+ | KV cache | Layers kept in bf16 | GSM8K | Pass-key 2K–32K | ΔNLL vs bf16 | s/request (16K, B=128) |
106
+ | :--- | :---: | :---: | :---: | :---: | :---: |
107
+ | Turing bf16 (reference) | — | 57.2% | 100.0% | — | 2.05 |
108
+ | Turing int8 | — | 58.2% | 100.0% | +0.003 ± 0.002 | 2.32 |
109
+ | Turing int4 | automatic | 52.8% | 100.0% | +0.020 ± 0.005 | 2.95 |
110
+ | vLLM bf16 (reference) | — | 57.4% | 100.0% | — | 2.51 |
111
+ | vLLM fp8 | — | 2.4% | 5.0% | +2.286 ± 0.394 | 1.66 |
112
+ | vLLM fp8 | layer 0 (manual) | 56.8% | 100.0% | +0.013 ± 0.003 | 1.73 |
113
+ | vLLM fp8_per_token_head | — | 0.6% | 0.0% | +2.404 ± 0.364 | — |
114
+ | vLLM int8_per_token_head | — | 41.4% | 100.0% | +0.023 ± 0.007 | 4.72 |
115
+ | vLLM int4_per_token_head | — | 0.6% | 0.0% | +8.127 ± 0.495 | 4.41 |
116
+ | vLLM int4_per_token_head | layer 0 (manual) | 47.8% | 100.0% | +0.058 ± 0.010 | 4.30 |
117
+ | vLLM turboquant_k8v4 | — | 52.0% | 100.0% | +0.001 ± 0.001 | — |
118
+ <!-- /table -->
119
+
120
+ vLLM fp8 with layer 0 skipped *by hand* matches Turing's quality at 0.6–0.75× Turing's time per request, which is the
121
+ point: the calibration finds that layer automatically. It is also packaged on its own for vLLM users, under
122
+ Apache-2.0: [`packages/kv-layer-guard`](packages/kv-layer-guard). Validated on six instruct models (Qwen2.5 1.5B
123
+ and 7B, Llama 3.2, Gemma 2, Phi-3.5, Mistral), including one limit it does not catch
124
+ ([benchmarks §2](docs/benchmarks.md#2-kv-cache-quality-and-the-layers-it-keeps)).
125
+ * **Measured correctness.** The exact model reproduces HuggingFace's logits on 16 model families in the tests, 13 of them
126
+ also on real checkpoints ([models & hardware](docs/models_and_hardware.md)); 13 real GGUF files agree with llama.cpp.
127
+ * **A codebase small enough to change.** Paged KV pool, Triton decode kernels, GPTQ, TEAL sparsity, prefix caching,
128
+ speculative decoding and the OpenAI, Anthropic and Ollama APIs are a few Python modules and kernels, with a
129
+ standalone C++ engine beside them. The eval scripts (`scripts/eval_kv_quality.py`, `turing eval-accuracy`,
130
+ `turing eval-niah`, the Turing-vs-vLLM and llama.cpp benchmarks) run any idea against real models.
131
+
132
+ **Not measured:** multi-GPU (tensor and pipeline parallelism are tested as CPU processes only), models larger than
133
+ Qwen2.5-7B (7.6B), SGLang and TensorRT-LLM.
134
+
135
+ ---
136
+
137
+ ## Quickstart
138
+
139
+ ### 1. Install from source
140
+ ```bash
141
+ git clone https://github.com/intutic/turing.git && cd turing
142
+ pip install -e . # builds the C++ extension
143
+ pip install -e ".[structured]" # optional: JSON-schema and tool_choice enforcement (llguidance)
144
+ ```
145
+ The package is not on PyPI yet; the release workflow (`.github/workflows/release.yml`) publishes wheels and Docker
146
+ images when a version tag is pushed. Docker: [docs/docker.md](docs/docker.md).
147
+
148
+ ### 2. Chat in the terminal
149
+ ```bash
150
+ turing chat --model smollm2 # alias for HuggingFaceTB/SmolLM2-135M
151
+ turing chat --model Qwen/Qwen2.5-0.5B-Instruct
152
+ turing chat --model ./models/qwen2.5-0.5b-instruct-q8_0.gguf # llama.cpp GGUF, no conversion
153
+ ```
154
+
155
+ ### 3. Serve OpenAI, Anthropic and Ollama APIs on one port
156
+ ```bash
157
+ turing serve --model Qwen/Qwen2.5-7B-Instruct --port 8000
158
+ ```
159
+ OpenAI (`/v1/chat/completions`, `/v1/completions`, `/v1/embeddings`), Anthropic (`/v1/messages`) and Ollama
160
+ (`/api/chat`, `/api/generate`, `/api/pull`, …) clients can point at `http://localhost:8000`. The server listens on
161
+ `0.0.0.0` by default and needs no key unless started with `--api-key` (or `TURING_API_KEY`).
162
+
163
+ ### 4. Quantize to 4-bit once, serve the result
164
+ ```bash
165
+ turing convert --model Qwen/Qwen2.5-7B-Instruct --output ./qwen7b-gptq --method gptq
166
+ turing serve --model ./qwen7b-gptq
167
+ ```
168
+
169
+ ### 5. Turing DSL
170
+ ```python
171
+ import turing
172
+
173
+ @turing.chain(model="smollm2", device="auto")
174
+ def three_answers(question: str):
175
+ turing.gen(f"Question: {question}\nThink step by step.", max_tokens=64)
176
+ branches = turing.fork(3, temperature=0.8) # the context so far is prefilled once and shared
177
+ for i, b in enumerate(branches):
178
+ b.gen(f"\nAnswer {i + 1}:", max_tokens=64)
179
+ return turing.join(branches, strategy="best") # highest mean log-probability
180
+ ```
181
+
182
+ ### 6. Standalone C++ engine (`turing-cli`)
183
+ ```bash
184
+ cmake -B build && cmake --build build
185
+ ./build/turing-cli generate --model ./models/llama-3.2-1b-instruct-f16.gguf --prompt "Hello"
186
+ ./build/turing-cli serve --model ./models/llama-3.2-1b-instruct-f16.gguf --port 8000 # binds 127.0.0.1
187
+ ```
188
+ It runs Llama-layout GGUF models (RMSNorm, SwiGLU, RoPE, grouped-query attention) on the CPU with AVX2 or NEON, with
189
+ an optional int8 KV cache (`--kv-cache-dtype int8`).
190
+
191
+ ### 7. Tensor and pipeline parallelism
192
+ ```bash
193
+ ./scripts/launch_distributed.sh Qwen/Qwen2.5-7B-Instruct 2 2 # MODEL TP PP, via torchrun; rank 0 serves HTTP
194
+ ```
195
+ Sharded weights and KV pages over `torch.distributed`. The tests run TP 2/4, PP 2 and TP 2 × PP 2 as CPU (gloo)
196
+ processes and compare logits with a single process; no multi-GPU (NCCL) run has been recorded.
197
+
198
+ ---
199
+
200
+ ## Models
201
+
202
+ `tests/test_hf_parity.py` checks prefill, chunked prefill, decode and batched decode against HuggingFace
203
+ (atol 1e-3) for 25 configurations of these model types: **llama**, **mistral** (sliding window), **qwen2**,
204
+ **qwen3**, **gemma**, **gemma2** (soft-capping), **gemma3_text** (local/global RoPE), **phi** (Phi-2), **phi3** (incl.
205
+ LongRoPE), **gpt2**, **opt** (incl. post-LN and projected embeddings), **gpt_neox**, **mixtral**, **qwen2_moe**,
206
+ **qwen3_moe** and **olmoe**. RoPE scaling types: default, linear, dynamic, YaRN, LongRoPE, Llama 3 and proportional.
207
+ Any other architecture is refused before download (`hf_loader.FAMILIES`, `ArchitectureRegistry`); weights never fall
208
+ back to random values. Every family except OPT also loads from GGUF (Mistral and Mixtral through llama.cpp's
209
+ `llama` architecture). Details: [models & hardware](docs/models_and_hardware.md).
210
+
211
+ ## Hardware
212
+
213
+ Recorded runs exist for an NVIDIA L4 (CUDA, Triton kernels, CUDA graphs), an Apple M4 Pro (MPS) and CPUs. `--device`
214
+ also accepts `rocm` (PyTorch's HIP build) and the auto-detection picks `xpu` or `vulkan` when PyTorch reports them,
215
+ but none of those has been run.
216
+
217
+ ---
218
+
219
+ ## Features
220
+
221
+ | Area | What the code does |
222
+ | :--- | :--- |
223
+ | KV cache | One paged pool per model (16-token pages), `native`/`int8`/`int4` storage with the layers that format damages kept in the model dtype (chosen at startup), copy-on-write forks; Quest page selection (`--kv-page-budget`), also inside CUDA graphs |
224
+ | Prefix caching | Automatic: full pages indexed by chained token hashes, reused copy-on-write, evicted LRU (`--no-prefix-caching`) |
225
+ | Speculative decoding | Prompt lookup (no draft model), `--draft-tokens` (default 4); output distribution equals plain decoding for greedy and sampling |
226
+ | Weights | fp32/fp16/bf16; 4-bit GPTQ or RTN (`turing convert`, `--quantization`); TEAL-style activation sparsity in batch-1 decode on CUDA (`--activation-sparsity`, off by default) |
227
+ | LoRA | Several PEFT adapters at once (`--lora NAME=PATH`), chosen per request by `model: "base:NAME"` or `X-Turing-Adapter` |
228
+ | API | Chat templates, tools (OpenAI and Anthropic; Hermes, Mistral and Llama 3 call formats), reasoning (`reasoning_content`, Anthropic thinking blocks, effort budgets), JSON schema by token-level constrained decoding, stop strings, usage with cached tokens |
229
+ | Traffic | Admission control sized to the KV pool and three QoS lanes, on by default (429/503 with `Retry-After`) |
230
+ | Other endpoints | Embeddings, rerank, `/v1/extract`, render endpoints, Prometheus `/metrics`, llm-d KV events |
231
+ | Distributed | Tensor and pipeline parallelism (torchrun); prefill/decode disaggregation over TCP (`--prefill-worker`, `--prefill-server`) |
232
+ | Evals | `turing eval-accuracy` (GSM8K exact match) and `turing eval-niah` (pass-key retrieval), through the engine on real weights |
233
+
234
+ The repository also holds research components outside the serving path: cross-model KV transfer, `clean_base`
235
+ lineage, k-slot pooling, an MoE expert-offload runner, hybrid linear/softmax attention (needs a model trained with it)
236
+ and untrained Matryoshka draft heads. What was measured on real models, including what did not work, is in
237
+ [research findings](docs/measured-differentiators.md).
238
+
239
+ ---
240
+
241
+ ## CLI
242
+
243
+ ```bash
244
+ turing serve --model <id|.gguf|.tgate4 dir> [--port 8000] # HTTP server
245
+ turing chat --model <id> # terminal chat
246
+ turing generate --model gpt2 --prompt "Artificial intelligence is"
247
+ turing convert --model <hf id> --output <dir> [--method gptq|rtn]
248
+ turing eval-accuracy --model <id> --samples 100 # GSM8K, k-shot greedy
249
+ turing eval-niah --model <id> --context-len 1024 4096 # pass-key retrieval
250
+ turing info # devices and runtime
251
+ ```
252
+
253
+ ## Client SDKs
254
+
255
+ ```python
256
+ from openai import OpenAI
257
+ client = OpenAI(base_url="http://localhost:8000/v1", api_key="unused")
258
+ r = client.chat.completions.create(model="Qwen/Qwen2.5-7B-Instruct",
259
+ messages=[{"role": "user", "content": "Write a binary search in Python."}])
260
+ print(r.choices[0].message.content)
261
+
262
+ import anthropic
263
+ client = anthropic.Anthropic(base_url="http://localhost:8000", api_key="unused")
264
+ m = client.messages.create(model="Qwen/Qwen2.5-7B-Instruct", max_tokens=128,
265
+ messages=[{"role": "user", "content": "Hello"}])
266
+ print(m.content[0].text)
267
+
268
+ import ollama
269
+ client = ollama.Client(host="http://localhost:8000")
270
+ print(client.chat(model="Qwen/Qwen2.5-7B-Instruct", messages=[{"role": "user", "content": "Hello"}])["message"]["content"])
271
+ ```
272
+
273
+ ---
274
+
275
+ ## Documentation
276
+
277
+ * [Quickstart](https://intutic.github.io/turing/quickstart/) · [Models & hardware](https://intutic.github.io/turing/models_and_hardware/) · [Serving & API](https://intutic.github.io/turing/serving/)
278
+ * [Architecture](https://intutic.github.io/turing/architecture/) · [Benchmarks](https://intutic.github.io/turing/benchmarks/) · [Claims audit](https://intutic.github.io/turing/claims-audit/)
279
+ * [Comparison](https://intutic.github.io/turing/comparison/) · [Docker](https://intutic.github.io/turing/docker/) · [Kubernetes & llm-d](https://intutic.github.io/turing/llmd-integration/) · [Integrations](https://intutic.github.io/turing/integrations/) · [Licensing](https://intutic.github.io/turing/licensing/)
280
+
281
+ ---
282
+
283
+ ## 📄 License
284
+
285
+ Turing Engine is licensed under the **Business Source License 1.1 (BSL 1.1)**.
286
+ * **Free for non-production use**: development, local testing, academic research, personal single-GPU workstations and benchmarking ([`LICENSE`](LICENSE), Additional Use Grant). Production use (multi-GPU clusters, commercial hosting, revenue-generating API traffic) needs a separate commercial license.
287
+ * `packages/kv-layer-guard/` (the KV layer calibration, usable with vLLM) is under the **Apache License 2.0** now.
288
+ * Converts automatically to **Apache 2.0** on **August 24, 2030** or the fourth anniversary of the first public release (as [`LICENSE`](LICENSE) §3 states).
@@ -0,0 +1,243 @@
1
+ # ⚡ Turing Engine
2
+
3
+ **A small, readable LLM inference server for testing KV-cache and quantization ideas against real models, where every
4
+ number in the docs comes from a committed results file.**
5
+
6
+ [![Docs: Live](https://img.shields.io/badge/Documentation-intutic.github.io%2Fturing-blue.svg)](https://intutic.github.io/turing/)
7
+ [![Release: v2.0.0](https://img.shields.io/badge/Release-v2.0.0-blue.svg)](CHANGELOG.md)
8
+ [![License: BSL 1.1](https://img.shields.io/badge/License-BSL%201.1-green.svg)](LICENSE)
9
+ [![Tests: 1108](https://img.shields.io/badge/Tests-1108-brightgreen.svg)](https://github.com/intutic/turing/actions)
10
+
11
+ [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/intutic/turing/blob/master/demo/turing_quickstart_colab.ipynb)
12
+
13
+ ---
14
+
15
+ ## Is it faster than vLLM or llama.cpp?
16
+
17
+ Mostly no; in a few measured settings, yes. On one NVIDIA L4, same model and prompts (Qwen2.5-1.5B-Instruct,
18
+ 512-token prompts, 256 new tokens; `results_4bit_speed_cuda.json`, `results_4bit_quality_*_cuda.json`):
19
+
20
+ <!-- table:vs_4bit -->
21
+ | Setting | Batch 1, tok/s | Batch 8, tok/s | Batch 64, tok/s | GSM8K (n=500) |
22
+ | :--- | :---: | :---: | :---: | :---: |
23
+ | llama.cpp Q4_K_M | 180 | 752 | 2,157 | 52.4% ± 2.2% |
24
+ | vLLM GPTQ-Int4 (Qwen's checkpoint) | 171 | 1,093 | 3,065 | 50.2% ± 2.2% |
25
+ | Turing GPTQ | 155 | 1,035 | 2,739 | 50.4% ± 2.2% |
26
+ | Turing GPTQ + 4-bit LM head (opt-in) | 197 | 1,266 | 2,961 | 51.8% ± 2.2% |
27
+ | Turing GPTQ + TEAL 25% | 107 | 953 | 2,600 | 46.2% ± 2.2% |
28
+ | Turing GPTQ + TEAL 40% | 112 | 960 | 2,614 | 42.0% ± 2.2% |
29
+ | vLLM fp16 (reference) | 75 | 537 | 2,235 | — |
30
+ | Turing fp16 (reference) | 73 | 530 | 2,152 | — |
31
+ <!-- /table -->
32
+
33
+ * **fp16:** vLLM is 1.01–1.04× faster at batch 1–64. On SmolLM2 at 1,024-token prompts Turing reaches 88–103% of
34
+ vLLM's throughput, and its first token at batch 64 on SmolLM2-1.7B takes 2.3× as long (6.7 s against 2.9 s).
35
+ * **4 bits, fp16 LM head (default):** vLLM is 1.06–1.12× faster. llama.cpp is 1.17× faster at batch 1; Turing is
36
+ faster than llama.cpp at batch 8 and 64 (1.38× and 1.27×).
37
+ * **4 bits with the opt-in 4-bit LM head** (`--quantize-lm-head`): Turing is 1.15–1.16× vLLM at batch 1 and 8 and 1.09×
38
+ llama.cpp at batch 1; vLLM stays 1.04× faster at batch 64. This quantizes one more matrix than vLLM's GPTQ
39
+ checkpoint does; GSM8K 51.8% against vLLM's 50.2% (each ± 2.2%).
40
+ * **16K-token prompts, fp16 KV at equal memory:** Turing is 1.0–1.22× faster per request than vLLM, more at larger
41
+ batches. vLLM's fp8 cache with layer 0 kept in fp16 (the setting that is correct on this model) is 1.3–1.4×
42
+ faster than Turing's int8 at equal quality.
43
+ * **Cold start:** from process start to first token Turing takes 25.4 s from a cold page cache and 10.0 s warm,
44
+ against vLLM's 51.7 s and 34.2 s. vLLM was measured in an earlier session, where Turing's code at the time took
45
+ 27.4 s and 12.1 s (1.9–2.8× sooner); llama.cpp with its 4-bit GGUF takes 7.1 s and 1.3 s
46
+ (`results_cold_start_*_cuda.json`).
47
+
48
+ Details and every other setting are in the [comparison](docs/comparison.md). For production serving use vLLM, SGLang
49
+ or TensorRT-LLM; on a laptop, llama.cpp or Ollama.
50
+
51
+ ## What it is good for
52
+
53
+ * **Low-bit KV caches that do not silently break the model.** When a pool stores KV in int8 or int4, Turing measures
54
+ at startup which layers that format damages (each layer's K and V are round-tripped alone and the change in the
55
+ next-token distribution is measured on random tokens, in a few seconds) and keeps those layers in the model's
56
+ dtype; outlier key channels are scaled down for int4. On Qwen2.5-1.5B-Instruct vLLM's default fp8, per-token fp8
57
+ and per-token int4 caches collapse (GSM8K 0.6–2.4%); Turing's int8 and int4 keep it working with no setting:
58
+
59
+ <!-- table:vs_kv -->
60
+ | KV cache | Layers kept in bf16 | GSM8K | Pass-key 2K–32K | ΔNLL vs bf16 | s/request (16K, B=128) |
61
+ | :--- | :---: | :---: | :---: | :---: | :---: |
62
+ | Turing bf16 (reference) | — | 57.2% | 100.0% | — | 2.05 |
63
+ | Turing int8 | — | 58.2% | 100.0% | +0.003 ± 0.002 | 2.32 |
64
+ | Turing int4 | automatic | 52.8% | 100.0% | +0.020 ± 0.005 | 2.95 |
65
+ | vLLM bf16 (reference) | — | 57.4% | 100.0% | — | 2.51 |
66
+ | vLLM fp8 | — | 2.4% | 5.0% | +2.286 ± 0.394 | 1.66 |
67
+ | vLLM fp8 | layer 0 (manual) | 56.8% | 100.0% | +0.013 ± 0.003 | 1.73 |
68
+ | vLLM fp8_per_token_head | — | 0.6% | 0.0% | +2.404 ± 0.364 | — |
69
+ | vLLM int8_per_token_head | — | 41.4% | 100.0% | +0.023 ± 0.007 | 4.72 |
70
+ | vLLM int4_per_token_head | — | 0.6% | 0.0% | +8.127 ± 0.495 | 4.41 |
71
+ | vLLM int4_per_token_head | layer 0 (manual) | 47.8% | 100.0% | +0.058 ± 0.010 | 4.30 |
72
+ | vLLM turboquant_k8v4 | — | 52.0% | 100.0% | +0.001 ± 0.001 | — |
73
+ <!-- /table -->
74
+
75
+ vLLM fp8 with layer 0 skipped *by hand* matches Turing's quality at 0.6–0.75× Turing's time per request, which is the
76
+ point: the calibration finds that layer automatically. It is also packaged on its own for vLLM users, under
77
+ Apache-2.0: [`packages/kv-layer-guard`](packages/kv-layer-guard). Validated on six instruct models (Qwen2.5 1.5B
78
+ and 7B, Llama 3.2, Gemma 2, Phi-3.5, Mistral), including one limit it does not catch
79
+ ([benchmarks §2](docs/benchmarks.md#2-kv-cache-quality-and-the-layers-it-keeps)).
80
+ * **Measured correctness.** The exact model reproduces HuggingFace's logits on 16 model families in the tests, 13 of them
81
+ also on real checkpoints ([models & hardware](docs/models_and_hardware.md)); 13 real GGUF files agree with llama.cpp.
82
+ * **A codebase small enough to change.** Paged KV pool, Triton decode kernels, GPTQ, TEAL sparsity, prefix caching,
83
+ speculative decoding and the OpenAI, Anthropic and Ollama APIs are a few Python modules and kernels, with a
84
+ standalone C++ engine beside them. The eval scripts (`scripts/eval_kv_quality.py`, `turing eval-accuracy`,
85
+ `turing eval-niah`, the Turing-vs-vLLM and llama.cpp benchmarks) run any idea against real models.
86
+
87
+ **Not measured:** multi-GPU (tensor and pipeline parallelism are tested as CPU processes only), models larger than
88
+ Qwen2.5-7B (7.6B), SGLang and TensorRT-LLM.
89
+
90
+ ---
91
+
92
+ ## Quickstart
93
+
94
+ ### 1. Install from source
95
+ ```bash
96
+ git clone https://github.com/intutic/turing.git && cd turing
97
+ pip install -e . # builds the C++ extension
98
+ pip install -e ".[structured]" # optional: JSON-schema and tool_choice enforcement (llguidance)
99
+ ```
100
+ The package is not on PyPI yet; the release workflow (`.github/workflows/release.yml`) publishes wheels and Docker
101
+ images when a version tag is pushed. Docker: [docs/docker.md](docs/docker.md).
102
+
103
+ ### 2. Chat in the terminal
104
+ ```bash
105
+ turing chat --model smollm2 # alias for HuggingFaceTB/SmolLM2-135M
106
+ turing chat --model Qwen/Qwen2.5-0.5B-Instruct
107
+ turing chat --model ./models/qwen2.5-0.5b-instruct-q8_0.gguf # llama.cpp GGUF, no conversion
108
+ ```
109
+
110
+ ### 3. Serve OpenAI, Anthropic and Ollama APIs on one port
111
+ ```bash
112
+ turing serve --model Qwen/Qwen2.5-7B-Instruct --port 8000
113
+ ```
114
+ OpenAI (`/v1/chat/completions`, `/v1/completions`, `/v1/embeddings`), Anthropic (`/v1/messages`) and Ollama
115
+ (`/api/chat`, `/api/generate`, `/api/pull`, …) clients can point at `http://localhost:8000`. The server listens on
116
+ `0.0.0.0` by default and needs no key unless started with `--api-key` (or `TURING_API_KEY`).
117
+
118
+ ### 4. Quantize to 4-bit once, serve the result
119
+ ```bash
120
+ turing convert --model Qwen/Qwen2.5-7B-Instruct --output ./qwen7b-gptq --method gptq
121
+ turing serve --model ./qwen7b-gptq
122
+ ```
123
+
124
+ ### 5. Turing DSL
125
+ ```python
126
+ import turing
127
+
128
+ @turing.chain(model="smollm2", device="auto")
129
+ def three_answers(question: str):
130
+ turing.gen(f"Question: {question}\nThink step by step.", max_tokens=64)
131
+ branches = turing.fork(3, temperature=0.8) # the context so far is prefilled once and shared
132
+ for i, b in enumerate(branches):
133
+ b.gen(f"\nAnswer {i + 1}:", max_tokens=64)
134
+ return turing.join(branches, strategy="best") # highest mean log-probability
135
+ ```
136
+
137
+ ### 6. Standalone C++ engine (`turing-cli`)
138
+ ```bash
139
+ cmake -B build && cmake --build build
140
+ ./build/turing-cli generate --model ./models/llama-3.2-1b-instruct-f16.gguf --prompt "Hello"
141
+ ./build/turing-cli serve --model ./models/llama-3.2-1b-instruct-f16.gguf --port 8000 # binds 127.0.0.1
142
+ ```
143
+ It runs Llama-layout GGUF models (RMSNorm, SwiGLU, RoPE, grouped-query attention) on the CPU with AVX2 or NEON, with
144
+ an optional int8 KV cache (`--kv-cache-dtype int8`).
145
+
146
+ ### 7. Tensor and pipeline parallelism
147
+ ```bash
148
+ ./scripts/launch_distributed.sh Qwen/Qwen2.5-7B-Instruct 2 2 # MODEL TP PP, via torchrun; rank 0 serves HTTP
149
+ ```
150
+ Sharded weights and KV pages over `torch.distributed`. The tests run TP 2/4, PP 2 and TP 2 × PP 2 as CPU (gloo)
151
+ processes and compare logits with a single process; no multi-GPU (NCCL) run has been recorded.
152
+
153
+ ---
154
+
155
+ ## Models
156
+
157
+ `tests/test_hf_parity.py` checks prefill, chunked prefill, decode and batched decode against HuggingFace
158
+ (atol 1e-3) for 25 configurations of these model types: **llama**, **mistral** (sliding window), **qwen2**,
159
+ **qwen3**, **gemma**, **gemma2** (soft-capping), **gemma3_text** (local/global RoPE), **phi** (Phi-2), **phi3** (incl.
160
+ LongRoPE), **gpt2**, **opt** (incl. post-LN and projected embeddings), **gpt_neox**, **mixtral**, **qwen2_moe**,
161
+ **qwen3_moe** and **olmoe**. RoPE scaling types: default, linear, dynamic, YaRN, LongRoPE, Llama 3 and proportional.
162
+ Any other architecture is refused before download (`hf_loader.FAMILIES`, `ArchitectureRegistry`); weights never fall
163
+ back to random values. Every family except OPT also loads from GGUF (Mistral and Mixtral through llama.cpp's
164
+ `llama` architecture). Details: [models & hardware](docs/models_and_hardware.md).
165
+
166
+ ## Hardware
167
+
168
+ Recorded runs exist for an NVIDIA L4 (CUDA, Triton kernels, CUDA graphs), an Apple M4 Pro (MPS) and CPUs. `--device`
169
+ also accepts `rocm` (PyTorch's HIP build) and the auto-detection picks `xpu` or `vulkan` when PyTorch reports them,
170
+ but none of those has been run.
171
+
172
+ ---
173
+
174
+ ## Features
175
+
176
+ | Area | What the code does |
177
+ | :--- | :--- |
178
+ | KV cache | One paged pool per model (16-token pages), `native`/`int8`/`int4` storage with the layers that format damages kept in the model dtype (chosen at startup), copy-on-write forks; Quest page selection (`--kv-page-budget`), also inside CUDA graphs |
179
+ | Prefix caching | Automatic: full pages indexed by chained token hashes, reused copy-on-write, evicted LRU (`--no-prefix-caching`) |
180
+ | Speculative decoding | Prompt lookup (no draft model), `--draft-tokens` (default 4); output distribution equals plain decoding for greedy and sampling |
181
+ | Weights | fp32/fp16/bf16; 4-bit GPTQ or RTN (`turing convert`, `--quantization`); TEAL-style activation sparsity in batch-1 decode on CUDA (`--activation-sparsity`, off by default) |
182
+ | LoRA | Several PEFT adapters at once (`--lora NAME=PATH`), chosen per request by `model: "base:NAME"` or `X-Turing-Adapter` |
183
+ | API | Chat templates, tools (OpenAI and Anthropic; Hermes, Mistral and Llama 3 call formats), reasoning (`reasoning_content`, Anthropic thinking blocks, effort budgets), JSON schema by token-level constrained decoding, stop strings, usage with cached tokens |
184
+ | Traffic | Admission control sized to the KV pool and three QoS lanes, on by default (429/503 with `Retry-After`) |
185
+ | Other endpoints | Embeddings, rerank, `/v1/extract`, render endpoints, Prometheus `/metrics`, llm-d KV events |
186
+ | Distributed | Tensor and pipeline parallelism (torchrun); prefill/decode disaggregation over TCP (`--prefill-worker`, `--prefill-server`) |
187
+ | Evals | `turing eval-accuracy` (GSM8K exact match) and `turing eval-niah` (pass-key retrieval), through the engine on real weights |
188
+
189
+ The repository also holds research components outside the serving path: cross-model KV transfer, `clean_base`
190
+ lineage, k-slot pooling, an MoE expert-offload runner, hybrid linear/softmax attention (needs a model trained with it)
191
+ and untrained Matryoshka draft heads. What was measured on real models, including what did not work, is in
192
+ [research findings](docs/measured-differentiators.md).
193
+
194
+ ---
195
+
196
+ ## CLI
197
+
198
+ ```bash
199
+ turing serve --model <id|.gguf|.tgate4 dir> [--port 8000] # HTTP server
200
+ turing chat --model <id> # terminal chat
201
+ turing generate --model gpt2 --prompt "Artificial intelligence is"
202
+ turing convert --model <hf id> --output <dir> [--method gptq|rtn]
203
+ turing eval-accuracy --model <id> --samples 100 # GSM8K, k-shot greedy
204
+ turing eval-niah --model <id> --context-len 1024 4096 # pass-key retrieval
205
+ turing info # devices and runtime
206
+ ```
207
+
208
+ ## Client SDKs
209
+
210
+ ```python
211
+ from openai import OpenAI
212
+ client = OpenAI(base_url="http://localhost:8000/v1", api_key="unused")
213
+ r = client.chat.completions.create(model="Qwen/Qwen2.5-7B-Instruct",
214
+ messages=[{"role": "user", "content": "Write a binary search in Python."}])
215
+ print(r.choices[0].message.content)
216
+
217
+ import anthropic
218
+ client = anthropic.Anthropic(base_url="http://localhost:8000", api_key="unused")
219
+ m = client.messages.create(model="Qwen/Qwen2.5-7B-Instruct", max_tokens=128,
220
+ messages=[{"role": "user", "content": "Hello"}])
221
+ print(m.content[0].text)
222
+
223
+ import ollama
224
+ client = ollama.Client(host="http://localhost:8000")
225
+ print(client.chat(model="Qwen/Qwen2.5-7B-Instruct", messages=[{"role": "user", "content": "Hello"}])["message"]["content"])
226
+ ```
227
+
228
+ ---
229
+
230
+ ## Documentation
231
+
232
+ * [Quickstart](https://intutic.github.io/turing/quickstart/) · [Models & hardware](https://intutic.github.io/turing/models_and_hardware/) · [Serving & API](https://intutic.github.io/turing/serving/)
233
+ * [Architecture](https://intutic.github.io/turing/architecture/) · [Benchmarks](https://intutic.github.io/turing/benchmarks/) · [Claims audit](https://intutic.github.io/turing/claims-audit/)
234
+ * [Comparison](https://intutic.github.io/turing/comparison/) · [Docker](https://intutic.github.io/turing/docker/) · [Kubernetes & llm-d](https://intutic.github.io/turing/llmd-integration/) · [Integrations](https://intutic.github.io/turing/integrations/) · [Licensing](https://intutic.github.io/turing/licensing/)
235
+
236
+ ---
237
+
238
+ ## 📄 License
239
+
240
+ Turing Engine is licensed under the **Business Source License 1.1 (BSL 1.1)**.
241
+ * **Free for non-production use**: development, local testing, academic research, personal single-GPU workstations and benchmarking ([`LICENSE`](LICENSE), Additional Use Grant). Production use (multi-GPU clusters, commercial hosting, revenue-generating API traffic) needs a separate commercial license.
242
+ * `packages/kv-layer-guard/` (the KV layer calibration, usable with vLLM) is under the **Apache License 2.0** now.
243
+ * Converts automatically to **Apache 2.0** on **August 24, 2030** or the fourth anniversary of the first public release (as [`LICENSE`](LICENSE) §3 states).