| 摘要: |
| 作为人工智能的基础设施, 深度学习框架已经成为人工智能实现跨越发展的重要突破口. 但是由于缺乏统一标准, 不同框架的兼容水平较差. 忠实模型转换通过将源模型迁移为另一种目标框架下的等价模型, 来增强框架间的互操作性. 然而, 深度学习框架数量较多且相互间差异较大, 并且自主框架的需求逐渐增多, 互相转换成本较高. 因此, 提出基于领域知识图谱的框架间AI源码自动迁移方法. 该方法基于领域知识图谱和抽象语法树来系统地处理迁移挑战, 首先将源代码转换为特定的抽象语法树, 提取通用依赖信息和特定算子信息, 然后再利用存储在领域知识图谱中的框架间算子及参数映射关系来迁移到目标框架下, 形成目标框架下的目标模型代码, 大大降低了工程复杂度. 对比同类型的代码迁移工具, 所提方法可以在国内外流行深度学习框架如PyTorch、PaddlePaddle和MindSpore之间进行互相迁移, 达到了较好的成熟度和质量, 部分成果已经开源到百度官方迁移工具PaConvert中. |
| 关键词: 深度学习框架 代码迁移 知识图谱 抽象语法树 |
| DOI:10.13328/j.cnki.jos.007451 |
| 分类号:TP311 |
| 基金项目:科技创新2030—“新一代人工智能”重大项目(2021ZD0110600); 百度合作项目(Z231100010323007); 华为合作项目(22081500805582B) |
|
| Automatic Migration of AI Source Code Between Frameworks Based on Domain Knowledge Graph |
|
DING Rong1, LIU Yi-Zhou2, WANG Yu-Qian2, LI Yi-Qi1
|
|
1.Institute of Artificial Intelligence, Beihang University, Beijing 100191, China;2.School of Computer Science and Engineering, Beihang University, Beijing 100191, China
|
| Abstract: |
| As the foundation of AI, deep learning frameworks play a vital role in driving the rapid progress of AI technologies. However, due to the lack of unified standards, compatibility across different frameworks remains limited. Faithful model transformation enhances interoperability by converting a source model into an equivalent model in the target framework. However, the large number and diversity of deep learning frameworks, combined with the increasing demand for custom frameworks, lead to high conversion costs. To address this issue, this study proposes an automatic AI source code migration method between frameworks based on a domain knowledge graph. The method integrates domain knowledge graphs and abstract syntax trees to systematically manage migration challenges. First, the source code is transformed into a framework-specific abstract syntax tree, from which general dependency information and operator-specific details are extracted. By applying the operator and parameter mappings stored in the domain knowledge graph, the code is migrated to the target framework, generating equivalent target model code while significantly reducing engineering complexity. Compared with existing code migration tools, the proposed method supports mutual migration among widely used deep learning frameworks, such as PyTorch, PaddlePaddle, and MindSpore. The approach has proven to be both mature and reliable, with part of its implementation open-sourced in Baidu’s official migration tool, PaConvert. |
| Key words: deep learning framework code migration knowledge graph abstract syntax tree (AST) |