WenmuZhou / PaDiff

Paddle Automatically Diff Precision Toolkits.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PaDiff

Paddle Automatically Diff precision toolkits.

最近更新

  • 添加了api级别对齐检查,可以通过设置环境变量来关闭:export PADIFF_API_CHECK=OFF
  • 更新对齐策略:自顶向下对齐
  • 更新模型遍历策略:现在会尽可能滤过wrap layer,大部分情况无需手动调用LayerMap
  • 提供了新接口:assign_weight接口,将torch模型的权重拷贝到paddle模型
  • 优化权重初始化过程以及对齐报错信息: 现在会打印树形结构,并标注出错的位置
  • 更新了optimizer的使用方法:可以传入一个lambda(需要在lambda内自行clear grad)
  • 提供了自定义初始化接口:无法直接对齐的模型,现在能够通过提供一个自定义初始化函数进行初始化

简介

PaDiff是基于PaddlePaddle与PyTorch的模型精度对齐工具。传入Paddle与Torch模型,对齐训练中间结果以及训练后的模型权重,并提示精度diff第一次出现的位置。

安装

PaDiff v0.1 版本已发布,可通过如下命令安装:

pip install padiff

尝鲜版或开发者推荐clone源码并使用如下命令安装:

python setup.py install

快速开始

from padiff import auto_diff
import torch
import paddle

class SimpleLayer(paddle.nn.Layer):
  def __init__(self):
      super(SimpleLayer, self).__init__()
      self.linear1 = paddle.nn.Linear(100, 10)
  def forward(self, x):
      x = self.linear1(x)
      return x

class SimpleModule(torch.nn.Module):
  def __init__(self):
      super(SimpleModule, self).__init__()
      self.linear1 = torch.nn.Linear(100, 10)
  def forward(self, x):
      x = self.linear1(x)
      return x

layer = SimpleLayer()
module = SimpleModule()

inp = paddle.rand((100, 100)).numpy().astype("float32")
inp = ({'x': paddle.to_tensor(inp)},
     {'y': torch.as_tensor(inp) })

auto_diff(layer, module, inp, auto_weights=True, options={'atol': 1e-4, 'rtol':0, 'compare_mode': 'strict', 'single_step':False})

已支持Special Init的组件

  • MultiHeadAttention
  • LSTM
  • BatchNorm2D

About

Paddle Automatically Diff Precision Toolkits.


Languages

Language:Python 99.2%Language:Makefile 0.8%