---
title: 如何处理内存不足
description: "TensorFlow训练场景下调优时，可能会出现如下类似报错。"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/devaids/aoe/aoepar_16_084.html
sourcePath: /source/zh/canncommercial/900/devaids/aoe/aoepar_16_084.html
indexId: 5a168d7142e59f80b69bc066e0c29988b6955a710b799a7c965d2668b1da104960
---
# 如何处理内存不足

#### 问题现象

TensorFlow训练场景下调优时，可能会出现如下类似报错。

- 第一种报错

```
[
ERROR
] GE(685297,python3):2022-04-06-07:15:09.383.996 [graph_var_manager.cc:402]687614 AssignVarMem: ErrorNo: 1343225857(Parameter's invalid!) [COMP][MEM_ALLOC][Check][Param]
Out of memory
:
current var size[13962468864] exceeds total var size[13958643712]
```


- 第二种报错

```
[
ERROR
] GE(685297,python3):2022-04-06-07:15:09.383.996 [graph_var_manager.cc:402]687614 AssignVarMem: ErrorNo: 1343225857(Parameter's invalid!) [COMP][MEM_ALLOC][Check][Param]
Out of memory
:
current graph size[13962468864] exceeds total graph size[13958643712]
```


#### 解决方案

修改sess.run模式下的session配置项或者Estimator模式下的npu_bridge.estimator.npu.npu_config。具体修改方法如下。

- 第一种报错处理办法：修改variable_memory_max_size的取值为报错信息中的current var size+1GB，修改graph_memory_max_size的取值为31GB –variable_memory_max_size。具体配置项说明请参见  表1
。
- 第二种报错处理办法：修改graph_memory_max_size的取值为报错信息中的current graph size+1GB，修改variable_memory_max_size的取值为31GB –graph_memory_max_size。具体配置项说明请参见  表1
。


**表1 配置项说明**

| 配置项 | 说明 |
| --- | --- |
| graph\_memory\_max\_size | 网络静态内存和最大动态内存，可根据网络大小指定。单位：Byte，取值范围：[0, 256\*1024\*1024\*1024]或[0, 274877906944]。当前受昇腾AI处理器硬件限制，graph\_memory\_max\_size和variable\_memory\_max\_size总和为31GB。如果不设置，默认为26GB。 配置示例： sess.run模式 custom\_op.parameter\_map["graph\_memory\_max\_size"].s = tf.compat.as\_bytes(str(26\*1024 \* 1024 \* 1024)) Estimator模式 config = NPURunConfig(graph\_memory\_max\_size=str(26\*1024 \* 1024 \* 1024)) variable\_memory\_max\_size |
| variable\_memory\_max\_size | 变量内存，可根据网络大小指定。单位：Byte，取值范围：[0，256\*1024\*1024\*1024]或[0, 274877906944]。当前受昇腾AI处理器硬件限制，graph\_memory\_max\_size和variable\_memory\_max\_size总和为31GB。如果不设置，默认为5GB。 配置示例： sess.run模式 custom\_op.parameter\_map["variable\_memory\_max\_size"].s = tf.compat.as\_bytes(str(5\*1024 \* 1024 \* 1024)) Estimator模式 config = NPURunConfig(variable\_memory\_max\_size=str(5\*1024 \* 1024 \* 1024)) |
