Agent: fix graph hash generation for multi-subgraph models and unify hash utilities#716
Merged
Conversation
- _generate_graph_hash: generate per-subgraph hashes (subgraph_N/graph_hash.txt) instead of a single top-level hash, avoiding false collisions - is_duplicate_sample: use frozenset of subgraph hashes for multi-subgraph models, preventing rglob false matches on per-subgraph hash files - Single-graph model logic unchanged (root graph_hash.txt)
Replace inline SHA256 implementation with the canonical get_sha256_hash from graph_net.hash_util, consistent with the agent extraction pipeline and other modules.
|
Thanks for your contribution! |
- Add _get_subgraph_dirs() helper: returns [sample_dir] for single-graph or [subgraph_0, subgraph_1, ...] for multi-subgraph models - Refactor _fix_model_name, _generate_graph_hash, is_duplicate_sample to use the helper, eliminating hardcoded subgraph_xxx globs - is_duplicate_sample now collects hashes from all subgraphs uniformly via frozenset comparison, regardless of model layout
Xreki
approved these changes
May 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Category
Feature Enhancement
Description
背景
原
_generate_graph_hash只处理单图模型(根目录下有model.py),对多子图模型(目录结构为subgraph_0/,subgraph_1/, ...)直接跳过,导致graph_hash.txt始终无法生成。具体影响:graph_hash.txtis_duplicate_sample()依赖graph_hash.txt做去重,缺失时直接返回False,相同计算图结构会被重复抽取同时,子图去重脚本
gen_hash_and_dedup.py内联实现了 SHA256 哈希计算,与库内统一的graph_net.hash_util.get_sha256_hash不一致,不利于维护。修改内容
1. 修复多子图模型的 hash 生成与去重 (
graph_net_agent.py)单/多子图统一处理:新增
_get_subgraph_dirs()辅助方法[sample_dir][subgraph_0, subgraph_1, ...]排序后的列表subgraph_xxxhardcoded glob_generate_graph_hash:基于_get_subgraph_dirs统一循环处理model.py的 sha256,生成对应目录下的graph_hash.txtis_duplicate_sample:基于_get_subgraph_dirs统一收集 hash_collect_hashes()函数,遍历所有子图目录收集graph_hash.txtfrozenset比对,消除重复分支_fix_model_name:同样复用_get_subgraph_dirs,消除硬编码 glob2. 统一 hash 工具 (
gen_hash_and_dedup.py)get_sha256_hash实现graph_net.hash_util.get_sha256_hash,与 Agent 抽取流程及其他模块保持一致验证结果
对历史成功样本
/home/luotao02/workspace/success_backup_20260519运行去重分析:输出: