feat: isolate DeepSeek history boundary token
This commit is contained in:
@@ -0,0 +1,148 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { readFileSync, statSync, writeFileSync } from "node:fs";
|
||||
import { resolve } from "node:path";
|
||||
|
||||
const root = resolve(import.meta.dirname, "..");
|
||||
const mainPath = resolve(
|
||||
root,
|
||||
"src/data/deepseek-v2-lite-routing-history-boundary-token-control.json",
|
||||
);
|
||||
const reproPath = resolve(
|
||||
root,
|
||||
"src/data/deepseek-v2-lite-routing-history-boundary-token-control-repro.json",
|
||||
);
|
||||
const outputPath = resolve(
|
||||
root,
|
||||
"src/data/deepseek-v2-lite-routing-history-boundary-token-control-compact.json",
|
||||
);
|
||||
|
||||
const sha256 = (path) => createHash("sha256")
|
||||
.update(readFileSync(path))
|
||||
.digest("hex");
|
||||
|
||||
const mainSha256 = sha256(mainPath);
|
||||
const reproSha256 = sha256(reproPath);
|
||||
const mainBytes = statSync(mainPath).size;
|
||||
const reproBytes = statSync(reproPath).size;
|
||||
const exact = mainSha256 === reproSha256 && mainBytes === reproBytes;
|
||||
if (!exact) {
|
||||
throw new Error("boundary-token formal run and rerun are not byte-exact");
|
||||
}
|
||||
|
||||
const boundary = JSON.parse(readFileSync(mainPath, "utf8"));
|
||||
const boundaryEdges = [
|
||||
"system_eos",
|
||||
"system_x",
|
||||
"system_period",
|
||||
"system_newline",
|
||||
"x_at_s0",
|
||||
"x_at_s1",
|
||||
"period_at_s0",
|
||||
"period_at_s1",
|
||||
"newline_at_s0",
|
||||
"newline_at_s1",
|
||||
];
|
||||
|
||||
const aggregateAlignment = (layer, domain, edge) => {
|
||||
const rows = layer.prompts
|
||||
.filter((prompt) => prompt.domain === domain)
|
||||
.map((prompt) => prompt.alignments[edge]);
|
||||
const aligned = rows.reduce(
|
||||
(sum, row) => sum + row.aligned_tokens,
|
||||
0,
|
||||
);
|
||||
const setExact = rows.reduce(
|
||||
(sum, row) => sum + row.set_topk_exact,
|
||||
0,
|
||||
);
|
||||
const orderedExact = rows.reduce(
|
||||
(sum, row) => sum + row.ordered_topk_exact,
|
||||
0,
|
||||
);
|
||||
const weightedJaccard = rows.reduce(
|
||||
(sum, row) => sum + row.mean_jaccard * row.aligned_tokens,
|
||||
0,
|
||||
);
|
||||
return {
|
||||
aligned,
|
||||
setExactRate: setExact / aligned,
|
||||
orderedExactRate: orderedExact / aligned,
|
||||
meanJaccard: weightedJaccard / aligned,
|
||||
};
|
||||
};
|
||||
|
||||
const compact = {
|
||||
schemaVersion: 1,
|
||||
source: {
|
||||
mainSha256,
|
||||
reproSha256,
|
||||
mainBytes,
|
||||
reproBytes,
|
||||
exact,
|
||||
},
|
||||
domains: boundary.corpus_contract.domains,
|
||||
labels: boundary.corpus_contract.domain_labels,
|
||||
inference: boundary.inference_contract,
|
||||
contract: {
|
||||
tokenIds: boundary.history_boundary_token_contract.boundary_token_ids,
|
||||
validation: boundary.history_boundary_token_contract.render_validation,
|
||||
official: boundary.boundary.official_serialization_by_boundary,
|
||||
},
|
||||
layers: boundary.layers.slice(1).map((layer) => ({
|
||||
layer: layer.layer,
|
||||
alignment: Object.fromEntries(
|
||||
boundary.corpus_contract.domains.map((domain) => [
|
||||
domain,
|
||||
Object.fromEntries(
|
||||
boundaryEdges.map((edge) => [
|
||||
edge,
|
||||
aggregateAlignment(layer, domain, edge),
|
||||
]),
|
||||
),
|
||||
]),
|
||||
),
|
||||
scopes: Object.fromEntries(
|
||||
["target_content", "full_input"].map((scope) => [
|
||||
scope,
|
||||
{
|
||||
modes: Object.fromEntries(
|
||||
["prompt_balanced", "token_weighted"].map((mode) => {
|
||||
const control = (
|
||||
layer.statistics[scope].modes[mode].boundary_control
|
||||
);
|
||||
return [
|
||||
mode,
|
||||
Object.fromEntries(
|
||||
boundary.corpus_contract.domains.map((domain) => [
|
||||
domain,
|
||||
{
|
||||
distances: control[domain].system_edge_distances,
|
||||
contrasts: (
|
||||
control[domain].system_edge_distance_contrasts
|
||||
),
|
||||
cvEdges: control[domain].metric_system_edges.cv,
|
||||
cvContrasts: (
|
||||
control[domain].metric_system_edge_contrasts.cv
|
||||
),
|
||||
direct: control[domain].direct_substitutions,
|
||||
},
|
||||
]),
|
||||
),
|
||||
];
|
||||
}),
|
||||
),
|
||||
},
|
||||
]),
|
||||
),
|
||||
})),
|
||||
};
|
||||
|
||||
writeFileSync(
|
||||
outputPath,
|
||||
`${JSON.stringify(compact, null, 2)}\n`,
|
||||
"utf8",
|
||||
);
|
||||
process.stdout.write(
|
||||
`${outputPath}\n${mainSha256}\n${mainBytes} bytes source → `
|
||||
+ `${statSync(outputPath).size} bytes compact\n`,
|
||||
);
|
||||
@@ -519,6 +519,68 @@ await evaluate(`(() => {
|
||||
await pause(120);
|
||||
await screenshot("/tmp/llm-atlas-deepseek-distance-results-desktop.png");
|
||||
|
||||
const artifactBoundary = await evaluate(`(() => {
|
||||
const root = document.querySelector("[data-dsv2-lab]");
|
||||
root.querySelector('[data-artifact-tab="boundary"]').click();
|
||||
const read = () => ({
|
||||
panel: root.querySelector("[data-artifact-panel]:not([hidden])").dataset.artifactPanel,
|
||||
tokenCards: root.querySelectorAll(".boundary-token-grid > article").length,
|
||||
domainCards: root.querySelectorAll("[data-boundary-domain-grid] > article").length,
|
||||
domains: [...root.querySelectorAll("[data-boundary-domain-grid] > article")].map((node) => ({
|
||||
label: node.querySelector(":scope > span").textContent.trim(),
|
||||
values: [...node.querySelectorAll(".boundary-tv-ladder > b")].map((cell) => ({
|
||||
name: cell.querySelector("small").textContent.trim(),
|
||||
value: cell.querySelector("strong").textContent.trim(),
|
||||
})),
|
||||
effect: node.querySelector(":scope > strong").textContent.trim(),
|
||||
className: node.querySelector(":scope > strong").className,
|
||||
ci: node.querySelector(":scope > p").textContent.trim(),
|
||||
stability: node.querySelector(":scope > small").textContent.trim(),
|
||||
substitution: node.querySelector(":scope > em").textContent.trim(),
|
||||
interaction: node.querySelector(":scope > u").textContent.trim(),
|
||||
cv: node.querySelector(":scope > i").textContent.trim(),
|
||||
})),
|
||||
summary: [...root.querySelectorAll('[data-artifact-panel="boundary"] .boundary-summary article b')].map((node) => node.textContent.trim()),
|
||||
depthRows: root.querySelectorAll("[data-boundary-depth-map] > div").length,
|
||||
depthCells: root.querySelectorAll("[data-boundary-depth-map] > div > span").length,
|
||||
depthTitle: root.querySelector("[data-boundary-depth-title]").textContent.trim(),
|
||||
exact: root.querySelector(".boundary-ledger .exact b").textContent.trim(),
|
||||
note: root.querySelector("[data-boundary-note]").textContent.trim(),
|
||||
trackToken: root.querySelector("[data-boundary-track-token]").textContent.trim(),
|
||||
activeLayer: root.querySelector("[data-boundary-layer].active").textContent.trim(),
|
||||
activeScope: root.querySelector('[data-boundary-scope][aria-pressed="true"]').dataset.boundaryScope,
|
||||
activeMode: root.querySelector('[data-boundary-mode][aria-pressed="true"]').dataset.boundaryMode,
|
||||
activeContrast: root.querySelector('[data-boundary-contrast][aria-pressed="true"]').dataset.boundaryContrast,
|
||||
});
|
||||
const layer1X = read();
|
||||
root.querySelector('[data-boundary-layer="4"]').click();
|
||||
const layer4X = read();
|
||||
root.querySelector('[data-boundary-contrast="period_minus_eos"]').click();
|
||||
const layer4Period = read();
|
||||
root.querySelector('[data-boundary-contrast="newline_minus_eos"]').click();
|
||||
const layer4Newline = read();
|
||||
root.querySelector('[data-boundary-scope="full_input"]').click();
|
||||
const layer4Full = read();
|
||||
root.querySelector('[data-boundary-mode="token_weighted"]').click();
|
||||
const layer4FullToken = read();
|
||||
root.querySelector('[data-boundary-layer="1"]').click();
|
||||
root.querySelector('[data-boundary-scope="target_content"]').click();
|
||||
root.querySelector('[data-boundary-mode="prompt_balanced"]').click();
|
||||
root.querySelector('[data-boundary-contrast="x_minus_eos"]').click();
|
||||
return { layer1X, layer4X, layer4Period, layer4Newline, layer4Full, layer4FullToken, restored: read() };
|
||||
})()`);
|
||||
await evaluate(`(() => {
|
||||
document.querySelector("[data-dsv2-lab]").scrollIntoView({ block: "start", behavior: "instant" });
|
||||
window.scrollBy(0, -82);
|
||||
})()`);
|
||||
await pause(180);
|
||||
await screenshot("/tmp/llm-atlas-deepseek-boundary-desktop.png");
|
||||
await evaluate(`(() => {
|
||||
document.querySelector(".boundary-domain-grid").scrollIntoView({ block: "center", behavior: "instant" });
|
||||
})()`);
|
||||
await pause(120);
|
||||
await screenshot("/tmp/llm-atlas-deepseek-boundary-results-desktop.png");
|
||||
|
||||
const artifactEvidence = await evaluate(`(() => {
|
||||
const root = document.querySelector("[data-dsv2-lab]");
|
||||
root.querySelector('[data-artifact-tab="evidence"]').click();
|
||||
@@ -609,6 +671,13 @@ const mobile = await evaluate(`(() => {
|
||||
distanceContrasts: artifact.querySelectorAll("[data-distance-contrast]").length,
|
||||
distanceDomainCards: artifact.querySelectorAll("[data-distance-domain-grid] > article").length,
|
||||
distanceDepthCells: artifact.querySelectorAll("[data-distance-depth-map] > div > span").length,
|
||||
boundaryLayers: artifact.querySelectorAll("[data-boundary-layer]").length,
|
||||
boundaryScopes: artifact.querySelectorAll("[data-boundary-scope]").length,
|
||||
boundaryModes: artifact.querySelectorAll("[data-boundary-mode]").length,
|
||||
boundaryContrasts: artifact.querySelectorAll("[data-boundary-contrast]").length,
|
||||
boundaryTokenCards: artifact.querySelectorAll(".boundary-token-grid > article").length,
|
||||
boundaryDomainCards: artifact.querySelectorAll("[data-boundary-domain-grid] > article").length,
|
||||
boundaryDepthCells: artifact.querySelectorAll("[data-boundary-depth-map] > div > span").length,
|
||||
offenders: [...document.querySelectorAll("body *")]
|
||||
.filter((node) => !node.closest(".paper-chain, .advantage-table, .precision-table, .mapping-table, [data-deepseek-lab], [data-dsv2-lab]"))
|
||||
.filter((node) => node.getBoundingClientRect().right > document.documentElement.clientWidth + 1)
|
||||
@@ -678,8 +747,22 @@ await evaluate(`(() => {
|
||||
})()`);
|
||||
await pause(120);
|
||||
await screenshot("/tmp/llm-atlas-deepseek-distance-results-mobile.png");
|
||||
await evaluate(`(() => {
|
||||
const artifact = document.querySelector("[data-dsv2-lab]");
|
||||
artifact.querySelector('[data-artifact-tab="boundary"]').click();
|
||||
artifact.scrollIntoView({ block: "start", behavior: "instant" });
|
||||
window.scrollBy(0, -70);
|
||||
})()`);
|
||||
await pause(180);
|
||||
await screenshot("/tmp/llm-atlas-deepseek-boundary-mobile.png");
|
||||
await evaluate(`(() => {
|
||||
document.querySelector(".boundary-domain-grid").scrollIntoView({ block: "start", behavior: "instant" });
|
||||
window.scrollBy(0, -72);
|
||||
})()`);
|
||||
await pause(120);
|
||||
await screenshot("/tmp/llm-atlas-deepseek-boundary-results-mobile.png");
|
||||
|
||||
const report = { overview, capacity, cache, codesign, rl, artifactRoute, artifactLoad, artifactCache, artifactAbsorb, artifactCorpus, artifactTemplate, artifactHistory, artifactDistance, artifactEvidence, home, papers, mobile, exceptions };
|
||||
const report = { overview, capacity, cache, codesign, rl, artifactRoute, artifactLoad, artifactCache, artifactAbsorb, artifactCorpus, artifactTemplate, artifactHistory, artifactDistance, artifactBoundary, artifactEvidence, home, papers, mobile, exceptions };
|
||||
console.log(JSON.stringify(report, null, 2));
|
||||
|
||||
const numeric = (text) => Number.parseFloat(text.replaceAll(",", ""));
|
||||
@@ -689,8 +772,8 @@ if (overview.sections !== 26 || overview.tocLinks !== 26) failures.push("二十
|
||||
if (overview.ledgers !== 24 || overview.waves !== 10) failures.push("二十四张问题账或十次转向结构异常");
|
||||
if (overview.paperLinks !== 60 || overview.branches !== 5 || overview.followups !== 1) failures.push("论文链、旁支或公开后续标记异常");
|
||||
if (overview.labTabs !== 4 || overview.labPanels !== 4) failures.push("四联实验结构异常");
|
||||
if (overview.artifactTabs !== 9 || overview.artifactPanels !== 9 || overview.artifactLayers !== 27) failures.push("真实权重九联实验结构异常");
|
||||
if (overview.heroLabs !== "13 个可操作实验") failures.push("DeepSeek 实验总数账异常");
|
||||
if (overview.artifactTabs !== 10 || overview.artifactPanels !== 10 || overview.artifactLayers !== 27) failures.push("真实权重十联实验结构异常");
|
||||
if (overview.heroLabs !== "14 个可操作实验") failures.push("DeepSeek 实验总数账异常");
|
||||
if (overview.navLinks !== 20 || home.navLinks !== 20 || mobile.mobileLinks !== 20 || overview.activeNav !== "DeepSeek") failures.push("全站导航未同步 DeepSeek");
|
||||
if (overview.documentOverflow > 1 || mobile.documentOverflow > 1) failures.push("桌面或移动端存在文档级横向溢出");
|
||||
if (capacity.initial.panel !== "capacity" || capacity.initial.total !== "32.1× FFN" || capacity.initial.active !== "1.13× FFN") failures.push("V3 稀疏容量初始账异常");
|
||||
@@ -744,12 +827,20 @@ if (artifactDistance.layer4Filler.domains[1].values.map((cell) => cell.value).jo
|
||||
if (artifactDistance.layer4Demo.domains[1].effect !== "DEMO − FILLER · ΔTV -0.014" || artifactDistance.layer4Demo.activeContrast !== "demo_minus_filler" || !artifactDistance.layer4Demo.depthTitle.includes("文本替换")) failures.push("等长历史文本替换 contrast 异常");
|
||||
if (artifactDistance.layer4FullDemo.domains[1].effect !== "DEMO − FILLER · ΔTV -0.023" || artifactDistance.layer4FullDemo.activeScope !== "full_input" || !artifactDistance.layer4FullDemo.note.includes("完整输入")) failures.push("等长历史完整输入 scope 异常");
|
||||
if (artifactDistance.layer4FullToken.activeMode !== "token_weighted" || artifactDistance.restored.activeScope !== "target_content" || artifactDistance.restored.activeMode !== "prompt_balanced" || artifactDistance.restored.activeContrast !== "filler_minus_none") failures.push("等长历史聚合口径或恢复状态异常");
|
||||
if (artifactBoundary.layer1X.panel !== "boundary" || artifactBoundary.layer1X.tokenCards !== 4 || artifactBoundary.layer1X.domainCards !== 4 || artifactBoundary.layer1X.depthRows !== 4 || artifactBoundary.layer1X.depthCells !== 24 || artifactBoundary.layer1X.exact !== "BYTE-EXACT") failures.push("单 token 边界控制结构或独立复跑闸门异常");
|
||||
if (artifactBoundary.layer1X.domains[0].values.map((cell) => cell.value).join("/") !== "0.056/0.084/0.081/0.080" || artifactBoundary.layer1X.domains[0].effect !== "X − EOS · ΔTV +0.028" || !artifactBoundary.layer1X.domains[0].ci.includes("+0.019, +0.035")) failures.push("L1 英文边界替换统计异常");
|
||||
if (artifactBoundary.layer1X.summary.join("|") !== "24 / 24 ↑|24 / 24 ↑|23 / 24 ↑|.037 → .054 / .055 / .049" || artifactBoundary.layer1X.trackToken !== "X" || !artifactBoundary.layer1X.domains[0].stability.includes("EOS 50.7%")) failures.push("边界控制总账、协议轨或逐 token 稳定性异常");
|
||||
if (artifactBoundary.layer4X.domains[0].values.map((cell) => cell.value).join("/") !== "0.032/0.051/0.051/0.045" || artifactBoundary.layer4X.domains[0].effect !== "X − EOS · ΔTV +0.019") failures.push("L4 英文 x 边界替换异常");
|
||||
if (artifactBoundary.layer4Period.domains[2].effect !== "PERIOD − EOS · ΔTV +0.034" || artifactBoundary.layer4Period.activeContrast !== "period_minus_eos" || artifactBoundary.layer4Period.trackToken !== ".") failures.push("L4 代码句点边界替换异常");
|
||||
if (artifactBoundary.layer4Newline.activeContrast !== "newline_minus_eos" || artifactBoundary.layer4Newline.trackToken !== "↵" || !artifactBoundary.layer4Newline.depthTitle.includes("换行")) failures.push("换行边界替换切换异常");
|
||||
if (artifactBoundary.layer4Full.activeScope !== "full_input" || !artifactBoundary.layer4Full.note.includes("完整输入") || artifactBoundary.layer4Full.domains[0].values[0].value === artifactBoundary.layer4Newline.domains[0].values[0].value) failures.push("边界控制完整输入 scope 异常");
|
||||
if (artifactBoundary.layer4FullToken.activeMode !== "token_weighted" || artifactBoundary.restored.activeLayer !== "L1" || artifactBoundary.restored.activeScope !== "target_content" || artifactBoundary.restored.activeMode !== "prompt_balanced" || artifactBoundary.restored.activeContrast !== "x_minus_eos") failures.push("边界控制聚合口径或恢复状态异常");
|
||||
if (artifactEvidence.panel !== "evidence" || artifactEvidence.layers !== 27 || artifactEvidence.executed !== 7 || artifactEvidence.split !== 1 || artifactEvidence.unloaded !== 19 || artifactEvidence.exact !== "31 / 31") failures.push("真实工件执行边界或复跑闸门异常");
|
||||
if (!artifactEvidence.dependency.includes("Transformers 5.5") || !artifactEvidence.dependency.includes("4.41.2") || !artifactEvidence.boundary.includes("完整 27 层生成")) failures.push("依赖版本或未覆盖边界异常");
|
||||
if (artifactEvidence.keyboardSelected !== "load" || artifactEvidence.keyboardVisible !== "load") failures.push("真实工件实验键盘 tab 导航异常");
|
||||
if (home.releaseCards !== 17 || !home.firstRelease.includes("47 页不再压成摘要") || home.firstHref !== "/k3/" || home.paperCount !== "486") failures.push("首页 DeepSeek 首发入口或论文数异常");
|
||||
if (papers.total !== 486 || !papers.hasFilter || papers.visible < 20 || !papers.hasCoder || !papers.hasEngram) failures.push("论文库 DeepSeek 聚光异常");
|
||||
if (!mobile.menuVisible || mobile.menuOpen !== "true" || mobile.tabs !== 4 || mobile.artifactTabs !== 9 || mobile.artifactHeatCells !== 64 || mobile.corpusCohorts !== 3 || mobile.lengthDeltaCards !== 4 || mobile.templateLayers !== 6 || mobile.templateScopes !== 2 || mobile.templateModes !== 2 || mobile.templateDomainCards !== 4 || mobile.templateDepthCells !== 24 || mobile.historyLayers !== 6 || mobile.historyScopes !== 2 || mobile.historyModes !== 2 || mobile.historyEffects !== 3 || mobile.historyDomainCards !== 4 || mobile.historyDepthCells !== 24 || mobile.distanceLayers !== 6 || mobile.distanceScopes !== 2 || mobile.distanceModes !== 2 || mobile.distanceContrasts !== 2 || mobile.distanceDomainCards !== 4 || mobile.distanceDepthCells !== 24) failures.push("移动端导航或实验异常");
|
||||
if (!mobile.menuVisible || mobile.menuOpen !== "true" || mobile.tabs !== 4 || mobile.artifactTabs !== 10 || mobile.artifactHeatCells !== 64 || mobile.corpusCohorts !== 3 || mobile.lengthDeltaCards !== 4 || mobile.templateLayers !== 6 || mobile.templateScopes !== 2 || mobile.templateModes !== 2 || mobile.templateDomainCards !== 4 || mobile.templateDepthCells !== 24 || mobile.historyLayers !== 6 || mobile.historyScopes !== 2 || mobile.historyModes !== 2 || mobile.historyEffects !== 3 || mobile.historyDomainCards !== 4 || mobile.historyDepthCells !== 24 || mobile.distanceLayers !== 6 || mobile.distanceScopes !== 2 || mobile.distanceModes !== 2 || mobile.distanceContrasts !== 2 || mobile.distanceDomainCards !== 4 || mobile.distanceDepthCells !== 24 || mobile.boundaryLayers !== 6 || mobile.boundaryScopes !== 2 || mobile.boundaryModes !== 2 || mobile.boundaryContrasts !== 3 || mobile.boundaryTokenCards !== 4 || mobile.boundaryDomainCards !== 4 || mobile.boundaryDepthCells !== 24) failures.push("移动端导航或实验异常");
|
||||
if (mobile.offenders.length) failures.push(`移动端越界元素:${JSON.stringify(mobile.offenders)}`);
|
||||
if (exceptions.length) failures.push(`浏览器异常:${exceptions.join(" | ")}`);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user