economize 0.3.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 (434) hide show
  1. economize-0.3.0/.gitignore +9 -0
  2. economize-0.3.0/CHANGELOG.md +13 -0
  3. economize-0.3.0/LICENSE +201 -0
  4. economize-0.3.0/PKG-INFO +372 -0
  5. economize-0.3.0/README.md +307 -0
  6. economize-0.3.0/docs/ARCHITECTURE.md +1219 -0
  7. economize-0.3.0/docs/CONTRIBUTING.md +53 -0
  8. economize-0.3.0/docs/REPRODUCTION.md +265 -0
  9. economize-0.3.0/docs/depth_kv.md +166 -0
  10. economize-0.3.0/docs/drafters.md +165 -0
  11. economize-0.3.0/docs/ecosystem.md +391 -0
  12. economize-0.3.0/docs/training.md +326 -0
  13. economize-0.3.0/docs/weights.md +278 -0
  14. economize-0.3.0/hub/custom_generate/README.md +77 -0
  15. economize-0.3.0/hub/custom_generate/custom_generate/drafter.py +344 -0
  16. economize-0.3.0/hub/custom_generate/custom_generate/generate.py +228 -0
  17. economize-0.3.0/hub/custom_generate/custom_generate/requirements.txt +3 -0
  18. economize-0.3.0/hub/custom_generate/custom_generate/speculative.py +197 -0
  19. economize-0.3.0/pyproject.toml +152 -0
  20. economize-0.3.0/src/economize/__init__.py +120 -0
  21. economize-0.3.0/src/economize/_deprecation.py +59 -0
  22. economize-0.3.0/src/economize/_version.py +4 -0
  23. economize-0.3.0/src/economize/_wiring.py +22 -0
  24. economize-0.3.0/src/economize/arch/__init__.py +63 -0
  25. economize-0.3.0/src/economize/arch/base.py +594 -0
  26. economize-0.3.0/src/economize/arch/config.py +90 -0
  27. economize-0.3.0/src/economize/arch/families/__init__.py +12 -0
  28. economize-0.3.0/src/economize/arch/families/deepseek_v3.py +16 -0
  29. economize-0.3.0/src/economize/arch/families/gemma.py +13 -0
  30. economize-0.3.0/src/economize/arch/families/gemma2.py +13 -0
  31. economize-0.3.0/src/economize/arch/families/gemma3.py +23 -0
  32. economize-0.3.0/src/economize/arch/families/gemma4.py +136 -0
  33. economize-0.3.0/src/economize/arch/families/gemma4_unified.py +37 -0
  34. economize-0.3.0/src/economize/arch/families/gpt_oss.py +18 -0
  35. economize-0.3.0/src/economize/arch/families/granite.py +23 -0
  36. economize-0.3.0/src/economize/arch/families/llama.py +15 -0
  37. economize-0.3.0/src/economize/arch/families/ministral.py +13 -0
  38. economize-0.3.0/src/economize/arch/families/ministral3.py +16 -0
  39. economize-0.3.0/src/economize/arch/families/mistral.py +18 -0
  40. economize-0.3.0/src/economize/arch/families/mixtral.py +13 -0
  41. economize-0.3.0/src/economize/arch/families/nemotron_h.py +110 -0
  42. economize-0.3.0/src/economize/arch/families/olmo2.py +13 -0
  43. economize-0.3.0/src/economize/arch/families/olmo3.py +13 -0
  44. economize-0.3.0/src/economize/arch/families/olmoe.py +13 -0
  45. economize-0.3.0/src/economize/arch/families/phi3.py +13 -0
  46. economize-0.3.0/src/economize/arch/families/qwen2.py +16 -0
  47. economize-0.3.0/src/economize/arch/families/qwen2_moe.py +15 -0
  48. economize-0.3.0/src/economize/arch/families/qwen3.py +16 -0
  49. economize-0.3.0/src/economize/arch/families/qwen3_5.py +33 -0
  50. economize-0.3.0/src/economize/arch/families/qwen3_moe.py +13 -0
  51. economize-0.3.0/src/economize/arch/families/recurrent.py +34 -0
  52. economize-0.3.0/src/economize/arch/families/smollm3.py +13 -0
  53. economize-0.3.0/src/economize/arch/spec.py +217 -0
  54. economize-0.3.0/src/economize/arch/standard.py +120 -0
  55. economize-0.3.0/src/economize/backends/__init__.py +49 -0
  56. economize-0.3.0/src/economize/backends/drafter.py +32 -0
  57. economize-0.3.0/src/economize/backends/exporters.py +185 -0
  58. economize-0.3.0/src/economize/backends/sglang/__init__.py +47 -0
  59. economize-0.3.0/src/economize/backends/sglang/export.py +40 -0
  60. economize-0.3.0/src/economize/backends/vllm/__init__.py +71 -0
  61. economize-0.3.0/src/economize/backends/vllm/drafters.py +150 -0
  62. economize-0.3.0/src/economize/backends/vllm/export.py +109 -0
  63. economize-0.3.0/src/economize/backends/vllm/jump/__init__.py +34 -0
  64. economize-0.3.0/src/economize/backends/vllm/jump/export.py +98 -0
  65. economize-0.3.0/src/economize/backends/vllm/jump/model.py +414 -0
  66. economize-0.3.0/src/economize/backends/vllm/jump/proposer.py +214 -0
  67. economize-0.3.0/src/economize/backends/vllm/model.py +27 -0
  68. economize-0.3.0/src/economize/backends/vllm/plugin.py +153 -0
  69. economize-0.3.0/src/economize/backends/vllm/proposer.py +20 -0
  70. economize-0.3.0/src/economize/backends/vllm/spec.py +68 -0
  71. economize-0.3.0/src/economize/bench/__init__.py +58 -0
  72. economize-0.3.0/src/economize/bench/cost_model.py +559 -0
  73. economize-0.3.0/src/economize/bench/prompts.py +145 -0
  74. economize-0.3.0/src/economize/bench/shape_readers.py +80 -0
  75. economize-0.3.0/src/economize/bench/timing.py +215 -0
  76. economize-0.3.0/src/economize/compat/__init__.py +12 -0
  77. economize-0.3.0/src/economize/compat/tskip.py +454 -0
  78. economize-0.3.0/src/economize/core/__init__.py +60 -0
  79. economize-0.3.0/src/economize/core/calibration.py +548 -0
  80. economize-0.3.0/src/economize/core/config.py +81 -0
  81. economize-0.3.0/src/economize/core/hub.py +314 -0
  82. economize-0.3.0/src/economize/core/lora_capable.py +29 -0
  83. economize-0.3.0/src/economize/core/model.py +290 -0
  84. economize-0.3.0/src/economize/core/recipe.py +167 -0
  85. economize-0.3.0/src/economize/core/serialization.py +373 -0
  86. economize-0.3.0/src/economize/core/technique.py +183 -0
  87. economize-0.3.0/src/economize/decoding/__init__.py +72 -0
  88. economize-0.3.0/src/economize/decoding/capabilities.py +123 -0
  89. economize-0.3.0/src/economize/decoding/commit.py +166 -0
  90. economize-0.3.0/src/economize/decoding/config.py +92 -0
  91. economize-0.3.0/src/economize/decoding/cost.py +203 -0
  92. economize-0.3.0/src/economize/decoding/drafting.py +65 -0
  93. economize-0.3.0/src/economize/decoding/generation.py +188 -0
  94. economize-0.3.0/src/economize/decoding/graphs.py +171 -0
  95. economize-0.3.0/src/economize/decoding/loop.py +220 -0
  96. economize-0.3.0/src/economize/decoding/passes.py +144 -0
  97. economize-0.3.0/src/economize/decoding/plain.py +73 -0
  98. economize-0.3.0/src/economize/decoding/policies.py +45 -0
  99. economize-0.3.0/src/economize/decoding/protocols.py +401 -0
  100. economize-0.3.0/src/economize/decoding/request.py +252 -0
  101. economize-0.3.0/src/economize/decoding/result.py +44 -0
  102. economize-0.3.0/src/economize/decoding/selectors.py +112 -0
  103. economize-0.3.0/src/economize/decoding/stop.py +40 -0
  104. economize-0.3.0/src/economize/decoding/verifiers.py +413 -0
  105. economize-0.3.0/src/economize/distributed/__init__.py +27 -0
  106. economize-0.3.0/src/economize/distributed/ssd.py +266 -0
  107. economize-0.3.0/src/economize/distributed/tp.py +143 -0
  108. economize-0.3.0/src/economize/distributed/workers.py +334 -0
  109. economize-0.3.0/src/economize/errors.py +58 -0
  110. economize-0.3.0/src/economize/integrations/__init__.py +21 -0
  111. economize-0.3.0/src/economize/integrations/_generation_args.py +223 -0
  112. economize-0.3.0/src/economize/integrations/_scoring.py +111 -0
  113. economize-0.3.0/src/economize/integrations/_trl_common.py +29 -0
  114. economize-0.3.0/src/economize/integrations/compressed_tensors.py +201 -0
  115. economize-0.3.0/src/economize/integrations/generate.py +283 -0
  116. economize-0.3.0/src/economize/integrations/hub.py +98 -0
  117. economize-0.3.0/src/economize/integrations/kernels.py +252 -0
  118. economize-0.3.0/src/economize/integrations/lm_eval.py +205 -0
  119. economize-0.3.0/src/economize/integrations/peft.py +295 -0
  120. economize-0.3.0/src/economize/integrations/quantized.py +39 -0
  121. economize-0.3.0/src/economize/integrations/trl.py +323 -0
  122. economize-0.3.0/src/economize/integrations/trl_vllm.py +445 -0
  123. economize-0.3.0/src/economize/modules/__init__.py +31 -0
  124. economize-0.3.0/src/economize/modules/dtype.py +119 -0
  125. economize-0.3.0/src/economize/modules/kv_cache.py +145 -0
  126. economize-0.3.0/src/economize/modules/lora.py +134 -0
  127. economize-0.3.0/src/economize/modules/norm.py +42 -0
  128. economize-0.3.0/src/economize/modules/readout.py +34 -0
  129. economize-0.3.0/src/economize/modules/rotary.py +164 -0
  130. economize-0.3.0/src/economize/modules/swiglu.py +70 -0
  131. economize-0.3.0/src/economize/py.typed +0 -0
  132. economize-0.3.0/src/economize/registry.py +192 -0
  133. economize-0.3.0/src/economize/runtime/__init__.py +44 -0
  134. economize-0.3.0/src/economize/runtime/cache.py +573 -0
  135. economize-0.3.0/src/economize/runtime/context.py +205 -0
  136. economize-0.3.0/src/economize/runtime/graphs.py +97 -0
  137. economize-0.3.0/src/economize/runtime/mask.py +184 -0
  138. economize-0.3.0/src/economize/runtime/phase.py +52 -0
  139. economize-0.3.0/src/economize/runtime/policy.py +79 -0
  140. economize-0.3.0/src/economize/runtime/runner.py +230 -0
  141. economize-0.3.0/src/economize/runtime/transfer.py +31 -0
  142. economize-0.3.0/src/economize/techniques/__init__.py +28 -0
  143. economize-0.3.0/src/economize/techniques/_drafting/__init__.py +82 -0
  144. economize-0.3.0/src/economize/techniques/_drafting/drafters.py +206 -0
  145. economize-0.3.0/src/economize/techniques/_drafting/formats.py +72 -0
  146. economize-0.3.0/src/economize/techniques/_drafting/head.py +118 -0
  147. economize-0.3.0/src/economize/techniques/_drafting/training.py +40 -0
  148. economize-0.3.0/src/economize/techniques/_drafting/wrapping.py +263 -0
  149. economize-0.3.0/src/economize/techniques/_kv/__init__.py +41 -0
  150. economize-0.3.0/src/economize/techniques/_kv/base.py +79 -0
  151. economize-0.3.0/src/economize/techniques/_kv/wrapper.py +408 -0
  152. economize-0.3.0/src/economize/techniques/_weights/__init__.py +61 -0
  153. economize-0.3.0/src/economize/techniques/_weights/hessian.py +47 -0
  154. economize-0.3.0/src/economize/techniques/_weights/layerwise.py +106 -0
  155. economize-0.3.0/src/economize/techniques/_weights/obs.py +79 -0
  156. economize-0.3.0/src/economize/techniques/_weights/snapshot.py +75 -0
  157. economize-0.3.0/src/economize/techniques/_weights/technique.py +59 -0
  158. economize-0.3.0/src/economize/techniques/_weights/transaction.py +71 -0
  159. economize-0.3.0/src/economize/techniques/draft_model/__init__.py +16 -0
  160. economize-0.3.0/src/economize/techniques/draft_model/config.py +43 -0
  161. economize-0.3.0/src/economize/techniques/draft_model/drafter.py +213 -0
  162. economize-0.3.0/src/economize/techniques/draft_model/technique.py +163 -0
  163. economize-0.3.0/src/economize/techniques/dynamic_depth/__init__.py +149 -0
  164. economize-0.3.0/src/economize/techniques/dynamic_depth/base.py +514 -0
  165. economize-0.3.0/src/economize/techniques/dynamic_depth/calm.py +349 -0
  166. economize-0.3.0/src/economize/techniques/dynamic_depth/flexidepth.py +232 -0
  167. economize-0.3.0/src/economize/techniques/dynamic_depth/gateskip.py +137 -0
  168. economize-0.3.0/src/economize/techniques/dynamic_depth/loradrop.py +244 -0
  169. economize-0.3.0/src/economize/techniques/dynamic_depth/mod.py +161 -0
  170. economize-0.3.0/src/economize/techniques/dynamic_depth/objective.py +267 -0
  171. economize-0.3.0/src/economize/techniques/dynamic_depth/skipdecode.py +130 -0
  172. economize-0.3.0/src/economize/techniques/eagle3/__init__.py +33 -0
  173. economize-0.3.0/src/economize/techniques/eagle3/config.py +142 -0
  174. economize-0.3.0/src/economize/techniques/eagle3/drafter.py +109 -0
  175. economize-0.3.0/src/economize/techniques/eagle3/formats.py +220 -0
  176. economize-0.3.0/src/economize/techniques/eagle3/layer.py +148 -0
  177. economize-0.3.0/src/economize/techniques/eagle3/objective.py +100 -0
  178. economize-0.3.0/src/economize/techniques/eagle3/technique.py +322 -0
  179. economize-0.3.0/src/economize/techniques/early_exit/__init__.py +42 -0
  180. economize-0.3.0/src/economize/techniques/early_exit/config.py +69 -0
  181. economize-0.3.0/src/economize/techniques/early_exit/drafter.py +95 -0
  182. economize-0.3.0/src/economize/techniques/early_exit/formats.py +27 -0
  183. economize-0.3.0/src/economize/techniques/early_exit/layerskip.py +196 -0
  184. economize-0.3.0/src/economize/techniques/early_exit/objective.py +140 -0
  185. economize-0.3.0/src/economize/techniques/early_exit/path.py +96 -0
  186. economize-0.3.0/src/economize/techniques/early_exit/rollout.py +59 -0
  187. economize-0.3.0/src/economize/techniques/early_exit/technique.py +161 -0
  188. economize-0.3.0/src/economize/techniques/frspec/__init__.py +20 -0
  189. economize-0.3.0/src/economize/techniques/frspec/config.py +64 -0
  190. economize-0.3.0/src/economize/techniques/frspec/drafter.py +122 -0
  191. economize-0.3.0/src/economize/techniques/frspec/technique.py +100 -0
  192. economize-0.3.0/src/economize/techniques/frspec/vocab.py +54 -0
  193. economize-0.3.0/src/economize/techniques/hybrid/__init__.py +15 -0
  194. economize-0.3.0/src/economize/techniques/hybrid/config.py +72 -0
  195. economize-0.3.0/src/economize/techniques/hybrid/drafter.py +138 -0
  196. economize-0.3.0/src/economize/techniques/hybrid/technique.py +76 -0
  197. economize-0.3.0/src/economize/techniques/jump/__init__.py +75 -0
  198. economize-0.3.0/src/economize/techniques/jump/aware.py +68 -0
  199. economize-0.3.0/src/economize/techniques/jump/config.py +141 -0
  200. economize-0.3.0/src/economize/techniques/jump/drafter.py +170 -0
  201. economize-0.3.0/src/economize/techniques/jump/export.py +220 -0
  202. economize-0.3.0/src/economize/techniques/jump/formats.py +29 -0
  203. economize-0.3.0/src/economize/techniques/jump/mixer.py +97 -0
  204. economize-0.3.0/src/economize/techniques/jump/objective.py +224 -0
  205. economize-0.3.0/src/economize/techniques/jump/predictor.py +457 -0
  206. economize-0.3.0/src/economize/techniques/jump/predictor_flow.py +147 -0
  207. economize-0.3.0/src/economize/techniques/jump/rl.py +120 -0
  208. economize-0.3.0/src/economize/techniques/jump/rollout.py +153 -0
  209. economize-0.3.0/src/economize/techniques/jump/technique.py +254 -0
  210. economize-0.3.0/src/economize/techniques/kv_evict/__init__.py +47 -0
  211. economize-0.3.0/src/economize/techniques/kv_evict/policies.py +214 -0
  212. economize-0.3.0/src/economize/techniques/kv_evict/tap.py +89 -0
  213. economize-0.3.0/src/economize/techniques/kv_evict/technique.py +410 -0
  214. economize-0.3.0/src/economize/techniques/kv_quant/__init__.py +58 -0
  215. economize-0.3.0/src/economize/techniques/kv_quant/fp8.py +153 -0
  216. economize-0.3.0/src/economize/techniques/kv_quant/kivi.py +183 -0
  217. economize-0.3.0/src/economize/techniques/layer_skip/__init__.py +37 -0
  218. economize-0.3.0/src/economize/techniques/layer_skip/config.py +85 -0
  219. economize-0.3.0/src/economize/techniques/layer_skip/drafter.py +16 -0
  220. economize-0.3.0/src/economize/techniques/layer_skip/metrics.py +66 -0
  221. economize-0.3.0/src/economize/techniques/layer_skip/policy.py +32 -0
  222. economize-0.3.0/src/economize/techniques/layer_skip/search.py +143 -0
  223. economize-0.3.0/src/economize/techniques/layer_skip/technique.py +120 -0
  224. economize-0.3.0/src/economize/techniques/lookup/__init__.py +29 -0
  225. economize-0.3.0/src/economize/techniques/lookup/config.py +55 -0
  226. economize-0.3.0/src/economize/techniques/lookup/drafter.py +70 -0
  227. economize-0.3.0/src/economize/techniques/lookup/matching.py +66 -0
  228. economize-0.3.0/src/economize/techniques/lookup/proposal.py +69 -0
  229. economize-0.3.0/src/economize/techniques/lookup/technique.py +45 -0
  230. economize-0.3.0/src/economize/techniques/lowrank/__init__.py +32 -0
  231. economize-0.3.0/src/economize/techniques/lowrank/config.py +56 -0
  232. economize-0.3.0/src/economize/techniques/lowrank/factorize.py +118 -0
  233. economize-0.3.0/src/economize/techniques/lowrank/model.py +76 -0
  234. economize-0.3.0/src/economize/techniques/lowrank/module.py +55 -0
  235. economize-0.3.0/src/economize/techniques/lowrank/technique.py +36 -0
  236. economize-0.3.0/src/economize/techniques/medusa/__init__.py +38 -0
  237. economize-0.3.0/src/economize/techniques/medusa/config.py +76 -0
  238. economize-0.3.0/src/economize/techniques/medusa/drafter.py +105 -0
  239. economize-0.3.0/src/economize/techniques/medusa/formats.py +129 -0
  240. economize-0.3.0/src/economize/techniques/medusa/heads.py +52 -0
  241. economize-0.3.0/src/economize/techniques/medusa/objective.py +107 -0
  242. economize-0.3.0/src/economize/techniques/medusa/technique.py +140 -0
  243. economize-0.3.0/src/economize/techniques/medusa/trees.py +123 -0
  244. economize-0.3.0/src/economize/techniques/prune/__init__.py +42 -0
  245. economize-0.3.0/src/economize/techniques/prune/calibration.py +45 -0
  246. economize-0.3.0/src/economize/techniques/prune/config.py +144 -0
  247. economize-0.3.0/src/economize/techniques/prune/depth.py +190 -0
  248. economize-0.3.0/src/economize/techniques/prune/masks.py +95 -0
  249. economize-0.3.0/src/economize/techniques/prune/methods.py +100 -0
  250. economize-0.3.0/src/economize/techniques/prune/model.py +99 -0
  251. economize-0.3.0/src/economize/techniques/prune/semi_structured.py +40 -0
  252. economize-0.3.0/src/economize/techniques/prune/sparsegpt.py +82 -0
  253. economize-0.3.0/src/economize/techniques/prune/technique.py +71 -0
  254. economize-0.3.0/src/economize/techniques/prune/wanda.py +40 -0
  255. economize-0.3.0/src/economize/techniques/quant/__init__.py +73 -0
  256. economize-0.3.0/src/economize/techniques/quant/awq.py +346 -0
  257. economize-0.3.0/src/economize/techniques/quant/backends.py +233 -0
  258. economize-0.3.0/src/economize/techniques/quant/config.py +187 -0
  259. economize-0.3.0/src/economize/techniques/quant/constraints.py +152 -0
  260. economize-0.3.0/src/economize/techniques/quant/draft.py +109 -0
  261. economize-0.3.0/src/economize/techniques/quant/gptq.py +179 -0
  262. economize-0.3.0/src/economize/techniques/quant/grid.py +242 -0
  263. economize-0.3.0/src/economize/techniques/quant/marlin.py +488 -0
  264. economize-0.3.0/src/economize/techniques/quant/methods.py +199 -0
  265. economize-0.3.0/src/economize/techniques/quant/model.py +160 -0
  266. economize-0.3.0/src/economize/techniques/quant/technique.py +80 -0
  267. economize-0.3.0/src/economize/techniques/sparsity/__init__.py +48 -0
  268. economize-0.3.0/src/economize/techniques/sparsity/backends.py +76 -0
  269. economize-0.3.0/src/economize/techniques/sparsity/config.py +100 -0
  270. economize-0.3.0/src/economize/techniques/sparsity/model.py +192 -0
  271. economize-0.3.0/src/economize/techniques/sparsity/sparsify.py +269 -0
  272. economize-0.3.0/src/economize/techniques/sparsity/technique.py +115 -0
  273. economize-0.3.0/src/economize/techniques/vendor_mtp/__init__.py +42 -0
  274. economize-0.3.0/src/economize/techniques/vendor_mtp/config.py +113 -0
  275. economize-0.3.0/src/economize/techniques/vendor_mtp/drafter.py +177 -0
  276. economize-0.3.0/src/economize/techniques/vendor_mtp/families.py +146 -0
  277. economize-0.3.0/src/economize/techniques/vendor_mtp/formats.py +263 -0
  278. economize-0.3.0/src/economize/techniques/vendor_mtp/module.py +67 -0
  279. economize-0.3.0/src/economize/techniques/vendor_mtp/objective.py +18 -0
  280. economize-0.3.0/src/economize/techniques/vendor_mtp/technique.py +213 -0
  281. economize-0.3.0/src/economize/train/__init__.py +185 -0
  282. economize-0.3.0/src/economize/train/checkpoint.py +302 -0
  283. economize-0.3.0/src/economize/train/data/__init__.py +57 -0
  284. economize-0.3.0/src/economize/train/data/chat.py +134 -0
  285. economize-0.3.0/src/economize/train/data/masks.py +23 -0
  286. economize-0.3.0/src/economize/train/data/sources.py +304 -0
  287. economize-0.3.0/src/economize/train/data/tokens.py +81 -0
  288. economize-0.3.0/src/economize/train/evaluate.py +160 -0
  289. economize-0.3.0/src/economize/train/loop.py +442 -0
  290. economize-0.3.0/src/economize/train/module.py +124 -0
  291. economize-0.3.0/src/economize/train/objective.py +535 -0
  292. economize-0.3.0/src/economize/train/objectives/__init__.py +59 -0
  293. economize-0.3.0/src/economize/train/objectives/base.py +45 -0
  294. economize-0.3.0/src/economize/train/objectives/ce.py +52 -0
  295. economize-0.3.0/src/economize/train/objectives/common.py +220 -0
  296. economize-0.3.0/src/economize/train/objectives/distill.py +107 -0
  297. economize-0.3.0/src/economize/train/objectives/divergences.py +86 -0
  298. economize-0.3.0/src/economize/train/objectives/steps.py +288 -0
  299. economize-0.3.0/src/economize/train/objectives/weights.py +58 -0
  300. economize-0.3.0/src/economize/train/offload.py +96 -0
  301. economize-0.3.0/src/economize/train/optim.py +70 -0
  302. economize-0.3.0/src/economize/train/rl.py +139 -0
  303. economize-0.3.0/src/economize/train/rollout/__init__.py +36 -0
  304. economize-0.3.0/src/economize/train/rollout/cache.py +175 -0
  305. economize-0.3.0/src/economize/train/rollout/recurrent.py +171 -0
  306. economize-0.3.0/src/economize/train/schedule.py +43 -0
  307. economize-0.3.0/src/economize/train/teacher.py +113 -0
  308. economize-0.3.0/src/economize/train/trainer.py +427 -0
  309. economize-0.3.0/src/economize/train/utils.py +64 -0
  310. economize-0.3.0/src/economize/unwrap.py +42 -0
  311. economize-0.3.0/src/economize/validation.py +167 -0
  312. economize-0.3.0/tests/conftest.py +29 -0
  313. economize-0.3.0/tests/distributed/test_ssd.py +154 -0
  314. economize-0.3.0/tests/distributed/test_ssd_gpu.py +82 -0
  315. economize-0.3.0/tests/distributed/test_ssd_loop.py +189 -0
  316. economize-0.3.0/tests/distributed/test_tp.py +159 -0
  317. economize-0.3.0/tests/distributed/tp_driver.py +37 -0
  318. economize-0.3.0/tests/helpers.py +374 -0
  319. economize-0.3.0/tests/integrations/conftest.py +90 -0
  320. economize-0.3.0/tests/integrations/eco_fakes.py +88 -0
  321. economize-0.3.0/tests/integrations/grpo_driver.py +134 -0
  322. economize-0.3.0/tests/integrations/test_bench_cost.py +465 -0
  323. economize-0.3.0/tests/integrations/test_bench_prompts.py +89 -0
  324. economize-0.3.0/tests/integrations/test_bench_timing.py +124 -0
  325. economize-0.3.0/tests/integrations/test_custom_generate.py +344 -0
  326. economize-0.3.0/tests/integrations/test_custom_generate_parity.py +225 -0
  327. economize-0.3.0/tests/integrations/test_exporters.py +214 -0
  328. economize-0.3.0/tests/integrations/test_grpo_gpu.py +101 -0
  329. economize-0.3.0/tests/integrations/test_hf_generate.py +338 -0
  330. economize-0.3.0/tests/integrations/test_hf_quantizers.py +229 -0
  331. economize-0.3.0/tests/integrations/test_hub_mixin.py +252 -0
  332. economize-0.3.0/tests/integrations/test_hub_model_cards.py +60 -0
  333. economize-0.3.0/tests/integrations/test_kernels.py +162 -0
  334. economize-0.3.0/tests/integrations/test_lm_eval.py +247 -0
  335. economize-0.3.0/tests/integrations/test_lossless_sampling.py +95 -0
  336. economize-0.3.0/tests/integrations/test_peft_coverage.py +95 -0
  337. economize-0.3.0/tests/integrations/test_peft_lora.py +222 -0
  338. economize-0.3.0/tests/integrations/test_trl_rollouts.py +252 -0
  339. economize-0.3.0/tests/integrations/test_trl_vllm.py +398 -0
  340. economize-0.3.0/tests/integrations/test_vllm_export.py +354 -0
  341. economize-0.3.0/tests/integrations/test_vllm_gpu.py +96 -0
  342. economize-0.3.0/tests/integrations/test_vllm_plugin.py +334 -0
  343. economize-0.3.0/tests/integrations/vllm_driver.py +100 -0
  344. economize-0.3.0/tests/integrations/vllm_fakes.py +201 -0
  345. economize-0.3.0/tests/oracle/test_checkpoints.py +92 -0
  346. economize-0.3.0/tests/oracle/test_drafter_draft_model_oracle.py +64 -0
  347. economize-0.3.0/tests/oracle/test_drafter_eagle3_oracle.py +198 -0
  348. economize-0.3.0/tests/oracle/test_drafter_early_exit_oracle.py +78 -0
  349. economize-0.3.0/tests/oracle/test_drafter_frspec_oracle.py +93 -0
  350. economize-0.3.0/tests/oracle/test_drafter_hybrid_oracle.py +81 -0
  351. economize-0.3.0/tests/oracle/test_drafter_layer_skip_oracle.py +40 -0
  352. economize-0.3.0/tests/oracle/test_drafter_lookup_oracle.py +99 -0
  353. economize-0.3.0/tests/oracle/test_drafter_medusa_oracle.py +103 -0
  354. economize-0.3.0/tests/oracle/test_tskip_oracle.py +123 -0
  355. economize-0.3.0/tests/techniques/conftest.py +91 -0
  356. economize-0.3.0/tests/techniques/test_depth_objectives.py +94 -0
  357. economize-0.3.0/tests/techniques/test_depth_paper_fidelity.py +172 -0
  358. economize-0.3.0/tests/techniques/test_depth_policies.py +470 -0
  359. economize-0.3.0/tests/techniques/test_drafter_draft_model.py +390 -0
  360. economize-0.3.0/tests/techniques/test_drafter_eagle3.py +705 -0
  361. economize-0.3.0/tests/techniques/test_drafter_early_exit.py +286 -0
  362. economize-0.3.0/tests/techniques/test_drafter_families.py +145 -0
  363. economize-0.3.0/tests/techniques/test_drafter_formats_autodetect.py +60 -0
  364. economize-0.3.0/tests/techniques/test_drafter_frspec.py +543 -0
  365. economize-0.3.0/tests/techniques/test_drafter_hybrid.py +363 -0
  366. economize-0.3.0/tests/techniques/test_drafter_layer_skip.py +281 -0
  367. economize-0.3.0/tests/techniques/test_drafter_lookup.py +216 -0
  368. economize-0.3.0/tests/techniques/test_drafter_medusa.py +429 -0
  369. economize-0.3.0/tests/techniques/test_drafter_vendor_mtp.py +184 -0
  370. economize-0.3.0/tests/techniques/test_jump_cached_predictor.py +272 -0
  371. economize-0.3.0/tests/techniques/test_jump_drafter.py +81 -0
  372. economize-0.3.0/tests/techniques/test_jump_formats.py +94 -0
  373. economize-0.3.0/tests/techniques/test_kv_evict.py +338 -0
  374. economize-0.3.0/tests/techniques/test_kv_quant.py +391 -0
  375. economize-0.3.0/tests/techniques/test_lowrank.py +236 -0
  376. economize-0.3.0/tests/techniques/test_prune.py +443 -0
  377. economize-0.3.0/tests/techniques/test_quant.py +475 -0
  378. economize-0.3.0/tests/techniques/test_quant_marlin.py +211 -0
  379. economize-0.3.0/tests/techniques/test_quant_options.py +229 -0
  380. economize-0.3.0/tests/techniques/test_quant_reference.py +225 -0
  381. economize-0.3.0/tests/techniques/test_sparsity.py +445 -0
  382. economize-0.3.0/tests/techniques/test_weights_layerwise.py +157 -0
  383. economize-0.3.0/tests/techniques/test_weights_rollback.py +228 -0
  384. economize-0.3.0/tests/techniques/test_weights_shared.py +127 -0
  385. economize-0.3.0/tests/train/conftest.py +91 -0
  386. economize-0.3.0/tests/train/test_block_predictor.py +191 -0
  387. economize-0.3.0/tests/train/test_data_sources.py +349 -0
  388. economize-0.3.0/tests/train/test_fit.py +229 -0
  389. economize-0.3.0/tests/train/test_flow_predictor.py +252 -0
  390. economize-0.3.0/tests/train/test_jump_rollout_families.py +374 -0
  391. economize-0.3.0/tests/train/test_jump_rollout_oracle.py +250 -0
  392. economize-0.3.0/tests/train/test_objectives.py +417 -0
  393. economize-0.3.0/tests/train/test_offload.py +161 -0
  394. economize-0.3.0/tests/train/test_resume.py +153 -0
  395. economize-0.3.0/tests/train/test_rl.py +224 -0
  396. economize-0.3.0/tests/train/test_schedules.py +147 -0
  397. economize-0.3.0/tests/train/test_step_distill.py +336 -0
  398. economize-0.3.0/tests/train/test_technique_objective.py +243 -0
  399. economize-0.3.0/tests/train/test_trainer.py +305 -0
  400. economize-0.3.0/tests/unit/test_arch_heterogeneous.py +70 -0
  401. economize-0.3.0/tests/unit/test_arch_hooks.py +117 -0
  402. economize-0.3.0/tests/unit/test_arch_layer_kinds.py +82 -0
  403. economize-0.3.0/tests/unit/test_arch_remove_layers.py +107 -0
  404. economize-0.3.0/tests/unit/test_cache_interface.py +142 -0
  405. economize-0.3.0/tests/unit/test_calibration_padding.py +88 -0
  406. economize-0.3.0/tests/unit/test_calibration_replay.py +48 -0
  407. economize-0.3.0/tests/unit/test_compat_tskip.py +83 -0
  408. economize-0.3.0/tests/unit/test_config.py +123 -0
  409. economize-0.3.0/tests/unit/test_core_model_decoder.py +61 -0
  410. economize-0.3.0/tests/unit/test_core_shared_pieces.py +112 -0
  411. economize-0.3.0/tests/unit/test_cuda.py +88 -0
  412. economize-0.3.0/tests/unit/test_cuda_graphs.py +145 -0
  413. economize-0.3.0/tests/unit/test_decoding.py +464 -0
  414. economize-0.3.0/tests/unit/test_decoding_validation.py +70 -0
  415. economize-0.3.0/tests/unit/test_deprecation.py +56 -0
  416. economize-0.3.0/tests/unit/test_exception_contract.py +75 -0
  417. economize-0.3.0/tests/unit/test_families.py +163 -0
  418. economize-0.3.0/tests/unit/test_family_decoding.py +92 -0
  419. economize-0.3.0/tests/unit/test_hf.py +94 -0
  420. economize-0.3.0/tests/unit/test_import_layering.py +142 -0
  421. economize-0.3.0/tests/unit/test_in_model_dtype.py +76 -0
  422. economize-0.3.0/tests/unit/test_jump.py +263 -0
  423. economize-0.3.0/tests/unit/test_modules_rotary.py +84 -0
  424. economize-0.3.0/tests/unit/test_recipe.py +324 -0
  425. economize-0.3.0/tests/unit/test_registry.py +201 -0
  426. economize-0.3.0/tests/unit/test_root_api.py +29 -0
  427. economize-0.3.0/tests/unit/test_runtime.py +141 -0
  428. economize-0.3.0/tests/unit/test_runtime_hybrid_cache.py +61 -0
  429. economize-0.3.0/tests/unit/test_sampling_exact.py +272 -0
  430. economize-0.3.0/tests/unit/test_serialization.py +267 -0
  431. economize-0.3.0/tests/unit/test_tensor_parallel.py +96 -0
  432. economize-0.3.0/tests/unit/test_verifiers.py +343 -0
  433. economize-0.3.0/tests/unit/test_wiring.py +90 -0
  434. economize-0.3.0/tests/unit/tp_jump_driver.py +48 -0
@@ -0,0 +1,9 @@
1
+ __pycache__/
2
+ *.pyc
3
+ .pytest_cache/
4
+ *.egg-info/
5
+ build/
6
+ dist/
7
+ .venv*/
8
+ .mypy_cache/
9
+ .ruff_cache/
@@ -0,0 +1,13 @@
1
+ # Changelog
2
+
3
+ ## 0.3.0 (2026-10-11)
4
+
5
+ First release on PyPI. The library was developed as `effkit` and is renamed to `economize`: the import name, the
6
+ distribution, the entry-point groups (`economize.techniques`, `economize.formats`, ...), the checkpoint files
7
+ (`economize_config.json`, `economize_model.safetensors`), the exported drafter block (`economize_jump`) and the vLLM
8
+ draft architecture (`EconomizeJumpEagle3`) all carry the new name.
9
+
10
+ Checkpoints saved under the old name (`effkit_config.json`, `effkit_model.safetensors`) load as before through the
11
+ `"effkit"` checkpoint format, and `JumpDrafterSpec.from_hf_config` still reads an `effkit_jump` block. Drafters
12
+ exported for vLLM before the rename name the old draft architecture: export them again with
13
+ `economize.backends.export_drafter`.
@@ -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 [yyyy] [name of copyright owner]
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,372 @@
1
+ Metadata-Version: 2.5
2
+ Name: economize
3
+ Version: 0.3.0
4
+ Summary: Composable efficiency techniques (cross-layer jump drafting, early exit, speculative decoding, ...) for Hugging Face causal LMs.
5
+ Project-URL: Homepage, https://github.com/Thiggel/economize
6
+ Project-URL: Repository, https://github.com/Thiggel/economize
7
+ Project-URL: Issues, https://github.com/Thiggel/economize/issues
8
+ Project-URL: Documentation, https://github.com/Thiggel/economize/tree/main/docs
9
+ Author-email: Filipe Laitenberger <f.laitenberger@gmail.com>
10
+ License-Expression: Apache-2.0
11
+ License-File: LICENSE
12
+ Keywords: early-exit,efficiency,huggingface,inference,kv-cache,layer-skipping,llm,pruning,quantization,speculative-decoding,transformers,vllm
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3 :: Only
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
24
+ Classifier: Typing :: Typed
25
+ Requires-Python: >=3.10
26
+ Requires-Dist: huggingface-hub>=1.0
27
+ Requires-Dist: safetensors>=0.4
28
+ Requires-Dist: torch>=2.4
29
+ Requires-Dist: transformers>=5.0
30
+ Provides-Extra: all
31
+ Requires-Dist: accelerate>=1.14; extra == 'all'
32
+ Requires-Dist: compressed-tensors>=0.19; extra == 'all'
33
+ Requires-Dist: datasets>=5.0; extra == 'all'
34
+ Requires-Dist: kernels>=0.17; extra == 'all'
35
+ Requires-Dist: lm-eval[hf]>=0.4.13; extra == 'all'
36
+ Requires-Dist: peft>=0.21; extra == 'all'
37
+ Requires-Dist: torchao>=0.18; extra == 'all'
38
+ Requires-Dist: trl>=1.14; extra == 'all'
39
+ Provides-Extra: bench
40
+ Requires-Dist: datasets>=5.0; extra == 'bench'
41
+ Provides-Extra: dev
42
+ Requires-Dist: mypy==2.4.0; extra == 'dev'
43
+ Requires-Dist: pytest>=8; extra == 'dev'
44
+ Requires-Dist: ruff==0.16.10; extra == 'dev'
45
+ Provides-Extra: eval
46
+ Requires-Dist: lm-eval[hf]>=0.4.13; extra == 'eval'
47
+ Provides-Extra: kernels
48
+ Requires-Dist: kernels>=0.17; extra == 'kernels'
49
+ Provides-Extra: peft
50
+ Requires-Dist: peft>=0.21; extra == 'peft'
51
+ Provides-Extra: quant
52
+ Requires-Dist: compressed-tensors>=0.19; extra == 'quant'
53
+ Requires-Dist: torchao>=0.18; extra == 'quant'
54
+ Provides-Extra: sglang
55
+ Requires-Dist: sglang; extra == 'sglang'
56
+ Provides-Extra: test
57
+ Requires-Dist: pytest>=8; extra == 'test'
58
+ Provides-Extra: train
59
+ Requires-Dist: accelerate>=1.14; extra == 'train'
60
+ Requires-Dist: datasets>=5.0; extra == 'train'
61
+ Requires-Dist: trl>=1.14; extra == 'train'
62
+ Provides-Extra: vllm
63
+ Requires-Dist: vllm>=0.30; extra == 'vllm'
64
+ Description-Content-Type: text/markdown
65
+
66
+ # economize
67
+
68
+ Composable efficiency techniques for Hugging Face causal language models.
69
+
70
+ economize attaches techniques to an unmodified `transformers` model. The base model keeps its module tree and its
71
+ `forward`. Drafters and other added components bring their own parameters and act only while decoding; weight
72
+ transforms (pruning, low rank, quantization) rewrite the base weights in place, once, when they attach. Any set of
73
+ registered techniques can be combined in one call, and every architecture adapter, technique, verifier, cache and
74
+ checkpoint format is added by registration.
75
+
76
+ Version 0.3 ships cross-layer jump drafting, static depth pruning, Wanda / SparseGPT pruning, SVD and SVD-LLM low
77
+ rank, GPTQ / AWQ / round-to-nearest quantization, TEAL activation sparsity and draft-only quantization, on 44 model
78
+ types (dense, MoE, and hybrid attention plus Mamba / linear-attention models), with batched decoding of ragged
79
+ prompts, draft trees and lossless speculative sampling.
80
+
81
+ ## Install
82
+
83
+ ```bash
84
+ pip install economize # torch>=2.4, transformers>=5.0, safetensors, huggingface_hub
85
+ pip install "economize[all]" # every optional integration below except vLLM and SGLang
86
+ ```
87
+
88
+ From source:
89
+
90
+ ```bash
91
+ git clone https://github.com/Thiggel/economize.git
92
+ pip install -e "./economize[dev]"
93
+ ```
94
+
95
+ | Extra | Installs | For |
96
+ |---|---|---|
97
+ | `test` | pytest | the test suite |
98
+ | `peft` | peft | PEFT-wrapped base models and LoRA training of the base |
99
+ | `quant` | torchao, compressed-tensors | quantized kernels, compressed-tensors export |
100
+ | `kernels` | kernels | Hugging Face `kernels` hub kernels (`economize.integrations.kernels`) |
101
+ | `train` | accelerate, datasets, trl | drafter training and online RL rollouts |
102
+ | `eval` | lm-eval[hf] | `economize-lm-eval`, lm-evaluation-harness with economize's decoding loop |
103
+ | `bench` | datasets | prompt suites of `economize.bench` (Spec-Bench, GSM8K, HumanEval) |
104
+ | `vllm`, `sglang` | vllm, sglang | serving backends (`economize.backends`; drafters are written by `economize.backends.export_drafter`) |
105
+
106
+ Installing the package registers the vLLM plugin (`vllm.general_plugins`), the compressed-tensors quantization
107
+ backend and the `economize-lm-eval` command through entry points.
108
+
109
+ ## Quick start
110
+
111
+ ```python
112
+ import torch
113
+ import economize
114
+ from transformers import AutoModelForCausalLM, AutoTokenizer
115
+
116
+ base = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-0.5B", dtype=torch.bfloat16, device_map="cuda")
117
+ model = economize.load(base, "path/to/drafter") # a trained drafter: a folder or a Hub repo id
118
+ # or in one step, loading the base model named in the checkpoint:
119
+ model = economize.from_pretrained("path/to/drafter", dtype=torch.bfloat16, device_map="cuda")
120
+
121
+ tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-0.5B")
122
+ ids = tokenizer("The water cycle describes", return_tensors="pt").input_ids.cuda()
123
+ out = model.generate(ids, max_new_tokens=128) # lossless: the same tokens as base.generate
124
+ ```
125
+
126
+ `model.generate` accepts the usual `transformers` arguments (logits processors such as `repetition_penalty`,
127
+ `eos_token_id`, `return_dict_in_generate`, ...) and routes them through economize's decoding loop. `model.decode`
128
+ returns the tokens together with a log of every model call and the acceptance of each cycle:
129
+
130
+ ```python
131
+ result = model.decode(ids[0], 128, decoding=economize.DecodeConfig(cycle_length=4))
132
+ result.cost_summary() # exact passes, draft steps, layer applications relative to plain decoding
133
+ result.mean_accepted # accepted drafts per cycle
134
+ ```
135
+
136
+ ## Jump drafting
137
+
138
+ A draft step for the next token predicts its hidden state after layer `m` from the current token's state after
139
+ layer `u` and the next token's embedding, runs only layers `m+1..r` and reads out logits. Layers `1..m` (and
140
+ `r+1..L`) are skipped. One *cycle* of `N = cycle_length` tokens runs the unmodified model once, in parallel, over
141
+ every token not yet computed exactly, which also yields one exact token, followed by up to `N-1` draft steps.
142
+
143
+ ```python
144
+ config = economize.JumpConfig(
145
+ target_layer=12, # m
146
+ source_layer=18, # u
147
+ exit_layer=None, # r (default: the last layer; below it a readout adapter is added)
148
+ adaptation="frozen", # or "lora" (LoRA active only on the jump path) or "full" (trainable layer copies)
149
+ )
150
+ model = economize.apply(base, config)
151
+ list(model.technique_parameters()) # the added parameters only; the base model is untouched
152
+ ```
153
+
154
+ `DecodeConfig` chooses how drafts are used:
155
+
156
+ | Option | Meaning |
157
+ |---|---|
158
+ | `cycle_length` | Tokens per cycle `N` (`1` is ordinary decoding). |
159
+ | `lossless=True` | Speculative decoding: drafts are verified by the exact pass, the output equals greedy decoding. |
160
+ | `lossless=False` | Every draft is kept and the exact pass only refreshes the cache (lossy, cheaper). |
161
+ | `min_confidence` | Stop drafting in a cycle once the drafter's top probability falls below this value. |
162
+ | `verifier` | A registered verifier by name: `"greedy"`, `"rejection"` (lossless speculative sampling at T > 0, chains and trees), `"typical"` (Medusa's typical acceptance, lossy) or `"accept_all"`. |
163
+ | `verifier_options` | Keyword options of the verifier, e.g. `{"threshold": 0.09, "alpha": 0.3}` for `"typical"`. |
164
+ | `cuda_graphs` | Replay the exact passes and the draft steps from CUDA graphs (see below). |
165
+ | `sync_interval` | Ordinary decoding reads tokens back and checks stop conditions every this many steps (default 8; the output is the same as reading every step). |
166
+
167
+ Other conditioning variants are part of `JumpConfig`: several source layers (`extra_source_layers`) combined by a
168
+ registered `mixer` (`"concat"`, `"fused_linear"`, `"layer_attention"`), the predictor (`"mlp"`, `"linear"`, its
169
+ width and depth, or `"flow"` / `"flow_linear"`: that mean followed by a few Euler steps of a rectified flow, trained by
170
+ flow matching, with `flow_steps`, `flow_sigma`, `flow_width`), and ablations (`use_state`, `use_token`,
171
+ `token_residual`).
172
+
173
+ Several prompts of different lengths decode as one batch, each row accepting its own number of drafts per cycle.
174
+ With `verifier="rejection"` and a sampling selector the output follows the model's own sampling distribution
175
+ (speculative sampling):
176
+
177
+ ```python
178
+ results = model.decode_batch([ids_a, ids_b, ids_c], 128) # one DecodeResult per prompt
179
+ sampled = model.decode_batch(
180
+ [ids_a, ids_b], 128,
181
+ decoding=economize.DecodeConfig(cycle_length=4, verifier="rejection"),
182
+ selector=economize.TopPSampler(temperature=0.7, top_p=0.9, seed=0, device="cuda"),
183
+ )
184
+ ```
185
+
186
+ Each row may also have its own selector, stop condition and token limit (`selectors=`, `stops=`, and a list for
187
+ `max_new_tokens`). Rows that share a selector object are drafted and verified together.
188
+
189
+ At batch size 1 a draft step and a short exact pass are bound by kernel launches. With
190
+ `DecodeConfig(cuda_graphs=True)` the decoder records its exact chain passes and the jump drafter's steps as CUDA
191
+ graphs on a static KV cache and replays them. The model keeps one decoder per configuration, so the graphs recorded
192
+ in the first generation serve the following ones; `model.refresh()` drops them after the weights or the techniques
193
+ change. Draft trees, dynamic-depth policies, KV-cache techniques and models with recurrent layers decode eagerly
194
+ whatever the flag says.
195
+
196
+ ## Combining techniques
197
+
198
+ `economize.apply` takes any number of configurations and attaches them in a fixed order, whatever the order of the
199
+ arguments: weight transforms (by their `order`: depth pruning, pruning, low rank, quantization), activation hooks,
200
+ KV-cache wrappers, dynamic depth, the drafter, then the rest. Techniques that need data calibrate on the model as it
201
+ is at that point, so quantization sees the pruned weights.
202
+
203
+ ```python
204
+ from economize.techniques.prune import PruneConfig
205
+ from economize.techniques.quant import QuantConfig
206
+ from economize.techniques.sparsity import TealConfig
207
+
208
+ model = economize.apply(
209
+ base,
210
+ PruneConfig(method="wanda", sparsity="2:4"),
211
+ QuantConfig(format="int4", method="gptq", group_size=128),
212
+ TealConfig(sparsity=0.4),
213
+ economize.JumpConfig(target_layer=12, source_layer=18),
214
+ calibration=calibration_ids, # LongTensor [N, S], an iterable of batches, or a callable
215
+ )
216
+ ```
217
+
218
+ See [docs/weights.md](https://github.com/Thiggel/economize/blob/main/docs/weights.md) for every weight and activation technique and its options.
219
+
220
+ ## Training
221
+
222
+ `economize.train` trains what the techniques add (drafters, readout adapters, LoRA on a drafter's path, early-exit
223
+ heads) and, where a technique needs it, the base model:
224
+
225
+ ```python
226
+ from economize.train import fit
227
+
228
+ model = economize.apply(base, economize.JumpConfig(target_layer=16, source_layer=17, exit_layer=17))
229
+ fit(model, "data/qwen/train.bin", steps=2000, output_dir="runs/jump_m16_u17") # uint32 token file
230
+ model = economize.load(base, "runs/jump_m16_u17/final")
231
+ ```
232
+
233
+ `fit` picks the objective registered for the attached drafter (`jump_rollout` for `jump`, the objective of
234
+ `tskip/train.py`). An existing `transformers.Trainer` pipeline uses `EffTrainer` with the same objectives:
235
+
236
+ ```python
237
+ from economize.train import EffTrainer, JumpRollout, economize_training_args
238
+
239
+ objective = JumpRollout(horizon=16)
240
+ args = economize_training_args(objective, "runs/jump_trainer", max_steps=2000, per_device_train_batch_size=8)
241
+ EffTrainer(model, objective, args, train_dataset=dataset).train()
242
+ ```
243
+
244
+ `pip install "economize[train]"` adds `accelerate`, `datasets` and `trl` (`fit` itself needs only torch).
245
+ [docs/training.md](https://github.com/Thiggel/economize/blob/main/docs/training.md) lists the objectives, the data formats, data-parallel runs under `accelerate launch` and how
246
+ to register an objective.
247
+
248
+ ## Ecosystem
249
+
250
+ | Library | Entry point | Details |
251
+ |---|---|---|
252
+ | `transformers` | `model.generate(...)`, `custom_generate` Hub recipe | logits processors, stopping criteria, `return_dict_in_generate` |
253
+ | Hugging Face Hub | `model.save_pretrained`, `push_to_hub`, `economize.from_pretrained` | only the technique weights are uploaded |
254
+ | PEFT | `economize.apply(peft_model, ...)` | the adapter finds the base model inside a `PeftModel` |
255
+ | `kernels` | `economize.integrations.kernels.kernelize(model)`, `op(name)` | hub kernels for the base model and every added module |
256
+ | lm-evaluation-harness | `economize-lm-eval run --model economize --model_args pretrained=...,economize=...` | generation runs economize's decoding loop |
257
+ | TRL | `economize.integrations.trl.attach_rollouts` | in-process GRPO / RLOO rollouts with the drafter refreshed after each step |
258
+ | vLLM | `economize.backends.vllm` | drafter export (`export_drafter(model, dir, backend="vllm")`), plugin entry point, jump drafting in the V2 model runner (tested with vLLM 0.30) |
259
+ | SGLang | `economize.backends.sglang` | interface only (`JumpDraftBackend`); its registered exporter raises `UnsupportedBackendError`, and nothing is patched in SGLang yet |
260
+
261
+ [docs/ecosystem.md](https://github.com/Thiggel/economize/blob/main/docs/ecosystem.md) describes each integration and its tests.
262
+
263
+ ## Saving and loading
264
+
265
+ ```python
266
+ model.save_pretrained("my_drafter") # economize_config.json + technique weights in safetensors
267
+ model = economize.load(base, "my_drafter")
268
+ ```
269
+
270
+ Only the technique weights are saved. Checkpoints of the research code (`tskip`, a `jump.pt` file or its run
271
+ directory) are detected and converted on load. Further formats are added through the `FORMATS` registry.
272
+
273
+ ## Extending economize
274
+
275
+ Everything that varies is a registry, and new entries are added by registration, never by editing economize:
276
+
277
+ | Registry | Module | Entry-point group |
278
+ |---|---|---|
279
+ | `TECHNIQUES` | `economize.core` | `economize.techniques` |
280
+ | `ARCHITECTURES`, `LAYER_KINDS` | `economize.arch` | `economize.architectures`, `economize.layer_kinds` |
281
+ | `FORMATS` | `economize.core` | `economize.formats` |
282
+ | `VERIFIERS`, `POLICIES` | `economize.decoding` | `economize.verifiers`, `economize.draft_policies` |
283
+ | `CACHES`, `MASKS`, `MASK_FORMATS` | `economize.runtime` | `economize.caches`, `economize.masks`, `economize.mask_formats` |
284
+ | `PREDICTORS`, `MIXERS` | `economize.techniques.jump` | `economize.jump_predictors`, `economize.jump_mixers` |
285
+ | `SKIP_SEARCHES`, `SKIP_METRICS` | `economize.techniques.layer_skip` | `economize.skip_searches`, `economize.skip_metrics` |
286
+ | `MEDUSA_TREES` | `economize.techniques.medusa` | `economize.medusa_trees` |
287
+ | `MTP_FAMILIES` | `economize.techniques.vendor_mtp` | `economize.mtp_families` |
288
+ | `CONFIDENCE_MEASURES`, `FLEXI_ROUTERS` | `economize.techniques.dynamic_depth` | `economize.calm_confidence`, `economize.flexi_routers` |
289
+ | `PRUNE_METHODS`, `DEPTH_CRITERIA` | `economize.techniques.prune` | `economize.prune_methods`, `economize.depth_criteria` |
290
+ | `QUANT_METHODS`, `QUANT_BACKENDS`, `QUANT_FORMATS`, `AWQ_SCALE_GROUPS`, `TORCHAO_TENSORS` | `economize.techniques.quant` | `economize.quant_methods`, `economize.quant_backends`, `economize.quant_formats`, `economize.awq_scale_groups`, `economize.torchao_tensors` |
291
+ | `FACTORIZERS` | `economize.techniques.lowrank` | `economize.factorizers` |
292
+ | `TEAL_BACKENDS` | `economize.techniques.sparsity` | `economize.teal_backends` |
293
+ | `EVICTION_METHODS` | `economize.techniques.kv_evict` | `economize.kv_eviction` |
294
+ | `KERNEL_OPS` | `economize.integrations.kernels` | `economize.kernel_ops` |
295
+ | `OBJECTIVES`, `DIVERGENCES`, `SCHEDULES`, `STATE_LOSSES` | `economize.train` | `economize.objectives`, `economize.divergences`, `economize.schedules`, `economize.state_losses` |
296
+ | `PROMPT_SOURCES`, `HARDWARE`, `SHAPE_READERS` | `economize.bench` | `economize.prompt_sources`, `economize.hardware`, `economize.shape_readers` |
297
+ | `EXPORTERS` | `economize.backends` | `economize.exporters` |
298
+ | `VLLM_DRAFTERS` | `economize.backends.vllm` | `economize.vllm_drafters` |
299
+ | `CT_SCHEMES` | `economize.integrations.compressed_tensors` | `economize.ct_schemes` |
300
+
301
+ A new predictor, for example:
302
+
303
+ ```python
304
+ from economize.techniques.jump import PREDICTORS, Predictor
305
+
306
+ @PREDICTORS.register("residual_linear")
307
+ class ResidualLinear(Predictor):
308
+ def __init__(self, hidden_size, config):
309
+ super().__init__(hidden_size, config)
310
+ self.proj = torch.nn.Linear(2 * hidden_size, hidden_size)
311
+
312
+ def forward(self, source, token_embedding):
313
+ return token_embedding.float() + self.proj(torch.cat([source, token_embedding], -1).float())
314
+
315
+ model = economize.apply(base, economize.JumpConfig(target_layer=12, source_layer=18, predictor="residual_linear"))
316
+ ```
317
+
318
+ An installed package can contribute the same entry without an import, through the entry-point group in its
319
+ `pyproject.toml`:
320
+
321
+ ```toml
322
+ [project.entry-points."economize.jump_predictors"]
323
+ residual_linear = "my_pkg.predictors:ResidualLinear"
324
+ ```
325
+
326
+ A new technique subclasses `economize.Technique` with a frozen `TechniqueConfig` dataclass and is registered with
327
+ `@economize.register_technique`. A drafting technique declares `Capability.DRAFTER` and returns an object that follows
328
+ the `economize.decoding.Drafter` protocol. A new model family registers an `ArchAdapter` under its `model_type`;
329
+ most decoder-only families share the built-in `StandardDecoderAdapter`. Family facts that techniques and the cost
330
+ model need are set on the adapter: `layer_layout = "llama"` gives AWQ the Llama scale groups, `shape_fields`
331
+ corrects the cost model's config reading, and `module_path(module)` names modules for exporters. A drafter is
332
+ written for a serving backend by a `DrafterExporter` registered with
333
+ `@economize.backends.register_exporter("<backend>", "<technique>")`; a new backend is one such class.
334
+ [docs/ARCHITECTURE.md](https://github.com/Thiggel/economize/blob/main/docs/ARCHITECTURE.md) describes every contract.
335
+
336
+ ## Scope of version 0.2
337
+
338
+ - Techniques: jump drafting (frozen, LoRA, full; one or several source layers mixed by concatenation, a fused
339
+ linear map or layer attention; MLP or linear predictors), `depth_prune`, `prune`, `lowrank`, `quant`, `teal`,
340
+ `draft_quant`.
341
+ - Decoding: batched ragged prompts with per-row selectors, stops and limits, chains and draft trees, greedy
342
+ verification, lossless speculative sampling on chains and trees, typical acceptance, lossy drafting, fixed or
343
+ confidence-based draft length, CUDA graphs for chain decoding, a log of every model call for cost accounting.
344
+ - Training: `economize.train` (`fit`, `EffTrainer`, registered objectives).
345
+ - Checkpoints record a fingerprint of the base weights; loading onto different weights warns
346
+ (`economize.TeacherMismatchWarning`, off with `check_teacher=False`).
347
+ - Not yet: flex-attention masks for draft trees (trees use `sdpa` or `eager` masks), draft trees on models with
348
+ recurrent layers, and the vLLM / SGLang draft step.
349
+
350
+ ## Tests
351
+
352
+ ```bash
353
+ cd TJEPA-Eff && source env.sh
354
+ PYTHONPATH=economize/src:economize/tests:. $PY -m pytest economize/tests # unit, technique, integration, oracle (CPU)
355
+ PYTHONPATH=economize/src:economize/tests:. $PY -m pytest economize/tests -m slow # trained checkpoints on Qwen2.5-0.5B
356
+ PYTHONPATH=economize/src:economize/tests:. $PY -m pytest economize/tests -m gpu # batched decoding on a CUDA device
357
+ ```
358
+
359
+ The lint (`uvx ruff check src tests hub`) and type (`uvx mypy --python-executable <python> src/economize`) gates and
360
+ the design rules a change must follow are in [docs/CONTRIBUTING.md](https://github.com/Thiggel/economize/blob/main/docs/CONTRIBUTING.md).
361
+
362
+ The unit tests check that the exact path equals the model's own logits on every supported family, that batched
363
+ lossless decoding equals greedy decoding of each prompt alone (chains, trees and jump drafters, with partial
364
+ acceptance and hybrid recurrent layers), that rejection sampling outputs the target distribution (chi-square
365
+ tests with a negative control), the recipe's ordering and rollback, and the checkpoint round trips. The oracle
366
+ tests check that economize produces the same tokens, the same log of model calls and the same acceptance as the
367
+ research decoder `tskip.decode.Decoder`, on random drafters of a tiny model and on three trained drafters of
368
+ Qwen2.5-0.5B.
369
+
370
+ ## License
371
+
372
+ Apache License 2.0, see [LICENSE](https://github.com/Thiggel/economize/blob/main/LICENSE).