Skip to content

Conversation

@wanghaoshuang
Copy link
Contributor

@wanghaoshuang wanghaoshuang commented Nov 15, 2022

PR types

New features

PR changes

APIs

Describe

Add configure of quantization for dynamic graph

原PR: #47530

和之前有什么不同

整个量化功能可以分为两部分:

  • 基础设施:比较固定,主要体现为『往待量化模型中插入OP』的操作
  • 算法实现:相对多变,主要体现为『转换/统计Tensor数值』的操作

本次调整,将量化功能和API放在合适的位置:

之前,

  • 实现:『基础设施』和『算法实现』均实现在Paddle核心框架中,
  • API:Paddle核心框架不对外开放任何量化API,PaddleSlim对外开放所有量化API

现在,

  • 整理优化现有量化功能实现
  • 实现:基础设施在Paddle核心框架中,算法实现在PaddleSlim中
  • API:Paddle核心框架对外开放『基础设施』API, PaddleSlim对外提供『算法实现』API

当前PR为本次调整的部分工作

当前PR包括以下架构图中的QuantConfig, QuanterFactory和部分quanter
image

关键概念

Quanter

对OP的输入或输出执行量化操作。

  • FakeQuanter:执行量化和反量化
  • QuanterWithObserver:除了Quanter本身的职责,还附带Observer的职责

image

ObserverFactory & QuanterFactory
  • 信息载体:是量化配置信息的主要载体,存储类型和参数
  • 构造实例:用于构造Observer/Quanter实例
QauntConfig

对ObserverFactory & QuanterFactory实例进行管理,存储模型量化配置的所有信息。

关键类设计

在执行量化操作之前,用户首先要配置量化相关的信息,主要是指定每层的各个输入使用什么Observer或Quanter.
配置功能主要涉及三个类:QuantConfig,SingleLayerConfig,ObserverFactory/QuanterFactory。以上三个类分别存储整个模型、单层和单个Observer的配置信息。他们之间是组合关系,QuantConfig实例中包含若干SingleLayerConfig实例,SingleLayerConfig实例包含若干ObserverFactory/QuanterFactory实例。

image

@paddle-bot
Copy link

paddle-bot bot commented Nov 15, 2022

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

yghstill
yghstill previously approved these changes Dec 12, 2022
chenwhql
chenwhql previously approved these changes Dec 13, 2022
Copy link
Contributor

@chenwhql chenwhql left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for setup.py.in

@wanghaoshuang wanghaoshuang requested a review from Ligoml December 13, 2022 06:26
@wanghaoshuang wanghaoshuang dismissed stale reviews from chenwhql and yghstill via c12d15c December 13, 2022 10:08
1. Fix typo
2. Create new directory for unitests of quantization
3. Import quanter to paddle.quantization package
4. Refine docs
…y to make the doc can be extracted from code

2. remvoe some __all__
qingqing01
qingqing01 previously approved these changes Dec 20, 2022
2. remove unused __all__
Copy link
Contributor

@jeff41404 jeff41404 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@Ligoml Ligoml left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

api文档有一些小问题,可以先合入,再补充中文文档

Copy link
Contributor

@XiaoguangHu01 XiaoguangHu01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wanghaoshuang wanghaoshuang merged commit 941444a into PaddlePaddle:develop Dec 23, 2022
@wanghaoshuang wanghaoshuang deleted the quant_config branch December 23, 2022 06:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants