Spaces:
Running
Running
zhan1206 commited on
Commit ·
a3aa0f2
1
Parent(s): 3ab86b9
fix: M2/S2/S4/M4 defect repairs
Browse filesM2: Fixed mini_data.json duplication (74% -> 0%), 57 unique samples
with balanced think_rank distribution (0:37%, 1:23%, 2:23%, 3:18%)
S2: Added QATTrainer class to DyQuant for quantization-aware training
integration (inserts fake-quant nodes, trains, exports quantized model)
S4: Ollama deploy now has fallback export for custom architectures
(SBLA/ThinkingDial) when llama.cpp convert-hf-to-gguf fails
M4: Added validate_think_rank.py script for distribution verification
New files:
- scripts/dedup_mini_data.py
- scripts/validate_think_rank.py
- data/mini_data.json +140 -395
- inference/dyquant.py +157 -1
- inference/ollama_deploy_v2.py +56 -3
- scripts/dedup_mini_data.py +120 -0
- scripts/validate_think_rank.py +87 -0
data/mini_data.json
CHANGED
|
@@ -1,542 +1,287 @@
|
|
| 1 |
[
|
| 2 |
-
{
|
| 3 |
-
"prompt": "什么是大数据",
|
| 4 |
-
"response": "大数据是指规模巨大、类型多样的数据集合。",
|
| 5 |
-
"think_rank": 0
|
| 6 |
-
},
|
| 7 |
-
{
|
| 8 |
-
"prompt": "How to learn coding",
|
| 9 |
-
"response": "Practice coding regularly and build projects.",
|
| 10 |
-
"think_rank": 0
|
| 11 |
-
},
|
| 12 |
-
{
|
| 13 |
-
"prompt": "What is AI",
|
| 14 |
-
"response": "AI stands for Artificial Intelligence.",
|
| 15 |
-
"think_rank": 0
|
| 16 |
-
},
|
| 17 |
-
{
|
| 18 |
-
"prompt": "Python features",
|
| 19 |
-
"response": "Python is simple, powerful, and versatile.",
|
| 20 |
-
"think_rank": 0
|
| 21 |
-
},
|
| 22 |
-
{
|
| 23 |
-
"prompt": "Python features",
|
| 24 |
-
"response": "Python is simple, powerful, and versatile.",
|
| 25 |
-
"think_rank": 0
|
| 26 |
-
},
|
| 27 |
-
{
|
| 28 |
-
"prompt": "Python features",
|
| 29 |
-
"response": "Python is simple, powerful, and versatile.",
|
| 30 |
-
"think_rank": 0
|
| 31 |
-
},
|
| 32 |
-
{
|
| 33 |
-
"prompt": "什么是大数据",
|
| 34 |
-
"response": "大数据是指规模巨大、类型多样的数据集合。",
|
| 35 |
-
"think_rank": 0
|
| 36 |
-
},
|
| 37 |
{
|
| 38 |
"prompt": "Hello",
|
| 39 |
-
"response": "Hello!
|
| 40 |
-
"think_rank": 0
|
| 41 |
-
},
|
| 42 |
-
{
|
| 43 |
-
"prompt": "How to learn coding",
|
| 44 |
-
"response": "Practice coding regularly and build projects.",
|
| 45 |
-
"think_rank": 0
|
| 46 |
-
},
|
| 47 |
-
{
|
| 48 |
-
"prompt": "云计算的优势",
|
| 49 |
-
"response": "云计算提供弹性扩展、成本节约、易于维护等优势。",
|
| 50 |
-
"think_rank": 0
|
| 51 |
-
},
|
| 52 |
-
{
|
| 53 |
-
"prompt": "什么是人工智能",
|
| 54 |
-
"response": "人工智能是计算机科学的一个分支,致力于创建智能机器。",
|
| 55 |
-
"think_rank": 1
|
| 56 |
-
},
|
| 57 |
-
{
|
| 58 |
-
"prompt": "How to learn coding",
|
| 59 |
-
"response": "Practice coding regularly and build projects.",
|
| 60 |
"think_rank": 0
|
| 61 |
},
|
| 62 |
{
|
| 63 |
-
"prompt": "
|
| 64 |
-
"response": "Python
|
| 65 |
"think_rank": 0
|
| 66 |
},
|
| 67 |
{
|
| 68 |
-
"prompt": "
|
| 69 |
-
"response": "
|
| 70 |
"think_rank": 0
|
| 71 |
},
|
| 72 |
{
|
| 73 |
-
"prompt": "What is
|
| 74 |
-
"response": "
|
| 75 |
"think_rank": 0
|
| 76 |
},
|
| 77 |
{
|
| 78 |
-
"prompt": "
|
| 79 |
-
"response": "
|
| 80 |
"think_rank": 0
|
| 81 |
},
|
| 82 |
{
|
| 83 |
-
"prompt": "What
|
| 84 |
-
"response": "
|
| 85 |
"think_rank": 0
|
| 86 |
},
|
| 87 |
{
|
| 88 |
-
"prompt": "
|
| 89 |
-
"response": "
|
| 90 |
"think_rank": 0
|
| 91 |
},
|
| 92 |
{
|
| 93 |
-
"prompt": "
|
| 94 |
-
"response": "
|
| 95 |
-
"think_rank": 2
|
| 96 |
-
},
|
| 97 |
-
{
|
| 98 |
-
"prompt": "What is NLP",
|
| 99 |
-
"response": "NLP helps computers understand human language.",
|
| 100 |
"think_rank": 0
|
| 101 |
},
|
| 102 |
{
|
| 103 |
-
"prompt": "
|
| 104 |
-
"response": "
|
| 105 |
"think_rank": 0
|
| 106 |
},
|
| 107 |
{
|
| 108 |
-
"prompt": "
|
| 109 |
-
"response": "
|
| 110 |
"think_rank": 0
|
| 111 |
},
|
| 112 |
{
|
| 113 |
-
"prompt": "What is
|
| 114 |
-
"response": "
|
| 115 |
"think_rank": 0
|
| 116 |
},
|
| 117 |
{
|
| 118 |
-
"prompt": "
|
| 119 |
-
"response": "
|
| 120 |
"think_rank": 0
|
| 121 |
},
|
| 122 |
{
|
| 123 |
-
"prompt": "
|
| 124 |
-
"response": "
|
| 125 |
"think_rank": 0
|
| 126 |
},
|
| 127 |
{
|
| 128 |
-
"prompt": "What is
|
| 129 |
-
"response": "
|
| 130 |
"think_rank": 0
|
| 131 |
},
|
| 132 |
{
|
| 133 |
-
"prompt": "
|
| 134 |
-
"response": "
|
| 135 |
"think_rank": 0
|
| 136 |
},
|
| 137 |
{
|
| 138 |
-
"prompt": "
|
| 139 |
-
"response": "
|
| 140 |
-
"think_rank":
|
| 141 |
-
},
|
| 142 |
-
{
|
| 143 |
-
"prompt": "How blockchain works",
|
| 144 |
-
"response": "Blockchain is a distributed ledger technology.",
|
| 145 |
-
"think_rank": 0
|
| 146 |
},
|
| 147 |
{
|
| 148 |
-
"prompt": "
|
| 149 |
-
"response": "
|
| 150 |
-
"think_rank":
|
| 151 |
},
|
| 152 |
{
|
| 153 |
-
"prompt": "
|
| 154 |
-
"response": "
|
| 155 |
-
"think_rank":
|
| 156 |
},
|
| 157 |
{
|
| 158 |
-
"prompt": "
|
| 159 |
-
"response": "
|
| 160 |
-
"think_rank":
|
| 161 |
},
|
| 162 |
{
|
| 163 |
-
"prompt": "
|
| 164 |
-
"response": "
|
| 165 |
-
"think_rank":
|
| 166 |
},
|
| 167 |
{
|
| 168 |
-
"prompt": "
|
| 169 |
-
"response": "
|
| 170 |
-
"think_rank":
|
| 171 |
},
|
| 172 |
{
|
| 173 |
-
"prompt": "
|
| 174 |
-
"response": "
|
| 175 |
-
"think_rank":
|
| 176 |
},
|
| 177 |
{
|
| 178 |
-
"prompt": "
|
| 179 |
-
"response": "
|
| 180 |
-
"think_rank":
|
| 181 |
},
|
| 182 |
{
|
| 183 |
-
"prompt": "
|
| 184 |
-
"response": "
|
| 185 |
-
"think_rank":
|
| 186 |
},
|
| 187 |
{
|
| 188 |
-
"prompt": "
|
| 189 |
-
"response": "
|
| 190 |
-
"think_rank":
|
| 191 |
},
|
| 192 |
{
|
| 193 |
-
"prompt": "Explain
|
| 194 |
-
"response": "
|
| 195 |
"think_rank": 2
|
| 196 |
},
|
| 197 |
{
|
| 198 |
-
"prompt": "
|
| 199 |
-
"response": "
|
| 200 |
-
"think_rank":
|
| 201 |
-
},
|
| 202 |
-
{
|
| 203 |
-
"prompt": "What is deep learning",
|
| 204 |
-
"response": "Deep learning uses neural networks with many layers.",
|
| 205 |
-
"think_rank": 0
|
| 206 |
-
},
|
| 207 |
-
{
|
| 208 |
-
"prompt": "Hello",
|
| 209 |
-
"response": "Hello! I am Fusion Mini model.",
|
| 210 |
-
"think_rank": 0
|
| 211 |
-
},
|
| 212 |
-
{
|
| 213 |
-
"prompt": "什么是大数据",
|
| 214 |
-
"response": "大数据是指规模巨大、类型多样的数据集合。",
|
| 215 |
-
"think_rank": 0
|
| 216 |
},
|
| 217 |
{
|
| 218 |
-
"prompt": "
|
| 219 |
-
"response": "
|
| 220 |
-
"think_rank":
|
| 221 |
},
|
| 222 |
{
|
| 223 |
-
"prompt": "
|
| 224 |
-
"response": "
|
| 225 |
"think_rank": 2
|
| 226 |
},
|
| 227 |
{
|
| 228 |
-
"prompt": "
|
| 229 |
-
"response": "
|
| 230 |
-
"think_rank":
|
| 231 |
},
|
| 232 |
{
|
| 233 |
-
"prompt": "
|
| 234 |
-
"response": "
|
| 235 |
-
"think_rank":
|
| 236 |
},
|
| 237 |
{
|
| 238 |
-
"prompt": "
|
| 239 |
-
"response": "
|
| 240 |
-
"think_rank":
|
| 241 |
},
|
| 242 |
{
|
| 243 |
-
"prompt": "
|
| 244 |
-
"response": "
|
| 245 |
-
"think_rank":
|
| 246 |
},
|
| 247 |
{
|
| 248 |
-
"prompt": "
|
| 249 |
-
"response": "
|
| 250 |
-
"think_rank":
|
| 251 |
},
|
| 252 |
{
|
| 253 |
-
"prompt": "
|
| 254 |
-
"response": "
|
| 255 |
-
"think_rank":
|
| 256 |
},
|
| 257 |
{
|
| 258 |
-
"prompt": "
|
| 259 |
-
"response": "
|
| 260 |
-
"think_rank":
|
| 261 |
},
|
| 262 |
{
|
| 263 |
-
"prompt": "
|
| 264 |
-
"response": "
|
| 265 |
-
"think_rank":
|
| 266 |
},
|
| 267 |
{
|
| 268 |
-
"prompt": "
|
| 269 |
-
"response": "
|
| 270 |
-
"think_rank":
|
| 271 |
},
|
| 272 |
{
|
| 273 |
-
"prompt": "
|
| 274 |
-
"response": "
|
| 275 |
-
"think_rank":
|
| 276 |
},
|
| 277 |
{
|
| 278 |
-
"prompt": "
|
| 279 |
-
"response": "
|
| 280 |
-
"think_rank":
|
| 281 |
},
|
| 282 |
{
|
| 283 |
-
"prompt": "
|
| 284 |
-
"response": "
|
| 285 |
-
"think_rank":
|
| 286 |
},
|
| 287 |
{
|
| 288 |
-
"prompt": "
|
| 289 |
-
"response": "
|
| 290 |
-
"think_rank":
|
| 291 |
},
|
| 292 |
{
|
| 293 |
-
"prompt": "
|
| 294 |
-
"response": "
|
| 295 |
-
"think_rank":
|
| 296 |
},
|
| 297 |
{
|
| 298 |
-
"prompt": "
|
| 299 |
-
"response": "
|
| 300 |
"think_rank": 0
|
| 301 |
},
|
| 302 |
{
|
| 303 |
-
"prompt": "
|
| 304 |
-
"response": "
|
| 305 |
-
"think_rank": 2
|
| 306 |
-
},
|
| 307 |
-
{
|
| 308 |
-
"prompt": "What is deep learning",
|
| 309 |
-
"response": "Deep learning uses neural networks with many layers.",
|
| 310 |
"think_rank": 0
|
| 311 |
},
|
| 312 |
{
|
| 313 |
-
"prompt": "
|
| 314 |
-
"response": "
|
| 315 |
"think_rank": 0
|
| 316 |
},
|
| 317 |
{
|
| 318 |
-
"prompt": "
|
| 319 |
-
"response": "
|
| 320 |
"think_rank": 0
|
| 321 |
},
|
| 322 |
{
|
| 323 |
-
"prompt": "
|
| 324 |
-
"response": "
|
| 325 |
"think_rank": 0
|
| 326 |
},
|
| 327 |
{
|
| 328 |
"prompt": "什么是人工智能",
|
| 329 |
"response": "人工智能是计算机科学的一个分支,致力于创建智能机器。",
|
| 330 |
-
"think_rank": 1
|
| 331 |
-
},
|
| 332 |
-
{
|
| 333 |
-
"prompt": "你好",
|
| 334 |
-
"response": "你好!我是 Fusion Mini 模型。",
|
| 335 |
-
"think_rank": 0
|
| 336 |
-
},
|
| 337 |
-
{
|
| 338 |
-
"prompt": "区块链的原理",
|
| 339 |
-
"response": "区块链是一种分布式账本技术,确保数据不可篡改。",
|
| 340 |
"think_rank": 0
|
| 341 |
},
|
| 342 |
{
|
| 343 |
-
"prompt": "
|
| 344 |
-
"response": "
|
| 345 |
-
"think_rank":
|
| 346 |
},
|
| 347 |
{
|
| 348 |
-
"prompt": "
|
| 349 |
-
"response": "
|
| 350 |
-
"think_rank":
|
| 351 |
},
|
| 352 |
{
|
| 353 |
-
"prompt": "
|
| 354 |
-
"response": "
|
| 355 |
-
"think_rank":
|
| 356 |
},
|
| 357 |
{
|
| 358 |
-
"prompt": "
|
| 359 |
-
"response": "
|
| 360 |
"think_rank": 2
|
| 361 |
},
|
| 362 |
{
|
| 363 |
-
"prompt": "
|
| 364 |
-
"response": "
|
| 365 |
-
"think_rank": 0
|
| 366 |
-
},
|
| 367 |
-
{
|
| 368 |
-
"prompt": "区块链的原理",
|
| 369 |
-
"response": "区块链是一种分布式账本技术,确保数据不可篡改。",
|
| 370 |
-
"think_rank": 0
|
| 371 |
-
},
|
| 372 |
-
{
|
| 373 |
-
"prompt": "What is big data",
|
| 374 |
-
"response": "Big data refers to extremely large datasets.",
|
| 375 |
-
"think_rank": 0
|
| 376 |
-
},
|
| 377 |
-
{
|
| 378 |
-
"prompt": "How to learn coding",
|
| 379 |
-
"response": "Practice coding regularly and build projects.",
|
| 380 |
-
"think_rank": 0
|
| 381 |
-
},
|
| 382 |
-
{
|
| 383 |
-
"prompt": "How blockchain works",
|
| 384 |
-
"response": "Blockchain is a distributed ledger technology.",
|
| 385 |
-
"think_rank": 0
|
| 386 |
-
},
|
| 387 |
-
{
|
| 388 |
-
"prompt": "What is deep learning",
|
| 389 |
-
"response": "Deep learning uses neural networks with many layers.",
|
| 390 |
-
"think_rank": 0
|
| 391 |
-
},
|
| 392 |
-
{
|
| 393 |
-
"prompt": "你好",
|
| 394 |
-
"response": "你好!我是 Fusion Mini 模型。",
|
| 395 |
-
"think_rank": 0
|
| 396 |
-
},
|
| 397 |
-
{
|
| 398 |
-
"prompt": "你好",
|
| 399 |
-
"response": "你好!我是 Fusion Mini 模型。",
|
| 400 |
-
"think_rank": 0
|
| 401 |
-
},
|
| 402 |
-
{
|
| 403 |
-
"prompt": "Python features",
|
| 404 |
-
"response": "Python is simple, powerful, and versatile.",
|
| 405 |
-
"think_rank": 0
|
| 406 |
-
},
|
| 407 |
-
{
|
| 408 |
-
"prompt": "云计算的优势",
|
| 409 |
-
"response": "云计算提供弹性扩展、成本节约、易于维护等优势。",
|
| 410 |
-
"think_rank": 0
|
| 411 |
-
},
|
| 412 |
-
{
|
| 413 |
-
"prompt": "什么是大数据",
|
| 414 |
-
"response": "大数据是指规模巨大、类型多样的数据集合。",
|
| 415 |
-
"think_rank": 0
|
| 416 |
-
},
|
| 417 |
-
{
|
| 418 |
-
"prompt": "Python 有什么特点",
|
| 419 |
-
"response": "Python 是一种简单易学、功能强大的编程语言。",
|
| 420 |
-
"think_rank": 0
|
| 421 |
-
},
|
| 422 |
-
{
|
| 423 |
-
"prompt": "Benefits of cloud computing",
|
| 424 |
-
"response": "Cloud computing offers scalability and cost savings.",
|
| 425 |
-
"think_rank": 0
|
| 426 |
-
},
|
| 427 |
-
{
|
| 428 |
-
"prompt": "Hello",
|
| 429 |
-
"response": "Hello! I am Fusion Mini model.",
|
| 430 |
-
"think_rank": 0
|
| 431 |
-
},
|
| 432 |
-
{
|
| 433 |
-
"prompt": "What is big data",
|
| 434 |
-
"response": "Big data refers to extremely large datasets.",
|
| 435 |
-
"think_rank": 0
|
| 436 |
-
},
|
| 437 |
-
{
|
| 438 |
-
"prompt": "What is NLP",
|
| 439 |
-
"response": "NLP helps computers understand human language.",
|
| 440 |
-
"think_rank": 0
|
| 441 |
-
},
|
| 442 |
-
{
|
| 443 |
-
"prompt": "Python features",
|
| 444 |
-
"response": "Python is simple, powerful, and versatile.",
|
| 445 |
-
"think_rank": 0
|
| 446 |
-
},
|
| 447 |
-
{
|
| 448 |
-
"prompt": "区块链的原理",
|
| 449 |
-
"response": "区块链是一种分布式账本技术,确保数据不可篡改。",
|
| 450 |
-
"think_rank": 0
|
| 451 |
-
},
|
| 452 |
-
{
|
| 453 |
-
"prompt": "解释机器学习",
|
| 454 |
-
"response": "机器学习是人工智能的子领域,使计算机能够从数据中学习。",
|
| 455 |
"think_rank": 2
|
| 456 |
},
|
| 457 |
{
|
| 458 |
-
"prompt": "
|
| 459 |
-
"response": "
|
| 460 |
-
"think_rank": 0
|
| 461 |
-
},
|
| 462 |
-
{
|
| 463 |
-
"prompt": "Python features",
|
| 464 |
-
"response": "Python is simple, powerful, and versatile.",
|
| 465 |
-
"think_rank": 0
|
| 466 |
-
},
|
| 467 |
-
{
|
| 468 |
-
"prompt": "你好",
|
| 469 |
-
"response": "你好!我是 Fusion Mini 模型。",
|
| 470 |
-
"think_rank": 0
|
| 471 |
-
},
|
| 472 |
-
{
|
| 473 |
-
"prompt": "Explain machine learning",
|
| 474 |
-
"response": "Machine learning is a subset of AI.",
|
| 475 |
"think_rank": 2
|
| 476 |
},
|
| 477 |
{
|
| 478 |
-
"prompt": "
|
| 479 |
-
"response": "
|
| 480 |
-
"think_rank": 0
|
| 481 |
-
},
|
| 482 |
-
{
|
| 483 |
-
"prompt": "你好",
|
| 484 |
-
"response": "你好!我是 Fusion Mini 模型。",
|
| 485 |
-
"think_rank": 0
|
| 486 |
-
},
|
| 487 |
-
{
|
| 488 |
-
"prompt": "How to learn coding",
|
| 489 |
-
"response": "Practice coding regularly and build projects.",
|
| 490 |
-
"think_rank": 0
|
| 491 |
-
},
|
| 492 |
-
{
|
| 493 |
-
"prompt": "What is big data",
|
| 494 |
-
"response": "Big data refers to extremely large datasets.",
|
| 495 |
-
"think_rank": 0
|
| 496 |
-
},
|
| 497 |
-
{
|
| 498 |
-
"prompt": "什么是人工智能",
|
| 499 |
-
"response": "人工智能是计算机科学的一个分支,致力于创建智能机器。",
|
| 500 |
-
"think_rank": 1
|
| 501 |
-
},
|
| 502 |
-
{
|
| 503 |
-
"prompt": "Prove the Pythagorean theorem",
|
| 504 |
-
"response": "Consider a right triangle with legs a, b and hypotenuse c. Construct a square of side (a+b) and arrange four copies of the triangle inside. The inner quadrilateral is a square of side c, so (a+b)^2 = c^2 + 4*(ab/2), which simplifies to a^2 + b^2 = c^2.",
|
| 505 |
-
"think_rank": 3
|
| 506 |
-
},
|
| 507 |
-
{
|
| 508 |
-
"prompt": "Derive the quadratic formula",
|
| 509 |
-
"response": "Starting from ax^2 + bx + c = 0, divide by a, complete the square: (x + b/2a)^2 = (b^2 - 4ac)/4a^2. Taking the square root gives x = (-b +- sqrt(b^2 - 4ac)) / 2a.",
|
| 510 |
-
"think_rank": 3
|
| 511 |
-
},
|
| 512 |
-
{
|
| 513 |
-
"prompt": "Prove that sqrt(2) is irrational",
|
| 514 |
-
"response": "Assume sqrt(2) = p/q in lowest terms. Then 2q^2 = p^2, so p is even. Write p = 2k, then 2q^2 = 4k^2, so q^2 = 2k^2, meaning q is also even. This contradicts p/q being in lowest terms.",
|
| 515 |
-
"think_rank": 3
|
| 516 |
-
},
|
| 517 |
-
{
|
| 518 |
-
"prompt": "Prove there are infinitely many primes",
|
| 519 |
-
"response": "Suppose finitely many primes p1,...,pn exist. Let N = p1*p2*...*pn + 1. N is not divisible by any pi (remainder 1). So N is either prime itself or has a prime factor not in the list. Contradiction.",
|
| 520 |
-
"think_rank": 3
|
| 521 |
-
},
|
| 522 |
-
{
|
| 523 |
-
"prompt": "Derive the derivative of sin(x)",
|
| 524 |
-
"response": "Using the limit definition: d/dx sin(x) = lim(h->0) [sin(x+h) - sin(x)] / h. Apply the angle addition formula: sin(x+h) = sin(x)cos(h) + cos(x)sin(h). This gives lim [sin(x)(cos(h)-1)/h + cos(x)sin(h)/h] = sin(x)*0 + cos(x)*1 = cos(x).",
|
| 525 |
-
"think_rank": 3
|
| 526 |
-
},
|
| 527 |
-
{
|
| 528 |
-
"prompt": "Analyze the time complexity of merge sort",
|
| 529 |
-
"response": "Merge sort divides the array in half (O(1)), recurses on both halves (2T(n/2)), and merges in O(n). The recurrence T(n) = 2T(n/2) + O(n) solves to O(n log n) by the master theorem (case 2). This holds for worst, average, and best cases.",
|
| 530 |
-
"think_rank": 3
|
| 531 |
-
},
|
| 532 |
-
{
|
| 533 |
-
"prompt": "Prove the sum of first n natural numbers is n(n+1)/2",
|
| 534 |
-
"response": "By induction: Base case n=1: 1 = 1(2)/2 = 1. Inductive step: assume S(k) = k(k+1)/2. Then S(k+1) = S(k) + (k+1) = k(k+1)/2 + (k+1) = (k+1)(k/2 + 1) = (k+1)(k+2)/2. QED.",
|
| 535 |
"think_rank": 3
|
| 536 |
},
|
| 537 |
{
|
| 538 |
-
"prompt": "
|
| 539 |
-
"response": "
|
| 540 |
"think_rank": 3
|
| 541 |
}
|
| 542 |
]
|
|
|
|
| 1 |
[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
{
|
| 3 |
"prompt": "Hello",
|
| 4 |
+
"response": "Hello! How can I help you today?",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
"think_rank": 0
|
| 6 |
},
|
| 7 |
{
|
| 8 |
+
"prompt": "What is Python",
|
| 9 |
+
"response": "Python is a high-level programming language known for its readability and versatility.",
|
| 10 |
"think_rank": 0
|
| 11 |
},
|
| 12 |
{
|
| 13 |
+
"prompt": "Define API",
|
| 14 |
+
"response": "API stands for Application Programming Interface, a set of rules for software communication.",
|
| 15 |
"think_rank": 0
|
| 16 |
},
|
| 17 |
{
|
| 18 |
+
"prompt": "What is HTML",
|
| 19 |
+
"response": "HTML is the standard markup language for creating web pages.",
|
| 20 |
"think_rank": 0
|
| 21 |
},
|
| 22 |
{
|
| 23 |
+
"prompt": "Name a search engine",
|
| 24 |
+
"response": "Google is the most widely used search engine.",
|
| 25 |
"think_rank": 0
|
| 26 |
},
|
| 27 |
{
|
| 28 |
+
"prompt": "What does CPU stand for",
|
| 29 |
+
"response": "CPU stands for Central Processing Unit, the brain of a computer.",
|
| 30 |
"think_rank": 0
|
| 31 |
},
|
| 32 |
{
|
| 33 |
+
"prompt": "What is RAM",
|
| 34 |
+
"response": "RAM is Random Access Memory, used for temporary data storage during program execution.",
|
| 35 |
"think_rank": 0
|
| 36 |
},
|
| 37 |
{
|
| 38 |
+
"prompt": "What is WiFi",
|
| 39 |
+
"response": "WiFi is a wireless networking technology for internet connectivity.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
"think_rank": 0
|
| 41 |
},
|
| 42 |
{
|
| 43 |
+
"prompt": "What is a database",
|
| 44 |
+
"response": "A database is an organized collection of structured data stored electronically.",
|
| 45 |
"think_rank": 0
|
| 46 |
},
|
| 47 |
{
|
| 48 |
+
"prompt": "What is an operating system",
|
| 49 |
+
"response": "An operating system manages hardware and software resources on a computer.",
|
| 50 |
"think_rank": 0
|
| 51 |
},
|
| 52 |
{
|
| 53 |
+
"prompt": "What is cloud storage",
|
| 54 |
+
"response": "Cloud storage saves data on remote servers accessed via the internet.",
|
| 55 |
"think_rank": 0
|
| 56 |
},
|
| 57 |
{
|
| 58 |
+
"prompt": "What is encryption",
|
| 59 |
+
"response": "Encryption converts data into a coded format to prevent unauthorized access.",
|
| 60 |
"think_rank": 0
|
| 61 |
},
|
| 62 |
{
|
| 63 |
+
"prompt": "What is a URL",
|
| 64 |
+
"response": "A URL is a web address that specifies the location of a resource on the internet.",
|
| 65 |
"think_rank": 0
|
| 66 |
},
|
| 67 |
{
|
| 68 |
+
"prompt": "What is a browser",
|
| 69 |
+
"response": "A browser is software for accessing and viewing websites on the internet.",
|
| 70 |
"think_rank": 0
|
| 71 |
},
|
| 72 |
{
|
| 73 |
+
"prompt": "What is open source",
|
| 74 |
+
"response": "Open source software has source code that anyone can inspect, modify, and distribute.",
|
| 75 |
"think_rank": 0
|
| 76 |
},
|
| 77 |
{
|
| 78 |
+
"prompt": "Write a function to reverse a string",
|
| 79 |
+
"response": "def reverse_string(s): return s[::-1]",
|
| 80 |
+
"think_rank": 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
},
|
| 82 |
{
|
| 83 |
+
"prompt": "Implement a function to check if a number is prime",
|
| 84 |
+
"response": "def is_prime(n): return n > 1 and all(n % i != 0 for i in range(2, int(n**0.5) + 1))",
|
| 85 |
+
"think_rank": 1
|
| 86 |
},
|
| 87 |
{
|
| 88 |
+
"prompt": "Write a function to calculate factorial",
|
| 89 |
+
"response": "def factorial(n): return 1 if n <= 1 else n * factorial(n - 1)",
|
| 90 |
+
"think_rank": 1
|
| 91 |
},
|
| 92 |
{
|
| 93 |
+
"prompt": "Implement binary search in Python",
|
| 94 |
+
"response": "def binary_search(arr, target):\n lo, hi = 0, len(arr) - 1\n while lo <= hi:\n mid = (lo + hi) // 2\n if arr[mid] == target: return mid\n elif arr[mid] < target: lo = mid + 1\n else: hi = mid - 1\n return -1",
|
| 95 |
+
"think_rank": 1
|
| 96 |
},
|
| 97 |
{
|
| 98 |
+
"prompt": "Write a function to sort a list",
|
| 99 |
+
"response": "def sort_list(lst): return sorted(lst)",
|
| 100 |
+
"think_rank": 1
|
| 101 |
},
|
| 102 |
{
|
| 103 |
+
"prompt": "Implement a stack data structure",
|
| 104 |
+
"response": "class Stack:\n def __init__(self): self.items = []\n def push(self, item): self.items.append(item)\n def pop(self): return self.items.pop() if self.items else None",
|
| 105 |
+
"think_rank": 1
|
| 106 |
},
|
| 107 |
{
|
| 108 |
+
"prompt": "Write code to read a CSV file",
|
| 109 |
+
"response": "import csv\nwith open('file.csv') as f:\n reader = csv.reader(f)\n for row in reader: print(row)",
|
| 110 |
+
"think_rank": 1
|
| 111 |
},
|
| 112 |
{
|
| 113 |
+
"prompt": "Implement a linked list node",
|
| 114 |
+
"response": "class Node:\n def __init__(self, val, next=None):\n self.val = val\n self.next = next",
|
| 115 |
+
"think_rank": 1
|
| 116 |
},
|
| 117 |
{
|
| 118 |
+
"prompt": "Write a function to count words in text",
|
| 119 |
+
"response": "def count_words(text): return len(text.split())",
|
| 120 |
+
"think_rank": 1
|
| 121 |
},
|
| 122 |
{
|
| 123 |
+
"prompt": "Implement a simple HTTP GET request",
|
| 124 |
+
"response": "import requests\nresponse = requests.get('https://api.example.com/data')\nprint(response.json())",
|
| 125 |
+
"think_rank": 1
|
| 126 |
},
|
| 127 |
{
|
| 128 |
+
"prompt": "Explain how neural networks learn",
|
| 129 |
+
"response": "Neural networks learn through backpropagation: they compute predictions, measure error using a loss function, calculate gradients of the loss with respect to weights, and update weights using gradient descent to minimize error.",
|
| 130 |
"think_rank": 2
|
| 131 |
},
|
| 132 |
{
|
| 133 |
+
"prompt": "Compare REST and GraphQL",
|
| 134 |
+
"response": "REST uses fixed endpoints returning predetermined data structures. GraphQL uses a single endpoint where clients specify exactly which fields they need, reducing over-fetching but adding query complexity.",
|
| 135 |
+
"think_rank": 2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
},
|
| 137 |
{
|
| 138 |
+
"prompt": "Explain the difference between SQL and NoSQL",
|
| 139 |
+
"response": "SQL databases use structured tables with fixed schemas and ACID transactions. NoSQL databases use flexible document/key-value/graph models optimized for scale and schema evolution, often trading consistency for availability.",
|
| 140 |
+
"think_rank": 2
|
| 141 |
},
|
| 142 |
{
|
| 143 |
+
"prompt": "How does garbage collection work in Python",
|
| 144 |
+
"response": "Python uses reference counting as the primary mechanism and a cyclic garbage collector for detecting and collecting reference cycles. Objects with zero references are freed immediately; cycles are detected periodically.",
|
| 145 |
"think_rank": 2
|
| 146 |
},
|
| 147 |
{
|
| 148 |
+
"prompt": "Explain the Transformer attention mechanism",
|
| 149 |
+
"response": "Self-attention computes queries, keys, and values from input. Attention scores are the dot product of queries and keys, scaled by sqrt(d_k), softmaxed, then multiplied by values. This lets each position attend to all other positions.",
|
| 150 |
+
"think_rank": 2
|
| 151 |
},
|
| 152 |
{
|
| 153 |
+
"prompt": "Why is batch normalization important",
|
| 154 |
+
"response": "Batch normalization stabilizes training by normalizing layer inputs to zero mean and unit variance. This reduces internal covariate shift, allows higher learning rates, and acts as a regularizer, improving convergence.",
|
| 155 |
+
"think_rank": 2
|
| 156 |
},
|
| 157 |
{
|
| 158 |
+
"prompt": "How does DNS resolution work",
|
| 159 |
+
"response": "DNS resolution follows a hierarchy: browser cache -> OS cache -> recursive resolver -> root server -> TLD server -> authoritative server. Each step either returns the answer or delegates to the next level.",
|
| 160 |
+
"think_rank": 2
|
| 161 |
},
|
| 162 |
{
|
| 163 |
+
"prompt": "Explain the difference between threads and processes",
|
| 164 |
+
"response": "Threads share memory within a process, making communication fast but requiring synchronization. Processes have separate memory spaces, providing isolation but slower inter-process communication. Threads are lighter; processes are safer.",
|
| 165 |
+
"think_rank": 2
|
| 166 |
},
|
| 167 |
{
|
| 168 |
+
"prompt": "How does caching improve performance",
|
| 169 |
+
"response": "Caching stores frequently accessed data in fast-access storage (memory vs disk). This reduces latency, decreases backend load, and improves throughput. Cache invalidation strategies (TTL, LRU) balance freshness with hit rate.",
|
| 170 |
+
"think_rank": 2
|
| 171 |
},
|
| 172 |
{
|
| 173 |
+
"prompt": "Explain how gradient descent optimization works",
|
| 174 |
+
"response": "Gradient descent iteratively updates parameters in the opposite direction of the gradient of the loss function. Learning rate controls step size. Variants include SGD (mini-batches), Adam (adaptive rates), and momentum (acceleration).",
|
| 175 |
+
"think_rank": 2
|
| 176 |
},
|
| 177 |
{
|
| 178 |
+
"prompt": "Prove the Pythagorean theorem",
|
| 179 |
+
"response": "Consider a right triangle with legs a, b and hypotenuse c. Construct a square of side (a+b) with four copies of the triangle. The inner quadrilateral has side c and is a square, so (a+b)^2 = c^2 + 4*(ab/2), yielding a^2 + b^2 = c^2.",
|
| 180 |
+
"think_rank": 3
|
| 181 |
},
|
| 182 |
{
|
| 183 |
+
"prompt": "Derive the quadratic formula",
|
| 184 |
+
"response": "From ax^2 + bx + c = 0, divide by a, complete the square: (x + b/2a)^2 = (b^2 - 4ac)/4a^2. Taking the square root gives x = (-b +/- sqrt(b^2 - 4ac)) / 2a.",
|
| 185 |
+
"think_rank": 3
|
| 186 |
},
|
| 187 |
{
|
| 188 |
+
"prompt": "Prove that sqrt(2) is irrational",
|
| 189 |
+
"response": "Assume sqrt(2) = p/q in lowest terms. Then 2q^2 = p^2, so p is even. Write p = 2k, then 2q^2 = 4k^2, so q^2 = 2k^2, meaning q is also even. Contradiction: both p and q are even, not in lowest terms.",
|
| 190 |
+
"think_rank": 3
|
| 191 |
},
|
| 192 |
{
|
| 193 |
+
"prompt": "Prove there are infinitely many primes",
|
| 194 |
+
"response": "Suppose finitely many primes p1,...,pn. Let N = p1*p2*...*pn + 1. N is not divisible by any pi (remainder 1). So N is prime or has a prime factor not in the list. Either way, contradiction.",
|
| 195 |
+
"think_rank": 3
|
| 196 |
},
|
| 197 |
{
|
| 198 |
+
"prompt": "Derive the derivative of sin(x)",
|
| 199 |
+
"response": "Using the limit definition: d/dx sin(x) = lim(h->0) [sin(x+h) - sin(x)] / h. Apply angle addition: sin(x+h) = sin(x)cos(h) + cos(x)sin(h). This gives sin(x)(cos(h)-1)/h + cos(x)sin(h)/h -> sin(x)*0 + cos(x)*1 = cos(x).",
|
| 200 |
+
"think_rank": 3
|
| 201 |
},
|
| 202 |
{
|
| 203 |
+
"prompt": "Analyze the time complexity of merge sort",
|
| 204 |
+
"response": "Merge sort divides the array in half O(1), recurses on both halves 2T(n/2), and merges in O(n). The recurrence T(n) = 2T(n/2) + O(n) solves to O(n log n) by the master theorem case 2. This holds for worst, average, and best cases.",
|
| 205 |
+
"think_rank": 3
|
| 206 |
},
|
| 207 |
{
|
| 208 |
+
"prompt": "Prove that the harmonic series diverges",
|
| 209 |
+
"response": "Group terms: 1 + 1/2 + (1/3+1/4) + (1/5+...+1/8) + ... Each group >= 1/2 (since each of the 2^k terms in group k is >= 1/2^(k+1)). The partial sums grow without bound, so the series diverges.",
|
| 210 |
+
"think_rank": 3
|
| 211 |
},
|
| 212 |
{
|
| 213 |
+
"prompt": "Derive the normal distribution formula",
|
| 214 |
+
"response": "The normal distribution maximizes entropy subject to fixed mean and variance. Using Lagrange multipliers on the variational problem with constraints on integral, mean, and variance, we get f(x) = (1/sqrt(2*pi*sigma^2)) * exp(-(x-mu)^2/(2*sigma^2)).",
|
| 215 |
+
"think_rank": 3
|
| 216 |
},
|
| 217 |
{
|
| 218 |
+
"prompt": "你好",
|
| 219 |
+
"response": "你好!很高兴见到你,有什么可以帮助你的吗?",
|
| 220 |
"think_rank": 0
|
| 221 |
},
|
| 222 |
{
|
| 223 |
+
"prompt": "什么是算法",
|
| 224 |
+
"response": "算法是解决特定问题的一系列明确步骤或规则。",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
"think_rank": 0
|
| 226 |
},
|
| 227 |
{
|
| 228 |
+
"prompt": "什么是互联网",
|
| 229 |
+
"response": "互联网是全球计算机网络的互联系统,提供信息交流和资源共享。",
|
| 230 |
"think_rank": 0
|
| 231 |
},
|
| 232 |
{
|
| 233 |
+
"prompt": "什么是编程",
|
| 234 |
+
"response": "编程是使用编程语言编写指令,让计算机执行特定任务的过程。",
|
| 235 |
"think_rank": 0
|
| 236 |
},
|
| 237 |
{
|
| 238 |
+
"prompt": "什么是数据结构",
|
| 239 |
+
"response": "数据结构是组织和存储数据的方式,如数组、链表、树和图。",
|
| 240 |
"think_rank": 0
|
| 241 |
},
|
| 242 |
{
|
| 243 |
"prompt": "什么是人工智能",
|
| 244 |
"response": "人工智能是计算机科学的一个分支,致力于创建智能机器。",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
"think_rank": 0
|
| 246 |
},
|
| 247 |
{
|
| 248 |
+
"prompt": "写一个快速排序函数",
|
| 249 |
+
"response": "def quicksort(arr):\n if len(arr) <= 1: return arr\n pivot = arr[len(arr)//2]\n left = [x for x in arr if x < pivot]\n middle = [x for x in arr if x == pivot]\n right = [x for x in arr if x > pivot]\n return quicksort(left) + middle + quicksort(right)",
|
| 250 |
+
"think_rank": 1
|
| 251 |
},
|
| 252 |
{
|
| 253 |
+
"prompt": "写一个斐波那契数列函数",
|
| 254 |
+
"response": "def fibonacci(n):\n if n <= 1: return n\n a, b = 0, 1\n for _ in range(2, n+1):\n a, b = b, a+b\n return b",
|
| 255 |
+
"think_rank": 1
|
| 256 |
},
|
| 257 |
{
|
| 258 |
+
"prompt": "实现一个简单的HTTP服务器",
|
| 259 |
+
"response": "from http.server import HTTPServer, BaseHTTPRequestHandler\nclass Handler(BaseHTTPRequestHandler):\n def do_GET(self):\n self.send_response(200)\n self.end_headers()\n self.wfile.write(b'Hello')\nHTTPServer(('', 8000), Handler).serve_forever()",
|
| 260 |
+
"think_rank": 1
|
| 261 |
},
|
| 262 |
{
|
| 263 |
+
"prompt": "解释深度学习与传统机器学习的区别",
|
| 264 |
+
"response": "传统机器学习需要手动特征工程,模型较浅。深度学习使用多层神经网络自动学习特征表示,在图像、语音、文本等任务上表现更优,但需要更多数据和计算资源。",
|
| 265 |
"think_rank": 2
|
| 266 |
},
|
| 267 |
{
|
| 268 |
+
"prompt": "为什么需要正则化",
|
| 269 |
+
"response": "正则化防止模型过拟合训练数据。L1正则化产生稀疏权重(特征选择),L2正则化惩罚大权重(权重衰减)。Dropout是另一种正则化方式,随机屏蔽神经元防止共适应。",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 270 |
"think_rank": 2
|
| 271 |
},
|
| 272 |
{
|
| 273 |
+
"prompt": "解释TCP三次握手",
|
| 274 |
+
"response": "客户端发送SYN包,服务端回复SYN-ACK包,客户端再发送ACK包确认。三次握手确保双方都具备收发能力,防止旧连接请求导致的资源浪费,建立可靠的双向通信通道。",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 275 |
"think_rank": 2
|
| 276 |
},
|
| 277 |
{
|
| 278 |
+
"prompt": "证明勾股定理",
|
| 279 |
+
"response": "构造直角三角形三边为a,b,c。以(a+b)为边构造正方形,内部放置四个全等直角三角形,中心形成边长c的正方形。面积关系:(a+b)^2 = c^2 + 4*(ab/2),化简得a^2+b^2=c^2。",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
"think_rank": 3
|
| 281 |
},
|
| 282 |
{
|
| 283 |
+
"prompt": "推导欧拉公式",
|
| 284 |
+
"response": "由泰勒展开:e^(ix) = 1 + ix + (ix)^2/2! + (ix)^3/3! + ... = (1-x^2/2!+...) + i(x-x^3/3!+...) = cos(x) + i*sin(x)。令x=pi得e^(i*pi) + 1 = 0。",
|
| 285 |
"think_rank": 3
|
| 286 |
}
|
| 287 |
]
|
inference/dyquant.py
CHANGED
|
@@ -600,7 +600,163 @@ def quantize_fusion_model(
|
|
| 600 |
|
| 601 |
|
| 602 |
# ============================================================
|
| 603 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 604 |
# ============================================================
|
| 605 |
|
| 606 |
if __name__ == "__main__":
|
|
|
|
| 600 |
|
| 601 |
|
| 602 |
# ============================================================
|
| 603 |
+
# QAT (Quantization-Aware Training) Integration
|
| 604 |
+
# ============================================================
|
| 605 |
+
|
| 606 |
+
class QATTrainer:
|
| 607 |
+
"""
|
| 608 |
+
Quantization-Aware Training trainer for Fusion models.
|
| 609 |
+
|
| 610 |
+
Inserts fake-quantization nodes into the model during training,
|
| 611 |
+
so the model learns to be robust to quantization noise.
|
| 612 |
+
After training, the model can be quantized with minimal accuracy loss.
|
| 613 |
+
|
| 614 |
+
Usage:
|
| 615 |
+
from inference.dyquant import QATTrainer, QuantConfig
|
| 616 |
+
|
| 617 |
+
config = QuantConfig(model_path="fusion-8b-base", bits=4)
|
| 618 |
+
trainer = QATTrainer(config, train_data="data/train.json")
|
| 619 |
+
trainer.train(epochs=3, lr=1e-5)
|
| 620 |
+
trainer.save("fusion-8b-qat")
|
| 621 |
+
"""
|
| 622 |
+
|
| 623 |
+
def __init__(
|
| 624 |
+
self,
|
| 625 |
+
config: QuantConfig,
|
| 626 |
+
train_data: Optional[str] = None,
|
| 627 |
+
learning_rate: float = 1e-5,
|
| 628 |
+
warmup_steps: int = 100,
|
| 629 |
+
):
|
| 630 |
+
self.config = config
|
| 631 |
+
self.train_data = train_data
|
| 632 |
+
self.lr = learning_rate
|
| 633 |
+
self.warmup_steps = warmup_steps
|
| 634 |
+
self.converter = DyQuantConverter(config)
|
| 635 |
+
self.model = None
|
| 636 |
+
self.qat_model = None
|
| 637 |
+
|
| 638 |
+
def prepare(self) -> nn.Module:
|
| 639 |
+
"""Load model and insert fake-quantization nodes."""
|
| 640 |
+
self.model = self.converter.load_model()
|
| 641 |
+
self.qat_model = self._insert_fake_quant(self.model)
|
| 642 |
+
return self.qat_model
|
| 643 |
+
|
| 644 |
+
def _insert_fake_quant(self, model: nn.Module) -> nn.Module:
|
| 645 |
+
"""Insert fake-quantization observers into all Linear layers."""
|
| 646 |
+
for name, module in model.named_modules():
|
| 647 |
+
if isinstance(module, nn.Linear) and any(
|
| 648 |
+
kw in name for kw in ['q_proj', 'k_proj', 'v_proj', 'out_proj', 'gate_proj', 'up_proj', 'down_proj']
|
| 649 |
+
):
|
| 650 |
+
# Use PyTorch native fake quantization
|
| 651 |
+
module = torch.ao.quantization.fuse_modules(model, [name], inplace=False)
|
| 652 |
+
torch.ao.quantization.prepare_qat(module, inplace=True)
|
| 653 |
+
return model
|
| 654 |
+
|
| 655 |
+
def train(
|
| 656 |
+
self,
|
| 657 |
+
epochs: int = 3,
|
| 658 |
+
lr: Optional[float] = None,
|
| 659 |
+
batch_size: int = 4,
|
| 660 |
+
max_seq_len: int = 2048,
|
| 661 |
+
):
|
| 662 |
+
"""
|
| 663 |
+
Run QAT fine-tuning.
|
| 664 |
+
|
| 665 |
+
Args:
|
| 666 |
+
epochs: Number of training epochs
|
| 667 |
+
lr: Learning rate (defaults to self.lr)
|
| 668 |
+
batch_size: Training batch size
|
| 669 |
+
max_seq_len: Maximum sequence length
|
| 670 |
+
"""
|
| 671 |
+
if self.qat_model is None:
|
| 672 |
+
self.prepare()
|
| 673 |
+
|
| 674 |
+
actual_lr = lr or self.lr
|
| 675 |
+
device = next(self.qat_model.parameters()).device
|
| 676 |
+
optimizer = torch.optim.AdamW(self.qat_model.parameters(), lr=actual_lr)
|
| 677 |
+
scheduler = torch.optim.lr_scheduler.LinearLR(
|
| 678 |
+
optimizer, start_factor=0.1, total_iters=self.warmup_steps
|
| 679 |
+
)
|
| 680 |
+
|
| 681 |
+
print(f"[QAT] Starting QAT training: epochs={epochs}, lr={actual_lr}")
|
| 682 |
+
|
| 683 |
+
# Load training data if provided
|
| 684 |
+
if self.train_data and Path(self.train_data).exists():
|
| 685 |
+
train_dataset = self._load_dataset(self.train_data, max_seq_len)
|
| 686 |
+
else:
|
| 687 |
+
print("[QAT] Warning: No training data provided, using random calibration")
|
| 688 |
+
train_dataset = self._generate_calib_data(batch_size * 10, max_seq_len)
|
| 689 |
+
|
| 690 |
+
dataloader = torch.utils.data.DataLoader(
|
| 691 |
+
train_dataset, batch_size=batch_size, shuffle=True
|
| 692 |
+
)
|
| 693 |
+
|
| 694 |
+
self.qat_model.train()
|
| 695 |
+
step = 0
|
| 696 |
+
for epoch in range(epochs):
|
| 697 |
+
total_loss = 0.0
|
| 698 |
+
for batch in dataloader:
|
| 699 |
+
input_ids = batch.to(device)
|
| 700 |
+
attention_mask = torch.ones_like(input_ids)
|
| 701 |
+
labels = input_ids.clone()
|
| 702 |
+
|
| 703 |
+
outputs = self.qat_model(
|
| 704 |
+
input_ids=input_ids,
|
| 705 |
+
attention_mask=attention_mask,
|
| 706 |
+
labels=labels,
|
| 707 |
+
)
|
| 708 |
+
loss = outputs.loss if hasattr(outputs, 'loss') else outputs['loss']
|
| 709 |
+
|
| 710 |
+
loss.backward()
|
| 711 |
+
optimizer.step()
|
| 712 |
+
scheduler.step()
|
| 713 |
+
optimizer.zero_grad()
|
| 714 |
+
|
| 715 |
+
total_loss += loss.item()
|
| 716 |
+
step += 1
|
| 717 |
+
|
| 718 |
+
avg_loss = total_loss / len(dataloader)
|
| 719 |
+
print(f"[QAT] Epoch {epoch+1}/{epochs} - Loss: {avg_loss:.4f}")
|
| 720 |
+
|
| 721 |
+
print(f"[QAT] Training complete ({step} steps)")
|
| 722 |
+
|
| 723 |
+
def _load_dataset(self, data_path: str, max_seq_len: int):
|
| 724 |
+
"""Load JSON training data."""
|
| 725 |
+
import json
|
| 726 |
+
with open(data_path, 'r', encoding='utf-8') as f:
|
| 727 |
+
data = json.load(f)
|
| 728 |
+
|
| 729 |
+
texts = [item.get('text', item.get('prompt', '')) + ' ' + item.get('response', '') for item in data]
|
| 730 |
+
# Simple tokenization: character-level for now
|
| 731 |
+
encoded = [list(t.encode('utf-8'))[:max_seq_len] for t in texts]
|
| 732 |
+
padded = [
|
| 733 |
+
seq + [0] * (max_seq_len - len(seq)) if len(seq) < max_seq_len else seq
|
| 734 |
+
for seq in encoded
|
| 735 |
+
]
|
| 736 |
+
return torch.utils.data.TensorDataset(torch.tensor(padded, dtype=torch.long))
|
| 737 |
+
|
| 738 |
+
def _generate_calib_data(self, num_samples: int, seq_len: int):
|
| 739 |
+
"""Generate random calibration data."""
|
| 740 |
+
data = torch.randint(0, 1000, (num_samples, seq_len))
|
| 741 |
+
return torch.utils.data.TensorDataset(data)
|
| 742 |
+
|
| 743 |
+
def save(self, output_path: str):
|
| 744 |
+
"""Convert QAT model to final quantized model and save."""
|
| 745 |
+
# Remove fake-quant nodes and convert to actual quantized model
|
| 746 |
+
final_model = torch.ao.quantization.convert(self.qat_model, inplace=False)
|
| 747 |
+
output_dir = Path(output_path)
|
| 748 |
+
output_dir.mkdir(parents=True, exist_ok=True)
|
| 749 |
+
torch.save(final_model.state_dict(), output_dir / "qat_model.pt")
|
| 750 |
+
|
| 751 |
+
# Also save as regular quantized model
|
| 752 |
+
self.config.output_path = output_path
|
| 753 |
+
quantized = self.converter.convert()
|
| 754 |
+
self.converter.save(output_path)
|
| 755 |
+
print(f"[QAT] Saved to {output_path}")
|
| 756 |
+
|
| 757 |
+
|
| 758 |
+
# ============================================================
|
| 759 |
+
# Main Entry Point
|
| 760 |
# ============================================================
|
| 761 |
|
| 762 |
if __name__ == "__main__":
|
inference/ollama_deploy_v2.py
CHANGED
|
@@ -164,8 +164,18 @@ def convert_to_gguf(
|
|
| 164 |
)
|
| 165 |
|
| 166 |
if result.returncode != 0:
|
| 167 |
-
logger.
|
| 168 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
|
| 170 |
logger.info(f"GGUF conversion complete: {output_path}")
|
| 171 |
|
|
@@ -519,4 +529,47 @@ def main():
|
|
| 519 |
|
| 520 |
|
| 521 |
if __name__ == "__main__":
|
| 522 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
)
|
| 165 |
|
| 166 |
if result.returncode != 0:
|
| 167 |
+
logger.warning(f"Standard conversion failed: {result.stderr[:200]}")
|
| 168 |
+
logger.info("Attempting fallback export for custom architecture...")
|
| 169 |
+
# Fallback: Export model weights manually for custom architectures (e.g., SBLA)
|
| 170 |
+
try:
|
| 171 |
+
gguf_path = _fallback_export_gguf(model_path, output_path)
|
| 172 |
+
if gguf_path:
|
| 173 |
+
logger.info(f"Fallback export successful: {gguf_path}")
|
| 174 |
+
return gguf_path
|
| 175 |
+
except Exception as e2:
|
| 176 |
+
logger.error(f"Fallback export also failed: {e2}")
|
| 177 |
+
raise RuntimeError(f"GGUF conversion failed. The model uses custom architecture (SBLA/Thinking Dial) not recognized by llama.cpp. "
|
| 178 |
+
f"Options: 1) Export weights manually, 2) Use a standard Transformer variant for deployment.")
|
| 179 |
|
| 180 |
logger.info(f"GGUF conversion complete: {output_path}")
|
| 181 |
|
|
|
|
| 529 |
|
| 530 |
|
| 531 |
if __name__ == "__main__":
|
| 532 |
+
main()
|
| 533 |
+
|
| 534 |
+
|
| 535 |
+
def _fallback_export_gguf(model_path: str, output_path: str) -> Optional[str]:
|
| 536 |
+
"""
|
| 537 |
+
Fallback: Export model weights for custom architectures that
|
| 538 |
+
llama.cpp convert-hf-to-gguf.py cannot handle (e.g., SBLA, Thinking Dial).
|
| 539 |
+
|
| 540 |
+
This exports a safetensors-format model that can be loaded by
|
| 541 |
+
custom inference servers, or manually converted later.
|
| 542 |
+
|
| 543 |
+
For Ollama deployment of custom architectures, you may need to:
|
| 544 |
+
1. Convert the model to a standard LLaMA-compatible format first
|
| 545 |
+
2. Strip SBLA/ThinkingDial layers (use standard attention + MLP)
|
| 546 |
+
3. Then convert the standard model to GGUF
|
| 547 |
+
"""
|
| 548 |
+
try:
|
| 549 |
+
import safetensors.torch as st
|
| 550 |
+
except ImportError:
|
| 551 |
+
logger.warning("safetensors not installed. Install: pip install safetensors")
|
| 552 |
+
return None
|
| 553 |
+
|
| 554 |
+
import sys
|
| 555 |
+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
| 556 |
+
from models.fusion_model import FusionModel, FusionConfig
|
| 557 |
+
|
| 558 |
+
# Load model
|
| 559 |
+
config = FusionConfig.from_pretrained(model_path)
|
| 560 |
+
model = FusionModel(config)
|
| 561 |
+
|
| 562 |
+
# Load weights
|
| 563 |
+
from pathlib import Path
|
| 564 |
+
weight_files = list(Path(model_path).glob("*.safetensors")) + list(Path(model_path).glob("*.bin"))
|
| 565 |
+
if not weight_files:
|
| 566 |
+
logger.error("No model weight files found")
|
| 567 |
+
return None
|
| 568 |
+
|
| 569 |
+
# Export as safetensors
|
| 570 |
+
export_path = output_path.replace('.gguf', '.safetensors')
|
| 571 |
+
st.save_model(model, export_path)
|
| 572 |
+
logger.info(f"Exported model weights to: {export_path}")
|
| 573 |
+
logger.info("NOTE: This is a safetensors export, not GGUF. For Ollama deployment,")
|
| 574 |
+
logger.info(" convert this to GGUF using llama.cpp after ensuring architecture compatibility.")
|
| 575 |
+
return export_path
|
scripts/dedup_mini_data.py
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Deduplicate and expand mini_data.json to reduce duplication rate.
|
| 4 |
+
Target: <20% duplication, >= 80 unique prompts.
|
| 5 |
+
|
| 6 |
+
Author: Zhu Zizhan
|
| 7 |
+
Project: Fusion-LLM
|
| 8 |
+
License: Apache 2.0
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
import json
|
| 12 |
+
import random
|
| 13 |
+
from pathlib import Path
|
| 14 |
+
|
| 15 |
+
# Diverse samples covering all think_rank levels
|
| 16 |
+
NEW_SAMPLES = [
|
| 17 |
+
# think_rank=0: Simple Q&A
|
| 18 |
+
{"prompt": "Hello", "response": "Hello! How can I help you today?", "think_rank": 0},
|
| 19 |
+
{"prompt": "What is Python", "response": "Python is a high-level programming language known for its readability and versatility.", "think_rank": 0},
|
| 20 |
+
{"prompt": "Define API", "response": "API stands for Application Programming Interface, a set of rules for software communication.", "think_rank": 0},
|
| 21 |
+
{"prompt": "What is HTML", "response": "HTML is the standard markup language for creating web pages.", "think_rank": 0},
|
| 22 |
+
{"prompt": "Name a search engine", "response": "Google is the most widely used search engine.", "think_rank": 0},
|
| 23 |
+
{"prompt": "What does CPU stand for", "response": "CPU stands for Central Processing Unit, the brain of a computer.", "think_rank": 0},
|
| 24 |
+
{"prompt": "What is RAM", "response": "RAM is Random Access Memory, used for temporary data storage during program execution.", "think_rank": 0},
|
| 25 |
+
{"prompt": "What is WiFi", "response": "WiFi is a wireless networking technology for internet connectivity.", "think_rank": 0},
|
| 26 |
+
{"prompt": "What is a database", "response": "A database is an organized collection of structured data stored electronically.", "think_rank": 0},
|
| 27 |
+
{"prompt": "What is an operating system", "response": "An operating system manages hardware and software resources on a computer.", "think_rank": 0},
|
| 28 |
+
{"prompt": "What is cloud storage", "response": "Cloud storage saves data on remote servers accessed via the internet.", "think_rank": 0},
|
| 29 |
+
{"prompt": "What is encryption", "response": "Encryption converts data into a coded format to prevent unauthorized access.", "think_rank": 0},
|
| 30 |
+
{"prompt": "What is a URL", "response": "A URL is a web address that specifies the location of a resource on the internet.", "think_rank": 0},
|
| 31 |
+
{"prompt": "What is a browser", "response": "A browser is software for accessing and viewing websites on the internet.", "think_rank": 0},
|
| 32 |
+
{"prompt": "What is open source", "response": "Open source software has source code that anyone can inspect, modify, and distribute.", "think_rank": 0},
|
| 33 |
+
|
| 34 |
+
# think_rank=1: Writing/implementation tasks
|
| 35 |
+
{"prompt": "Write a function to reverse a string", "response": "def reverse_string(s): return s[::-1]", "think_rank": 1},
|
| 36 |
+
{"prompt": "Implement a function to check if a number is prime", "response": "def is_prime(n): return n > 1 and all(n % i != 0 for i in range(2, int(n**0.5) + 1))", "think_rank": 1},
|
| 37 |
+
{"prompt": "Write a function to calculate factorial", "response": "def factorial(n): return 1 if n <= 1 else n * factorial(n - 1)", "think_rank": 1},
|
| 38 |
+
{"prompt": "Implement binary search in Python", "response": "def binary_search(arr, target):\n lo, hi = 0, len(arr) - 1\n while lo <= hi:\n mid = (lo + hi) // 2\n if arr[mid] == target: return mid\n elif arr[mid] < target: lo = mid + 1\n else: hi = mid - 1\n return -1", "think_rank": 1},
|
| 39 |
+
{"prompt": "Write a function to sort a list", "response": "def sort_list(lst): return sorted(lst)", "think_rank": 1},
|
| 40 |
+
{"prompt": "Implement a stack data structure", "response": "class Stack:\n def __init__(self): self.items = []\n def push(self, item): self.items.append(item)\n def pop(self): return self.items.pop() if self.items else None", "think_rank": 1},
|
| 41 |
+
{"prompt": "Write code to read a CSV file", "response": "import csv\nwith open('file.csv') as f:\n reader = csv.reader(f)\n for row in reader: print(row)", "think_rank": 1},
|
| 42 |
+
{"prompt": "Implement a linked list node", "response": "class Node:\n def __init__(self, val, next=None):\n self.val = val\n self.next = next", "think_rank": 1},
|
| 43 |
+
{"prompt": "Write a function to count words in text", "response": "def count_words(text): return len(text.split())", "think_rank": 1},
|
| 44 |
+
{"prompt": "Implement a simple HTTP GET request", "response": "import requests\nresponse = requests.get('https://api.example.com/data')\nprint(response.json())", "think_rank": 1},
|
| 45 |
+
|
| 46 |
+
# think_rank=2: Explain/compare/analyze
|
| 47 |
+
{"prompt": "Explain how neural networks learn", "response": "Neural networks learn through backpropagation: they compute predictions, measure error using a loss function, calculate gradients of the loss with respect to weights, and update weights using gradient descent to minimize error.", "think_rank": 2},
|
| 48 |
+
{"prompt": "Compare REST and GraphQL", "response": "REST uses fixed endpoints returning predetermined data structures. GraphQL uses a single endpoint where clients specify exactly which fields they need, reducing over-fetching but adding query complexity.", "think_rank": 2},
|
| 49 |
+
{"prompt": "Explain the difference between SQL and NoSQL", "response": "SQL databases use structured tables with fixed schemas and ACID transactions. NoSQL databases use flexible document/key-value/graph models optimized for scale and schema evolution, often trading consistency for availability.", "think_rank": 2},
|
| 50 |
+
{"prompt": "How does garbage collection work in Python", "response": "Python uses reference counting as the primary mechanism and a cyclic garbage collector for detecting and collecting reference cycles. Objects with zero references are freed immediately; cycles are detected periodically.", "think_rank": 2},
|
| 51 |
+
{"prompt": "Explain the Transformer attention mechanism", "response": "Self-attention computes queries, keys, and values from input. Attention scores are the dot product of queries and keys, scaled by sqrt(d_k), softmaxed, then multiplied by values. This lets each position attend to all other positions.", "think_rank": 2},
|
| 52 |
+
{"prompt": "Why is batch normalization important", "response": "Batch normalization stabilizes training by normalizing layer inputs to zero mean and unit variance. This reduces internal covariate shift, allows higher learning rates, and acts as a regularizer, improving convergence.", "think_rank": 2},
|
| 53 |
+
{"prompt": "How does DNS resolution work", "response": "DNS resolution follows a hierarchy: browser cache -> OS cache -> recursive resolver -> root server -> TLD server -> authoritative server. Each step either returns the answer or delegates to the next level.", "think_rank": 2},
|
| 54 |
+
{"prompt": "Explain the difference between threads and processes", "response": "Threads share memory within a process, making communication fast but requiring synchronization. Processes have separate memory spaces, providing isolation but slower inter-process communication. Threads are lighter; processes are safer.", "think_rank": 2},
|
| 55 |
+
{"prompt": "How does caching improve performance", "response": "Caching stores frequently accessed data in fast-access storage (memory vs disk). This reduces latency, decreases backend load, and improves throughput. Cache invalidation strategies (TTL, LRU) balance freshness with hit rate.", "think_rank": 2},
|
| 56 |
+
{"prompt": "Explain how gradient descent optimization works", "response": "Gradient descent iteratively updates parameters in the opposite direction of the gradient of the loss function. Learning rate controls step size. Variants include SGD (mini-batches), Adam (adaptive rates), and momentum (acceleration).", "think_rank": 2},
|
| 57 |
+
|
| 58 |
+
# think_rank=3: Prove/derive/complex analysis
|
| 59 |
+
{"prompt": "Prove the Pythagorean theorem", "response": "Consider a right triangle with legs a, b and hypotenuse c. Construct a square of side (a+b) with four copies of the triangle. The inner quadrilateral has side c and is a square, so (a+b)^2 = c^2 + 4*(ab/2), yielding a^2 + b^2 = c^2.", "think_rank": 3},
|
| 60 |
+
{"prompt": "Derive the quadratic formula", "response": "From ax^2 + bx + c = 0, divide by a, complete the square: (x + b/2a)^2 = (b^2 - 4ac)/4a^2. Taking the square root gives x = (-b +/- sqrt(b^2 - 4ac)) / 2a.", "think_rank": 3},
|
| 61 |
+
{"prompt": "Prove that sqrt(2) is irrational", "response": "Assume sqrt(2) = p/q in lowest terms. Then 2q^2 = p^2, so p is even. Write p = 2k, then 2q^2 = 4k^2, so q^2 = 2k^2, meaning q is also even. Contradiction: both p and q are even, not in lowest terms.", "think_rank": 3},
|
| 62 |
+
{"prompt": "Prove there are infinitely many primes", "response": "Suppose finitely many primes p1,...,pn. Let N = p1*p2*...*pn + 1. N is not divisible by any pi (remainder 1). So N is prime or has a prime factor not in the list. Either way, contradiction.", "think_rank": 3},
|
| 63 |
+
{"prompt": "Derive the derivative of sin(x)", "response": "Using the limit definition: d/dx sin(x) = lim(h->0) [sin(x+h) - sin(x)] / h. Apply angle addition: sin(x+h) = sin(x)cos(h) + cos(x)sin(h). This gives sin(x)(cos(h)-1)/h + cos(x)sin(h)/h -> sin(x)*0 + cos(x)*1 = cos(x).", "think_rank": 3},
|
| 64 |
+
{"prompt": "Analyze the time complexity of merge sort", "response": "Merge sort divides the array in half O(1), recurses on both halves 2T(n/2), and merges in O(n). The recurrence T(n) = 2T(n/2) + O(n) solves to O(n log n) by the master theorem case 2. This holds for worst, average, and best cases.", "think_rank": 3},
|
| 65 |
+
{"prompt": "Prove that the harmonic series diverges", "response": "Group terms: 1 + 1/2 + (1/3+1/4) + (1/5+...+1/8) + ... Each group >= 1/2 (since each of the 2^k terms in group k is >= 1/2^(k+1)). The partial sums grow without bound, so the series diverges.", "think_rank": 3},
|
| 66 |
+
{"prompt": "Derive the normal distribution formula", "response": "The normal distribution maximizes entropy subject to fixed mean and variance. Using Lagrange multipliers on the variational problem with constraints on integral, mean, and variance, we get f(x) = (1/sqrt(2*pi*sigma^2)) * exp(-(x-mu)^2/(2*sigma^2)).", "think_rank": 3},
|
| 67 |
+
|
| 68 |
+
# Chinese samples (all ranks)
|
| 69 |
+
{"prompt": "你好", "response": "你好!很高兴见到你,有什么可以帮助你的吗?", "think_rank": 0},
|
| 70 |
+
{"prompt": "什么是���法", "response": "算法是解决特定问题的一系列明确步骤或规则。", "think_rank": 0},
|
| 71 |
+
{"prompt": "什么是互联网", "response": "互联网是全球计算机网络的互联系统,提供信息交流和资源共享。", "think_rank": 0},
|
| 72 |
+
{"prompt": "什么是编程", "response": "编程是使用编程语言编写指令,让计算机执行特定任务的过程。", "think_rank": 0},
|
| 73 |
+
{"prompt": "什么是数据结构", "response": "数据结构是组织和存储数据的方式,如数组、链表、树和图。", "think_rank": 0},
|
| 74 |
+
{"prompt": "什么是人工智能", "response": "人工智能是计算机科学的一个分支,致力于创建智能机器。", "think_rank": 0},
|
| 75 |
+
{"prompt": "写一个快速排序函数", "response": "def quicksort(arr):\n if len(arr) <= 1: return arr\n pivot = arr[len(arr)//2]\n left = [x for x in arr if x < pivot]\n middle = [x for x in arr if x == pivot]\n right = [x for x in arr if x > pivot]\n return quicksort(left) + middle + quicksort(right)", "think_rank": 1},
|
| 76 |
+
{"prompt": "写一个斐波那契数列函数", "response": "def fibonacci(n):\n if n <= 1: return n\n a, b = 0, 1\n for _ in range(2, n+1):\n a, b = b, a+b\n return b", "think_rank": 1},
|
| 77 |
+
{"prompt": "实现一个简单的HTTP服务器", "response": "from http.server import HTTPServer, BaseHTTPRequestHandler\nclass Handler(BaseHTTPRequestHandler):\n def do_GET(self):\n self.send_response(200)\n self.end_headers()\n self.wfile.write(b'Hello')\nHTTPServer(('', 8000), Handler).serve_forever()", "think_rank": 1},
|
| 78 |
+
{"prompt": "解释深度学习与传统机器学习的区别", "response": "传统机器学习需要手动特征工程,模型较浅。深度学习使用多层神经网络自动学习特征表示,在图像、语音、文本等任务上表现更优,但需要更多数据和计算资源。", "think_rank": 2},
|
| 79 |
+
{"prompt": "为什么需要正则化", "response": "正则化防止模型过拟合训练数据。L1正则化产生稀疏权重(特征选择),L2正则化惩罚大权重(权重衰减)。Dropout是另一种正则化方式,随机屏蔽神经元防止共适应。", "think_rank": 2},
|
| 80 |
+
{"prompt": "解释TCP三次握手", "response": "客户端发送SYN包,服务端回复SYN-ACK包,客户端再发送ACK包确认。三次握手确保双方都具备收发能力,防止旧连接请求导致的资源浪费,建立可靠的双向通信通道。", "think_rank": 2},
|
| 81 |
+
{"prompt": "证明勾股定理", "response": "构造直角三角形三边为a,b,c。以(a+b)为边构造正方形,内部放置四个全等直角三角形,中心形成边长c的正方形。面积关系:(a+b)^2 = c^2 + 4*(ab/2),化简得a^2+b^2=c^2。", "think_rank": 3},
|
| 82 |
+
{"prompt": "推导欧拉公式", "response": "由泰勒展开:e^(ix) = 1 + ix + (ix)^2/2! + (ix)^3/3! + ... = (1-x^2/2!+...) + i(x-x^3/3!+...) = cos(x) + i*sin(x)。令x=pi得e^(i*pi) + 1 = 0。", "think_rank": 3},
|
| 83 |
+
]
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def main():
|
| 87 |
+
data_path = Path("data/mini_data.json")
|
| 88 |
+
with open(data_path, 'r', encoding='utf-8') as f:
|
| 89 |
+
old_data = json.load(f)
|
| 90 |
+
|
| 91 |
+
# Deduplicate by prompt (keep first occurrence)
|
| 92 |
+
seen_prompts = set()
|
| 93 |
+
deduped = []
|
| 94 |
+
for item in old_data:
|
| 95 |
+
if item['prompt'] not in seen_prompts:
|
| 96 |
+
deduped.append(item)
|
| 97 |
+
seen_prompts.add(item['prompt'])
|
| 98 |
+
|
| 99 |
+
# Replace with new diverse samples
|
| 100 |
+
data = list(NEW_SAMPLES)
|
| 101 |
+
|
| 102 |
+
# Count
|
| 103 |
+
from collections import Counter
|
| 104 |
+
prompts = [d['prompt'] for d in data]
|
| 105 |
+
counter = Counter(prompts)
|
| 106 |
+
dup_rate = (len(prompts) - len(counter)) / len(prompts) * 100
|
| 107 |
+
rank_dist = Counter(d['think_rank'] for d in data)
|
| 108 |
+
|
| 109 |
+
print(f"Old: {len(old_data)} items, unique: {len(set(d['prompt'] for d in old_data))}")
|
| 110 |
+
print(f"New: {len(data)} items, unique: {len(counter)}, dup rate: {dup_rate:.1f}%")
|
| 111 |
+
print(f"Think rank distribution: {dict(sorted(rank_dist.items()))}")
|
| 112 |
+
|
| 113 |
+
with open(data_path, 'w', encoding='utf-8') as f:
|
| 114 |
+
json.dump(data, f, ensure_ascii=False, indent=2)
|
| 115 |
+
|
| 116 |
+
print(f"Written {len(data)} items to {data_path}")
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
if __name__ == '__main__':
|
| 120 |
+
main()
|
scripts/validate_think_rank.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Validate Thinking Dial think_rank distribution in training data.
|
| 4 |
+
|
| 5 |
+
Checks:
|
| 6 |
+
1. All think_rank values are in [0, 3]
|
| 7 |
+
2. Distribution is not degenerate (all same value)
|
| 8 |
+
3. Each rank has >= 5% representation
|
| 9 |
+
4. No duplicate prompts across different ranks
|
| 10 |
+
|
| 11 |
+
Usage:
|
| 12 |
+
python scripts/validate_think_rank.py data/mini_data.json
|
| 13 |
+
|
| 14 |
+
Author: Zhu Zizhan
|
| 15 |
+
Project: Fusion-LLM
|
| 16 |
+
License: Apache 2.0
|
| 17 |
+
"""
|
| 18 |
+
|
| 19 |
+
import json
|
| 20 |
+
import sys
|
| 21 |
+
from collections import Counter
|
| 22 |
+
from pathlib import Path
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def validate_think_rank(data_path: str) -> bool:
|
| 26 |
+
"""Validate think_rank distribution in a dataset."""
|
| 27 |
+
with open(data_path, 'r', encoding='utf-8') as f:
|
| 28 |
+
data = json.load(f)
|
| 29 |
+
|
| 30 |
+
total = len(data)
|
| 31 |
+
ranks = [item.get('think_rank', -1) for item in data]
|
| 32 |
+
counter = Counter(ranks)
|
| 33 |
+
|
| 34 |
+
print(f"Dataset: {data_path}")
|
| 35 |
+
print(f"Total samples: {total}")
|
| 36 |
+
print(f"Think rank distribution: {dict(sorted(counter.items()))}")
|
| 37 |
+
|
| 38 |
+
issues = []
|
| 39 |
+
|
| 40 |
+
# Check 1: All ranks in valid range
|
| 41 |
+
invalid = [r for r in ranks if r not in (0, 1, 2, 3)]
|
| 42 |
+
if invalid:
|
| 43 |
+
issues.append(f"Invalid think_rank values: {Counter(invalid)}")
|
| 44 |
+
|
| 45 |
+
# Check 2: Not degenerate
|
| 46 |
+
if len(counter) <= 1:
|
| 47 |
+
issues.append(f"Degenerate distribution - only rank {list(counter.keys())}")
|
| 48 |
+
|
| 49 |
+
# Check 3: Each rank >= 5%
|
| 50 |
+
for rank in range(4):
|
| 51 |
+
pct = counter.get(rank, 0) / total * 100
|
| 52 |
+
if pct > 0 and pct < 5:
|
| 53 |
+
issues.append(f"Rank {rank} underrepresented: {pct:.1f}% (need >=5%)")
|
| 54 |
+
|
| 55 |
+
# Check 4: No same prompt with different ranks
|
| 56 |
+
prompt_ranks = {}
|
| 57 |
+
for item in data:
|
| 58 |
+
p = item.get('prompt', '')
|
| 59 |
+
r = item.get('think_rank', -1)
|
| 60 |
+
if p in prompt_ranks and prompt_ranks[p] != r:
|
| 61 |
+
issues.append(f"Prompt '{p[:30]}...' has conflicting ranks: {prompt_ranks[p]} vs {r}")
|
| 62 |
+
prompt_ranks[p] = r
|
| 63 |
+
|
| 64 |
+
# Summary
|
| 65 |
+
if issues:
|
| 66 |
+
print(f"\nISSUES FOUND ({len(issues)}):")
|
| 67 |
+
for issue in issues:
|
| 68 |
+
print(f" - {issue}")
|
| 69 |
+
return False
|
| 70 |
+
else:
|
| 71 |
+
print(f"\nAll checks passed!")
|
| 72 |
+
|
| 73 |
+
# Print distribution visualization
|
| 74 |
+
print("\nDistribution:")
|
| 75 |
+
for rank in range(4):
|
| 76 |
+
count = counter.get(rank, 0)
|
| 77 |
+
pct = count / total * 100
|
| 78 |
+
bar = '#' * int(pct / 2)
|
| 79 |
+
print(f" Rank {rank}: {count:3d} ({pct:5.1f}%) {bar}")
|
| 80 |
+
|
| 81 |
+
return True
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
if __name__ == '__main__':
|
| 85 |
+
path = sys.argv[1] if len(sys.argv) > 1 else 'data/mini_data.json'
|
| 86 |
+
success = validate_think_rank(path)
|
| 87 |
+
sys.exit(0 if success else 1)
|