---
title: 训练GPT2-13B大模型时报错ValueError: For 'AdamWeightDecay', the 'var_shape' should be = grad_shape: [1], but 
description: 训练GPT2-13B大模型时报错ValueError: For 'AdamWeightDecay', the 'var_shape' should be = grad_shape: [1], but got [2560]  ms版本：1.9.0 开源代码路径：https://gitee.com/mindspore/mindformers/tree/dev
keywords: 训练GPT2-13B;AdamWeightDecay
url: https://www.hiascend.com/document/caselibrary/detail/case_9527
section: (其他)
---

# 训练GPT2-13B大模型时报错ValueError: For 'AdamWeightDecay', the 'var_shape' should be = grad_shape: [1], but 

URL: https://www.hiascend.com/document/caselibrary/detail/case_9527
描述: 训练GPT2-13B大模型时报错ValueError: For 'AdamWeightDecay', the 'var_shape' should be = grad_shape: [1], but got [2560]  ms版本：1.9.0 开源代码路径：https://gitee.com/mindspore/mindformers/tree/dev
关键词: 训练GPT2-13B;AdamWeightDecay

昇腾文档 [了解详情](https://www.hiascend.com/document)

故障案例 [了解详情](https://www.hiascend.com/document/caselibrary)

训练GPT2-13B大模型时报错ValueError: For 'AdamWeightDecay', the 'var_shape' should be = grad_shape: [1], but got [2560]

训练GPT2-13B大模型时报错ValueError: For 'AdamWeightDecay', the 'var_shape' should be = grad_shape: [1], but got [2560]

2024/02/22

830

问题信息

| 问题来源 | 产品大类 | 产品子类 | 关键字 |
| --- | --- | --- | ---|
| 官方 | 模型训练 | MindSpore | 训练GPT2-13B、AdamWeightDecay |

#### 问题现象描述

训练GPT2-13B大模型时报错ValueError: For 'AdamWeightDecay', the 'var_shape' should be = grad_shape: [1], but got [2560]

ms版本：1.9.0

开源代码路径：https://gitee.com/mindspore/mindformers/tree/dev [了解详情](https://gitee.com/mindspore/mindformers/tree/dev)

#### 原因分析

AdamweightDecay优化器切分时不正确，可能是ms版本bug。

#### 排查方法

确认run_gpt2_13b.yaml文件中optimizer_shard是否为True。

#### 解决措施

需要将run_gpt2_13b.yaml中的optimizer_shard设置为False，但这样会增加内存消耗。

建议使用ms1.9.1及之后版本，同时将optimizer_shard设置为True。

本页内容

- 问题信息
- 问题现象描述
- 原因分析
- 排查方法
- 解决措施
