Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Docathon] Add paddle.incubate.ampdecorate and paddle.incubate.amp.prune_model API CN Doc #6222

Merged
merged 15 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions docs/api/paddle/incubate/asp/decorate_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.. _cn_api_paddle_incubate_asp_decorate:

decorate
-------------------------------

.. py:function:: paddle.incubate.asp.decorate(optimizer)


将给定的优化器包装为 `OptimizerWithSparsityGuarantee`。如果在动态图模式下运行,装饰时 ASP 会为支持的参数创建掩码变量。如果在静态图模式下运行,ASP 会在调用 minimize() 时创建掩码变量并插入必要的掩码操作。
ooooo-create marked this conversation as resolved.
Show resolved Hide resolved


参数
:::::::::

**optimizer** (Optimizer) – 用于模型训练的优化器。

返回
:::::::::

**OptimizerWithSparsityGuarantee** - 一个用于 ASP 的包装器,用于装饰给定优化器的 minimize() 或者 step()。

代码示例
:::::::::

1. 动态图模式

COPY-FROM: paddle.incubate.asp.decorate:dynamic_graph

2. 静态图模式

COPY-FROM: paddle.incubate.asp.decorate:static_graph
38 changes: 38 additions & 0 deletions docs/api/paddle/incubate/asp/prune_model_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.. _cn_api_paddle_incubate_asp_prune_model:

prune_model
-------------------------------

.. py:function:: paddle.incubate.asp.prune_model(model, n=2, m=4, mask_algo='mask_1d', with_mask=True)


使用 mask_algo 指定的掩码生成函数修剪 model 中支持 ASP 的子层参数。使用 with_mask 来控制模型训练和推理,如果 with_mask 是 True ,还有修剪参数相关的 ASP 掩码变量,如果是 False,仅仅裁剪参数。
ooooo-create marked this conversation as resolved.
Show resolved Hide resolved

.. note::
- 在静态图模式下,使用 with_mask 调用函数时,需要先调用 OptimizerWithSparsityGuarantee.minimize 和 exe.run(startup_program) 来成功获取掩码变量。通常情况下训练时(已调用 OptimizerWithSparsityGuarantee.minimize)设置 with_mask 为 True,而 with_mask 为 False 时只能用于推理。 要获取 OptimizerWithSparsityGuarantee,请参阅 paddle.incubate.asp.decoreate()。
ooooo-create marked this conversation as resolved.
Show resolved Hide resolved
- 在动态图模式下,使用 with_mask 调用函数是,需要先调用 paddle.incubate.asp.decorate() 来获取掩码变量。
ooooo-create marked this conversation as resolved.
Show resolved Hide resolved


参数
:::::::::
- **model** (Program|nn.Layer) - 带有模型定义和参数的 Program 或者 paddle.nn.Layer 对象
ooooo-create marked this conversation as resolved.
Show resolved Hide resolved
- **n** (int,可选) - n:m 稀疏中的 n
- **m** (int,可选) - n:m 稀疏中的 m
ooooo-create marked this conversation as resolved.
Show resolved Hide resolved
- **mask_algo** (string,可选) - 生成掩码的函数名。默认值为 mask_1d。有效输入应为 mask_1d , mask_2d_greedy 和 mask_2d_best 之一。
ooooo-create marked this conversation as resolved.
Show resolved Hide resolved
- **with_mask** (bool,可选) - 选择是否裁剪参数相关的 ASP 掩码变量,True 是要裁剪,False 就是不裁剪。默认是 True。

返回
:::::::::

**dictionary** - 一个字典,key 是参数名称,value 是 对应的掩码变量。
ooooo-create marked this conversation as resolved.
Show resolved Hide resolved

代码示例
:::::::::

1. 动态图模式

COPY-FROM: paddle.incubate.asp.prune_model:dynamic_graph

2. 静态图模式

COPY-FROM: paddle.incubate.asp.prune_model:static_graph