mate-llm 0.1.0__py3-none-any.whl

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 (107) hide show
  1. mate/__init__.py +279 -0
  2. mate/_bridge.py +1494 -0
  3. mate/_gguf_tables.py +380 -0
  4. mate/_hadamard.py +131 -0
  5. mate/_hf_utils.py +241 -0
  6. mate/_import_common.py +273 -0
  7. mate/_int8.py +37 -0
  8. mate/_policy.py +260 -0
  9. mate/_protocols.py +142 -0
  10. mate/_sampling.py +252 -0
  11. mate/_trellis_dispatch.py +849 -0
  12. mate/anthropic_api.py +840 -0
  13. mate/auto_fit.py +1936 -0
  14. mate/chat_drafters.py +2374 -0
  15. mate/cli.py +716 -0
  16. mate/cptc.py +620 -0
  17. mate/cpu_runner.py +3671 -0
  18. mate/csrc/mate_cuda_kernels.cu +4531 -0
  19. mate/csrc/mate_doorbell_moe.cu +737 -0
  20. mate/csrc/mate_doorbell_moe.cuh +84 -0
  21. mate/csrc/mate_e8_v3.cu +1348 -0
  22. mate/csrc/mate_e8_v3.cuh +34 -0
  23. mate/csrc/mate_gdn.cu +9004 -0
  24. mate/csrc/mate_gdn.cuh +288 -0
  25. mate/csrc/mate_gemv_v2.cuh +3608 -0
  26. mate/csrc/mate_gemv_v3.cu +4 -0
  27. mate/csrc/mate_gemv_v3.cuh +14499 -0
  28. mate/csrc/mate_hyper_res.cu +3500 -0
  29. mate/csrc/mate_hyper_res.cuh +152 -0
  30. mate/csrc/mate_inkling_engine.cu +12322 -0
  31. mate/csrc/mate_inkling_engine.cuh +263 -0
  32. mate/csrc/mate_kv_v2.cuh +3494 -0
  33. mate/csrc/mate_moe_gemv.cu +3617 -0
  34. mate/csrc/mate_moe_gemv.cuh +97 -0
  35. mate/csrc/mate_nvfp4_moe.cu +9323 -0
  36. mate/csrc/mate_nvfp4_moe.cuh +51 -0
  37. mate/csrc/mate_offload_async.cu +1863 -0
  38. mate/csrc/mate_offload_async.cuh +137 -0
  39. mate/csrc/mate_r4kv.cu +11066 -0
  40. mate/csrc/mate_r4kv.cuh +274 -0
  41. mate/csrc/mate_screened_head.cu +2261 -0
  42. mate/csrc/mate_screened_head.cuh +79 -0
  43. mate/csrc/mate_sparse_r4kv.cu +4017 -0
  44. mate/csrc/mate_sparse_r4kv.cuh +169 -0
  45. mate/csrc/mate_spec_gpu.cu +2151 -0
  46. mate/csrc/mate_spec_gpu.cuh +127 -0
  47. mate/csrc/mate_t2tc.cu +52 -0
  48. mate/csrc/runtime/CMakeLists.txt +76 -0
  49. mate/csrc/runtime/arena.hpp +1047 -0
  50. mate/csrc/runtime/cuda_runtime_kernels.cu +300 -0
  51. mate/csrc/runtime/http_server.hpp +1091 -0
  52. mate/csrc/runtime/jinja.hpp +2285 -0
  53. mate/csrc/runtime/mate_serve.cpp +254 -0
  54. mate/csrc/runtime/safetensors_mmap.hpp +927 -0
  55. mate/csrc/runtime/scheduler.hpp +1358 -0
  56. mate/csrc/runtime/tokenizer.hpp +1486 -0
  57. mate/csrc/runtime/wave1_runners.hpp +2372 -0
  58. mate/cuda_ext/__init__.py +430 -0
  59. mate/cuda_ext/_build.py +535 -0
  60. mate/cuda_ext/_ops_doorbell.py +428 -0
  61. mate/cuda_ext/_ops_gdn.py +3037 -0
  62. mate/cuda_ext/_ops_gemv.py +2548 -0
  63. mate/cuda_ext/_ops_hyper.py +1065 -0
  64. mate/cuda_ext/_ops_inkling.py +1713 -0
  65. mate/cuda_ext/_ops_kv.py +2666 -0
  66. mate/cuda_ext/_ops_moe.py +1830 -0
  67. mate/cuda_ext/_ops_offload.py +1175 -0
  68. mate/cuda_ext/_ops_sparse_kv.py +1160 -0
  69. mate/cuda_ext/_ops_spec.py +949 -0
  70. mate/double_hadamard.py +1408 -0
  71. mate/e8_kv.py +1468 -0
  72. mate/engram.py +2676 -0
  73. mate/exl3_codec.py +231 -0
  74. mate/exl3_import.py +626 -0
  75. mate/fast_decode.py +4512 -0
  76. mate/fused.py +236 -0
  77. mate/fused_proj.py +935 -0
  78. mate/gguf_import.py +1559 -0
  79. mate/hf.py +2268 -0
  80. mate/hf_cache.py +551 -0
  81. mate/hybrid_decode.py +9616 -0
  82. mate/inkling2_exact.py +4269 -0
  83. mate/inkling_mtp.py +3967 -0
  84. mate/kv_cache.py +345 -0
  85. mate/kvarn_kv.py +928 -0
  86. mate/linear.py +1108 -0
  87. mate/loftq.py +190 -0
  88. mate/mlx_import.py +1364 -0
  89. mate/model_resolver.py +830 -0
  90. mate/moe.py +2321 -0
  91. mate/nf12.py +538 -0
  92. mate/offload_engine.py +4015 -0
  93. mate/quantize.py +4200 -0
  94. mate/scale_tune.py +1938 -0
  95. mate/sensitivity.py +2154 -0
  96. mate/server.py +6510 -0
  97. mate/sparse_kv.py +4185 -0
  98. mate/speculative.py +12264 -0
  99. mate/static_kv.py +4050 -0
  100. mate/stream_parser.py +654 -0
  101. mate/stream_quant.py +3994 -0
  102. mate_llm-0.1.0.dist-info/METADATA +180 -0
  103. mate_llm-0.1.0.dist-info/RECORD +107 -0
  104. mate_llm-0.1.0.dist-info/WHEEL +5 -0
  105. mate_llm-0.1.0.dist-info/entry_points.txt +2 -0
  106. mate_llm-0.1.0.dist-info/licenses/LICENSE +137 -0
  107. mate_llm-0.1.0.dist-info/top_level.txt +1 -0
mate/__init__.py ADDED
@@ -0,0 +1,279 @@
1
+ """MATE (Memory-Aligned Trellis Engine): CPTC-TQIR trellis quantization, Trellis-QLoRA, and 3-bit IsoQuant KV/MoE kernels in Mojo."""
2
+ from __future__ import annotations
3
+
4
+ import importlib
5
+ from typing import Any
6
+
7
+ # Map public export name -> (relative_module_name, attribute_name_or_None_for_submodule).
8
+ _EXPORTS: dict[str, tuple[str, str | None]] = {
9
+ "cuda_ext": (".cuda_ext", None),
10
+ # cptc
11
+ "CPTCCodebook": (".cptc", "CPTCCodebook"),
12
+ "effective_bits_from_mse": (".cptc", "effective_bits_from_mse"),
13
+ "make_codebook": (".cptc", "make_codebook"),
14
+ # cpu_runner
15
+ "CpuFastDecodeRunner": (".cpu_runner", "CpuFastDecodeRunner"),
16
+ # double_hadamard
17
+ "DoubleHadamardTrellisLinear": (".double_hadamard", "DoubleHadamardTrellisLinear"),
18
+ # e8_kv
19
+ "E8_RATE_CONFIGS": (".e8_kv", "E8_RATE_CONFIGS"),
20
+ "E8LatticeKVCache": (".e8_kv", "E8LatticeKVCache"),
21
+ "fit_nova_key_preconditioner": (".e8_kv", "fit_nova_key_preconditioner"),
22
+ # exl3_codec
23
+ "EXL3CompatCodec": (".exl3_codec", "EXL3CompatCodec"),
24
+ "compare_cptc_vs_qtip": (".exl3_codec", "compare_cptc_vs_qtip"),
25
+ # exl3_import
26
+ "EXL3Linear": (".exl3_import", "EXL3Linear"),
27
+ "convert_exl3_to_mate": (".exl3_import", "convert_exl3_to_mate"),
28
+ "read_exl3_dir": (".exl3_import", "read_exl3_dir"),
29
+ # fast_decode
30
+ "FastDecodeRunner": (".fast_decode", "FastDecodeRunner"),
31
+ "is_supported_model": (".fast_decode", "is_supported_model"),
32
+ # hybrid_decode
33
+ "HybridFastDecodeRunner": (".hybrid_decode", "HybridFastDecodeRunner"),
34
+ "is_hybrid_supported_model": (".hybrid_decode", "is_hybrid_supported_model"),
35
+ # static_kv
36
+ "StaticE8KVCache": (".static_kv", "StaticE8KVCache"),
37
+ "StaticFP16KVCache": (".static_kv", "StaticFP16KVCache"),
38
+ "StaticKVarNKVCache": (".static_kv", "StaticKVarNKVCache"),
39
+ "StaticR4KVCache": (".static_kv", "StaticR4KVCache"),
40
+ # fused
41
+ "FusedRMSNorm": (".fused", "FusedRMSNorm"),
42
+ "fused_chunked_cross_entropy": (".fused", "fused_chunked_cross_entropy"),
43
+ "fused_rope": (".fused", "fused_rope"),
44
+ "fused_swiglu": (".fused", "fused_swiglu"),
45
+ # fused_proj
46
+ "BandedLMHeadLinear": (".fused_proj", "BandedLMHeadLinear"),
47
+ "FusedTrellisProjection": (".fused_proj", "FusedTrellisProjection"),
48
+ "quantize_lm_head": (".fused_proj", "quantize_lm_head"),
49
+ # gguf_import
50
+ "GGUFReader": (".gguf_import", "GGUFReader"),
51
+ "quantize_gguf_to_mate": (".gguf_import", "quantize_gguf_to_mate"),
52
+ # hf
53
+ "QuantReport": (".hf", "QuantReport"),
54
+ "attach_trellis_qlora": (".hf", "attach_trellis_qlora"),
55
+ "export_quantized_model": (".hf", "export_quantized_model"),
56
+ "load_quantized_model": (".hf", "load_quantized_model"),
57
+ "quantize_model": (".hf", "quantize_model"),
58
+ # hf_cache
59
+ "IsoQuantHFCache": (".hf_cache", "IsoQuantHFCache"),
60
+ "enable_fast_e8_attention": (".hf_cache", "enable_fast_e8_attention"),
61
+ "generate_with_isoquant": (".hf_cache", "generate_with_isoquant"),
62
+ "register_e8_attention": (".hf_cache", "register_e8_attention"),
63
+ # kv_cache
64
+ "IsoQuantKVCache": (".kv_cache", "IsoQuantKVCache"),
65
+ # kvarn_kv
66
+ "KVARN_PRESETS": (".kvarn_kv", "KVARN_PRESETS"),
67
+ "KVarNConfig": (".kvarn_kv", "KVarNConfig"),
68
+ "KVarNKVCache": (".kvarn_kv", "KVarNKVCache"),
69
+ "log_sinkhorn_varn": (".kvarn_kv", "log_sinkhorn_varn"),
70
+ # linear
71
+ "HRQLinear": (".linear", "HRQLinear"),
72
+ "TrellisLinear": (".linear", "TrellisLinear"),
73
+ "TrellisQLoRALinear": (".linear", "TrellisQLoRALinear"),
74
+ # loftq
75
+ "loftq_trellis_init": (".loftq", "loftq_trellis_init"),
76
+ "make_loftq_trellis_qlora": (".loftq", "make_loftq_trellis_qlora"),
77
+ # mlx_import
78
+ "convert_awq_gptq_to_mate": (".mlx_import", "convert_awq_gptq_to_mate"),
79
+ "convert_bnb_nf4_to_mate": (".mlx_import", "convert_bnb_nf4_to_mate"),
80
+ "convert_fp4_to_mate": (".mlx_import", "convert_fp4_to_mate"),
81
+ "convert_fp8_to_mate": (".mlx_import", "convert_fp8_to_mate"),
82
+ "convert_mlx_to_mate": (".mlx_import", "convert_mlx_to_mate"),
83
+ "detect_checkpoint_format": (".mlx_import", "detect_checkpoint_format"),
84
+ # moe
85
+ "DeferredColdResidual": (".moe", "DeferredColdResidual"),
86
+ "HybridMoERouterRunner": (".moe", "HybridMoERouterRunner"),
87
+ "Int8Linear": (".moe", "Int8Linear"),
88
+ "LRCExpertCachePolicy": (".moe", "LRCExpertCachePolicy"),
89
+ "LRUExpertPager": (".moe", "LRUExpertPager"),
90
+ "MoEExpertStat": (".moe", "MoEExpertStat"),
91
+ "RoleQuantPolicy": (".moe", "RoleQuantPolicy"),
92
+ "TrellisMoEBlock": (".moe", "TrellisMoEBlock"),
93
+ "allocate_moe_expert_bits": (".moe", "allocate_moe_expert_bits"),
94
+ # nf12
95
+ "NF12Embedding": (".nf12", "NF12Embedding"),
96
+ "NF12Linear": (".nf12", "NF12Linear"),
97
+ "NF12Tensor": (".nf12", "NF12Tensor"),
98
+ "nf12_pack": (".nf12", "nf12_pack"),
99
+ "nf12_unpack": (".nf12", "nf12_unpack"),
100
+ # quantize
101
+ "CPTCTQIRCodec": (".quantize", "CPTCTQIRCodec"),
102
+ "QuantizedMatrix": (".quantize", "QuantizedMatrix"),
103
+ "TrellisCodec": (".quantize", "TrellisCodec"),
104
+ "choose_subspace_dim": (".quantize", "choose_subspace_dim"),
105
+ "compute_esg_permutation": (".quantize", "compute_esg_permutation"),
106
+ "dequantize_matrix": (".quantize", "dequantize_matrix"),
107
+ "load_checkpoint": (".quantize", "load_checkpoint"),
108
+ "quantize_matrix": (".quantize", "quantize_matrix"),
109
+ "save_checkpoint": (".quantize", "save_checkpoint"),
110
+ # scale_tune
111
+ "ScaleTunableTrellisLinear": (".scale_tune", "ScaleTunableTrellisLinear"),
112
+ "ScaleTuneReport": (".scale_tune", "ScaleTuneReport"),
113
+ "cache_reference_logits": (".scale_tune", "cache_reference_logits"),
114
+ "mix_calibration_batches": (".scale_tune", "mix_calibration_batches"),
115
+ "tune_quantized_scales": (".scale_tune", "tune_quantized_scales"),
116
+ # sensitivity
117
+ "LMHeadBandPlan": (".sensitivity", "LMHeadBandPlan"),
118
+ "LayerSpec": (".sensitivity", "LayerSpec"),
119
+ "SensitivityPlan": (".sensitivity", "SensitivityPlan"),
120
+ "allocate_layer_bits": (".sensitivity", "allocate_layer_bits"),
121
+ "allocate_mixed_precision": (".sensitivity", "allocate_mixed_precision"),
122
+ "build_calibration_mixture": (".sensitivity", "build_calibration_mixture"),
123
+ "build_probability_banded_lm_head_plan": (".sensitivity", "build_probability_banded_lm_head_plan"),
124
+ "score_layer_sensitivity": (".sensitivity", "score_layer_sensitivity"),
125
+ "score_modules_kl_grad": (".sensitivity", "score_modules_kl_grad"),
126
+ # server
127
+ "MateEngine": (".server", "MateEngine"),
128
+ "create_server": (".server", "create_server"),
129
+ "run_interactive_chat": (".server", "run_interactive_chat"),
130
+ "serve_model": (".server", "serve_model"),
131
+ # speculative
132
+ "BilinearPathSelector": (".speculative", "BilinearPathSelector"),
133
+ "DFlash2Config": (".speculative", "DFlash2Config"),
134
+ "DFlash2Drafter": (".speculative", "DFlash2Drafter"),
135
+ "DSparkBucketScheduler": (".speculative", "DSparkBucketScheduler"),
136
+ "DynamicDepthwiseConv2Tap": (".speculative", "DynamicDepthwiseConv2Tap"),
137
+ "FRSpecVocabHead": (".speculative", "FRSpecVocabHead"),
138
+ "FeatureSink": (".speculative", "FeatureSink"),
139
+ "NativeMTPDrafter": (".speculative", "NativeMTPDrafter"),
140
+ "SpeculativeChunk": (".speculative", "SpeculativeChunk"),
141
+ "SpeculativeConfig": (".speculative", "SpeculativeConfig"),
142
+ "SpeculativeDecoder": (".speculative", "SpeculativeDecoder"),
143
+ "SpeculativeStats": (".speculative", "SpeculativeStats"),
144
+ "SuffixSpeculator": (".speculative", "SuffixSpeculator"),
145
+ "profile_sps": (".speculative", "profile_sps"),
146
+ "verify_greedy_vectorized": (".speculative", "verify_greedy_vectorized"),
147
+ "verify_rejection_vectorized": (".speculative", "verify_rejection_vectorized"),
148
+ }
149
+
150
+ __all__ = [
151
+ "BandedLMHeadLinear",
152
+ "BilinearPathSelector",
153
+ "CPTCCodebook",
154
+ "CPTCTQIRCodec",
155
+ "CpuFastDecodeRunner",
156
+ "DFlash2Config",
157
+ "DFlash2Drafter",
158
+ "DSparkBucketScheduler",
159
+ "DeferredColdResidual",
160
+ "DoubleHadamardTrellisLinear",
161
+ "DynamicDepthwiseConv2Tap",
162
+ "E8LatticeKVCache",
163
+ "E8_RATE_CONFIGS",
164
+ "EXL3CompatCodec",
165
+ "EXL3Linear",
166
+ "FRSpecVocabHead",
167
+ "FastDecodeRunner",
168
+ "FeatureSink",
169
+ "FusedRMSNorm",
170
+ "FusedTrellisProjection",
171
+ "GGUFReader",
172
+ "HRQLinear",
173
+ "HybridFastDecodeRunner",
174
+ "HybridMoERouterRunner",
175
+ "Int8Linear",
176
+ "IsoQuantHFCache",
177
+ "IsoQuantKVCache",
178
+ "KVARN_PRESETS",
179
+ "KVarNConfig",
180
+ "KVarNKVCache",
181
+ "LMHeadBandPlan",
182
+ "LRCExpertCachePolicy",
183
+ "LRUExpertPager",
184
+ "LayerSpec",
185
+ "MateEngine",
186
+ "MoEExpertStat",
187
+ "NF12Embedding",
188
+ "NF12Linear",
189
+ "NF12Tensor",
190
+ "NativeMTPDrafter",
191
+ "QuantReport",
192
+ "QuantizedMatrix",
193
+ "RoleQuantPolicy",
194
+ "ScaleTunableTrellisLinear",
195
+ "ScaleTuneReport",
196
+ "SensitivityPlan",
197
+ "SpeculativeChunk",
198
+ "SpeculativeConfig",
199
+ "SpeculativeDecoder",
200
+ "SpeculativeStats",
201
+ "StaticE8KVCache",
202
+ "StaticFP16KVCache",
203
+ "StaticKVarNKVCache",
204
+ "StaticR4KVCache",
205
+ "SuffixSpeculator",
206
+ "TrellisCodec",
207
+ "TrellisLinear",
208
+ "TrellisMoEBlock",
209
+ "TrellisQLoRALinear",
210
+ "allocate_layer_bits",
211
+ "allocate_mixed_precision",
212
+ "allocate_moe_expert_bits",
213
+ "attach_trellis_qlora",
214
+ "build_calibration_mixture",
215
+ "build_probability_banded_lm_head_plan",
216
+ "cache_reference_logits",
217
+ "choose_subspace_dim",
218
+ "compare_cptc_vs_qtip",
219
+ "compute_esg_permutation",
220
+ "convert_awq_gptq_to_mate",
221
+ "convert_bnb_nf4_to_mate",
222
+ "convert_exl3_to_mate",
223
+ "convert_fp4_to_mate",
224
+ "convert_fp8_to_mate",
225
+ "convert_mlx_to_mate",
226
+ "create_server",
227
+ "cuda_ext",
228
+ "dequantize_matrix",
229
+ "detect_checkpoint_format",
230
+ "effective_bits_from_mse",
231
+ "enable_fast_e8_attention",
232
+ "export_quantized_model",
233
+ "fit_nova_key_preconditioner",
234
+ "fused_chunked_cross_entropy",
235
+ "fused_rope",
236
+ "fused_swiglu",
237
+ "generate_with_isoquant",
238
+ "is_hybrid_supported_model",
239
+ "is_supported_model",
240
+ "load_checkpoint",
241
+ "load_quantized_model",
242
+ "loftq_trellis_init",
243
+ "log_sinkhorn_varn",
244
+ "make_codebook",
245
+ "make_loftq_trellis_qlora",
246
+ "mix_calibration_batches",
247
+ "nf12_pack",
248
+ "nf12_unpack",
249
+ "profile_sps",
250
+ "quantize_gguf_to_mate",
251
+ "quantize_lm_head",
252
+ "quantize_matrix",
253
+ "quantize_model",
254
+ "read_exl3_dir",
255
+ "register_e8_attention",
256
+ "run_interactive_chat",
257
+ "save_checkpoint",
258
+ "score_layer_sensitivity",
259
+ "score_modules_kl_grad",
260
+ "serve_model",
261
+ "tune_quantized_scales",
262
+ "verify_greedy_vectorized",
263
+ "verify_rejection_vectorized",
264
+ ]
265
+
266
+
267
+ def __getattr__(name: str) -> Any:
268
+ spec = _EXPORTS.get(name)
269
+ if spec is None:
270
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
271
+ mod_name, attr_name = spec
272
+ module = importlib.import_module(mod_name, __name__)
273
+ value = module if attr_name is None else getattr(module, attr_name)
274
+ globals()[name] = value
275
+ return value
276
+
277
+
278
+ def __dir__() -> list[str]:
279
+ return sorted(set(globals()) | set(__all__))