{"id":18524924,"url":"https://github.com/paddlepaddle/padiff","last_synced_at":"2025-04-10T04:12:55.526Z","repository":{"id":65315874,"uuid":"583199561","full_name":"PaddlePaddle/PaDiff","owner":"PaddlePaddle","description":"Paddle Automatically Diff Precision Toolkits.","archived":false,"fork":false,"pushed_at":"2024-04-17T10:01:28.000Z","size":442,"stargazers_count":49,"open_issues_count":7,"forks_count":14,"subscribers_count":6,"default_branch":"develop","last_synced_at":"2025-03-24T05:34:48.265Z","etag":null,"topics":["deep-learning","paddlepaddle"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PaddlePaddle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-29T04:01:34.000Z","updated_at":"2025-01-22T13:18:46.000Z","dependencies_parsed_at":"2024-01-18T09:03:34.611Z","dependency_job_id":"2ecb0ee5-401c-4b80-93c6-763393d906aa","html_url":"https://github.com/PaddlePaddle/PaDiff","commit_stats":{"total_commits":53,"total_committers":7,"mean_commits":7.571428571428571,"dds":0.4339622641509434,"last_synced_commit":"3fbe9ee50a3ebcd4d6d522b854da3e15f87235ff"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PaddlePaddle%2FPaDiff","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PaddlePaddle%2FPaDiff/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PaddlePaddle%2FPaDiff/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PaddlePaddle%2FPaDiff/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PaddlePaddle","download_url":"https://codeload.github.com/PaddlePaddle/PaDiff/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248154996,"owners_count":21056543,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deep-learning","paddlepaddle"],"created_at":"2024-11-06T17:43:45.169Z","updated_at":"2025-04-10T04:12:55.466Z","avatar_url":"https://github.com/PaddlePaddle.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PaDiff ![](https://img.shields.io/badge/version-v0.1-brightgreen) ![](https://img.shields.io/badge/docs-latest-brightgreen) ![](https://img.shields.io/badge/PRs-welcome-orange) ![](https://img.shields.io/badge/pre--commit-Yes-brightgreen)\n\n\n**P**addle  **A**utomatically  **Diff**  precision toolkits.\n\n\n\n## 最近更新\n\n-   支持添加Paddle自定义算子\n-   支持单模型运行并dump相关数据\n-   提供离线对齐工具\n\n\n\n## 简介\n\nPaDiff 是基于 PaddlePaddle 与 PyTorch 的模型精度对齐工具。传入 Paddle 或 Torch 模型，对齐训练中间结果以及训练后的模型权重，并提示精度 diff 第一次出现的位置。\n\n-   文档目录 [Guides](docs/README.md)\n-   使用教程 [Tutorial](docs/Tutorial.md)\n-   对齐ViTPose流程 [ViTPose](docs/CheckViTPose.md)\n-   接口参数说明 [Interface](docs/Interfaces.md)\n-   常见问题解答 [FAQs](docs/FAQs.md)\n\n\n\n\n## 安装\n\n  PaDiff v0.2 版本已发布，可通过如下命令安装：\n\n  ```\npip install padiff\n  ```\n\n  尝鲜版或开发者推荐clone源码并使用如下命令安装：\n\n  ```\npython setup.py install\n  ```\n\n\n\n## 快速开始\n\n### 使用 auto_diff 接口进行对齐\n\n```py\nfrom padiff import auto_diff\nimport torch\nimport paddle\n\nclass SimpleModule(torch.nn.Module):\n  def __init__(self):\n      super(SimpleModule, self).__init__()\n      self.linear1 = torch.nn.Linear(100, 10)\n  def forward(self, x):\n      x = self.linear1(x)\n      return x\n\nclass SimpleLayer(paddle.nn.Layer):\n  def __init__(self):\n      super(SimpleLayer, self).__init__()\n      self.linear1 = paddle.nn.Linear(100, 10)\n  def forward(self, x):\n      x = self.linear1(x)\n      return x\n\nmodule = SimpleModule()\nlayer = SimpleLayer()\n\ninp = paddle.rand((100, 100)).numpy().astype(\"float32\")\ninp = ({'x': torch.as_tensor(inp) },\n     {'x': paddle.to_tensor(inp)})\n\nauto_diff(module, layer, inp, atol=1e-4, auto_init=True)\n```\n\n\n\n### 离线对齐\n\n```py\n############################\n#      torch_model.py      #\n############################\n\nfrom padiff import *\nimport torch\n\nclass SimpleModule(torch.nn.Module):\n  def __init__(self):\n      super(SimpleModule, self).__init__()\n      self.linear1 = torch.nn.Linear(100, 10)\n  def forward(self, x):\n      x = self.linear1(x)\n      return x\n\nmodule = SimpleModule()\nmodule = create_model(module)\n\ninp = paddle.ones((100, 100)).numpy().astype(\"float32\")\n\nfor i in range(6):\n    out = module(torch.as_tensor(inp))\n    loss = out.mean()\n    module.backward(loss)\n    module.try_dump(2, f\"./torch/step_{i}\")\n\n\n############################\n#      paddle_model.py     #\n############################\n\nfrom padiff import *\nimport paddle\n\nclass SimpleLayer(paddle.nn.Layer):\n  def __init__(self):\n      super(SimpleLayer, self).__init__()\n      self.linear1 = paddle.nn.Linear(100, 10)\n  def forward(self, x):\n      x = self.linear1(x)\n      return x\n\n# 此处需自行保证两个模型的初始权重以及输入数据是对齐的\nlayer = SimpleLayer()\nlayer = create_model(layer)\n\ninp = paddle.rand((100, 100)).numpy().astype(\"float32\")\n\nfor i in range(6):\n    out = layer(paddle.to_tensor(inp))\n    loss = out.mean()\n    layer.backward(loss)\n    layer.try_dump(2, f\"./paddle/step_{i}\")\n\n\n############################\n#         check.py        #\n############################\n\nfrom padiff import *\n\nfor i in range(6):\n    if i % 2 == 0:\n        assert check_report(f\"./torch/step_{i}\", f\"./paddle/step_{i}\") == True\n        assert check_params(f\"./torch/step_{i}\", f\"./paddle/step_{i}\") == True\n```\n\n### 框架与编译器对齐\n使用文档 [CINN](padiff/cinn_diff/README.md)\n\n```python\nimport os\nfrom padiff import cinn_diff\n\n\ndef run(run_script, base_env, cinn_env):\n    run_env = cinn_diff.Env(run_script, base_env, cinn_env)\n    run_env.run_base_model() #可以注释掉选择不运行base model\n    run_env.run_cinn_model() #也可以注释掉选择不运行cinn model\n    cinn_diff.auto_diff(run_env.base_path, run_env.cinn_path, rtol=1e-3, atol=1e-3)\n\n\nif __name__ == '__main__':\n    run_script = \"/root/workspace/PaddleNLP/model_zoo/bert/run_bert.sh\"\n    run(run_script, None, None)\n```\n\n## 已支持 `Special Init` 的组件\n\n-   MultiHeadAttention\n-   LSTM\n-   BatchNorm2D\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaddlepaddle%2Fpadiff","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpaddlepaddle%2Fpadiff","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaddlepaddle%2Fpadiff/lists"}