提交 441de2c6 编写于 作者: D dengkaipeng

Merge branch 'develop' of https://github.com/PaddlePaddle/FluidDoc into hapi-en

......@@ -115,15 +115,6 @@ clang-formater.......................................(no files to check)Skipped
create mode 100644 233
```
<b> <font color="red">需要注意的是:您需要在commit中添加说明(commit message)以触发CI单测,写法如下:</font> </b>
```bash
# 触发develop分支的CI单测
➜ git commit -m "test=develop"
# 触发release/1.1分支的CI单侧
➜ git commit -m "test=release/1.1"
```
## 保持本地仓库最新
......
......@@ -113,14 +113,6 @@ clang-formater.......................................(no files to check)Skipped
create mode 100644 233
```
<b> <font color="red">Attention needs to be paid:you need to add commit message to trigger CI test.The command is as follows:</font> </b>
```bash
# Touch CI single test of develop branch
➜ git commit -m "test=develop"
# Touch CI single test of release/1.1 branch
➜ git commit -m "test=release/1.1"
```
## Keep the latest local repository
......
......@@ -26,7 +26,7 @@
<div align="center">
<img src="https://github.com/PaddlePaddle/FluidDoc/blob/release/1.1/doc/fluid/advanced_usage/development/contribute_to_paddle/img/cla_unsigned.png?raw=true" height="330" width="400">
<img src="https://github.com/PaddlePaddle/FluidDoc/blob/release/1.1/doc/fluid/advanced_usage/development/contribute_to_paddle/img/cla_unsigned.png?raw=true" height="40" width="500">
</div>
......
......@@ -26,7 +26,7 @@ For the first time to submit Pull Request,you need to sign CLA(Contributor Licen
<div align="center">
<img src="https://github.com/PaddlePaddle/FluidDoc/blob/release/1.1/doc/fluid/advanced_usage/development/contribute_to_paddle/img/cla_unsigned.png?raw=true" height="330" width="400">
<img src="https://github.com/PaddlePaddle/FluidDoc/blob/release/1.1/doc/fluid/advanced_usage/development/contribute_to_paddle/img/cla_unsigned.png?raw=true" height="40" width="500">
</div>
......
# VisualDL 工具简介
......@@ -8,14 +7,26 @@
VisualDL是深度学习模型可视化分析工具,以丰富的图表呈现训练参数变化趋势、模型结构、数据样本、高维数据分布等。可帮助用户更清晰直观地理解深度学习模型训练过程及模型结构,进而实现高效的模型优化。
VisualDL是飞桨可视化分析工具,以丰富的图表呈现训练参数变化趋势、模型结构、数据样本、直方图、PR曲线及高维数据分布。可帮助用户更清晰直观地理解深度学习模型训练过程及模型结构,进而实现高效的模型优化。
具体功能使用方式请参见**VisualDL使用指南**。项目正处于高速迭代中,敬请期待新组件的加入。
VisualDL提供丰富的可视化功能,支持实时训练参数分析、图结构、数据样本可视化及高维数据降维呈现等诸多功能。具体功能使用方式,请参见 **VisualDL 使用指南**。项目正处于高速迭代中,敬请期待新组件的加入
VisualDL支持浏览器种类:Chrome(81和83)、Safari 13、FireFox(77和78)、Edge(Chromium版)
VisualDL原生支持python的使用, 通过在模型的Python配置中添加几行代码,便可为训练过程提供丰富的可视化支持。
## 目录
* [核心亮点](#核心亮点)
* [安装方式](#安装方式)
* [使用方式](#使用方式)
* [可视化功能概览](#可视化功能概览)
* [开源贡献](#开源贡献)
* [更多细节](#更多细节)
* [技术交流](#技术交流)
## 核心亮点
......@@ -26,7 +37,7 @@ API设计简洁易懂,使用简单。模型结构一键实现可视化。
### 功能丰富
功能覆盖训练参数、图结构、数据样本及数据降维可视化。
功能覆盖标量、数据样本、图结构、直方图、PR曲线及数据降维可视化。
### 高兼容性
......@@ -40,13 +51,23 @@ API设计简洁易懂,使用简单。模型结构一键实现可视化。
## 安装方式
使用pip安装 VisualDL 运行范例:
### 使用pip安装
```shell
pip install --upgrade visualdl==2.0.0a2
pip install --upgrade --pre visualdl
```
### 使用代码安装
```
git clone https://github.com/PaddlePaddle/VisualDL.git
cd VisualDL
python setup.py bdist_wheel
pip install --upgrade dist/visualdl-*.whl
```
需要注意,官方自2020年1月1日起不再维护Python2,为了保障代码可用性,VisualDL现仅支持Python3
## 使用方式
......@@ -57,15 +78,13 @@ VisualDL将训练过程中的数据、参数等信息储存至日志文件中后
VisualDL的后端提供了Python SDK,可通过LogWriter定制一个日志记录器,接口如下:
```python
class LogWriter(
logdir=None,
class LogWriter(logdir=None,
comment='',
max_queue=10,
flush_secs=120,
filename_suffix='',
write_to_disk=True,
**kwargs
)
**kwargs)
```
#### 接口参数
......@@ -103,16 +122,21 @@ with LogWriter(logdir="./log/scalar_test/train") as writer:
使用命令行启动VisualDL面板,命令格式如下:
```python
visualdl --logdir <dir_1, dir_2, ... , dir_n> --host <host> --port <port>
visualdl --logdir <dir_1, dir_2, ... , dir_n> --host <host> --port <port> --cache-timeout <cache_timeout> --language <language> --public-path <public_path> --api-only
```
参数详情:
| 参数 | 意义 |
| -------- | ------------------------------------------------------------ |
| --logdir | 设定日志所在目录,可以指定多个目录,VisualDL将遍历并且迭代寻找指定目录的子目录,将所有实验结果进行可视化 |
| --host | 设定IP,默认为`127.0.0.1` |
| --port | 设定端口,默认为`8040` |
| 参数 | 意义 |
| --------------- | ------------------------------------------------------------ |
| --logdir | 设定日志所在目录,可以指定多个目录,VisualDL将遍历并且迭代寻找指定目录的子目录,将所有实验结果进行可视化 |
| --model | 设定模型文件路径(非文件夹路径),VisualDL将在此路径指定的模型文件进行可视化,目前可支持PaddlePaddle、ONNX、Keras、Core ML、Caffe等多种模型结构,详情可查看[graph支持模型种类]([https://github.com/PaddlePaddle/VisualDL/blob/develop/docs/components/README.md#Graph--%E7%BD%91%E7%BB%9C%E7%BB%93%E6%9E%84%E7%BB%84%E4%BB%B6](https://github.com/PaddlePaddle/VisualDL/blob/develop/docs/components/README.md#Graph--网络结构组件)) |
| --host | 设定IP,默认为`127.0.0.1` |
| --port | 设定端口,默认为`8040` |
| --cache-timeout | 后端缓存时间,在缓存时间内前端多次请求同一url,返回的数据从缓存中获取,默认为20秒 |
| --language | VisualDL面板语言,可指定为'EN'或'ZH',默认为浏览器使用语言 |
| --public-path | VisualDL面板URL路径,默认是'/app',即访问地址为'http://&lt;host&gt;:&lt;port&gt;/app' |
| --api-only | 是否只提供API,如果设置此参数,则VisualDL不提供页面展示,只提供API服务,此时API地址为'http://&lt;host&gt;:&lt;port&gt;/&lt;public_path&gt;/api';若没有设置public_path参数,则默认为'http://&lt;host&gt;:&lt;port&gt;/api' |
针对上一步生成的日志,启动命令为:
......@@ -130,19 +154,26 @@ visualdl.server.app.run(logdir,
port=8080,
cache_timeout=20,
language=None,
public_path=None,
api_only=False,
open_browser=False)
```
接口参数:
请注意:除`logdir`外,其他参数均为不定参数,传递时请指明参数名。
接口参数具体如下:
| 参数 | 格式 | 含义 |
| ------------- | ------------------------------------------------ | ------------------------------------------------------------ |
| logdir | string或list[string_1, string_2, ... , string_n] | 日志文件所在的路径,VisualDL将在此路径下递归搜索日志文件并进行可视化,可指定单个或多个路径 |
| model | string | 模型文件路径(非文件夹路径),VisualDL将在此路径指定的模型文件进行可视化 |
| host | string | 指定启动服务的ip,默认为`127.0.0.1` |
| port | int | 启动服务端口,默认为`8040` |
| cache_timeout | int | 后端缓存时间,在缓存时间内前端多次请求同一url,返回的数据从缓存中获取,默认为20秒 |
| language | string | VisualDL面板语言,可指定为'EN'或'CN',默认自动匹配操作系统使用语言 |
| open_browser | boolean | 是否打开浏览器,设置为True则在启动后自动打开浏览器并访问VisualDL面板 |
| language | string | VisualDL面板语言,可指定为'en'或'zh',默认为浏览器使用语言 |
| public_path | string | VisualDL面板URL路径,默认是'/app',即访问地址为'http://<host>:<port>/app' |
| api_only | boolean | 是否只提供API,如果设置此参数,则VisualDL不提供页面展示,只提供API服务,此时API地址为'http://<host>:<port>/<public_path>/api';若没有设置public_path参数,则默认为http://<host>:<port>/api' |
| open_browser | boolean | 是否打开浏览器,设置为True则在启动后自动打开浏览器并访问VisualDL面板,若设置api_only,则忽略此参数 |
针对上一步生成的日志,我们的启动脚本为:
......@@ -155,7 +186,7 @@ app.run(logdir="./log")
在使用任意一种方式启动VisualDL面板后,打开浏览器访问VisualDL面板,即可查看日志的可视化结果,如图:
<p align="center">
<img src="http://visualdl.bj.bcebos.com/images/3points_demo.png" width="60%"/>
<img src="https://user-images.githubusercontent.com/48054808/82786044-67ae9880-9e96-11ea-8a2b-3a0951a6ec19.png" width="60%"/>
</p>
......@@ -163,27 +194,31 @@ app.run(logdir="./log")
## 可视化功能概览
### Scalar
以图表形式实时展示训练过程参数,如loss、accuracy。让用户通过观察单组或多组训练参数变化,了解训练过程,加速模型调优。具有两大特点:
#### 动态展示
在启动VisualDL Board后,LogReader将不断增量的读取日志中数据并供前端调用展示,因此能够在训练中同步观测指标变化,如下图:
在启动VisualDL后,LogReader将不断增量的读取日志中数据并供前端调用展示,因此能够在训练中同步观测指标变化,如下图:
<p align="center">
<img src="http://visualdl.bj.bcebos.com/images/dynamic_display.gif" width="60%"/>
</p>
#### 多实验对比
只需在启动VisualDL Board的时将每个实验日志所在路径同时传入即可,每个实验中相同tag的指标将绘制在一张图中同步呈现,如下图:
只需在启动VisualDL时将每个实验日志所在路径同时传入即可,每个实验中相同tag的指标将绘制在一张图中同步呈现,如下图:
<p align="center">
<img src="http://visualdl.bj.bcebos.com/images/multi_experiments.gif" width="100%"/>
</p>
### Image
实时展示训练过程中的图像数据,用于观察不同训练阶段的图像变化,进而深入了解训练过程及效果。
<p align="center">
......@@ -191,6 +226,56 @@ app.run(logdir="./log")
</p>
### Audio
实时查看训练过程中的音频数据,监控语音识别与合成等任务的训练过程。
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/89017647-38605000-d34d-11ea-9d75-7d10b9854c36.gif" width="100%"/>
</p>
### Graph
一键可视化模型的网络结构。可查看模型属性、节点信息、节点输入输出等,并支持节点搜索,辅助用户快速分析模型结构与了解数据流向。
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/84483052-5acdd980-accb-11ea-8519-1608da7ee698.png" width="100%"/>
</p>
### Histogram
以直方图形式展示Tensor(weight、bias、gradient等)数据在训练过程中的变化趋势。深入了解模型各层效果,帮助开发者精准调整模型结构。
- Offset模式
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/86551031-86647c80-bf76-11ea-8ec2-8c86826c8137.png" width="100%"/>
</p>
- Overlay模式
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/86551033-882e4000-bf76-11ea-8e6a-af954c662ced.png" width="100%"/>
</p>
### PR Curve
精度-召回率曲线,帮助开发者权衡模型精度和召回率之间的平衡,设定最佳阈值。
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/86738774-ee46c000-c067-11ea-90d2-a98aac445cca.png" width="100%"/>
</p>
### High Dimensional
将高维数据进行降维展示,目前支持T-SNE、PCA两种降维方式,用于深入分析高维数据间的关系,方便用户根据数据特征进行算法优化。
......@@ -201,9 +286,15 @@ app.run(logdir="./log")
## 开源贡献
VisualDL 是由 [PaddlePaddle](http://www.paddlepaddle.org/)[ECharts](http://echarts.baidu.com/) 合作推出的开源项目。欢迎所有人使用,提意见以及贡献代码。
VisualDL 是由 [PaddlePaddle](https://www.paddlepaddle.org/)[ECharts](https://echarts.apache.org/) 合作推出的开源项目。
Graph 相关功能由 [Netron](https://github.com/lutzroeder/netron) 提供技术支持。
欢迎所有人使用,提意见以及贡献代码。
## 更多细节
想了解更多关于VisualDL可视化功能的使用详情介绍,请查看**Visual DL 使用指南**
想了解更多关于VisualDL可视化功能的使用详情介绍,请查看**VisualDL使用指南**
## 技术交流
欢迎您加入VisualDL官方QQ群:1045783368 与飞桨团队以及其他用户共同针对VisualDL进行讨论与交流。
......@@ -2,11 +2,22 @@
环境变量FLAGS
==================
调用说明
----------
PaddlePaddle中的环境变量FLAGS支持两种设置方式。
- 通过export来设置环境变量,如 :code:`export FLAGS_eager_delete_tensor_gb = 1.0` 。
- 通过API::code:`get_flag` 和 :code:`set_flags` 来打印和设置环境变量FLAGS。API使用详情请参考 :ref:`cn_api_fluid_get_flags` 与 :ref:`cn_api_fluid_set_flags` 。
环境变量FLAGS功能分类
----------------------
.. toctree::
:maxdepth: 1
cudnn_cn.rst
data_cn.rst
debug_cn.rst
......
......@@ -2,6 +2,17 @@
FLAGS
==================
Usage
------
These FLAGS in PaddlePaddle can be set in two ways.
- Set the FLAGS through export. For example: :code:`export FLAGS_eager_delete_tensor_gb = 1.0` .
- Through :code:`get_flags` and :code:`set_flags` to print and set the environment variables. For more information of using these API, please refer to :ref:`api_fluid_get_flags` and :ref:`api_fluid_get_flags` .
FLAGS Quick Search
------------------
.. toctree::
:maxdepth: 1
......
......@@ -11,13 +11,14 @@ FLAGS_allocator_strategy
取值范围
---------------
String型,['naive_best_fit', 'auto_growth']中的一个。缺省值为'naive_best_fit'。
String型,['naive_best_fit', 'auto_growth']中的一个。缺省值如果编译Paddle CMake时使用-DON_INFER=ON为'naive_best_fit'。
其他默认情况为'auto_growth'。PaddlePaddle pip安装包的默认策略也是'auto_growth'
示例
--------
FLAGS_allocator_strategy=naive_best_fit - 使用预分配best fit分配器。
FLAGS_allocator_strategy=naive_best_fit - 使用预分配best fit分配器,PaddlePaddle会先占用大多比例的可用内存/显存,在Paddle具体数据使用时分配,这种方式预占空间较大,但内存/显存碎片较少(比如能够支持模型的最大batch size会变大)
FLAGS_allocator_strategy=auto_growth - 使用auto growth分配器。
FLAGS_allocator_strategy=auto_growth - 使用auto growth分配器。PaddlePaddle会随着真实数据需要再占用内存/显存,但内存/显存可能会产生碎片(比如能够支持模型的最大batch size会变小)。
FLAGS_eager_delete_scope
......
......@@ -11,13 +11,13 @@ Use to choose allocator strategy of PaddlePaddle.
Values accepted
---------------
String, enum in ['naive_best_fit', 'auto_growth']. The default value is 'naive_best_fit'.
String, enum in ['naive_best_fit', 'auto_growth']. The default value will be 'naive_best_fit' if users compile PaddlePaddle with -DON_INFER=ON CMake flag, otherwise is 'auto_growth'. The default PaddlePaddle pip package uses 'auto_growth'.
Example
--------
FLAGS_allocator_strategy=naive_best_fit would use the pre-allocated best fit allocator.
FLAGS_allocator_strategy=naive_best_fit would use the pre-allocated best fit allocator. 'naive_best_fit' strategy would occupy almost all GPU memory by default but leads to less memory fragmentation (i.e., maximum batch size of models may be larger).
FLAGS_allocator_strategy=auto_growth would use the auto growth allocator.
FLAGS_allocator_strategy=auto_growth would use the auto growth allocator. 'auto_growth' strategy would allocate GPU memory on demand but may lead to more memory fragmentation (i.e., maximum batch size of models may be smaller).
......
......@@ -11,4 +11,4 @@
:hidden:
inference_deployment/index_cn.rst
flags/flags_cn.rst
......@@ -16,5 +16,5 @@ So far you have already been familiar with PaddlePaddle. And the next expectatio
:hidden:
inference_deployment/index_en.rst
flags/flags_en.rst
......@@ -7,15 +7,15 @@
-------------
.. csv-table::
:header: "版本说明", "预测库(1.8.1版本)", "预测库(develop版本)"
:header: "版本说明", "预测库(1.8.3版本)", "预测库(develop版本)"
:widths: 3, 2, 2
"ubuntu14.04_cpu_avx_mkl", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/1.8.1-cpu-avx-mkl/fluid_inference.tgz>`_", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/latest-cpu-avx-mkl/fluid_inference.tgz>`_"
"ubuntu14.04_cpu_avx_openblas", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/1.8.1-cpu-avx-openblas/fluid_inference.tgz>`_", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/latest-cpu-avx-openblas/fluid_inference.tgz>`_"
"ubuntu14.04_cpu_noavx_openblas", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/1.8.1-cpu-noavx-openblas/fluid_inference.tgz>`_", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/latest-cpu-noavx-openblas/fluid_inference.tgz>`_"
"ubuntu14.04_cuda9.0_cudnn7_avx_mkl", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/1.8.1-gpu-cuda9-cudnn7-avx-mkl/fluid_inference.tgz>`_", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/latest-gpu-cuda9-cudnn7-avx-mkl/fluid_inference.tgz>`_"
"ubuntu14.04_cuda10.0_cudnn7_avx_mkl", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/1.8.1-gpu-cuda10-cudnn7-avx-mkl/fluid_inference.tgz>`_", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/latest-gpu-cuda10-cudnn7-avx-mkl/fluid_inference.tgz>`_"
"ubuntu14.04_cuda10.1_cudnn7.6_avx_mkl_trt6", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/1.8.1-gpu-cuda10.1-cudnn7.6-avx-mkl-trt6%2Ffluid_inference.tgz>`_",
"ubuntu14.04_cpu_avx_mkl", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/1.8.3-cpu-avx-mkl/fluid_inference.tgz>`_", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/latest-cpu-avx-mkl/fluid_inference.tgz>`_"
"ubuntu14.04_cpu_avx_openblas", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/1.8.3-cpu-avx-openblas/fluid_inference.tgz>`_", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/latest-cpu-avx-openblas/fluid_inference.tgz>`_"
"ubuntu14.04_cpu_noavx_openblas", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/1.8.3-cpu-noavx-openblas/fluid_inference.tgz>`_", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/latest-cpu-noavx-openblas/fluid_inference.tgz>`_"
"ubuntu14.04_cuda9.0_cudnn7_avx_mkl", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/1.8.3-gpu-cuda9-cudnn7-avx-mkl/fluid_inference.tgz>`_", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/latest-gpu-cuda9-cudnn7-avx-mkl/fluid_inference.tgz>`_"
"ubuntu14.04_cuda10.0_cudnn7_avx_mkl", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/1.8.3-gpu-cuda10-cudnn7-avx-mkl/fluid_inference.tgz>`_", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/latest-gpu-cuda10-cudnn7-avx-mkl/fluid_inference.tgz>`_"
"ubuntu14.04_cuda10.1_cudnn7.6_avx_mkl_trt6", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/1.8.3-gpu-cuda10.1-cudnn7.6-avx-mkl-trt6%2Ffluid_inference.tgz>`_",
"nv-jetson-cuda10-cudnn7.5-trt5", "`fluid_inference.tar.gz <https://paddle-inference-lib.bj.bcebos.com/1.7.1-nv-jetson-cuda10-cudnn7.5-trt5/fluid_inference.tar.gz>`_",
......
......@@ -7,15 +7,15 @@ Direct Download and Installation
---------------------------------
.. csv-table:: c++ inference library list
:header: "version description", "inference library(1.8.1 version)", "inference library(develop version)"
:header: "version description", "inference library(1.8.3 version)", "inference library(develop version)"
:widths: 3, 2, 2
"ubuntu14.04_cpu_avx_mkl", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/1.8.1-cpu-avx-mkl/fluid_inference.tgz>`_", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/latest-cpu-avx-mkl/fluid_inference.tgz>`_"
"ubuntu14.04_cpu_avx_openblas", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/1.8.1-cpu-avx-openblas/fluid_inference.tgz>`_", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/latest-cpu-avx-openblas/fluid_inference.tgz>`_"
"ubuntu14.04_cpu_noavx_openblas", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/1.8.1-cpu-noavx-openblas/fluid_inference.tgz>`_", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/latest-cpu-noavx-openblas/fluid_inference.tgz>`_"
"ubuntu14.04_cuda9.0_cudnn7_avx_mkl", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/1.8.1-gpu-cuda9-cudnn7-avx-mkl/fluid_inference.tgz>`_", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/latest-gpu-cuda9-cudnn7-avx-mkl/fluid_inference.tgz>`_"
"ubuntu14.04_cuda10.0_cudnn7_avx_mkl", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/1.8.1-gpu-cuda10-cudnn7-avx-mkl/fluid_inference.tgz>`_", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/latest-gpu-cuda10-cudnn7-avx-mkl/fluid_inference.tgz>`_"
"ubuntu14.04_cuda10.1_cudnn7.6_avx_mkl_trt6", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/1.8.1-gpu-cuda10.1-cudnn7.6-avx-mkl-trt6%2Ffluid_inference.tgz>`_",
"ubuntu14.04_cpu_avx_mkl", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/1.8.3-cpu-avx-mkl/fluid_inference.tgz>`_", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/latest-cpu-avx-mkl/fluid_inference.tgz>`_"
"ubuntu14.04_cpu_avx_openblas", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/1.8.3-cpu-avx-openblas/fluid_inference.tgz>`_", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/latest-cpu-avx-openblas/fluid_inference.tgz>`_"
"ubuntu14.04_cpu_noavx_openblas", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/1.8.3-cpu-noavx-openblas/fluid_inference.tgz>`_", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/latest-cpu-noavx-openblas/fluid_inference.tgz>`_"
"ubuntu14.04_cuda9.0_cudnn7_avx_mkl", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/1.8.3-gpu-cuda9-cudnn7-avx-mkl/fluid_inference.tgz>`_", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/latest-gpu-cuda9-cudnn7-avx-mkl/fluid_inference.tgz>`_"
"ubuntu14.04_cuda10.0_cudnn7_avx_mkl", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/1.8.3-gpu-cuda10-cudnn7-avx-mkl/fluid_inference.tgz>`_", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/latest-gpu-cuda10-cudnn7-avx-mkl/fluid_inference.tgz>`_"
"ubuntu14.04_cuda10.1_cudnn7.6_avx_mkl_trt6", "`fluid_inference.tgz <https://paddle-inference-lib.bj.bcebos.com/1.8.3-gpu-cuda10.1-cudnn7.6-avx-mkl-trt6%2Ffluid_inference.tgz>`_",
"nv-jetson-cuda10-cudnn7.5-trt5", "`fluid_inference.tar.gz <https://paddle-inference-lib.bj.bcebos.com/1.7.1-nv-jetson-cuda10-cudnn7.5-trt5/fluid_inference.tar.gz>`_",
Build from Source Code
......
......@@ -5,13 +5,13 @@
下载安装包与对应的测试环境
-------------
| 版本说明 | 预测库(1.8.1版本) | 编译器 | 构建工具 | cuDNN | CUDA |
| 版本说明 | 预测库(1.8.3版本) | 编译器 | 构建工具 | cuDNN | CUDA |
|:---------|:-------------------|:-------------------|:----------------|:--------|:-------|
| cpu_avx_mkl | [fluid_inference.zip](https://paddle-wheel.bj.bcebos.com/1.8.1/win-infer/mkl/cpu/fluid_inference_install_dir.zip) | MSVC 2015 update 3| CMake v3.16.0 |
| cpu_avx_openblas | [fluid_inference.zip](https://paddle-wheel.bj.bcebos.com/1.8.1/win-infer/open/cpu/fluid_inference_install_dir.zip) | MSVC 2015 update 3| CMake v3.16.0 |
| cuda9.0_cudnn7_avx_mkl | [fluid_inference.zip](https://paddle-wheel.bj.bcebos.com/1.8.1/win-infer/mkl/post97/fluid_inference_install_dir.zip) | MSVC 2015 update 3 | CMake v3.16.0 | 7.3.1 | 9.0 |
| cuda9.0_cudnn7_avx_openblas | [fluid_inference.zip](https://paddle-wheel.bj.bcebos.com/1.8.1/win-infer/open/post97/fluid_inference_install_dir.zip) | MSVC 2015 update 3 | CMake v3.16.0 | 7.3.1 | 9.0 |
| cuda10.0_cudnn7_avx_mkl | [fluid_inference.zip](https://paddle-wheel.bj.bcebos.com/1.8.1/win-infer/mkl/post107/fluid_inference_install_dir.zip) | MSVC 2015 update 3 | CMake v3.16.0 | 7.3.1 | 10.0 |
| cpu_avx_mkl | [fluid_inference.zip](https://paddle-wheel.bj.bcebos.com/1.8.3/win-infer/mkl/cpu/fluid_inference_install_dir.zip) | MSVC 2015 update 3| CMake v3.16.0 |
| cpu_avx_openblas | [fluid_inference.zip](https://paddle-wheel.bj.bcebos.com/1.8.3/win-infer/open/cpu/fluid_inference_install_dir.zip) | MSVC 2015 update 3| CMake v3.16.0 |
| cuda9.0_cudnn7_avx_mkl | [fluid_inference.zip](https://paddle-wheel.bj.bcebos.com/1.8.3/win-infer/mkl/post97/fluid_inference_install_dir.zip) | MSVC 2015 update 3 | CMake v3.16.0 | 7.3.1 | 9.0 |
| cuda9.0_cudnn7_avx_openblas | [fluid_inference.zip](https://paddle-wheel.bj.bcebos.com/1.8.3/win-infer/open/post97/fluid_inference_install_dir.zip) | MSVC 2015 update 3 | CMake v3.16.0 | 7.3.1 | 9.0 |
| cuda10.0_cudnn7_avx_mkl | [fluid_inference.zip](https://paddle-wheel.bj.bcebos.com/1.8.3/win-infer/mkl/post107/fluid_inference_install_dir.zip) | MSVC 2015 update 3 | CMake v3.16.0 | 7.4.1 | 10.0 |
### 硬件环境
......
......@@ -5,13 +5,13 @@ Install and Compile C++ Inference Library on Windows
Direct Download and Install
-------------
| Version | Inference Libraries(v1.8.1) | Compiler | Build tools | cuDNN | CUDA |
| Version | Inference Libraries(v1.8.3) | Compiler | Build tools | cuDNN | CUDA |
|:---------|:-------------------|:-------------------|:----------------|:--------|:-------|
| cpu_avx_mkl | [fluid_inference.zip](https://paddle-wheel.bj.bcebos.com/1.8.1/win-infer/mkl/cpu/fluid_inference_install_dir.zip) | MSVC 2015 update 3| CMake v3.16.0 |
| cpu_avx_openblas | [fluid_inference.zip](https://paddle-wheel.bj.bcebos.com/1.8.1/win-infer/open/cpu/fluid_inference_install_dir.zip) | MSVC 2015 update 3| CMake v3.16.0 |
| cuda9.0_cudnn7_avx_mkl | [fluid_inference.zip](https://paddle-wheel.bj.bcebos.com/1.8.1/win-infer/mkl/post97/fluid_inference_install_dir.zip) | MSVC 2015 update 3 | CMake v3.16.0 | 7.3.1 | 9.0 |
| cuda9.0_cudnn7_avx_openblas | [fluid_inference.zip](https://paddle-wheel.bj.bcebos.com/1.8.1/win-infer/open/post97/fluid_inference_install_dir.zip) | MSVC 2015 update 3 | CMake v3.16.0 | 7.3.1 | 9.0 |
| cuda10.0_cudnn7_avx_mkl | [fluid_inference.zip](https://paddle-wheel.bj.bcebos.com/1.8.1/win-infer/mkl/post107/fluid_inference_install_dir.zip) | MSVC 2015 update 3 | CMake v3.16.0 | 7.3.1 | 10.0 |
| cpu_avx_mkl | [fluid_inference.zip](https://paddle-wheel.bj.bcebos.com/1.8.3/win-infer/mkl/cpu/fluid_inference_install_dir.zip) | MSVC 2015 update 3| CMake v3.16.0 |
| cpu_avx_openblas | [fluid_inference.zip](https://paddle-wheel.bj.bcebos.com/1.8.3/win-infer/open/cpu/fluid_inference_install_dir.zip) | MSVC 2015 update 3| CMake v3.16.0 |
| cuda9.0_cudnn7_avx_mkl | [fluid_inference.zip](https://paddle-wheel.bj.bcebos.com/1.8.3/win-infer/mkl/post97/fluid_inference_install_dir.zip) | MSVC 2015 update 3 | CMake v3.16.0 | 7.3.1 | 9.0 |
| cuda9.0_cudnn7_avx_openblas | [fluid_inference.zip](https://paddle-wheel.bj.bcebos.com/1.8.3/win-infer/open/post97/fluid_inference_install_dir.zip) | MSVC 2015 update 3 | CMake v3.16.0 | 7.3.1 | 9.0 |
| cuda10.0_cudnn7_avx_mkl | [fluid_inference.zip](https://paddle-wheel.bj.bcebos.com/1.8.3/win-infer/mkl/post107/fluid_inference_install_dir.zip) | MSVC 2015 update 3 | CMake v3.16.0 | 7.4.1 | 10.0 |
### Hardware Environment
......
# 混合精度训练最佳实践
Automatic Mixed Precision (AMP) 是一种自动混合使用半精度(FP16)和单精度(FP32)来加速模型训练的技术。AMP技术可方便用户快速将使用 FP32 训练的模型修改为使用混合精度训练,并通过黑白名单和动态`loss scaling`来保证训练时的数值稳定性进而避免梯度Infinite或者NaN(Not a Number)。借力于新一代NVIDIA GPU中Tensor Cores的计算性能,PaddlePaddle AMP技术在ResNet50、Transformer等模型上训练速度相对于FP32训练加速比可达1.5~2.9。
### 半精度浮点类型FP16
如图 1 所示,半精度(Float Precision16,FP16)是一种相对较新的浮点类型,在计算机中使用2字节(16位)存储。在IEEE 754-2008标准中,它亦被称作binary16。与计算中常用的单精度(FP32)和双精度(FP64)类型相比,FP16更适于在精度要求不高的场景中使用。
<figure align="center">
<img src="https://paddleweb-static.bj.bcebos.com/images/fp16.png" width="600" alt='missing'/>
<figcaption><center>图 1. 半精度和单精度数据示意图</center></figcaption>
</figure>
### 英伟达GPU的FP16算力
在使用相同的超参数下,混合精度训练使用半精度浮点(FP16)和单精度(FP32)浮点即可达到与使用纯单精度训练相同的准确率,并可加速模型的训练速度。这主要得益于英伟达推出的Volta及Turing架构GPU在使用FP16计算时具有如下特点:
* FP16可降低一半的内存带宽和存储需求,这使得在相同的硬件条件下研究人员可使用更大更复杂的模型以及更大的batch size大小。
* FP16可以充分利用英伟达Volta及Turing架构GPU提供的Tensor Cores技术。在相同的GPU硬件上,Tensor Cores的FP16计算吞吐量是FP32的8倍。
### PaddlePaddle AMP功能——牛刀小试
如前文所述,使用FP16数据类型可能会造成计算精度上的损失,但对深度学习领域而言,并不是所有计算都要求很高的精度,一些局部的精度损失对最终训练效果影响很微弱,却能使吞吐和训练速度带来大幅提升。因此,混合精度计算的需求应运而生。具体而言,训练过程中将一些对精度损失不敏感且能利用Tensor Cores进行加速的运算使用半精度处理,而对精度损失敏感部分依然保持FP32计算精度,用以最大限度提升访存和计算效率。
为了避免对每个具体模型人工地去设计和尝试精度混合的方法,PaddlePaadle框架提供自动混合精度训练(AMP)功能,解放"炼丹师"的双手。在PaddlePaddle中使用AMP训练是一件十分容易的事情,用户只需要增加一行代码即可将原有的FP32训练转变为AMP训练。下面以`MNIST`为例介绍PaddlePaddle AMP功能的使用示例。
**MNIST网络定义**
```python
import paddle.fluid as fluid
def MNIST(data, class_dim):
conv1 = fluid.layers.conv2d(data, 16, 5, 1, act=None, data_format='NHWC')
bn1 = fluid.layers.batch_norm(conv1, act='relu', data_layout='NHWC')
pool1 = fluid.layers.pool2d(bn1, 2, 'max', 2, data_format='NHWC')
conv2 = fluid.layers.conv2d(pool1, 64, 5, 1, act=None, data_format='NHWC')
bn2 = fluid.layers.batch_norm(conv2, act='relu', data_layout='NHWC')
pool2 = fluid.layers.pool2d(bn2, 2, 'max', 2, data_format='NHWC')
fc1 = fluid.layers.fc(pool2, size=64, act='relu')
fc2 = fluid.layers.fc(fc1, size=class_dim, act='softmax')
return fc2
```
针对CV(Computer Vision)类模型组网,为获得更高的训练性能需要注意如下三点:
* `conv2d``batch_norm`以及`pool2d`等需要将数据布局设置为`NHWC`,这样有助于使用TensorCore技术加速计算过程<sup><a href="#fn1" id="ref1">1</a></sup>
* Tensor Cores要求在使用FP16加速卷积运算时conv2d的输入/输出通道数为8的倍数<sup><a href="#fn2" id="ref2">2</a></sup>,因此设计网络时推荐将conv2d层的输入/输出通道数设置为8的倍数。
* Tensor Cores要求在使用FP16加速矩阵乘运算时矩阵行数和列数均为8的倍数<sup><a href="#fn3" id="ref3">3</a></sup>,因此设计网络时推荐将fc层的size参数设置为8的倍数。
**FP32 训练**
为了训练 MNIST 网络,还需要定义损失函数来更新权重参数,此处使用的优化器是SGDOptimizer。为了简化说明,这里省略了迭代训练的相关代码,仅体现损失函数及优化器定义相关的内容。
```python
import paddle
import numpy as np
data = fluid.layers.data(
name='image', shape=[None, 28, 28, 1], dtype='float32')
label = fluid.layers.data(name='label', shape=[None, 1], dtype='int64')
out = MNIST(data, class_dim=10)
loss = fluid.layers.cross_entropy(input=out, label=label)
avg_loss = fluid.layers.mean(loss)
sgd = fluid.optimizer.SGDOptimizer(learning_rate=1e-3)
sgd.minimize(avg_loss)
```
**AMP训练**
与FP32训练相比,用户仅需使用PaddlePaddle提供的`fluid.contrib.mixed_precision.decorate` 函数将原来的优化器SGDOptimizer进行封装,然后使用封装后的优化器(mp_sgd)更新参数梯度即可完成向AMP训练的转换,代码如下所示:
```python
sgd = SGDOptimizer(learning_rate=1e-3)
# 此处只需要使用fluid.contrib.mixed_precision.decorate将sgd封装成AMP训练所需的
# 优化器mp_sgd,并使用mp_sgd.minimize(avg_loss)代替原来的sgd.minimize(avg_loss)语句即可。
mp_sgd = fluid.contrib.mixed_precision.decorator.decorate(sgd)
mp_sgd.minimize(avg_loss)
```
运行上述混合精度训练python脚本时为得到更好的执行性能可配置如下环境参数,并保证cudnn版本在7.4.1及以上。
```shell
export FLAGS_conv_workspace_size_limit=1024 # MB,根据所使用的GPU显存容量及模型特点设置数值,值越大越有可能选择到更快的卷积算法
export FLAGS_cudnn_exhaustive_search=1 # 使用穷举搜索方法来选择快速卷积算法
export FLAGS_cudnn_batchnorm_spatial_persistent=1 # 用于触发batch_norm和relu的融合
```
上述即为最简单的PaddlePaddle AMP功能使用方法。ResNet50模型的AMP训练示例可[点击此处](https://github.com/PaddlePaddle/models/blob/develop/PaddleCV/image_classification/README.md#%E6%B7%B7%E5%90%88%E7%B2%BE%E5%BA%A6%E8%AE%AD%E7%BB%83)查看,其他模型使用PaddlePaddle AMP的方法也与此类似。若AMP训练过程中出现连续的loss nan等不收敛现象,可尝试使用[check nan inf工具](https://www.paddlepaddle.org.cn/documentation/docs/zh/advanced_guide/flags/check_nan_inf_cn.html#span-id-speed-span)进行调试。
### PaddlePaddle AMP功能——进阶使用
上一小节所述均为默认AMP训练行为,用户当然也可以改变一些默认的参数设置来满足特定的模型训练场景需求。接下来的章节将介绍PaddlePaddle AMP功能使用中用户可配置的参数行为,即进阶使用技巧。
#### 自定义黑白名单
PaddlePaddle AMP功能实现中根据FP16数据类型计算稳定性和加速效果在框架内部定义了算子(Op)的黑白名单。具体来说,将对FP16计算友好且能利用Tensor Cores的Op归类于白名单,将使用FP16计算会导致数值不稳定的Op归类于黑名单,将对FP16计算没有多少影响的Op归类于灰名单。然而,框架开发人员不可能考虑到所有的网络模型情况,尤其是那些特殊场景中使用到的模型。用户可以在使用`fluid.contrib.mixed_precision.decorate` 函数时通过指定自定义的黑白名单列表来改变默认的FP16计算行为。
```python
sgd = SGDOptimizer(learning_rate=1e-3)
# list1是白名单op列表,list2是黑名单op列表,list3是黑名单var_name列表(凡是以这些黑名单var_name为输入或输出的op均会被视为黑名单op)
amp_list = AutoMixedPrecisionLists(custom_white_list=list1, custom_black_list=list2, custom_black_varnames=list3)
mp_sgd = fluid.contrib.mixed_precision.decorator.decorate(sgd, amp_list)
mp_sgd.minimize(avg_loss)
```
#### 自动loss scaling
为了避免梯度Infinite或者NAN,PaddlePaddle AMP功能支持根据训练过程中梯度的数值自动调整loss scale值。用户在使用`fluid.contrib.mixed_precision.decorate` 函数时也可以改变与loss scaling相关的参数设置,示例如下:
```python
sgd = SGDOptimizer(learning_rate=1e-3)
mp_sgd = fluid.contrib.mixed_precision.decorator.decorate(sgd,
amp_lists=None,
init_loss_scaling=2**8,
incr_every_n_steps=500,
decr_every_n_nan_or_inf=4,
incr_ratio=2.0,
decr_ratio=0.5,
use_dynamic_loss_scaling=True)
mp_sgd.minimize(avg_loss)
```
`init_loss_scaling ``incr_every_n_steps` 以及`decr_every_n_nan_or_inf`等参数控制着自动loss scaling的行为。它们仅当 `use_dynamic_loss_scaling`设置为True时有效。下面详述这些参数的意义:
* init_loss_scaling(float):初始loss scaling值。
* incr_every_n_steps(int):每经过incr_every_n_steps个连续的正常梯度值才会增大loss scaling值。
* decr_every_n_nan_or_inf(int):每经过decr_every_n_nan_or_inf个连续的无效梯度值(nan或者inf)才会减小loss scaling值。
* incr_ratio(float):每次增大loss scaling值的扩增倍数,其为大于1的浮点数。
* decr_ratio(float):每次减小loss scaling值的比例系数,其为小于1的浮点数。
### 多卡GPU训练的优化
PaddlePaddle AMP功能对多卡GPU训练进行了深度优化。如图 2 所示,优化之前的参数梯度更新特点:梯度计算时虽然使用的是FP16数据类型,但是不同GPU卡之间的梯度传输数据类型仍为FP32。
<figure align="center">
<img src="https://paddleweb-static.bj.bcebos.com/images/transfer_fp32_grad.png" width="500" alt='missing'/>
<figcaption><center>图 2. 不同GPU卡之间传输梯度使用FP32数据类型(优化前)</center></figcaption>
</figure>
为了降低GPU多卡之间的梯度传输带宽,我们将梯度传输提前至`Cast`操作之前,而每个GPU卡在得到对应的FP16梯度后再执行`Cast`操作将其转变为FP32类型,具体操作详见图2。这一优化在训练大模型时对减少带宽占用尤其有效,如多卡训练BERT-Large模型。
<figure align="center">
<img src="https://paddleweb-static.bj.bcebos.com/images/transfer_fp16_grad.png" width="500" alt='missing'/>
<figcaption><center>图 3. 不同GPU卡之间传输梯度使用FP16数据类型(优化后)</center></figcaption>
</figure>
### 训练性能对比(AMP VS FP32)
PaddlePaddle AMP技术在ResNet50、Transformer等模型上训练速度相对于FP32训练上均有可观的加速比,下面是ResNet50和ERNIE Large模型的AMP训练相对于FP32训练的加速效果。
<table align="center">
<caption align="bottom"><center>图 4. Paddle AMP训练加速效果(横坐标为卡数,如8*8代表8机8卡)</center></caption>
<tr>
<td> <img src="https://paddleweb-static.bj.bcebos.com/images/resnet50.png" alt='missing'/> </td>
<td> <img src="https://paddleweb-static.bj.bcebos.com/images/ernie.png" alt='missing'/> </td>
</tr>
</table>
从图4所示的图表可以看出,ResNet50的AMP训练相对与FP32训练加速比可达$2.8 \times$以上,而ERNIE Large的AMP训练相对与FP32训练加速比亦可达 $1.7 \times -- 2.1 \times$ 。
### 参考文献
* <p> <a href="https://arxiv.org/abs/1710.03740"> Mixed Precision Training </a> </p>
* <p> <a href="https://on-demand-gtc.gputechconf.com/gtcnew/sessionview.php?sessionName=cn9312-%e4%bd%bf%e7%94%a8%e8%87%aa%e5%8a%a8%e6%b7%b7%e5%90%88%e7%b2%be%e5%ba%a6%e5%8a%a0%e9%80%9f+paddlepaddle+%e8%ae%ad%e7%bb%83"> 使用自动混合精度加速 PaddlePaddle 训练 </a> </p>
* <p id="fn1"> <a href="https://docs.nvidia.com/deeplearning/performance/dl-performance-convolutional/index.html#tensor-layout"> Tensor Layouts In Memory: NCHW vs NHWC </a> <sup> <a href="#ref1"></a> </sub> </p>
* <p id="fn2"> <a href="https://docs.nvidia.com/deeplearning/performance/dl-performance-convolutional/index.html#channels"> Channels In And Out Requirements </a> <sup> <a href="#ref2"></a> </sup> </p>
* <p id="fn3"> <a href="https://docs.nvidia.com/deeplearning/performance/dl-performance-matrix-multiplication/index.html#requirements-tc"> Matrix-Matrix Multiplication Requirements </a> <sup> <a href="#ref3"></a> </sup> </p>
......@@ -8,6 +8,7 @@
singlenode_training_improving/training_best_practice.rst
singlenode_training_improving/memory_optimize.rst
device_switching/device_switching.md
amp/amp.md
multinode_training_improving/cpu_train_best_practice.rst
multinode_training_improving/dist_training_gpu.rst
multinode_training_improving/gpu_training_with_recompute.rst
......
......@@ -31,6 +31,7 @@ fluid.dygraph
dygraph/guard.rst
dygraph/InstanceNorm.rst
dygraph/InverseTimeDecay.rst
dygraph/jit.rst
dygraph/Layer.rst
dygraph/LayerList.rst
dygraph/LayerNorm.rst
......@@ -48,10 +49,12 @@ fluid.dygraph
dygraph/PRelu.rst
dygraph/prepare_context.rst
dygraph/ProgramTranslator.rst
dygraph/ReduceLROnPlateau.rst
dygraph/save_dygraph.rst
dygraph/Sequential.rst
dygraph/SpectralNorm.rst
dygraph/to_variable.rst
dygraph/TracedLayer.rst
dygraph/Tracer.rst
dygraph/TranslatedLayer.rst
dygraph/TreeConv.rst
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_dygraph_ReduceLROnPlateau:
ReduceLROnPlateau
-----------------
.. autoclass:: paddle.fluid.dygraph.ReduceLROnPlateau
:members:
:noindex:
.. _api_fluid_dygraph_TranslatedLayer:
TranslatedLayer
-----------------------
.. autoclass:: paddle.fluid.dygraph.TranslatedLayer
:members:
:noindex:
===
jit
===
.. toctree::
:maxdepth: 1
jit/save.rst
jit/load.rst
jit/SaveLoadConfig.rst
.. _api_fluid_dygraph_jit_SaveLoadConfig:
SaveLoadConfig
-------------------------------
.. autoclass:: paddle.fluid.dygraph.jit.SaveLoadConfig
:members:
:noindex:
\ No newline at end of file
.. _api_fluid_dygraph_jit_load:
load
------------
.. autofunction:: paddle.fluid.dygraph.jit.load
:noindex:
.. _api_fluid_dygraph_jit_save:
save
------------
.. autofunction:: paddle.fluid.dygraph.jit.save
:noindex:
......@@ -10,7 +10,7 @@ python gen_doc.py --module_name "" --module_prefix "" --output fluid --output_na
python gen_module_index.py fluid fluid
# tensor
for module in math random stat
for module in math random stat linalg search
do
python gen_doc.py --module_name ${module} --module_prefix ${module} --output ${module} --output_name tensor --to_multiple_files True --output_dir tensor
python gen_module_index.py tensor.${module} ${module}
......
......@@ -4,7 +4,7 @@ import glob
import os
if __name__ == '__main__':
with open('index_en.rst', 'w') as file_object:
with open('index_en.rst', 'w') as file_object:
file_object = open('index_en.rst', 'w')
file_object.write('''=============
API Reference
......@@ -25,16 +25,16 @@ API Reference
else:
pattern = target_dir + '/*.rst'
file_names.extend(glob.glob(pattern))
for file_name in sorted(file_names):
with open(file_name, 'r')as f:
with open(file_name, 'r') as f:
for i in range(2):
line = f.readline().strip()
if line.find('paddle.') != -1:
file_object.write(' '+file_name + "\n")
file_object.write(' ' + file_name + "\n")
file_names.remove(file_name)
file_object.write(' '+'fluid.rst' + "\n")
file_object.write(' ' + 'fluid.rst' + "\n")
for file_name in sorted(file_names):
if file_name not in ['index_en.rst', 'fluid.rst']:
file_object.write(' '+file_name + "\n")
if file_name not in ['index_en.rst']:
file_object.write(' ' + file_name + "\n")
......@@ -13,6 +13,7 @@ paddle.imperative
imperative/grad.rst
imperative/guard.rst
imperative/InverseTimeDecay.rst
imperative/jit.rst
imperative/load.rst
imperative/NaturalExpDecay.rst
imperative/no_grad.rst
......@@ -25,3 +26,4 @@ paddle.imperative
imperative/save.rst
imperative/to_variable.rst
imperative/TracedLayer.rst
imperative/TranslatedLayer.rst
.. _api_imperative_TranslatedLayer:
TranslatedLayer
-------------------------------
:doc_source: paddle.fluid.dygraph.io.TranslatedLayer
===
jit
===
.. toctree::
:maxdepth: 1
jit/save.rst
jit/load.rst
jit/SaveLoadConfig.rst
.. _api_imperative_jit_SaveLoadConfig:
SaveLoadConfig
-------------------------------
:doc_source: paddle.fluid.dygraph.jit.SaveLoadConfig
.. _api_imperative_jit_load:
load
-------------------------------
:doc_source: paddle.fluid.dygraph.jit.load
.. _api_imperative_jit_save:
save
-------------------------------
:doc_source: paddle.fluid.dygraph.jit.save
......@@ -6,15 +6,30 @@ API Reference
:maxdepth: 1
../api_guides/index_en.rst
paddle.rst
dataset.rst
tensor.rst
nn.rst
imperative.rst
declarative.rst
optimizer.rst
metric.rst
framework.rst
imperative.rst
io.rst
utils.rst
incubate.rst
metric.rst
nn.rst
optimizer.rst
tensor.rst
fluid.rst
backward.rst
clip.rst
data/data_reader.rst
data/dataset.rst
dygraph.rst
executor.rst
fluid.rst
initializer.rst
layers.rst
metrics.rst
nets.rst
paddle.rst
profiler.rst
regularizer.rst
transpiler.rst
unique_name.rst
review_tmp.rst
......@@ -182,6 +182,7 @@ fluid.layers
layers/mul.rst
layers/multi_box_head.rst
layers/multiclass_nms.rst
layers/matrix_nms.rst
layers/multiplex.rst
layers/MultivariateNormalDiag.rst
layers/natural_exp_decay.rst
......
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_matrix_nms:
matrix_nms
--------------
.. autofunction:: paddle.fluid.layers.matrix_nms
:noindex:
......@@ -49,6 +49,7 @@ paddle.nn
nn/exponential_decay.rst
nn/filter_by_instag.rst
nn/fsp_matrix.rst
nn/functional.rst
nn/gather_tree.rst
nn/gelu.rst
nn/generate_mask_labels.rst
......@@ -67,6 +68,7 @@ paddle.nn
nn/huber_loss.rst
nn/image_resize.rst
nn/image_resize_short.rst
nn/initializer.rst
nn/inverse_time_decay.rst
nn/iou_similarity.rst
nn/kldiv_loss.rst
......@@ -82,7 +84,7 @@ paddle.nn
nn/logsigmoid.rst
nn/loss.rst
nn/lrn.rst
nn/margin_rank_loss.rst
nn/matrix_nms.rst
nn/maxout.rst
nn/mse_loss.rst
nn/multiclass_nms.rst
......@@ -91,14 +93,13 @@ paddle.nn
nn/npair_loss.rst
nn/one_hot.rst
nn/pad.rst
nn/pad_constant_like.rst
nn/pad2d.rst
nn/pad_constant_like.rst
nn/ParameterList.rst
nn/piecewise_decay.rst
nn/pixel_shuffle.rst
nn/polygon_box_transform.rst
nn/polynomial_decay.rst
nn/pool2d.rst
nn/Pool2D.rst
nn/pool3d.rst
nn/prior_box.rst
......@@ -148,3 +149,5 @@ paddle.nn
nn/while_loop.rst
nn/yolo_box.rst
nn/yolov3_loss.rst
nn/functional/loss/margin_ranking_loss.rst
nn/layer/loss/MarginRankingLoss.rst
==========
functional
==========
.. toctree::
:maxdepth: 1
functional/l1_loss.rst
functional/nll_loss.rst
.. _api_nn_functional_l1_loss:
l1_loss
------
.. autoclass:: paddle.nn.functional.l1_loss
:members:
:inherited-members:
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_nn_functional_loss_margin_ranking_loss:
margin_ranking_loss
-------------------
.. autofunction:: paddle.nn.functional.loss.margin_ranking_loss
:noindex:
.. _api_nn_functional_nll_loss:
nll_loss
-------------------------------
.. autoclass:: paddle.nn.functional.nll_loss
:members:
:inherited-members:
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_optimizer_PipelineOptimizer:
.. _api_nn_layer_loss_MarginRankingLoss:
PipelineOptimizer
MarginRankingLoss
-----------------
.. autoclass:: paddle.fluid.optimizer.PipelineOptimizer
.. autoclass:: paddle.nn.layer.loss.MarginRankingLoss
:members:
:inherited-members:
:exclude-members: apply_gradients, apply_optimize, backward, load
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_transpiler_RoundRobin:
.. _api_nn_loss_NLLLoss:
RoundRobin
----------
NLLLoss
-------------------------------
.. autoclass:: paddle.fluid.transpiler.RoundRobin
.. autoclass:: paddle.nn.loss.NLLLoss
:members:
:inherited-members:
:noindex:
......
.. _api_nn_margin_rank_loss:
margin_rank_loss
-------------------------------
:doc_source: paddle.fluid.layers.margin_rank_loss
.. _api_nn_matrix_nms:
matrix_nms
-------------------------------
:doc_source: paddle.fluid.layers.matrix_nms
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_nn_softmax:
softmax
-------------------------------
:doc_source: paddle.fluid.layers.softmax
-------
.. autofunction:: paddle.nn.functional.softmax
:noindex:
......@@ -28,7 +28,6 @@ paddle.optimizer
optimizer/ModelAverage.rst
optimizer/Momentum.rst
optimizer/MomentumOptimizer.rst
optimizer/PipelineOptimizer.rst
optimizer/RecomputeOptimizer.rst
optimizer/RMSPropOptimizer.rst
optimizer/SGD.rst
......
......@@ -45,10 +45,7 @@ paddle
paddle/dot.rst
paddle/elementwise_add.rst
paddle/elementwise_div.rst
paddle/elementwise_equal.rst
paddle/elementwise_floordiv.rst
paddle/elementwise_max.rst
paddle/elementwise_min.rst
paddle/elementwise_mod.rst
paddle/elementwise_mul.rst
paddle/elementwise_pow.rst
......@@ -56,6 +53,7 @@ paddle
paddle/elementwise_sum.rst
paddle/enable_imperative.rst
paddle/equal.rst
paddle/equal_all.rst
paddle/erf.rst
paddle/ExecutionStrategy.rst
paddle/Executor.rst
......@@ -99,9 +97,11 @@ paddle
paddle/manual_seed.rst
paddle/matmul.rst
paddle/max.rst
paddle/maximum.rst
paddle/mean.rst
paddle/meshgrid.rst
paddle/min.rst
paddle/minimum.rst
paddle/mm.rst
paddle/mul.rst
paddle/multiplex.rst
......
......@@ -2,6 +2,6 @@
ExecutionStrategy
-------------------------------
:doc_source: paddle.framework.ExecutionStrategy
:doc_source: paddle.fluid.ExecutionStrategy
......@@ -2,6 +2,6 @@
argsort
-------------------------------
:doc_source: paddle.fluid.layers.argsort
:doc_source: paddle.tensor.argsort
......@@ -2,6 +2,6 @@
cumsum
-------------------------------
:doc_source: paddle.fluid.layers.cumsum
:doc_source: paddle.tensor.cumsum
.. _api_paddle_elementwise_equal:
elementwise_equal
-------------------------------
:doc_source: paddle.fluid.layers.equal
.. _api_paddle_elementwise_max:
elementwise_max
-------------------------------
:doc_source: paddle.fluid.layers.elementwise_max
.. _api_paddle_elementwise_min:
elementwise_min
-------------------------------
:doc_source: paddle.fluid.layers.elementwise_min
.. _api_paddle_equal_all
equal_all
-------------------------------
:doc_source: paddle.tensor.equal_all
......@@ -2,6 +2,6 @@
greater_equal
-------------------------------
:doc_source: paddle.fluid.layers.greater_equal
:doc_source: paddle.tensor.greater_equal
......@@ -2,6 +2,6 @@
greater_than
-------------------------------
:doc_source: paddle.fluid.layers.greater_than
:doc_source: paddle.tensor.greater_than
......@@ -2,6 +2,6 @@
less_equal
-------------------------------
:doc_source: paddle.fluid.layers.less_equal
:doc_source: paddle.tensor.less_equal
......@@ -2,6 +2,6 @@
less_than
-------------------------------
:doc_source: paddle.fluid.layers.less_than
:doc_source: paddle.tensor.less_than
......@@ -2,6 +2,6 @@
max
-------------------------------
:doc_source: paddle.fluid.layers.reduce_max
:doc_source: paddle.tensor.max
.. _api_paddle_maximum:
maximum
-------------------------------
:doc_source: paddle.tensor.maximum
......@@ -2,6 +2,6 @@
min
-------------------------------
:doc_source: paddle.fluid.layers.reduce_min
:doc_source: paddle.tensor.min
.. _api_paddle_minimum:
minimum
-------------------------------
:doc_source: paddle.tensor.minimum
......@@ -2,6 +2,6 @@
not_equal
-------------------------------
:doc_source: paddle.fluid.layers.not_equal
:doc_source: paddle.tensor.not_equal
......@@ -2,6 +2,6 @@
sort
-------------------------------
:doc_source: paddle.fluid.layers.argsort
:doc_source: paddle.tensor.sort
=================
paddle.review_tmp
=================
.. toctree::
:maxdepth: 1
review_tmp/MarginRankingLoss.rst
review_tmp/margin_ranking_loss.rst
.. _api_nn_loss_MarginRankingLoss_tmp:
MarginRankingLoss
-----------------
.. autoclass:: paddle.nn.loss.MarginRankingLoss
:members:
:inherited-members:
:noindex:
.. _api_nn_functional_margin_ranking_loss_tmp:
margin_ranking_loss
-------------------
.. autofunction:: paddle.nn.functional.margin_ranking_loss
:noindex:
......@@ -20,19 +20,18 @@ paddle.tensor
tensor/cos.rst
tensor/create_tensor.rst
tensor/crop_tensor.rst
tensor/cross.rst
tensor/cumsum.rst
tensor/diag.rst
tensor/div.rst
tensor/elementwise_add.rst
tensor/elementwise_div.rst
tensor/elementwise_equal.rst
tensor/elementwise_floordiv.rst
tensor/elementwise_max.rst
tensor/elementwise_min.rst
tensor/elementwise_mod.rst
tensor/elementwise_mul.rst
tensor/elementwise_pow.rst
tensor/elementwise_sub.rst
tensor/equal_all.rst
tensor/erf.rst
tensor/exp.rst
tensor/expand.rst
......@@ -63,8 +62,10 @@ paddle.tensor
tensor/logical_xor.rst
tensor/math.rst
tensor/max.rst
tensor/maximum.rst
tensor/mean.rst
tensor/min.rst
tensor/minimum.rst
tensor/mm.rst
tensor/mul.rst
tensor/multiplex.rst
......@@ -92,6 +93,7 @@ paddle.tensor
tensor/scatter.rst
tensor/scatter_nd.rst
tensor/scatter_nd_add.rst
tensor/search.rst
tensor/shape.rst
tensor/shard_index.rst
tensor/shuffle.rst
......
......@@ -2,6 +2,6 @@
argsort
-------------------------------
:doc_source: paddle.fluid.layers.argsort
:doc_source: paddle.tensor.argsort
.. _api_tensor_cn_cos:
cross
-------------------------------
:doc_source: paddle.tensor.cross
......@@ -2,6 +2,6 @@
cumsum
-------------------------------
:doc_source: paddle.fluid.layers.cumsum
:doc_source: paddle.tensor.cumsum
.. _api_tensor_cn_elementwise_equal:
elementwise_equal
-------------------------------
:doc_source: paddle.fluid.layers.equal
.. _api_tensor_cn_elementwise_max:
elementwise_max
-------------------------------
:doc_source: paddle.fluid.layers.elementwise_max
.. _api_tensor_cn_elementwise_min:
elementwise_min
-------------------------------
:doc_source: paddle.fluid.layers.elementwise_min
.. _api_tensor_cn_equal_all:
equal_all
-------------------------------
:doc_source: paddle.tensor.equal_all
......@@ -2,6 +2,6 @@
greater_equal
-------------------------------
:doc_source: paddle.fluid.layers.greater_equal
:doc_source: paddle.tensor.greater_equal
......@@ -2,6 +2,6 @@
greater_than
-------------------------------
:doc_source: paddle.fluid.layers.greater_than
:doc_source: paddle.tensor.greater_than
......@@ -2,6 +2,6 @@
less_equal
-------------------------------
:doc_source: paddle.fluid.layers.less_equal
:doc_source: paddle.tensor.less_equal
......@@ -2,6 +2,6 @@
less_than
-------------------------------
:doc_source: paddle.fluid.layers.less_than
:doc_source: paddle.tensor.less_than
......@@ -2,6 +2,6 @@
max
-------------------------------
:doc_source: paddle.fluid.layers.reduce_max
:doc_source: paddle.tensor.max
.. _api_tensor_cn_maximum:
maximum
-------------------------------
:doc_source: paddle.tensor.maximum
.. _api_tensor_cn_mean:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_tensor_mean:
mean
-------------------------------
:doc_source: paddle.fluid.layers.mean
---------
.. autofunction:: paddle.tensor.mean
:noindex:
......@@ -2,6 +2,6 @@
min
-------------------------------
:doc_source: paddle.fluid.layers.reduce_min
:doc_source: paddle.tensor.min
.. _api_tensor_cn_minimum:
minimum
-------------------------------
:doc_source: paddle.tensor.minimum
......@@ -2,6 +2,6 @@
not_equal
-------------------------------
:doc_source: paddle.fluid.layers.not_equal
:doc_source: paddle.tensor.not_equal
.. _api_tensor_cn_ones_like:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_tensor_ones_like:
ones_like
-------------------------------
:doc_source: paddle.fluid.layers.ones_like
---------
.. autofunction:: paddle.tensor.ones_like
:noindex:
......@@ -5,6 +5,7 @@ random
.. toctree::
:maxdepth: 1
random/rand.rst
random/randint.rst
random/randn.rst
random/randperm.rst
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_tensor_random_randn:
randn
-----
.. autofunction:: paddle.tensor.random.randn
:noindex:
......@@ -2,6 +2,6 @@
sort
-------------------------------
:doc_source: paddle.fluid.layers.argsort
:doc_source: paddle.tensor.sort
......@@ -10,4 +10,3 @@ fluid.transpiler
transpiler/HashName.rst
transpiler/memory_optimize.rst
transpiler/release_memory.rst
transpiler/RoundRobin.rst
......@@ -64,8 +64,8 @@ GradientClipByGlobalNorm
# return Parameter.name=="fc_0.w_0"
# clip = fluid.clip.GradientClipByGlobalNorm(clip_norm=1.0, need_clip=fileter_func)
sgd_optimizer = fluid.optimizer.SGDOptimizer(learning_rate=0.1)
sgd_optimizer.minimize(loss, grad_clip=clip)
sgd_optimizer = fluid.optimizer.SGDOptimizer(learning_rate=0.1, grad_clip=clip)
sgd_optimizer.minimize(loss)
place = fluid.CPUPlace()
exe = fluid.Executor(place)
......@@ -101,5 +101,7 @@ GradientClipByGlobalNorm
# clip = fluid.clip.GradientClipByGlobalNorm(clip_norm=1.0, need_clip=fileter_func)
sgd_optimizer = fluid.optimizer.SGD(
learning_rate=0.1, parameter_list=linear.parameters())
sgd_optimizer.minimize(loss, grad_clip=clip)
\ No newline at end of file
learning_rate=0.1,
parameter_list=linear.parameters(),
grad_clip=clip)
sgd_optimizer.minimize(loss)
......@@ -15,6 +15,7 @@ fluid.dygraph
dygraph_cn/Conv2DTranspose_cn.rst
dygraph_cn/Conv3D_cn.rst
dygraph_cn/Conv3DTranspose_cn.rst
dygraph_cn/CosineAnnealingDecay_cn.rst
dygraph_cn/CosineDecay_cn.rst
dygraph_cn/declarative_cn.rst
dygraph_cn/Dropout_cn.rst
......@@ -27,11 +28,14 @@ fluid.dygraph
dygraph_cn/guard_cn.rst
dygraph_cn/InstanceNorm_cn.rst
dygraph_cn/InverseTimeDecay_cn.rst
dygraph_cn/jit_cn.rst
dygraph_cn/LambdaDecay_cn.rst
dygraph_cn/Layer_cn.rst
dygraph_cn/LayerList_cn.rst
dygraph_cn/LayerNorm_cn.rst
dygraph_cn/Linear_cn.rst
dygraph_cn/load_dygraph_cn.rst
dygraph_cn/MultiStepDecay_cn.rst
dygraph_cn/NaturalExpDecay_cn.rst
dygraph_cn/NCE_cn.rst
dygraph_cn/NoamDecay_cn.rst
......@@ -44,10 +48,13 @@ fluid.dygraph
dygraph_cn/PRelu_cn.rst
dygraph_cn/prepare_context_cn.rst
dygraph_cn/ProgramTranslator_cn.rst
dygraph_cn/ReduceLROnPlateau_cn.rst
dygraph_cn/save_dygraph_cn.rst
dygraph_cn/Sequential_cn.rst
dygraph_cn/SpectralNorm_cn.rst
dygraph_cn/StepDecay_cn.rst
dygraph_cn/to_variable_cn.rst
dygraph_cn/TracedLayer_cn.rst
dygraph_cn/Tracer_cn.rst
dygraph_cn/TranslatedLayer_cn.rst
dygraph_cn/TreeConv_cn.rst
......@@ -46,7 +46,7 @@ Conv2D
参数:
- **num_channels** (int) - 输入图像的通道数。
- **num_fliters** (int) - 滤波器的个数,和输出特征图个数相同。
- **num_filters** (int) - 滤波器的个数,和输出特征图个数相同。
- **filter_size** (int|tuple) - 滤波器大小。如果 ``filter_size`` 是一个元组,则必须包含两个整型数,分别表示滤波器高度和宽度。否则,表示滤波器高度和宽度均为 ``filter_size`` 。
- **stride** (int|tuple, 可选) - 步长大小。如果 ``stride`` 为元组,则必须包含两个整型数,分别表示垂直和水平滑动步长。否则,表示垂直和水平滑动步长均为 ``stride`` 。默认值:1。
- **padding** (int|tuple, 可选) - 填充大小。如果 ``padding`` 为元组,则必须包含两个整型数,分别表示竖直和水平边界填充大小。否则,表示竖直和水平边界填充大小均为 ``padding`` 。默认值:0。
......
.. _cn_api_fluid_dygraph_LambdaDecay:
LambdaDecay
-------------------------------
.. py:class:: paddle.fluid.dygraph.LambdaDecay(learning_rate, lr_lambda)
:api_attr: 命令式编程模式(动态图)
该API提供 lambda函数 设置学习率的功能。 ``lr_lambda`` 为一个lambda函数,其通过 ``epoch`` 计算出一个因子,该因子会乘以初始学习率。
算法可以描述为:
.. code-block:: text
learning_rate = 0.5 # init learning_rate
lr_lambda = lambda epoch: 0.95 ** epoch
learning_rate = 0.5 # epoch 0
learning_rate = 0.475 # epoch 1
learning_rate = 0.45125 # epoch 2
参数:
- **learning_rate** (float|int) - 初始化的学习率。可以是Python的float或int。
- **lr_lambda** (function) - ``lr_lambda`` 为一个lambda函数,其通过 ``epoch`` 计算出一个因子,该因子会乘以初始学习率。
返回: 无
**代码示例**:
.. code-block:: python
import paddle.fluid as fluid
import numpy as np
with fluid.dygraph.guard():
x = np.random.uniform(-1, 1, [10, 10]).astype("float32")
linear = fluid.dygraph.Linear(10, 10)
input = fluid.dygraph.to_variable(x)
scheduler = fluid.dygraph.LambdaDecay(0.5, lr_lambda=lambda x: 0.95**x)
adam = fluid.optimizer.Adam(learning_rate = scheduler, parameter_list = linear.parameters())
for epoch in range(6):
for batch_id in range(5):
out = linear(input)
loss = fluid.layers.reduce_mean(out)
adam.minimize(loss)
scheduler.epoch()
print("epoch:%d, current lr is %f" .format(epoch, adam.current_step_lr()))
# epoch:0, current lr is 0.5
# epoch:1, current lr is 0.475
# epoch:2, current lr is 0.45125
.. py:method:: epoch(epoch=None)
通过当前的 epoch 调整学习率,调整后的学习率将会在下一次调用 ``optimizer.minimize`` 时生效。
参数:
- **epoch** (int|float,可选) - 类型:int或float。指定当前的epoch数。默认:无,此时将会自动累计epoch数。
返回:
**代码示例**:
参照上述示例代码。
......@@ -256,6 +256,87 @@ hook(Layer, input, output) -> None or modified output
for prefix, layer in model.named_sublayers():
print(prefix, layer)
.. py:method:: register_buffer(name, variable, persistable=True)
将一个Variable注册为buffer
buffer是一个非参数类型的变量,不会被优化器更新,但在评估或预测阶段可能是必要的状态变量。比如 ``BatchNorm`` 中的均值和方差。
注册的buffer默认是可持久性的,会被保存到 ``state_dict`` 中。如果指定 ``persistable`` 参数为False,则会注册一个非持久性的buffer,即不会同步和保存到 ``state_dict`` 中。
参数:
- **name** (str) - 注册buffer的名字。可以通过此名字来访问已注册的buffer
- **variable** (Variable) - 将被注册为buffer的变量。
- **persistable** (bool, 可选) - 注册的buffer是否需要可持久性地保存到 ``state_dict`` 中。
返回:None
返回类型:None
**代码示例**
.. code-block:: python
import numpy as np
import paddle.fluid as fluid
with fluid.dygraph.guard():
linear = fluid.Linear(10, 3)
value = np.array([0]).astype("float32")
buffer = fluid.dygraph.to_variable(value)
linear.register_buffer("buf_name", buffer, persistable=True)
# get the buffer by attribute.
print(linear.buf_name)
.. py:method:: buffers(include_sublayers=True)
返回一个由当前层及其子层的所有buffers组成的列表。
参数:
- **include_sublayers** (bool, 可选) - 是否返回子层的buffers。如果为True,返回的列表中包含子层的buffers。默认值:True
返回:一个由当前层及其子层的所有buffers组成的列表,列表中的元素类型为Variable
返回类型:list
.. py:method:: named_buffers(prefix='', include_sublayers=True)
返回层中所有buffers的迭代器,生成名称和buffer的元组。
参数:
- **prefix** (str, 可选) - 在所有buffer名称前加的前缀。默认值:''
- **include_sublayers** (bool, 可选) - 是否返回子层的buffers。如果为True,返回的列表中包含子层的buffers。默认值:True
返回:产出名称和buffer的元组的迭代器。
返回类型:iterator
**代码示例**
.. code-block:: python
import numpy as np
import paddle.fluid as fluid
with fluid.dygraph.guard():
fc1 = fluid.Linear(10, 3)
buffer1 = fluid.dygraph.to_variable(np.array([0]).astype("float32"))
# register a variable as buffer by specific `persistable`
fc1.register_buffer("buf_name_1", buffer1, persistable=True)
fc2 = fluid.Linear(3, 10)
buffer2 = fluid.dygraph.to_variable(np.array([1]).astype("float32"))
# register a buffer by assigning an attribute with Variable.
# The `persistable` can only be False by this way.
fc2.buf_name_2 = buffer2
model = fluid.dygraph.Sequential(fc1, fc2)
# get all named buffers
for name, buffer in model.named_buffers():
print(name, buffer)
.. py:method:: forward(*inputs, **kwargs)
定义每次调用时执行的计算。应该被所有子类覆盖。
......@@ -290,13 +371,13 @@ hook(Layer, input, output) -> None or modified output
.. py:method:: state_dict(destination=None, include_sublayers=True)
获取当前层及其子层的所有参数。并将所有参数存放在dict结构中。
获取当前层及其子层的所有参数和可持久性buffers。并将所有参数和buffers存放在dict结构中。
参数:
- **destination** (dict, 可选) - 如果提供 ``destination`` ,则所有参数都将存放在 ``destination`` 中。 默认值:None
- **include_sublayers** (bool, 可选) - 如果设置为True,则包括子层的参数。默认值:True
- **destination** (dict, 可选) - 如果提供 ``destination`` ,则所有参数和可持久性buffers都将存放在 ``destination`` 中。 默认值:None
- **include_sublayers** (bool, 可选) - 如果设置为True,则包括子层的参数buffers。默认值:True
返回:包含所有参数的dict
返回:包含所有参数和可持久行buffersdict
返回类型:dict
......@@ -312,11 +393,11 @@ hook(Layer, input, output) -> None or modified output
.. py:method:: set_dict(stat_dict, include_sublayers=True)
根据传入的 ``stat_dict`` 设置参数 所有参数将由 ``stat_dict`` 中的 ``Tensor`` 设置。
根据传入的 ``stat_dict`` 设置参数和可持久性buffers 所有参数和buffers将由 ``stat_dict`` 中的 ``Tensor`` 设置。
参数:
- **state_dict** (dict) - 包含所有参数的dict
- **include_sublayers** (bool, 可选) - 如果设置为True,则还包括子层的参数。 默认值:True
- **state_dict** (dict) - 包含所有参数和可持久性buffersdict
- **include_sublayers** (bool, 可选) - 如果设置为True,则还包括子层的参数buffers 默认值:True
返回:None
......@@ -337,11 +418,11 @@ hook(Layer, input, output) -> None or modified output
.. warning::
该函数将被弃用。请使用set_dict函数。
根据传入的 ``stat_dict`` 设置参数 所有参数将由 ``stat_dict`` 中的 ``Tensor`` 设置。
根据传入的 ``stat_dict`` 设置参数和可持久性buffers 所有参数和buffers将由 ``stat_dict`` 中的 ``Tensor`` 设置。
参数:
- **state_dict** (dict) - 包含所有参数的dict
- **include_sublayers** (bool, 可选) - 如果设置为True,则还包括子层的参数。 默认值:True
- **state_dict** (dict) - 包含所有参数和可持久性buffersdict
- **include_sublayers** (bool, 可选) - 如果设置为True,则还包括子层的参数buffers 默认值:True
返回:None
......
.. _cn_api_fluid_dygraph_MultiStepDecay:
MultiStepDecay
-------------------------------
.. py:class:: paddle.fluid.dygraph.MultiStepDecay(learning_rate, milestones, decay_rate=0.1)
:api_attr: 命令式编程模式(动态图)
该接口提供 ``MultiStep`` 衰减学习率的功能。
算法可以描述为:
.. code-block:: text
learning_rate = 0.5
milestones = [30, 50]
decay_rate = 0.1
if epoch < 30:
learning_rate = 0.5
elif epoch < 50:
learning_rate = 0.05
else:
learning_rate = 0.005
参数:
- **learning_rate** (float|int) - 初始化的学习率。可以是Python的float或int。
- **milestones** (tuple|list) - 列表或元组。必须是递增的。
- **decay_rate** (float, optional) - 学习率的衰减率。 ``new_lr = origin_lr * decay_rate`` 。其值应该小于1.0。默认:0.1。
返回: 无
**代码示例**:
.. code-block:: python
import paddle.fluid as fluid
import numpy as np
with fluid.dygraph.guard():
x = np.random.uniform(-1, 1, [10, 10]).astype("float32")
linear = fluid.dygraph.Linear(10, 10)
input = fluid.dygraph.to_variable(x)
scheduler = fluid.dygraph.MultiStepDecay(0.5, milestones=[3, 5])
adam = fluid.optimizer.Adam(learning_rate = scheduler, parameter_list = linear.parameters())
for epoch in range(6):
for batch_id in range(5):
out = linear(input)
loss = fluid.layers.reduce_mean(out)
adam.minimize(loss)
scheduler.epoch()
print("epoch:{}, current lr is {}" .format(epoch, adam.current_step_lr()))
# epoch:0, current lr is 0.5
# epoch:1, current lr is 0.5
# epoch:2, current lr is 0.5
# epoch:3, current lr is 0.05
# epoch:4, current lr is 0.05
# epoch:5, current lr is 0.005
.. py:method:: epoch(epoch=None)
通过当前的 epoch 调整学习率,调整后的学习率将会在下一次调用 ``optimizer.minimize`` 时生效。
参数:
- **epoch** (int|float,可选) - 类型:int或float。指定当前的epoch数。默认:无,此时将会自动累计epoch数。
返回:
**代码示例**:
参照上述示例代码。
......@@ -45,7 +45,6 @@ NCE
words.append(fluid.dygraph.base.to_variable(inp_word[i]))
emb = fluid.Embedding(
'embedding',
size=[dict_size, 32],
param_attr='emb.w',
is_sparse=False)
......@@ -60,17 +59,17 @@ NCE
embs3 = fluid.layers.concat(input=embs3, axis=1)
nce = fluid.NCE(
num_total_classes=dict_size,
dim=embs3.shape[1],
num_neg_samples=2,
sampler="custom_dist",
custom_dist=nid_freq_arr.tolist(),
seed=1,
param_attr='nce.w',
bias_attr='nce.b')
num_total_classes=dict_size,
dim=embs3.shape[1],
num_neg_samples=2,
sampler="custom_dist",
custom_dist=nid_freq_arr.tolist(),
seed=1,
param_attr='nce.w',
bias_attr='nce.b')
wl = fluid.layers.unsqueeze(words[label_word], axes=[0])
nce_loss3 = nce(embs3, words[label_word])
nce_loss3 = nce(embs3, wl)
属性
::::::::::::
......
......@@ -42,7 +42,7 @@ NaturalExpDecay
- **staircase** (bool,可选) - 若为True, 学习率变化曲线呈阶梯状,若为False,学习率变化值曲线为平滑的曲线。默认值为False。
- **begin** (int,可选) – 起始步,即以上运算式子中global_step的初始化值。默认值为0。
- **step** (int,可选) – 步大小,即以上运算式子中global_step的每次的增量值。默认值为1。
- **dtype** – (str,可选) 初始化学习率变量的数据类型,可以为"float32", "float64"。默认值为"float32"。
- **dtype** (str,可选) – 学习率值的数据类型,可以为"float32", "float64"。默认值为"float32"。
返回: 无
......@@ -53,12 +53,14 @@ NaturalExpDecay
import paddle.fluid as fluid
base_lr = 0.1
with fluid.dygraph.guard():
emb = fluid.dygraph.Embedding([10, 10])
sgd_optimizer = fluid.optimizer.SGD(
learning_rate=fluid.dygraph.NaturalExpDecay(
learning_rate=base_lr,
decay_steps=10000,
decay_rate=0.5,
staircase=True))
learning_rate=base_lr,
decay_steps=10000,
decay_rate=0.5,
staircase=True),
parameter_list=emb.parameters())
......
......@@ -55,10 +55,8 @@ PolynomialDecay
total_step = 5000
end_lr = 0
with fluid.dygraph.guard():
emb = fluid.dygraph.Embedding( [10, 10])
optimizer = fluid.optimizer.SGD(
learning_rate = fluid.dygraph.PolynomialDecay(
start_lr, total_step, end_lr, power=1.0) )
start_lr, total_step, end_lr, power=1.0),
parameter_list = emb.parameters())
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册