Skip to content

Topic06 final submit - #45

Closed
2813183274-cloud wants to merge 2 commits into
ScratchV-Compiler:mainfrom
2813183274-cloud:topic06-final-submit
Closed

Topic06 final submit#45
2813183274-cloud wants to merge 2 commits into
ScratchV-Compiler:mainfrom
2813183274-cloud:topic06-final-submit

Conversation

@2813183274-cloud

Copy link
Copy Markdown

No description provided.

@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown

🤖 AI Code Review

共审查 10 个变更文件
⚠️ 另有 19 个文件超过上限(最多 10 个)未审查

📁 ScratchV-topic06-deliverable/.github/workflows/benchmark.yml

🔴 Unbounded triggeron: push and on: pull_request without branch filters. This runs on every push or PR to any branch, wasting CI resources. Consider restricting to main or using paths-ignore.

🟡 Hardcoded benchmark parameter--benchmark 3 is hardcoded. This makes it impossible to vary the iteration count without editing the workflow. Use a workflow input or environment variable.

🟡 Missing dependency filerequirements-topic06.txt may not exist in the repository. If absent, the pip install step will fail without a clear message. Add a check or ensure the file is committed.

🟡 Upload artifact may fail silentlyreports/report.md and reports/report.json may not be generated if the benchmark step crashes. The upload step will warn but not fail, leaving no artifacts. Consider adding if: always() to upload step or ensuring report generation is robust.

💭 No caching — Python dependencies are installed from scratch every run. Add actions/cache for pip to speed up successive runs.

💭 Hardcoded Python version3.11 will become outdated. Consider using 3.12 or a matrix strategy to test multiple versions, but this is a minor nit.


📁 ScratchV-topic06-deliverable/LICENSE

💭 Nit: 确认版权持有者 "ScratchV" 和年份 2025 是否与项目实际信息一致。标准 MIT 模板,无其他问题。


📁 ScratchV-topic06-deliverable/README.md

🟡 阈值单位不明确 — 在 "性能退化阈值" 部分,--regression-threshold 2 被描述为 "超过 2% 即判定为退化",但参数值是整数。建议明确说明单位是百分比(例如 2 表示 2%),或修改示例为 --regression-threshold 0.02 表示 2%。

🟡 目录结构可能误导 — 目录结构列出了 reports/failures/build/,但这些目录是运行后生成的。建议在目录后添加注释如 (运行后生成),避免用户误以为它们是预置的。

🟡 缺少放置路径说明 — 运行依赖提到 "该交付目录需要放在 ScratchV 项目环境中运行",但没有给出具体路径示例(如 ScratchV/scratchv-topic06-deliverable/)。建议增加一行建议的放置方式。

💭 静态运行结果可能过时 — "最近一次全量运行结果为 13 个通过、10 个失败" 写在 README 中会随版本过时。建议改为 "示例运行结果" 或直接删除,让用户自己运行获取最新结果。

💭 expected_output_file 缺少示例 — 添加测试用例部分提到了 expected_output_file,但没有给出 JSON 示例或字段说明,读者可能不清楚如何使用。建议补充一个简单示例。

💭 reports/course_report_instructions.png 文件名可疑 — 完整报告生成的 PNG 文件名为 course_report_instructions.png,与上下文无关(可能是某个课程要求)。建议改为更通用的名称如 performance_report.pngsummary.png

💭 轻量模式说明稍显冗余 — "轻量模式不会加载 jinja2 或 matplotlib,也不会刷新已有的 HTML、PNG 文件" 这句话在 "测试报告" 部分已经隐含(轻量只生成 md/json),可以删除或合并到前文,避免重复。


📁 ScratchV-topic06-deliverable/reports/benchmark_baseline.json

🔴 Missing trailing newline — File ends without a newline, which can cause diff noise or issues with POSIX tools. Suggest adding a final newline.

🟡 avg_instr_count values for dot_4 and dot_8 are 3.0 — A dot product of size 4 typically requires at least 4 multiplications and 3 additions; 3.0 instructions seems suspiciously low. Verify the measurement methodology or whether the benchmark is measuring only the kernel dispatch.

🟡 runs is always 3 — For a baseline benchmark, 3 runs may not be enough for statistically stable measurements. Consider increasing to 10+ or including variance/standard deviation.

💭 No metadata — Adding a top-level field like "benchmark_version": "1.0", "generated_at": "2025-02-18T12:00:00Z" would improve reproducibility and traceability.


📁 ScratchV-topic06-deliverable/reports/report.html

🔴 硬编码绝对路径泄露内部目录结构 — 第 8 行:<p>测试目录:D:\PycharmProjects\ScratchV\...\tests_main</p>。该路径暴露了开发者的本地文件系统布局,在报告中不应包含。建议:使用相对路径或仅显示测试目录名称。

🟡 失败用例的“是否退化”字段逻辑错误 — 表中 if_elseif_reluif_then 三个用例状态为 FAIL(模拟超时),但“是否退化”列均为 False。超时是一种性能退化,应标记为 TrueN/A,否则会误导读者。

🟡 图片路径硬编码且无后备 — 第 7 行:<img src="course_report_instructions.png">。若图片缺失或路径错误,页面将显示损坏图标。建议:使用相对路径,并考虑添加 alt 文本或错误处理(如 onerror 占位图)。

💭 响应式缺失 — 缺少 <meta name="viewport" content="width=device-width, initial-scale=1"> 标签,在移动设备上表格可能缩放不当。建议:为移动端适配添加 viewport。


📁 ScratchV-topic06-deliverable/reports/report.json

🔴 报告缺少失败原因字段 — 所有 FAIL 条目(如 if_elsedot_4matmul_2x2)都只有 matched: falseactual 值,但没有 failure_reasonerror_message。调试时无法得知是模拟错误、断言失败还是其他原因。建议为每个失败添加描述性字段。

🔴 backend 字段被误用为 timeout — 在 if_elseif_reluif_then 条目中,backend"timeout",而其他条目为 "tinyfive"。后端名称不应变成状态值。建议保留 backend: "tinyfive",并新增独立的 timed_out: true 字段或 simulation_timed_out 标志。

🟡 绝对路径泄露和个人化信息 — 所有 pathasm 字段包含本地绝对路径(如 D:\PycharmProjects\ScratchV\...),这会使报告不可移植,且可能泄露项目结构。建议改为相对路径或仅文件名。

🟡 时间戳精度过高compile_time_secsimulation_time_sec 等字段保留了过多小数位(如 0.07880300001124851),实际意义不大。建议统一四舍五入到合理精度(如毫秒微秒)。

🟡 未使用的字段冗余benchmark_runsbaseline_instr_countdelta 等字段在所有条目中均为 null,且 regression_threshold_pct 定义了但从未使用。如果未运行基准测试,建议省略这些字段或提供条件性输出,避免误导读者。

💭 initial_registers 空对象 — 部分条目(如 dot_4dot_8)的 initial_registers{},可能表示无寄存器输入,但也可以省略该字段。建议仅在非空时输出。

💭 selection 字段使用 nullcategoryfilternull,不如直接省略或使用空字符串,更符合 JSON 最佳实践。

数据一致性检查 — 无问题:summary.total 等于 results 长度(23),passed + failed = 13 + 10 = 23,数值一致。


📁 ScratchV-topic06-deliverable/reports/report.md

🔴 数据准确性存疑: matmul_4x4 预期输出 — 预期输出 [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]] 看起来像是恒等矩阵的输入,而非矩阵乘法结果。请核实测试用例定义,如果是复制粘贴错误,会导致全线失败。

🔴 分支用例全部超时 — 3 个 branch 测试的模拟后端均为 timeout,指令数 0,输出 None。说明生成的汇编代码可能陷入死循环或缺少终止条件。建议检查分支指令(如 beq/bne)的跳转逻辑,确保有明确的退出路径或 ebreak

🟡 性能报告无性能数据 — 所有性能相关字段(基线、变化量、变化率、退化标志)均为 null,但报告标题为“性能测试报告”且声明了阈值 5%。既然未运行基准测试,应说明原因或移除相关字段,避免误导。

🟡 硬编码 Windows 绝对路径 — 报告中多处出现 D:\PycharmProjects\...,在版本控制中会暴露私有目录结构,且跨平台不可移植。建议改为相对路径或占位符。

🟡 dot_4 / dot_8 输出为 0 但预期非零 — 指令数仅 3,说明 dot product 未能正确展开为多次乘加。可能循环展开或累加器初始化有 bug,导致返回 0。

💭 if_relu 初始寄存器为空 — 该用例初始化寄存器 {},但 if_relu 需要输入值才能正确分支。如果设计如此,请确认模拟器是否默认所有寄存器为 0;否则应补充初始值。

💭 报告缺少总结与建议 — 当前只是数据罗列,没有对 43% 失败率的原因分析或改进方向。建议增加一段文字总结,如“主要失败集中在分支、reduction 和 tensor 类别,需优先排查对应编译器后端”。


📁 ScratchV-topic06-deliverable/requirements-topic06-full.txt

🔴 Unpinned dependenciesjinja2 and matplotlib have no version specifiers. This makes builds non-reproducible and risks pulling in versions with known vulnerabilities or breaking changes.
Suggestion: Pin versions (e.g., jinja2==3.0.3, matplotlib==3.5.0) or use pip-tools/poetry to generate a lock file. Consider using ~= for compatible releases.

🟡 Potential redundancy — The -r requirements-topic06.txt reference might already include these packages. Verify they aren't duplicated, as that could cause conflicts if the base file later pins different versions.
Suggestion: Check the base file and remove duplicates if present.

💭 No constraints — There's no constraints.txt or --constraint usage. If the project aims for reproducibility, this is a gap.
Suggestion: Use a constraints file for transitive dependencies as well.

Overall, the file is simple but lacks version control. Address the above to ensure deterministic installs.


📁 ScratchV-topic06-deliverable/requirements-topic06.txt

🔴 Unpinned dependenciestinyfive and pytest have no version constraints, making builds non-reproducible. Use == or ~= to pin exact or compatible versions (e.g., pytest==8.2.0).

🟡 Potential typo or unknown packagetinyfive is not a well-known PyPI package. Verify the name (maybe tinyfivetinyfive? Check if it exists or if it's a local/path dependency). If it's a custom/internal module, consider using a path or Git URL.

💭 Consider separating dev dependencies — If pytest is only for testing, move it to requirements-dev.txt to keep production dependencies lean.

💭 Add a comment — A one-line comment explaining that tinyfive is a custom package (if so) would help future maintainers.


📁 ScratchV-topic06-deliverable/run_tests.py

🔴 Blocker: Duplicate function definitions — The file defines generate_report_text, write_html_report, generate_report_text_cn, write_html_report_cn, and write_report multiple times (e.g., lines 160–260, 300–400, 500–600, 700–800). Later definitions silently override earlier ones, leaving extensive dead code. This makes the file nearly impossible to maintain. Remove all duplicates and keep only the final generate_unified_report_text_cn, write_unified_html_report_cn, and the write_report that accepts full_report.

🔴 Blocker: Fragile register inferenceinfer_initial_registers (lines ~120–170) parses the IR dump to guess which input variables map to which registers. This is a heuristic that can easily break if the compiler output format changes, or if the first-use order does not match the actual register allocation used by tinyfive. This will cause spurious test failures. Consider having the compiler emit explicit register mappings, or use a deterministic scheme (e.g., alphabetical order) rather than parsing IR.

🟡 Suggestion: Subprocess overhead in benchmark — The benchmark loop runs each simulation in a fresh subprocess (run_simulation spawns python -c ... every time). For N runs this is N subprocess creations, which is slow. Consider executing verify_assembly in-process (import it directly) and only spawning a subprocess for timeout isolation, or reuse a persistent worker.

🟡 Suggestion: Unused top-level importfrom scratchv.simulator.tinyfive import verify_assembly is imported but never used at module level; it is only used inside the subprocess code string. Remove the import to avoid confusion.

🟡 Suggestion: Simplify report generation — The report functions are over-engineered and repetitive. Consolidate to a single generate_report that branches on benchmark_mode and full_report flags. This will reduce the file size by ~50% and eliminate the duplication described above.

🟡 Suggestion: Error handling for json.loads in run_simulation — The code catches json.JSONDecodeError but not TypeError if completed.stdout is None. Add a guard for None output.

💭 Nit: Magic numbersrel_tol=1e-7 and abs_tol=1e-7 in values_equal are fine, but consider naming them as constants. Also, 1.96 in summarize_benchmark_runs is a magic constant; add a comment.

💭 Nit: Use pathlib consistentlyos.environ.setdefault in write_chart is fine, but os.path usage is sparse; prefer pathlib for all paths.

Overall: The script has a serious maintainability problem due to duplicated code, and the register‑inference coupling to IR format is a correctness risk. Address the blockers before merging.



⚠️ 未审查的文件

  • ScratchV-topic06-deliverable/setup.py
  • ScratchV-topic06-deliverable/tests_main/activation/add_relu_relu.dsl
  • ScratchV-topic06-deliverable/tests_main/activation/add_relu_relu.meta.json
  • ScratchV-topic06-deliverable/tests_main/activation/relu_add.dsl
  • ScratchV-topic06-deliverable/tests_main/activation/relu_add.meta.json
  • ScratchV-topic06-deliverable/tests_main/activation/relu_only.dsl
  • ScratchV-topic06-deliverable/tests_main/activation/relu_only.meta.json
  • ScratchV-topic06-deliverable/tests_main/activation/relu_twice.dsl
  • ScratchV-topic06-deliverable/tests_main/activation/relu_twice.meta.json
  • ScratchV-topic06-deliverable/tests_main/branch/if_else.dsl
  • ScratchV-topic06-deliverable/tests_main/branch/if_else.meta.json
  • ScratchV-topic06-deliverable/tests_main/branch/if_relu.dsl
  • ScratchV-topic06-deliverable/tests_main/branch/if_relu.meta.json
  • ScratchV-topic06-deliverable/tests_main/branch/if_then.dsl
  • ScratchV-topic06-deliverable/tests_main/branch/if_then.meta.json
  • ScratchV-topic06-deliverable/tests_main/elementwise/add_chain.dsl
  • ScratchV-topic06-deliverable/tests_main/elementwise/add_chain.meta.json
  • ScratchV-topic06-deliverable/tests_main/elementwise/add_chain_3.dsl
  • ScratchV-topic06-deliverable/tests_main/elementwise/add_chain_3.meta.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant