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

Distributed Automatic SParsity with Fleet #33558

Merged
merged 25 commits into from
Jul 8, 2021

Conversation

mingxu1067
Copy link
Collaborator

PR types

New features

PR changes

APIs

Describe

  1. Implemented ASP MetaOptimizer in Fleet to enable distributed ASP training.
  2. ASP MetaOptimizer could be the top of other MetaOptimizers.
  3. Added a new attribute, asp, into DistributedStrategy .

Code example:

from paddle.fluid.contrib import sparsity

fleet.init(is_collective=True)
with fluid.program_guard(main_program, startup_program):
    input_data, loss = network()

    optimizer = fluid.optimizer.SGD(learning_rate=0.1)
	strategy = fleet.DistributedStragety()
    strategy.amp = True
    strategy.asp = True
    optimizer = fleet.distributed_optimizer(optimizer, strategy=strategy)
    optimizer.minimize(optimizer, loss, main_program, startup_program)

exe = fluid.Executor(place)
exe.run(startup_program)

# Must call `exe.run(startup_program)` first before calling `sparsity.prune_model`
sparsity.prune_model(place, main_program)

# Start training with ASP workflow.
for epoch in range(total_epochs):
    exe.run(main_program)

1. Added sparse mask generating functions, including 1D and 2Ds.
2. Added sparse pattern checking functions, including 1D and 2Ds.
1. Added model pruning functions.
2. Added optimizer decorator and sparse minimization functions.
1. Added model pruning functions.
2. Added optimizer decorator and sparse minimization functions.
1. Added ASPOptimizer into Fleet metaoptimizer.
2. Added asp attribute into Fleet DistributedStrategy.
3. Added related test cases.
@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@qingqing01
Copy link
Contributor

@mingxu1067 Do you have plan to support dygraph and inference?

@mingxu1067
Copy link
Collaborator Author

@mingxu1067 Do you have plan to support dygraph and inference?

We do not have determined plan on DyGraph supporting so far.

@@ -134,21 +130,36 @@ def prune_model(place,

place = fluid.CUDAPlace(0)



Copy link
Contributor

Choose a reason for hiding this comment

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

这里空行加的有点多了。

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, 分散式那邊有沒有甚麼comment? 我一起修改後再commit一次

optimizer = fluid.contrib.mixed_precision.decorator.decorate(optimizer )
# Calling sparsity.decorate() to wrap minimize() in optimizer, which
# will insert necessary masking operations for ASP workflow.
optimizer = sparsity.decorate(optimizer )
Copy link
Contributor

Choose a reason for hiding this comment

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

现在是amp和asp一起用有问题?那这个示例里面先不要加amp吧?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ASP與AMP一起使用沒有問題,有成功使用PaddleNLP/bert的AMP + ASP做過sparse finetuning

@paddle-bot-old
Copy link

Sorry to inform you that b6f90d4's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually.


return False

def _disable_strategy(self, dist_strategy):

Choose a reason for hiding this comment

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

set dist_strategy.asp = False ?

return

def _enable_strategy(self, dist_strategy, context):
return

Choose a reason for hiding this comment

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

set dist_strategy.asp = True ?

1. Added enable/disable policy controlling in asp_optimizer.
2. Changed unittests.
Copy link

@sandyhouse sandyhouse 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 Fleet strategy

@Xreki Xreki merged commit 86cb3fb into PaddlePaddle:develop Jul 8, 2021
@mingxu1067 mingxu1067 deleted the automatic_sparsity_with_fleet branch October 15, 2021 06:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants