为使您的问题得到快速解决,在建立Issues前,请您先通过如下方式搜索是否有相似问题:【搜索issue关键字】【使用labels筛选】【官方文档】
如果您没有查询到相似问题,为快速解决您的提问,建立issue时请提供如下细节信息:
- 标题:简洁、精准概括您的问题,例如“Insufficient Memory xxx" ”
- 版本、环境信息:
1)PaddlePaddle版本:请提供您的PaddlePaddle版本号,例如1.1或CommitID
2)CPU:预测若用CPU,请提供CPU型号,MKL/OpenBlas/MKLDNN/等数学库使用情况
3)GPU:预测若用GPU,请提供GPU型号、CUDA和CUDNN版本号
4)系统环境:请您描述系统类型、版本,例如Mac OS 10.14,Python版本
注:您可以通过执行summary_env.py获取以上信息。
- 训练信息
1)单机/多机,单卡/多卡
2)显存信息
3)Operator信息
- 复现信息:如为报错,请给出复现环境、复现步骤
- 问题描述:请详细描述您的问题,同步贴出报错信息、日志、可复现的代码片段
Thank you for contributing to PaddlePaddle.
Before submitting the issue, you could search issue in the github in case that there was a similar issue submitted or resolved before.
If there is no solution,please make sure that this is a training issue including the following details:
System information
-PaddlePaddle version (eg.1.1)or CommitID
-CPU: including CPUMKL/OpenBlas/MKLDNN version
-GPU: including CUDA/CUDNN version
-OS Platform (eg.Mac OS 10.14)
-Other imformation: Distriuted training/informantion of operator/
Graphics card storage
Note: You can get most of the information by running summary_env.py.
To Reproduce
Steps to reproduce the behavior
Describe your current behavior
Code to reproduce the issue
Other info / logs
class FGM():
"""针对embedding层梯度上升干扰的对抗训练方法,Fast Gradient Method(FGM)"""
def __init__(self, model):
self.model = model
self.backup = {}
def attack(self, epsilon=1., emb_name='emb'):
# emb_name这个参数要换成你模型中embedding的参数名
for name, param in self.model.named_parameters():
if not param.stop_gradient and emb_name in name: # 检验参数是否可训练及范围
self.backup[name] = param.numpy() # 备份原有参数值
grad_tensor = paddle.to_tensor(param.grad) # param.grad是个numpy对象
norm = paddle.norm(grad_tensor) # norm化
if norm != 0:
r_at = epsilon * grad_tensor / norm
param.add(r_at) # 在原有embed值上添加向上梯度干扰
def restore(self, emb_name='emb'):
# emb_name这个参数要换成你模型中embedding的参数名
for name, param in self.model.named_parameters():
if not param.stop_gradient and emb_name in name:
assert name in self.backup
param.set_value(self.backup[name]) # 将原有embed参数还原
self.backup = {}
6条答案
按热度按时间41zrol4v1#
您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看官网API文档、常见问题、历史Issue、AI社区来寻求解答。祝您生活愉快~
Hi! We've received your issue and please be patient to get responded. We will arrange technicians to answer your questions as soon as possible. Please make sure that you have posted enough message to demo your request. You may also check out the API,FAQ,Github Issue and AI community to get the answer.Have a nice day!
4si2a6ki2#
您好,报错信息需要复现代码,请提供代码和环境信息,我们复现后会尽快回复您~
krcsximq3#
aistudio的环境paddle-gpu 2.0.2
qqrboqgw4#
paddlehub 2.0.4
paddlenlp 2.0.7
paddlepaddle-gpu 2.1.2.post101
qxgroojn5#
你好,aistudio 推荐使用paddle 2.2.0rc,该版本可以解决该问题;
eqoofvh96#
好的,刚试了下,现在可以了