fusion_precision_analyzer【免费下载链接】graph-autofusionGraph-autofusion 是一个面向昇腾Ascend芯片的轻量级、解耦式组件集合旨在通过自动融合技术加速模型执行。 目前已开源 SuperKernel 组件未来将持续开放更多自动融合相关模块。项目地址: https://gitcode.com/cann/graph-autofusionFusion operator precision localization tool. When the network precision is normal with auto-fusion disabled but degrades with auto-fusion enabled, this tool compares dump data from both scenarios to identify which fusion operator caused the precision degradation.FeaturesThe tool supports two running modes:Mode 1 (default): Batch-compares the inputs and outputs of each fusion operator against the corresponding original operator outputs based on dump graph JSON and datadump NPY directories, outputting a console tableMode 2: Directly compares two NPY files, outputting cosine similarity, max absolute error, and max relative errorPrecision MetricsMetricFormulaCosine similaritydot(a, b) / (norm(a) * norm(b) 1e-8)Max absolute errormax(|a - b|)Max relative errormax(|a - b| / (max(|a|, |b|) 1e-8))Data Difference HandlingScenarioHandlingStatusNPY file not foundSkipFILE_NOT_FOUNDNPY load failureSkipNPY_LOAD_ERRORFormat mismatch, conversion supportedNC1HWC0 to NHWC/ND, NDC1HWC0 to NDHWC/NDFORMAT_CONVERTEDFormat mismatch, conversion unsupportedSkipFORMAT_UNSUPPORTEDdtype mismatchPromote lower precision to higherDTYPE_CASTShape mismatch, same element countFlatten and compareSHAPE_FLATTENEDShape mismatch, different element countSkipSHAPE_MISMATCHInput source is Constant/DataSkipSKIPPED_CONST_DATAMissing mapping attributeSkipNO_MAPPINGMetric computation failureSkipCOMPUTE_ERRORDependenciespip install numpyUsageMode 1: Batch Compare Fusion Operator Inputs and Outputspython3 fusion_precision_analyzer.py \ --af-open-graph af-open dump graph JSON \ --af-close-graph af-close dump graph JSON \ --af-open-data af-open datadump NPY directory \ --af-close-data af-close datadump NPY directory \ [--compare-input]ParameterRequiredDescription--modeNoRunning mode, 1 or 2, default 1--af-open-graphYesDump graph JSON file path with auto-fusion enabled--af-close-graphYesDump graph JSON file path with auto-fusion disabled--af-open-dataYesDatadump NPY directory with auto-fusion enabled--af-close-dataYesDatadump NPY directory with auto-fusion disabled--compare-inputNoWhether to compare fusion operator inputs, default offMode 2: Directly Compare Two NPY Filespython3 fusion_precision_analyzer.py \ --mode 2 \ --npy-a NPY file A \ --npy-b NPY file BParameterRequiredDescription--modeNoRunning mode, set to 2--npy-aYesFirst NPY file path--npy-bYesSecond NPY file pathExamplesExample 1: Mode 1, Compare Outputs Onlypython3 fusion_precision_analyzer.py \ --af-open-graph /home/user/dumpgraph_af_open/Build.json \ --af-close-graph /home/user/dumpgraph_af_close/Build.json \ --af-open-data /home/user/datadump_af_open \ --af-close-data /home/user/datadump_af_closeSample output:解析开启融合 dump 图: /home/user/dumpgraph_af_open/Build.json 解析关闭融合 dump 图: /home/user/dumpgraph_af_close/Build.json 找到 8 个融合算子输出映射 类型 | 融合算子名 | 索引 | 原算子名 | 原索引 | 余弦相似度 | 绝对误差最大值 | 相对误差最大值 | 状态 ----------------------------------------------------------------------------------------------------------------------- 输出 | autofuse_28_Pow_RealDiv_Square | 0 | ArithmeticOptimizer_... | 0 | 1.00000000 | 0.0000e00 | 0.0000e00 | OK 输出 | autofuse_38_Pow_Minimum_Reshape_... | 0 | truediv_9 | 0 | 0.99999832 | 1.2000e-05 | 3.4000e-06 | OK 输出 | autofuse_35_Pow_Maximum_Square_... | 0 | Sum_6 | 0 | - | - | - | FILE_NOT_FOUND 输出 | autofuse_33_Square_RealDiv | 0 | truediv_16 | 0 | 1.00000000 | 0.0000e00 | 0.0000e00 | OKExample 2: Mode 1, Compare Both Inputs and Outputspython3 fusion_precision_analyzer.py \ --af-open-graph /home/user/dumpgraph_af_open/Build.json \ --af-close-graph /home/user/dumpgraph_af_close/Build.json \ --af-open-data /home/user/datadump_af_open \ --af-close-data /home/user/datadump_af_close \ --compare-inputSample output:解析开启融合 dump 图: /home/user/dumpgraph_af_open/Build.json 解析关闭融合 dump 图: /home/user/dumpgraph_af_close/Build.json 找到 8 个融合算子输出映射, 5 个融合算子输入映射 类型 | 融合算子名 | 索引 | 原算子名 | 原索引 | 余弦相似度 | 绝对误差最大值 | 相对误差最大值 | 状态 ----------------------------------------------------------------------------------------------------------------------------------- 输出 | autofuse_28_Pow_RealDiv_Square | 0 | ArithmeticOptimizer_... | 0 | 1.00000000 | 0.0000e00 | 0.0000e00 | OK 输出 | autofuse_33_Square_RealDiv | 0 | truediv_16 | 0 | 1.00000000 | 0.0000e00 | 0.0000e00 | OK 输入 | autofuse_28_Pow_RealDiv_Square | 0 | dynamic_const_2309685_16| 0 | - | - | - | SKIPPED_CONST_DATA 输入 | autofuse_33_Square_RealDiv | 0 | truediv_3 | 0 | 1.00000000 | 0.0000e00 | 0.0000e00 | SHAPE_FLATTENEDExample 3: Mode 2, Directly Compare Two NPY Filespython3 fusion_precision_analyzer.py \ --mode 2 \ --npy-a /home/user/datadump_af_open/AscBackend.autofuse_28_Pow_RealDiv_Square.3.44.1783906987170021.output.0.npy \ --npy-b /home/user/datadump_af_close/Square.ArithmeticOptimizer_ReplaceMulWithSquare_Mul_7.9.44.1783906974676130.output.0.npySample output:文件A: /home/user/datadump_af_open/AscBackend.autofuse_28_Pow_RealDiv_Square.3.44.1783906987170021.output.0.npy 文件B: /home/user/datadump_af_close/Square.ArithmeticOptimizer_ReplaceMulWithSquare_Mul_7.9.44.1783906974676130.output.0.npy 状态: OK 余弦相似度: 1.0000000000 绝对误差最大值: 0.000000e00 相对误差最大值: 0.000000e00How It WorksMode 1Parse the auto-fusion-enabled dump graph JSON to identify fusion operators (typeisAscBackendorFusedAscBackend)Extract_datadump_origin_nameand_datadump_origin_output_indexattributes from the fusion operatorsoutput_descto build the mapping from fusion operator outputs to original operator outputsParse the auto-fusion-disabled dump graph JSON to build a lookup table from original operator names to output formatsParsenode:idxreferences from the fusion operatorsinputfield; if the input source is a fusion operator, further resolve it to the corresponding original operatorMatch NPY files in both datadump directories by op name (replacing/with_)Obtain the fusion-side format from the af_open graph and the original-side format from the af_close graph; for each matched pair, handle format/dtype/shape differences and compute precision metricsOutput a console table, ordered by the fusion operator traversal order in the graphMode 2Load two NPY filesHandle dtype/shape differences and compute precision metricsOutput resultsPrerequisitesUsers need to obtain the following data through the CANN precision debugging toolchain:Dump graph JSON: GE dump graph from the auto-fusion-enabled scenario, generated via environment variableDUMP_GE_GRAPH2or similarDatadump NPY files: Binary data collected via the CANN datadump mechanism, then converted to NPY format using themsaccucmp.pytool【免费下载链接】graph-autofusionGraph-autofusion 是一个面向昇腾Ascend芯片的轻量级、解耦式组件集合旨在通过自动融合技术加速模型执行。 目前已开源 SuperKernel 组件未来将持续开放更多自动融合相关模块。项目地址: https://gitcode.com/cann/graph-autofusion创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考