maque 0.2.1__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 (143) hide show
  1. maque/__init__.py +30 -0
  2. maque/__main__.py +926 -0
  3. maque/ai_platform/__init__.py +0 -0
  4. maque/ai_platform/crawl.py +45 -0
  5. maque/ai_platform/metrics.py +258 -0
  6. maque/ai_platform/nlp_preprocess.py +67 -0
  7. maque/ai_platform/webpage_screen_shot.py +195 -0
  8. maque/algorithms/__init__.py +78 -0
  9. maque/algorithms/bezier.py +15 -0
  10. maque/algorithms/bktree.py +117 -0
  11. maque/algorithms/core.py +104 -0
  12. maque/algorithms/hilbert.py +16 -0
  13. maque/algorithms/rate_function.py +92 -0
  14. maque/algorithms/transform.py +27 -0
  15. maque/algorithms/trie.py +272 -0
  16. maque/algorithms/utils.py +63 -0
  17. maque/algorithms/video.py +587 -0
  18. maque/api/__init__.py +1 -0
  19. maque/api/common.py +110 -0
  20. maque/api/fetch.py +26 -0
  21. maque/api/static/icon.png +0 -0
  22. maque/api/static/redoc.standalone.js +1782 -0
  23. maque/api/static/swagger-ui-bundle.js +3 -0
  24. maque/api/static/swagger-ui.css +3 -0
  25. maque/cli/__init__.py +1 -0
  26. maque/cli/clean_invisible_chars.py +324 -0
  27. maque/cli/core.py +34 -0
  28. maque/cli/groups/__init__.py +26 -0
  29. maque/cli/groups/config.py +205 -0
  30. maque/cli/groups/data.py +615 -0
  31. maque/cli/groups/doctor.py +259 -0
  32. maque/cli/groups/embedding.py +222 -0
  33. maque/cli/groups/git.py +29 -0
  34. maque/cli/groups/help.py +410 -0
  35. maque/cli/groups/llm.py +223 -0
  36. maque/cli/groups/mcp.py +241 -0
  37. maque/cli/groups/mllm.py +1795 -0
  38. maque/cli/groups/mllm_simple.py +60 -0
  39. maque/cli/groups/quant.py +210 -0
  40. maque/cli/groups/service.py +490 -0
  41. maque/cli/groups/system.py +570 -0
  42. maque/cli/mllm_run.py +1451 -0
  43. maque/cli/script.py +52 -0
  44. maque/cli/tree.py +49 -0
  45. maque/clustering/__init__.py +52 -0
  46. maque/clustering/analyzer.py +347 -0
  47. maque/clustering/clusterers.py +464 -0
  48. maque/clustering/sampler.py +134 -0
  49. maque/clustering/visualizer.py +205 -0
  50. maque/constant.py +13 -0
  51. maque/core.py +133 -0
  52. maque/cv/__init__.py +1 -0
  53. maque/cv/image.py +219 -0
  54. maque/cv/utils.py +68 -0
  55. maque/cv/video/__init__.py +3 -0
  56. maque/cv/video/keyframe_extractor.py +368 -0
  57. maque/embedding/__init__.py +43 -0
  58. maque/embedding/base.py +56 -0
  59. maque/embedding/multimodal.py +308 -0
  60. maque/embedding/server.py +523 -0
  61. maque/embedding/text.py +311 -0
  62. maque/git/__init__.py +24 -0
  63. maque/git/pure_git.py +912 -0
  64. maque/io/__init__.py +29 -0
  65. maque/io/core.py +38 -0
  66. maque/io/ops.py +194 -0
  67. maque/llm/__init__.py +111 -0
  68. maque/llm/backend.py +416 -0
  69. maque/llm/base.py +411 -0
  70. maque/llm/server.py +366 -0
  71. maque/mcp_server.py +1096 -0
  72. maque/mllm_data_processor_pipeline/__init__.py +17 -0
  73. maque/mllm_data_processor_pipeline/core.py +341 -0
  74. maque/mllm_data_processor_pipeline/example.py +291 -0
  75. maque/mllm_data_processor_pipeline/steps/__init__.py +56 -0
  76. maque/mllm_data_processor_pipeline/steps/data_alignment.py +267 -0
  77. maque/mllm_data_processor_pipeline/steps/data_loader.py +172 -0
  78. maque/mllm_data_processor_pipeline/steps/data_validation.py +304 -0
  79. maque/mllm_data_processor_pipeline/steps/format_conversion.py +411 -0
  80. maque/mllm_data_processor_pipeline/steps/mllm_annotation.py +331 -0
  81. maque/mllm_data_processor_pipeline/steps/mllm_refinement.py +446 -0
  82. maque/mllm_data_processor_pipeline/steps/result_validation.py +501 -0
  83. maque/mllm_data_processor_pipeline/web_app.py +317 -0
  84. maque/nlp/__init__.py +14 -0
  85. maque/nlp/ngram.py +9 -0
  86. maque/nlp/parser.py +63 -0
  87. maque/nlp/risk_matcher.py +543 -0
  88. maque/nlp/sentence_splitter.py +202 -0
  89. maque/nlp/simple_tradition_cvt.py +31 -0
  90. maque/performance/__init__.py +21 -0
  91. maque/performance/_measure_time.py +70 -0
  92. maque/performance/_profiler.py +367 -0
  93. maque/performance/_stat_memory.py +51 -0
  94. maque/pipelines/__init__.py +15 -0
  95. maque/pipelines/clustering.py +252 -0
  96. maque/quantization/__init__.py +42 -0
  97. maque/quantization/auto_round.py +120 -0
  98. maque/quantization/base.py +145 -0
  99. maque/quantization/bitsandbytes.py +127 -0
  100. maque/quantization/llm_compressor.py +102 -0
  101. maque/retriever/__init__.py +35 -0
  102. maque/retriever/chroma.py +654 -0
  103. maque/retriever/document.py +140 -0
  104. maque/retriever/milvus.py +1140 -0
  105. maque/table_ops/__init__.py +1 -0
  106. maque/table_ops/core.py +133 -0
  107. maque/table_viewer/__init__.py +4 -0
  108. maque/table_viewer/download_assets.py +57 -0
  109. maque/table_viewer/server.py +698 -0
  110. maque/table_viewer/static/element-plus-icons.js +5791 -0
  111. maque/table_viewer/static/element-plus.css +1 -0
  112. maque/table_viewer/static/element-plus.js +65236 -0
  113. maque/table_viewer/static/main.css +268 -0
  114. maque/table_viewer/static/main.js +669 -0
  115. maque/table_viewer/static/vue.global.js +18227 -0
  116. maque/table_viewer/templates/index.html +401 -0
  117. maque/utils/__init__.py +56 -0
  118. maque/utils/color.py +68 -0
  119. maque/utils/color_string.py +45 -0
  120. maque/utils/compress.py +66 -0
  121. maque/utils/constant.py +183 -0
  122. maque/utils/core.py +261 -0
  123. maque/utils/cursor.py +143 -0
  124. maque/utils/distance.py +58 -0
  125. maque/utils/docker.py +96 -0
  126. maque/utils/downloads.py +51 -0
  127. maque/utils/excel_helper.py +542 -0
  128. maque/utils/helper_metrics.py +121 -0
  129. maque/utils/helper_parser.py +168 -0
  130. maque/utils/net.py +64 -0
  131. maque/utils/nvidia_stat.py +140 -0
  132. maque/utils/ops.py +53 -0
  133. maque/utils/packages.py +31 -0
  134. maque/utils/path.py +57 -0
  135. maque/utils/tar.py +260 -0
  136. maque/utils/untar.py +129 -0
  137. maque/web/__init__.py +0 -0
  138. maque/web/image_downloader.py +1410 -0
  139. maque-0.2.1.dist-info/METADATA +450 -0
  140. maque-0.2.1.dist-info/RECORD +143 -0
  141. maque-0.2.1.dist-info/WHEEL +4 -0
  142. maque-0.2.1.dist-info/entry_points.txt +3 -0
  143. maque-0.2.1.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,60 @@
1
+ """简化版的MLLM chat命令测试"""
2
+
3
+ from rich.console import Console
4
+
5
+ console = Console(force_terminal=True, width=120)
6
+
7
+
8
+ def safe_print(*args, **kwargs):
9
+ """安全的打印函数,确保在所有终端中正确显示颜色"""
10
+ try:
11
+ console.print(*args, **kwargs)
12
+ except Exception:
13
+ # 降级到普通print,去除markup
14
+ clean_args = []
15
+ for arg in args:
16
+ if isinstance(arg, str):
17
+ # 简单去除rich markup
18
+ import re
19
+
20
+ clean_arg = re.sub(r"\[/?[^\]]*\]", "", str(arg))
21
+ clean_args.append(clean_arg)
22
+ else:
23
+ clean_args.append(arg)
24
+ print(*clean_args, **kwargs)
25
+
26
+
27
+ def simple_chat(cli_instance, message: str = None, model: str = None):
28
+ """简化的chat命令测试"""
29
+ import asyncio
30
+ from flexllm.mllm_client import MllmClient
31
+
32
+ async def _chat():
33
+ # 从配置获取默认值
34
+ mllm_config = cli_instance.maque_config.get("mllm", {})
35
+ model_name = model or mllm_config.get("model", "gemma3:latest")
36
+ base_url = mllm_config.get("base_url", "http://localhost:11434/v1")
37
+ api_key = mllm_config.get("api_key", "EMPTY")
38
+
39
+ # 初始化客户端
40
+ client = MllmClient(model=model_name, base_url=base_url, api_key=api_key)
41
+
42
+ if message:
43
+ try:
44
+ messages = [{"role": "user", "content": message}]
45
+ results = await client.call_llm(messages_list=[messages])
46
+ response = results[0] if results and results[0] else "无响应"
47
+ safe_print(f"[bold blue]Assistant:[/bold blue] {response}")
48
+ return response
49
+ except Exception as e:
50
+ safe_print(f"[red]错误: {e}[/red]")
51
+ return None
52
+ else:
53
+ safe_print("[yellow]请提供消息内容[/yellow]")
54
+ return None
55
+
56
+ try:
57
+ return asyncio.run(_chat())
58
+ except Exception as e:
59
+ safe_print(f"[red]运行错误: {e}[/red]")
60
+ return None
@@ -0,0 +1,210 @@
1
+ """量化命令组"""
2
+
3
+ from typing import Optional
4
+ from rich import print
5
+ from rich.console import Console
6
+ from rich.table import Table
7
+
8
+
9
+ class QuantGroup:
10
+ """量化命令组
11
+
12
+ 提供模型量化功能,支持多种量化方案:
13
+ - auto-round: Intel SGD 优化权重舍入 (推荐)
14
+ - awq: Activation-aware Weight Quantization
15
+ - gptq: 经典 GPTQ 量化
16
+ - bnb-nf4: 4-bit NormalFloat 量化 (QLoRA)
17
+ - bnb-int8: 8-bit 整数量化
18
+ """
19
+
20
+ def __init__(self, cli_instance):
21
+ self.cli = cli_instance
22
+ self.console = Console()
23
+
24
+ def run(
25
+ self,
26
+ model: str,
27
+ output: str = None,
28
+ method: str = "auto-round",
29
+ bits: int = 4,
30
+ group_size: int = 128,
31
+ iters: int = 200,
32
+ seqlen: int = 512,
33
+ nsamples: int = 256,
34
+ batch_size: int = 4,
35
+ low_gpu_mem: bool = True,
36
+ dataset: str = "NeelNanda/pile-10k",
37
+ ):
38
+ """量化模型
39
+
40
+ 将模型量化为低精度格式,减少显存占用和提升推理速度。
41
+
42
+ Args:
43
+ model: 模型路径或 HuggingFace 模型名称
44
+ output: 输出路径,默认为 {model}-{method}
45
+ method: 量化方法 (auto-round/awq/gptq/bnb-nf4/bnb-int8),默认 auto-round
46
+ bits: 量化位数,默认 4
47
+ group_size: 量化分组大小,默认 128
48
+ iters: 优化迭代次数 (仅 auto-round),默认 200
49
+ seqlen: 校准序列长度,默认 512
50
+ nsamples: 校准样本数,默认 256
51
+ batch_size: 批次大小,默认 4
52
+ low_gpu_mem: 低显存模式,默认 True
53
+ dataset: 校准数据集 (仅 auto-round),默认 NeelNanda/pile-10k
54
+
55
+ Examples:
56
+ maque quant run Qwen/Qwen3-4B
57
+ maque quant run ./my-model --method=awq --output=./my-model-awq
58
+ maque quant run ./model --dataset=wikitext2 --seqlen=4096
59
+ """
60
+ try:
61
+ from maque.quantization import get_quantizer
62
+ except ImportError as e:
63
+ print(f"[red]无法导入量化模块: {e}[/red]")
64
+ print("请确保已安装依赖: pip install maque[quant]")
65
+ return
66
+
67
+ # 设置默认输出路径
68
+ if output is None:
69
+ model_name = model.rstrip("/").split("/")[-1]
70
+ output = f"{model_name}-{method}"
71
+
72
+ print(f"[bold blue]模型量化[/bold blue]")
73
+ print(f" 模型: [cyan]{model}[/cyan]")
74
+ print(f" 输出: [green]{output}[/green]")
75
+ print(f" 方法: [yellow]{method}[/yellow]")
76
+ print(f" 精度: [yellow]{bits}-bit[/yellow]")
77
+ print()
78
+
79
+ try:
80
+ # 根据方法设置参数
81
+ kwargs = {
82
+ "bits": bits,
83
+ "group_size": group_size,
84
+ }
85
+
86
+ if method == "auto-round":
87
+ kwargs.update({
88
+ "iters": iters,
89
+ "seqlen": seqlen,
90
+ "nsamples": nsamples,
91
+ "batch_size": batch_size,
92
+ "low_gpu_mem_usage": low_gpu_mem,
93
+ "dataset": dataset,
94
+ })
95
+
96
+ quantizer = get_quantizer(method, **kwargs)
97
+ result_path = quantizer.quantize(model, output)
98
+
99
+ print()
100
+ print(f"[bold green]量化完成![/bold green]")
101
+ print(f" 输出路径: [cyan]{result_path}[/cyan]")
102
+
103
+ except Exception as e:
104
+ print(f"[red]量化失败: {e}[/red]")
105
+ raise
106
+
107
+ def methods(self):
108
+ """显示支持的量化方法
109
+
110
+ 列出所有可用的量化方法及其特点。
111
+
112
+ Examples:
113
+ maque quant methods
114
+ """
115
+ try:
116
+ from maque.quantization import list_methods
117
+ except ImportError:
118
+ print("[red]无法导入量化模块[/red]")
119
+ return
120
+
121
+ print("[bold blue]支持的量化方法[/bold blue]\n")
122
+
123
+ table = Table(show_header=True, header_style="bold magenta")
124
+ table.add_column("方法", style="cyan", width=12)
125
+ table.add_column("精度", style="green", width=8)
126
+ table.add_column("库", style="yellow", width=15)
127
+ table.add_column("描述", style="white")
128
+ table.add_column("用途", style="dim")
129
+
130
+ for name, info in list_methods().items():
131
+ table.add_row(
132
+ name,
133
+ info["precision"],
134
+ info["library"],
135
+ info["description"],
136
+ info["use_case"],
137
+ )
138
+
139
+ self.console.print(table)
140
+
141
+ print("\n[dim]使用示例:[/dim]")
142
+ print(" maque quant run Qwen/Qwen3-4B --method=auto-round")
143
+ print(" maque quant run ./my-model --method=awq --output=./my-model-awq")
144
+
145
+ def info(self, model: str):
146
+ """显示模型的量化信息
147
+
148
+ 读取模型的量化配置信息。
149
+
150
+ Args:
151
+ model: 模型路径
152
+
153
+ Examples:
154
+ maque quant info ./Qwen3-4B-awq
155
+ """
156
+ from pathlib import Path
157
+ import json
158
+
159
+ model_path = Path(model)
160
+
161
+ if not model_path.exists():
162
+ print(f"[red]模型路径不存在: {model}[/red]")
163
+ return
164
+
165
+ print(f"[bold blue]模型量化信息[/bold blue]")
166
+ print(f" 路径: [cyan]{model_path.resolve()}[/cyan]")
167
+ print()
168
+
169
+ # 检查 quantization_config.json
170
+ quant_config_path = model_path / "quantization_config.json"
171
+ config_path = model_path / "config.json"
172
+
173
+ quant_info = None
174
+
175
+ if quant_config_path.exists():
176
+ with open(quant_config_path, "r") as f:
177
+ quant_info = json.load(f)
178
+ elif config_path.exists():
179
+ with open(config_path, "r") as f:
180
+ config = json.load(f)
181
+ quant_info = config.get("quantization_config")
182
+
183
+ if quant_info:
184
+ print("[green]已量化[/green]")
185
+ print()
186
+
187
+ table = Table(show_header=True, header_style="bold magenta")
188
+ table.add_column("配置项", style="cyan")
189
+ table.add_column("值", style="yellow")
190
+
191
+ for key, value in quant_info.items():
192
+ table.add_row(str(key), str(value))
193
+
194
+ self.console.print(table)
195
+ else:
196
+ print("[yellow]未检测到量化配置,可能是原始模型[/yellow]")
197
+
198
+ # 显示模型文件大小
199
+ print()
200
+ total_size = 0
201
+ safetensors_files = list(model_path.glob("*.safetensors"))
202
+ bin_files = list(model_path.glob("*.bin"))
203
+
204
+ model_files = safetensors_files or bin_files
205
+ for f in model_files:
206
+ total_size += f.stat().st_size
207
+
208
+ if total_size > 0:
209
+ size_gb = total_size / (1024 ** 3)
210
+ print(f" 模型大小: [cyan]{size_gb:.2f} GB[/cyan]")