{
  "schema_version": 1,
  "kind": "computed CPU numerical experiments and explicit metadata simulations",
  "config": {
    "seed": 19,
    "tokens": 8,
    "python": "3.12.3",
    "implementation": "Python standard library",
    "gpu_measured": false
  },
  "experiments": [
    {
      "id": "layout",
      "title": "01 · 合头：shape 对了，元素为什么错了？",
      "question": "[head,token,d] 直接reshape回[token,H]，能恢复原输入吗？",
      "verdict": "先交换head/token轴，再合并相邻的head/d。目标shape相同并不代表元素对应相同。",
      "rows": [
        {
          "position": 0,
          "original": [
            0,
            1,
            2,
            3
          ],
          "correct": [
            0,
            1,
            2,
            3
          ],
          "wrong": [
            0,
            1,
            10,
            11
          ]
        },
        {
          "position": 1,
          "original": [
            10,
            11,
            12,
            13
          ],
          "correct": [
            10,
            11,
            12,
            13
          ],
          "wrong": [
            20,
            21,
            2,
            3
          ]
        },
        {
          "position": 2,
          "original": [
            20,
            21,
            22,
            23
          ],
          "correct": [
            20,
            21,
            22,
            23
          ],
          "wrong": [
            12,
            13,
            22,
            23
          ]
        }
      ],
      "columns": [
        [
          "position",
          "token位置"
        ],
        [
          "original",
          "原始通道"
        ],
        [
          "correct",
          "先转置再合头"
        ],
        [
          "wrong",
          "直接reshape的错误结果"
        ]
      ],
      "checks": [
        {
          "label": "正确合头逐元素恢复输入",
          "passed": true
        },
        {
          "label": "错误合头必须被检测到",
          "passed": true
        }
      ],
      "details": {
        "input_shape": [
          3,
          4
        ],
        "split_shape": [
          3,
          2,
          2
        ],
        "transposed_shape": [
          2,
          3,
          2
        ],
        "transposed_values": [
          [
            [
              0,
              1
            ],
            [
              10,
              11
            ],
            [
              20,
              21
            ]
          ],
          [
            [
              2,
              3
            ],
            [
              12,
              13
            ],
            [
              22,
              23
            ]
          ]
        ],
        "layout": "logical list order; not a measurement of physical torch strides"
      },
      "plot": null,
      "trace": []
    },
    {
      "id": "cache",
      "title": "02 · 完整模型缓存：找到第一个出错的token",
      "question": "同一组权重，full / token / chunk执行的每行logits是否相同？",
      "verdict": "两层模型的正确分块都应接近full结果。故意漏掉past偏移后，mask和RoPE分别出错；请从首个错误位置定位原因。",
      "rows": [
        {
          "chunk": 1,
          "calls": 8,
          "error": 0.0
        },
        {
          "chunk": 2,
          "calls": 4,
          "error": 0.0
        },
        {
          "chunk": 3,
          "calls": 3,
          "error": 0.0
        },
        {
          "chunk": 8,
          "calls": 1,
          "error": 0.0
        }
      ],
      "columns": [
        [
          "chunk",
          "chunk长度"
        ],
        [
          "calls",
          "forward调用次数"
        ],
        [
          "error",
          "最大logits绝对误差"
        ]
      ],
      "checks": [
        {
          "label": "chunk=1 logits等价",
          "passed": true
        },
        {
          "label": "chunk=2 logits等价",
          "passed": true
        },
        {
          "label": "chunk=3 logits等价",
          "passed": true
        },
        {
          "label": "chunk=8 logits等价",
          "passed": true
        },
        {
          "label": "局部mask故障产生可见误差",
          "passed": true
        },
        {
          "label": "RoPE重置故障产生可见误差",
          "passed": true
        }
      ],
      "details": {
        "model": "2 layers; H=8; Hq=4; Hkv=2; d=4; F=12; vocabulary=11",
        "inputs": "fixed synthetic hidden vectors, no language quality",
        "cache_bytes_float64": 2048,
        "negative_controls": "Only the suffix call is faulty; prefix cache stays fixed."
      },
      "plot": {
        "label": "错误mask造成的logits偏差",
        "unit": "最大绝对误差",
        "rows": [
          [
            "4",
            0.5602974379398744
          ],
          [
            "5",
            0.4557564955793961
          ],
          [
            "6",
            0.21943911476821254
          ],
          [
            "7",
            0.37502671346495264
          ]
        ]
      },
      "trace": [
        {
          "query_position": 4,
          "past_tokens": 4,
          "local_row": 0,
          "key_positions": [
            0,
            1,
            2,
            3,
            4,
            5,
            6,
            7
          ],
          "correct_mask": [
            1,
            1,
            1,
            1,
            1,
            0,
            0,
            0
          ],
          "wrong_mask": [
            1,
            0,
            0,
            0,
            0,
            0,
            0,
            0
          ],
          "correct_error": 0.0,
          "wrong_mask_error": 0.5602974379398744,
          "wrong_position_error": 0.11630646957803775,
          "reference_logits": [
            0.13120839297964587,
            0.5012688600335539,
            0.17309920294251238,
            -0.03627273858854025,
            -0.09144459308299917,
            -0.8172319707364111,
            0.12034592742055873,
            0.05277662149943499,
            0.13043371877134044,
            -0.9527606340379732,
            0.02958245364007147
          ],
          "wrong_mask_logits": [
            0.18495191033056713,
            0.4967608539629612,
            0.2196549419532734,
            0.23312729864338527,
            -0.08058342913279322,
            -0.9681210283397877,
            0.07531204284924609,
            -0.26474776463463123,
            0.18312406191643393,
            -0.9126222517367811,
            -0.5307149842998029
          ]
        },
        {
          "query_position": 5,
          "past_tokens": 4,
          "local_row": 1,
          "key_positions": [
            0,
            1,
            2,
            3,
            4,
            5,
            6,
            7
          ],
          "correct_mask": [
            1,
            1,
            1,
            1,
            1,
            1,
            0,
            0
          ],
          "wrong_mask": [
            1,
            1,
            0,
            0,
            0,
            0,
            0,
            0
          ],
          "correct_error": 0.0,
          "wrong_mask_error": 0.4557564955793961,
          "wrong_position_error": 0.3401133858792003,
          "reference_logits": [
            0.26100912190771397,
            -0.14578193493123254,
            -0.3906617279822479,
            0.6223781926048041,
            0.035319833892116584,
            -0.008188464203982537,
            -0.21224853348565492,
            -1.1677765942352671,
            -0.8761676435576666,
            0.7291815886687368,
            -1.2007638031946837
          ],
          "wrong_mask_logits": [
            0.2365759645329756,
            -0.08440401018134396,
            -0.27577800852380296,
            0.3748163386854565,
            -0.03296926895027634,
            0.0738520659456946,
            -0.2628167933880236,
            -1.0971072421720631,
            -1.0354218520322638,
            0.8307991327176114,
            -0.7450073076152876
          ]
        },
        {
          "query_position": 6,
          "past_tokens": 4,
          "local_row": 2,
          "key_positions": [
            0,
            1,
            2,
            3,
            4,
            5,
            6,
            7
          ],
          "correct_mask": [
            1,
            1,
            1,
            1,
            1,
            1,
            1,
            0
          ],
          "wrong_mask": [
            1,
            1,
            1,
            0,
            0,
            0,
            0,
            0
          ],
          "correct_error": 0.0,
          "wrong_mask_error": 0.21943911476821254,
          "wrong_position_error": 0.17784240445558436,
          "reference_logits": [
            -0.08860259716417189,
            0.2844534454811581,
            0.15527181006375984,
            0.2440616399744256,
            -0.135120252973409,
            -0.28707744609657004,
            0.13665769099723524,
            0.1713278775019731,
            -0.13273351829869526,
            0.8094060627429958,
            -0.3175210085978799
          ],
          "wrong_mask_logits": [
            -0.19258814413062209,
            0.3352038063812534,
            0.23240274801504027,
            0.026553510498674555,
            -0.19806307095678294,
            -0.4387712083417066,
            0.2531399159872952,
            0.1568301414698938,
            -0.017564223995373572,
            0.6896990693233764,
            -0.09808189382966735
          ]
        },
        {
          "query_position": 7,
          "past_tokens": 4,
          "local_row": 3,
          "key_positions": [
            0,
            1,
            2,
            3,
            4,
            5,
            6,
            7
          ],
          "correct_mask": [
            1,
            1,
            1,
            1,
            1,
            1,
            1,
            1
          ],
          "wrong_mask": [
            1,
            1,
            1,
            1,
            0,
            0,
            0,
            0
          ],
          "correct_error": 0.0,
          "wrong_mask_error": 0.37502671346495264,
          "wrong_position_error": 0.09384314789914028,
          "reference_logits": [
            -0.06179268383761977,
            0.1382097621252134,
            0.08181728538803835,
            0.11798489736491831,
            0.49306741458933717,
            0.9821810131261799,
            -0.14884231222587768,
            0.30528644208461436,
            0.2727356126718859,
            -0.40236352397444297,
            0.5266723674901731
          ],
          "wrong_mask_logits": [
            0.006747225276181407,
            0.13618936007748972,
            0.12232218158219049,
            0.27732378028086957,
            0.37350427901161487,
            0.8216496665637332,
            -0.13880418916925483,
            0.23525411891055728,
            0.3312817196400206,
            -0.35574010739813033,
            0.15164565402522043
          ]
        }
      ]
    },
    {
      "id": "online",
      "title": "03 · 在线softmax：跨块的分母如何合并？",
      "question": "每块先softmax再平均，是否等价于整行softmax？",
      "verdict": "正确算法同步重缩放旧分母和旧加权和；独立块的平均把不同概率质量误当成同等重要。",
      "rows": [
        {
          "tile": 1,
          "correct_error": 1.1102230246251565e-16,
          "averaged_error": 1.2269596428130973
        },
        {
          "tile": 2,
          "correct_error": 1.1102230246251565e-16,
          "averaged_error": 1.2766023487538565
        },
        {
          "tile": 3,
          "correct_error": 0.0,
          "averaged_error": 0.9163217656640755
        },
        {
          "tile": 5,
          "correct_error": 1.1102230246251565e-16,
          "averaged_error": 0.8667701170341091
        },
        {
          "tile": 9,
          "correct_error": 1.1102230246251565e-16,
          "averaged_error": 1.1102230246251565e-16
        }
      ],
      "columns": [
        [
          "tile",
          "tile长度"
        ],
        [
          "correct_error",
          "在线合并误差"
        ],
        [
          "averaged_error",
          "错误平均误差"
        ]
      ],
      "checks": [
        {
          "label": "tile=1在线归一化等价",
          "passed": true
        },
        {
          "label": "tile=2在线归一化等价",
          "passed": true
        },
        {
          "label": "tile=3在线归一化等价",
          "passed": true
        },
        {
          "label": "tile=5在线归一化等价",
          "passed": true
        },
        {
          "label": "tile=9在线归一化等价",
          "passed": true
        },
        {
          "label": "独立softmax后平均必须失败",
          "passed": true
        }
      ],
      "details": {
        "scores": [
          -1.549925681336953,
          -3.1450549583088807,
          -2.374224174084285,
          -0.3070018678583216,
          -5.320551564447222,
          4.206069662041372,
          -0.2773954728903456,
          12.0,
          -0.10805448465806944
        ],
        "values": [
          [
            0.7749020558540386,
            -0.36896451527122226,
            0.6982629423498969
          ],
          [
            0.6920903969267583,
            0.5554973676763494,
            -0.48583415103953015
          ],
          [
            1.2034839543756604,
            0.11467213763509215,
            0.36563154322898034
          ],
          [
            0.3673014666944228,
            1.1953223326764744,
            -1.2435941582974521
          ],
          [
            1.0478620251024677,
            0.3385589943719099,
            -0.9776210066420045
          ],
          [
            1.3092837965733715,
            0.9432098141068637,
            0.0357272002729364
          ],
          [
            -1.0036410941065215,
            -0.45932328785551413,
            -0.7068675915453531
          ],
          [
            1.63004790459489,
            -0.9654808377605862,
            0.646547981789094
          ],
          [
            -2.3951016693967704,
            0.1350840365403303,
            1.2481088597245316
          ]
        ],
        "dense_output": [
          1.6298739579929105,
          -0.9646743349624927,
          0.6462843278331794
        ],
        "numerical_stability": "scores include one intentionally large value; max subtraction avoids overflow"
      },
      "plot": {
        "label": "错误平均随tile变化",
        "unit": "最大绝对误差",
        "rows": [
          [
            "1",
            1.2269596428130973
          ],
          [
            "2",
            1.2766023487538565
          ],
          [
            "3",
            0.9163217656640755
          ],
          [
            "5",
            0.8667701170341091
          ],
          [
            "9",
            1.1102230246251565e-16
          ]
        ]
      },
      "trace": [
        {
          "old_max": null,
          "old_denominator": 0.0,
          "old_accumulator": [
            0.0,
            0.0,
            0.0
          ],
          "tile_scores": [
            -1.549925681336953,
            -3.1450549583088807,
            -2.374224174084285
          ],
          "tile_max": -1.549925681336953,
          "tile_denominator": 1.6414248241440839,
          "tile_accumulator": [
            1.4430938391240111,
            -0.20597532351552997,
            0.7600407732663423
          ],
          "tile_start": 0,
          "tile_end_exclusive": 3,
          "new_max": -1.549925681336953,
          "old_rescale": 0.0,
          "tile_rescale": 1.0,
          "denominator": 1.6414248241440839,
          "accumulator": [
            1.4430938391240111,
            -0.20597532351552997,
            0.7600407732663423
          ],
          "output_so_far": [
            0.8791714478160815,
            -0.12548568809597185,
            0.4630372113828992
          ]
        },
        {
          "old_max": -1.549925681336953,
          "old_denominator": 1.6414248241440839,
          "old_accumulator": [
            1.4430938391240111,
            -0.20597532351552997,
            0.7600407732663423
          ],
          "tile_scores": [
            -0.3070018678583216,
            -5.320551564447222,
            4.206069662041372
          ],
          "tile_max": 4.206069662041372,
          "tile_denominator": 1.0110376153767409,
          "tile_accumulator": [
            1.3133875318675325,
            0.9563408766659321,
            0.022020271847565918
          ],
          "tile_start": 3,
          "tile_end_exclusive": 6,
          "new_max": 4.206069662041372,
          "old_rescale": 0.003163756019757055,
          "tile_rescale": 1.0,
          "denominator": 1.0162306830451053,
          "accumulator": [
            1.3179531286881354,
            0.9556892209962384,
            0.024424855419248114
          ],
          "output_so_far": [
            1.2969034990548876,
            0.9404254732129754,
            0.024034754929913898
          ]
        },
        {
          "old_max": 4.206069662041372,
          "old_denominator": 1.0162306830451053,
          "old_accumulator": [
            1.3179531286881354,
            0.9556892209962384,
            0.024424855419248114
          ],
          "tile_scores": [
            -0.2773954728903456,
            12.0,
            -0.10805448465806944
          ],
          "tile_max": 12.0,
          "tile_denominator": 1.0000101707202766,
          "tile_accumulator": [
            1.6300300230565448,
            -0.9654822313039408,
            0.6465515739637054
          ],
          "tile_start": 6,
          "tile_end_exclusive": 9,
          "new_max": 12.0,
          "old_rescale": 0.0004122294946037961,
          "tile_rescale": 1.0,
          "denominator": 1.0004290909811493,
          "accumulator": [
            1.6305733222086953,
            -0.9650882680193713,
            0.6465616426095107
          ],
          "output_so_far": [
            1.6298739579929105,
            -0.9646743349624927,
            0.6462843278331794
          ]
        }
      ]
    },
    {
      "id": "gqa",
      "title": "04 · GQA：少存KV后，Q是否也少算？",
      "question": "8个Q头共用2个KV头，正确组号是 h//4 还是 h%2？",
      "verdict": "同一GQA模型的分组读取与重复KV得到相同输出。减少KV头只改变缓存轴；此处8个Q仍分别做匹配。",
      "rows": [
        {
          "head": 0,
          "group": 0,
          "wrong_group": 0,
          "correct_error": 0.0,
          "wrong_error": 0.0
        },
        {
          "head": 1,
          "group": 0,
          "wrong_group": 1,
          "correct_error": 0.0,
          "wrong_error": 1.5409384625915905
        },
        {
          "head": 2,
          "group": 0,
          "wrong_group": 0,
          "correct_error": 0.0,
          "wrong_error": 0.0
        },
        {
          "head": 3,
          "group": 0,
          "wrong_group": 1,
          "correct_error": 0.0,
          "wrong_error": 1.5533085978623151
        },
        {
          "head": 4,
          "group": 1,
          "wrong_group": 0,
          "correct_error": 0.0,
          "wrong_error": 1.4862374309115234
        },
        {
          "head": 5,
          "group": 1,
          "wrong_group": 1,
          "correct_error": 0.0,
          "wrong_error": 0.0
        },
        {
          "head": 6,
          "group": 1,
          "wrong_group": 0,
          "correct_error": 0.0,
          "wrong_error": 1.0325717844537448
        },
        {
          "head": 7,
          "group": 1,
          "wrong_group": 1,
          "correct_error": 0.0,
          "wrong_error": 0.0
        }
      ],
      "columns": [
        [
          "head",
          "Q头"
        ],
        [
          "group",
          "正确KV组"
        ],
        [
          "wrong_group",
          "错误取模组"
        ],
        [
          "correct_error",
          "等价实现误差"
        ],
        [
          "wrong_error",
          "错误映射偏差"
        ]
      ],
      "checks": [
        {
          "label": "分组与重复实现等价",
          "passed": true
        },
        {
          "label": "取模分组必须失败",
          "passed": true
        }
      ],
      "details": {
        "capacity_sweep": [
          {
            "kv_heads": 8,
            "kv_elements": 512,
            "qk_av_flops": 1024
          },
          {
            "kv_heads": 4,
            "kv_elements": 256,
            "qk_av_flops": 1024
          },
          {
            "kv_heads": 2,
            "kv_elements": 128,
            "qk_av_flops": 1024
          },
          {
            "kv_heads": 1,
            "kv_elements": 64,
            "qk_av_flops": 1024
          }
        ],
        "baseline": "fixed GQA weights; not conversion of arbitrary trained MHA",
        "repeat_note": "logical repeat example; Python references are not actual duplicated GPU allocations"
      },
      "plot": {
        "label": "不同KV头数的逻辑缓存",
        "unit": "元素",
        "rows": [
          [
            "8",
            512
          ],
          [
            "4",
            256
          ],
          [
            "2",
            128
          ],
          [
            "1",
            64
          ]
        ]
      },
      "trace": []
    },
    {
      "id": "rope",
      "title": "05 · RoPE：共同平移与只移动Q的区别",
      "question": "位置2和5同时加7，与只给Q位置加7，会发生什么？",
      "verdict": "共同平移保留相对角度；只改Q会改变相对距离。数学不变量不能证明长上下文的语言质量。",
      "rows": [
        {
          "shift": 0,
          "together": -5.147133694324172,
          "error": 0.0,
          "q_only": -5.147133694324172
        },
        {
          "shift": 1,
          "together": -5.147133694324171,
          "error": 8.881784197001252e-16,
          "q_only": -1.532485602406705
        },
        {
          "shift": 7,
          "together": -5.147133694324172,
          "error": 0.0,
          "q_only": -2.556826800216116
        },
        {
          "shift": 100,
          "together": -5.147133694324171,
          "error": 8.881784197001252e-16,
          "q_only": -5.581009531117803
        },
        {
          "shift": 1000,
          "together": -5.14713369432417,
          "error": 1.7763568394002505e-15,
          "q_only": 4.939831006052736
        }
      ],
      "columns": [
        [
          "shift",
          "平移量"
        ],
        [
          "together",
          "Q/K同移点积"
        ],
        [
          "error",
          "对原点积误差"
        ],
        [
          "q_only",
          "只移动Q的点积"
        ]
      ],
      "checks": [
        {
          "label": "共同平移保持点积",
          "passed": true
        },
        {
          "label": "只移动Q出现差异",
          "passed": true
        }
      ],
      "details": {
        "q": [
          -0.7749628406684765,
          -1.5725274791544404,
          -1.1871120870421425,
          -0.1535009339291608
        ],
        "k": [
          -2.660275782223611,
          2.103034831020686,
          -0.1386977364451728,
          0.5492816930894947
        ],
        "pairing": "half-split channel pairs (0,2), (1,3)",
        "baseline_dot": -5.147133694324172
      },
      "plot": null,
      "trace": []
    },
    {
      "id": "quant",
      "title": "06 · 量化：相同bit数，为什么误差不同？",
      "question": "一个权重离群值，怎样影响per-tensor与per-output-channel的scale？",
      "verdict": "比较同bit数的两行，分开看权重误差和层输出误差。本小样本的输出RMSE不保证随bit单调变化，舍入与误差抵消会影响结果。scale有元数据成本；Python整数列表本身没有真的压成4bit。",
      "rows": [
        {
          "bits": 8,
          "scale": "tensor",
          "weight_error": 0.03114584249332708,
          "output_error": 0.1311019948474348,
          "output_rmse": 0.052004932274443326,
          "packed_payload_bytes": 64,
          "fp32_scale_bytes": 4
        },
        {
          "bits": 8,
          "scale": "row",
          "weight_error": 0.028317691872958767,
          "output_error": 0.1311019948474348,
          "output_rmse": 0.032755026684558375,
          "packed_payload_bytes": 64,
          "fp32_scale_bytes": 32
        },
        {
          "bits": 4,
          "scale": "tensor",
          "weight_error": 0.5440817255079502,
          "output_error": 1.8602561896929637,
          "output_rmse": 0.6057537396582763,
          "packed_payload_bytes": 32,
          "fp32_scale_bytes": 4
        },
        {
          "bits": 4,
          "scale": "row",
          "weight_error": 0.5257587077551715,
          "output_error": 1.8602561896929637,
          "output_rmse": 0.3487148563162826,
          "packed_payload_bytes": 32,
          "fp32_scale_bytes": 32
        },
        {
          "bits": 3,
          "scale": "tensor",
          "weight_error": 0.6650689455559028,
          "output_error": 1.1295289440683862,
          "output_rmse": 0.48735867146013817,
          "packed_payload_bytes": 24,
          "fp32_scale_bytes": 4
        },
        {
          "bits": 3,
          "scale": "row",
          "weight_error": 0.6650689455559028,
          "output_error": 1.1295289440683862,
          "output_rmse": 0.2545171348078944,
          "packed_payload_bytes": 24,
          "fp32_scale_bytes": 32
        },
        {
          "bits": 2,
          "scale": "tensor",
          "weight_error": 0.6650689455559028,
          "output_error": 1.1295289440683862,
          "output_rmse": 0.48735867146013817,
          "packed_payload_bytes": 16,
          "fp32_scale_bytes": 4
        },
        {
          "bits": 2,
          "scale": "row",
          "weight_error": 0.6650689455559028,
          "output_error": 1.1295289440683862,
          "output_rmse": 0.3706683257276053,
          "packed_payload_bytes": 16,
          "fp32_scale_bytes": 32
        }
      ],
      "columns": [
        [
          "bits",
          "bit"
        ],
        [
          "scale",
          "scale粒度"
        ],
        [
          "weight_error",
          "权重最大误差"
        ],
        [
          "output_error",
          "层输出最大误差"
        ],
        [
          "output_rmse",
          "层输出RMSE"
        ],
        [
          "packed_payload_bytes",
          "理论payload字节"
        ],
        [
          "fp32_scale_bytes",
          "scale字节"
        ]
      ],
      "checks": [
        {
          "label": "忘记反量化scale必须失败",
          "passed": true
        },
        {
          "label": "全部误差为有限数",
          "passed": true
        }
      ],
      "details": {
        "weights_out_in": [
          [
            8.0,
            -0.3931318697886101,
            -0.29677802176053564,
            -0.0383752334822902,
            -0.6650689455559028,
            0.5257587077551715,
            -0.0346744341112932,
            0.13732042327237368
          ],
          [
            -0.01350681058225868,
            0.19372551396350965,
            -0.09224112881780556,
            0.17456573558747424,
            0.17302259923168958,
            0.13887434191908735,
            -0.12145853775988254,
            0.3008709885939151
          ],
          [
            0.028668034408773038,
            0.09140788580724508,
            0.0918253666736057,
            0.2988305831691186,
            -0.31089853957436303,
            0.26196550627561693,
            0.08463974859297747,
            -0.24440525166050112
          ],
          [
            0.32732094914334287,
            0.23580245352671592,
            0.0089318000682341,
            -0.25091027352663037,
            -0.11483082196387853,
            -0.17671689788633826,
            0.4075119761487225,
            -0.24137020944014656
          ],
          [
            0.1616369954472735,
            -0.5987754173491926,
            0.033771009135082575,
            0.3120272149311329,
            -0.052483229706603234,
            -0.44648635003792997,
            -0.10535371599081887,
            0.08684431237244768
          ],
          [
            -0.08242490842955144,
            -0.0838007747514281,
            -0.008176244592832432,
            -0.02838219257238569,
            -0.27420028342929675,
            0.08059779544845892,
            0.20872135200569214,
            0.19550629010195816
          ],
          [
            -0.23993819339547326,
            -9.99956447187479e-05,
            0.39855236968061664,
            -0.3040738651915079,
            0.14477749185869287,
            -0.11895331533475775,
            0.2398429585124818,
            0.03935165682764173
          ],
          [
            0.2952835680482154,
            0.25593551939111236,
            -0.01064183165236365,
            0.13062326483598952,
            -0.05341579732041714,
            0.24842542011197782,
            -0.025463879502677363,
            -0.27679560224471456
          ]
        ],
        "inputs": [
          [
            -0.47538161828916464,
            1.427063767051873,
            0.6575550997508312,
            0.19250194093696404,
            -0.6393863399215054,
            -1.542795127460302,
            0.2982538713584852,
            0.22046443458025594
          ],
          [
            -1.46082603941072,
            -0.05322645865508773,
            1.0660318819451298,
            0.10831470118869388,
            -0.06545590149318485,
            0.4166624852255294,
            0.3901451671576079,
            0.7218621285703788
          ],
          [
            -0.4774967968297691,
            0.10032509158466993,
            -1.4944347072219866,
            -1.4094487353079062,
            -0.1512314863776341,
            -0.3433988276404675,
            -0.844031621680155,
            -1.1389169410738158
          ],
          [
            0.984043458354343,
            0.054276976743931823,
            -1.4075179437067151,
            -2.0040023153307147,
            1.1711395114368486,
            -0.5605302324464633,
            -2.1394529506498943,
            -1.3361736908785469
          ]
        ],
        "four_bit_trace": {
          "tensor": {
            "scales": [
              1.1428571428571428,
              1.1428571428571428,
              1.1428571428571428,
              1.1428571428571428,
              1.1428571428571428,
              1.1428571428571428,
              1.1428571428571428,
              1.1428571428571428
            ],
            "integer_weights": [
              [
                7,
                0,
                0,
                0,
                -1,
                0,
                0,
                0
              ],
              [
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0
              ],
              [
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0
              ],
              [
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0
              ],
              [
                0,
                -1,
                0,
                0,
                0,
                0,
                0,
                0
              ],
              [
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0
              ],
              [
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0
              ],
              [
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0
              ]
            ],
            "restored_weights": [
              [
                8.0,
                0.0,
                0.0,
                0.0,
                -1.1428571428571428,
                0.0,
                0.0,
                0.0
              ],
              [
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0
              ],
              [
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0
              ],
              [
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0
              ],
              [
                0.0,
                -1.1428571428571428,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0
              ],
              [
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0
              ],
              [
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0
              ],
              [
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0
              ]
            ]
          },
          "row": {
            "scales": [
              1.1428571428571428,
              0.042981569799130724,
              0.04441407708205186,
              0.05821599659267464,
              0.08553934533559894,
              0.03917146906132811,
              0.05693605281151666,
              0.04218336686403077
            ],
            "integer_weights": [
              [
                7,
                0,
                0,
                0,
                -1,
                0,
                0,
                0
              ],
              [
                0,
                5,
                -2,
                4,
                4,
                3,
                -3,
                7
              ],
              [
                1,
                2,
                2,
                7,
                -7,
                6,
                2,
                -6
              ],
              [
                6,
                4,
                0,
                -4,
                -2,
                -3,
                7,
                -4
              ],
              [
                2,
                -7,
                0,
                4,
                -1,
                -5,
                -1,
                1
              ],
              [
                -2,
                -2,
                0,
                -1,
                -7,
                2,
                5,
                5
              ],
              [
                -4,
                0,
                7,
                -5,
                3,
                -2,
                4,
                1
              ],
              [
                7,
                6,
                0,
                3,
                -1,
                6,
                -1,
                -7
              ]
            ],
            "restored_weights": [
              [
                8.0,
                0.0,
                0.0,
                0.0,
                -1.1428571428571428,
                0.0,
                0.0,
                0.0
              ],
              [
                0.0,
                0.21490784899565363,
                -0.08596313959826145,
                0.1719262791965229,
                0.1719262791965229,
                0.12894470939739217,
                -0.12894470939739217,
                0.3008709885939151
              ],
              [
                0.04441407708205186,
                0.08882815416410372,
                0.08882815416410372,
                0.31089853957436303,
                -0.31089853957436303,
                0.26648446249231117,
                0.08882815416410372,
                -0.26648446249231117
              ],
              [
                0.34929597955604785,
                0.23286398637069855,
                0.0,
                -0.23286398637069855,
                -0.11643199318534928,
                -0.17464798977802393,
                0.4075119761487225,
                -0.23286398637069855
              ],
              [
                0.17107869067119788,
                -0.5987754173491926,
                0.0,
                0.34215738134239576,
                -0.08553934533559894,
                -0.4276967266779947,
                -0.08553934533559894,
                0.08553934533559894
              ],
              [
                -0.07834293812265622,
                -0.07834293812265622,
                0.0,
                -0.03917146906132811,
                -0.27420028342929675,
                0.07834293812265622,
                0.19585734530664056,
                0.19585734530664056
              ],
              [
                -0.22774421124606664,
                0.0,
                0.39855236968061664,
                -0.2846802640575833,
                0.17080815843455,
                -0.11387210562303332,
                0.22774421124606664,
                0.05693605281151666
              ],
              [
                0.2952835680482154,
                0.25310020118418464,
                0.0,
                0.12655010059209232,
                -0.04218336686403077,
                0.25310020118418464,
                -0.04218336686403077,
                -0.2952835680482154
              ]
            ]
          }
        },
        "missing_scale_error": 25.678452692780468,
        "method": "symmetric absmax toy; not GPTQ or a quality benchmark"
      },
      "plot": {
        "label": "层输出RMSE：同bit比较scale粒度",
        "unit": "RMSE",
        "rows": [
          [
            "8b tensor",
            0.052004932274443326
          ],
          [
            "8b row",
            0.032755026684558375
          ],
          [
            "4b tensor",
            0.6057537396582763
          ],
          [
            "4b row",
            0.3487148563162826
          ],
          [
            "3b tensor",
            0.48735867146013817
          ],
          [
            "3b row",
            0.2545171348078944
          ],
          [
            "2b tensor",
            0.48735867146013817
          ],
          [
            "2b row",
            0.3706683257276053
          ]
        ]
      },
      "trace": []
    },
    {
      "id": "moe",
      "title": "07 · MoE：路由、加权合并与热点专家",
      "question": "top-2只激活两位专家，是否意味着所有专家一样忙？",
      "verdict": "dispatch后按token身份和gate权重合并，才能恢复参考输出。仅提高专家0的路由偏好，就能观察负载变集中；这不是负载均衡算法。",
      "rows": [
        {
          "bias": 0.0,
          "expert_load": [
            5,
            4,
            3,
            4
          ],
          "max_to_mean": 1.25,
          "correct_error": 0.0,
          "missing_gate_error": 0.3730595730414295
        },
        {
          "bias": 4.0,
          "expert_load": [
            8,
            4,
            0,
            4
          ],
          "max_to_mean": 2.0,
          "correct_error": 0.0,
          "missing_gate_error": 0.5019076420485754
        }
      ],
      "columns": [
        [
          "bias",
          "专家0人为bias"
        ],
        [
          "expert_load",
          "各专家接收token数"
        ],
        [
          "max_to_mean",
          "最大负载/均值"
        ],
        [
          "correct_error",
          "合并误差"
        ],
        [
          "missing_gate_error",
          "漏乘gate误差"
        ]
      ],
      "checks": [
        {
          "label": "bias=0.0dispatch/combine等价",
          "passed": true
        },
        {
          "label": "bias=0.0漏gate权重必须失败",
          "passed": true
        },
        {
          "label": "bias=4.0dispatch/combine等价",
          "passed": true
        },
        {
          "label": "bias=4.0漏gate权重必须失败",
          "passed": true
        }
      ],
      "details": {
        "routes_by_case": [
          [
            {
              "token": 0,
              "selected": [
                0,
                1
              ],
              "weights": [
                0.5220693171457168,
                0.47793068285428314
              ]
            },
            {
              "token": 1,
              "selected": [
                3,
                0
              ],
              "weights": [
                0.7044531540348689,
                0.29554684596513126
              ]
            },
            {
              "token": 2,
              "selected": [
                1,
                2
              ],
              "weights": [
                0.7309247653026253,
                0.2690752346973747
              ]
            },
            {
              "token": 3,
              "selected": [
                1,
                2
              ],
              "weights": [
                0.8933534594288426,
                0.10664654057115736
              ]
            },
            {
              "token": 4,
              "selected": [
                1,
                0
              ],
              "weights": [
                0.9232088751492562,
                0.07679112485074371
              ]
            },
            {
              "token": 5,
              "selected": [
                3,
                0
              ],
              "weights": [
                0.9780607803455453,
                0.0219392196544547
              ]
            },
            {
              "token": 6,
              "selected": [
                3,
                2
              ],
              "weights": [
                0.8332552519328681,
                0.16674474806713194
              ]
            },
            {
              "token": 7,
              "selected": [
                3,
                0
              ],
              "weights": [
                0.938374597315236,
                0.06162540268476407
              ]
            }
          ],
          [
            {
              "token": 0,
              "selected": [
                0,
                1
              ],
              "weights": [
                0.983509367394287,
                0.016490632605713172
              ]
            },
            {
              "token": 1,
              "selected": [
                0,
                3
              ],
              "weights": [
                0.9581697632002176,
                0.041830236799782324
              ]
            },
            {
              "token": 2,
              "selected": [
                0,
                1
              ],
              "weights": [
                0.9191561536787934,
                0.0808438463212066
              ]
            },
            {
              "token": 3,
              "selected": [
                0,
                1
              ],
              "weights": [
                0.6371442177065342,
                0.3628557822934659
              ]
            },
            {
              "token": 4,
              "selected": [
                0,
                1
              ],
              "weights": [
                0.8195399263175076,
                0.18046007368249234
              ]
            },
            {
              "token": 5,
              "selected": [
                0,
                3
              ],
              "weights": [
                0.5505032091770508,
                0.44949679082294935
              ]
            },
            {
              "token": 6,
              "selected": [
                3,
                0
              ],
              "weights": [
                0.5717079954857991,
                0.4282920045142009
              ]
            },
            {
              "token": 7,
              "selected": [
                0,
                3
              ],
              "weights": [
                0.7819258785632875,
                0.21807412143671243
              ]
            }
          ]
        ],
        "expert_parameters": 64,
        "active_expert_parameters_per_token": 32,
        "scope": "linear toy experts, not trained SwiGLU experts; no all-to-all time"
      },
      "plot": {
        "label": "提高专家0偏好后的接收数量",
        "unit": "token-expert分配次数",
        "rows": [
          [
            "E0",
            8
          ],
          [
            "E1",
            4
          ],
          [
            "E2",
            0
          ],
          [
            "E3",
            4
          ]
        ]
      },
      "trace": []
    },
    {
      "id": "scheduler",
      "title": "08 · 调度：一次只改一个变量",
      "question": "prefix、块数、预算、策略，分别改变哪一种工作和等待？",
      "verdict": "与基线逐行比较。输入token工作量包含重算；首输出迭代只反映这个简化模型的离散轮次，不是TTFT毫秒。",
      "rows": [
        {
          "case": "基线",
          "blocks": 8,
          "budget": 4,
          "prefix": true,
          "policy": "mixed",
          "work": 34,
          "iterations": 11,
          "preemptions": 0,
          "hits": 3
        },
        {
          "case": "仅关prefix",
          "blocks": 8,
          "budget": 4,
          "prefix": false,
          "policy": "mixed",
          "work": 46,
          "iterations": 14,
          "preemptions": 0,
          "hits": 0
        },
        {
          "case": "仅减block",
          "blocks": 4,
          "budget": 4,
          "prefix": true,
          "policy": "mixed",
          "work": 38,
          "iterations": 15,
          "preemptions": 0,
          "hits": 10
        },
        {
          "case": "仅增budget",
          "blocks": 8,
          "budget": 8,
          "prefix": true,
          "policy": "mixed",
          "work": 34,
          "iterations": 10,
          "preemptions": 0,
          "hits": 3
        },
        {
          "case": "仅换policy",
          "blocks": 8,
          "budget": 4,
          "prefix": true,
          "policy": "prefill-first",
          "work": 35,
          "iterations": 12,
          "preemptions": 1,
          "hits": 4
        }
      ],
      "columns": [
        [
          "case",
          "对照条件"
        ],
        [
          "blocks",
          "块数"
        ],
        [
          "budget",
          "预算"
        ],
        [
          "work",
          "输入token工作量"
        ],
        [
          "iterations",
          "总迭代"
        ],
        [
          "preemptions",
          "抢占次数"
        ],
        [
          "hits",
          "前缀块命中"
        ]
      ],
      "checks": [
        {
          "label": "基线请求全部完成",
          "passed": true
        },
        {
          "label": "仅关prefix请求全部完成",
          "passed": true
        },
        {
          "label": "仅减block请求全部完成",
          "passed": true
        },
        {
          "label": "仅增budget请求全部完成",
          "passed": true
        },
        {
          "label": "仅换policy请求全部完成",
          "passed": true
        }
      ],
      "details": {
        "基线": {
          "first_output_iteration": {
            "A": 2,
            "B": 2,
            "C": 5,
            "D": 7
          },
          "finish_iteration": {
            "A": 5,
            "B": 6,
            "C": 7,
            "D": 10
          },
          "config": {
            "blocks": 8,
            "block_size": 4,
            "budget": 4,
            "policy": "mixed",
            "prefix": true
          },
          "summary": {
            "iterations": 11,
            "input_token_work": 34,
            "output_tokens": 16,
            "prefix_block_hits": 3,
            "preemptions": 0,
            "all_finished": true
          }
        },
        "仅关prefix": {
          "first_output_iteration": {
            "A": 2,
            "B": 4,
            "C": 8,
            "D": 10
          },
          "finish_iteration": {
            "A": 5,
            "B": 8,
            "C": 10,
            "D": 13
          },
          "config": {
            "blocks": 8,
            "block_size": 4,
            "budget": 4,
            "policy": "mixed",
            "prefix": false
          },
          "summary": {
            "iterations": 14,
            "input_token_work": 46,
            "output_tokens": 16,
            "prefix_block_hits": 0,
            "preemptions": 0,
            "all_finished": true
          }
        },
        "仅减block": {
          "first_output_iteration": {
            "A": 2,
            "B": 2,
            "D": 7,
            "C": 12
          },
          "finish_iteration": {
            "A": 5,
            "B": 7,
            "D": 10,
            "C": 14
          },
          "config": {
            "blocks": 4,
            "block_size": 4,
            "budget": 4,
            "policy": "mixed",
            "prefix": true
          },
          "summary": {
            "iterations": 15,
            "input_token_work": 38,
            "output_tokens": 16,
            "prefix_block_hits": 10,
            "preemptions": 0,
            "all_finished": true
          }
        },
        "仅增budget": {
          "first_output_iteration": {
            "A": 1,
            "B": 1,
            "C": 3,
            "D": 6
          },
          "finish_iteration": {
            "A": 4,
            "B": 5,
            "C": 5,
            "D": 9
          },
          "config": {
            "blocks": 8,
            "block_size": 4,
            "budget": 8,
            "policy": "mixed",
            "prefix": true
          },
          "summary": {
            "iterations": 10,
            "input_token_work": 34,
            "output_tokens": 16,
            "prefix_block_hits": 3,
            "preemptions": 0,
            "all_finished": true
          }
        },
        "仅换policy": {
          "first_output_iteration": {
            "A": 2,
            "B": 2,
            "C": 4,
            "D": 7
          },
          "finish_iteration": {
            "C": 8,
            "A": 10,
            "B": 11,
            "D": 11
          },
          "config": {
            "blocks": 8,
            "block_size": 4,
            "budget": 4,
            "policy": "prefill-first",
            "prefix": true
          },
          "summary": {
            "iterations": 12,
            "input_token_work": 35,
            "output_tokens": 16,
            "prefix_block_hits": 4,
            "preemptions": 1,
            "all_finished": true
          }
        }
      },
      "plot": {
        "label": "固定工作负载：输入计算及重算",
        "unit": "token次",
        "rows": [
          [
            "基线",
            34
          ],
          [
            "仅关prefix",
            46
          ],
          [
            "仅减block",
            38
          ],
          [
            "仅增budget",
            34
          ],
          [
            "仅换policy",
            35
          ]
        ]
      },
      "trace": []
    }
  ]
}
