# gather算子报错：TypeError以及定位解决

**1. 系统**

**环境**

硬件环境\(Ascend/GPU/CPU\): CPU

软件环境: MindSpore 版本: 1.9

执行模式（静态图/动态图）： 不限

Python 版本: 3.7.6

操作系统平台: linux

**2. 报错信息**

2.1 问题描述

有一个模型，在construct里进行了一些计算，计算完毕后想删除某个tensor。

2.2 报错信息

```
Traceback (most recent call last):
  File "D:/cons.py", line 11, in <module>
    m(1, 2)
  File "D:\python3.7\lib\site-packages\mindspore\nn\cell.py", line 622, in __call__
    out = self.compile_and_run(*args)
  File "D:\python3.7\lib\site-packages\mindspore\nn\cell.py", line 1007, in compile_and_run
    self.compile(*inputs)
  File "D:\python3.7\lib\site-packages\mindspore\nn\cell.py", line 979, in compile
    jit_config_dict=self._jit_config_dict)
  File "D:\python3.7\lib\site-packages\mindspore\common\api.py", line 1147, in compile
    result = self._graph_executor.compile(obj, args_list, phase, self._use_vm_mode())
RuntimeError: Unsupported statement 'Delete'.
More details please refer to syntax support at https://www.mindspore.cn

----------------------------------------------------
- The Traceback of Net Construct Code:
----------------------------------------------------

# In file D:/cons.py:9
        del a
        ^

----------------------------------------------------
- C++ Call Stack: (For framework developers)
----------------------------------------------------
mindspore\ccsrc\pipeline\jit\parse\parse.cc:772 mindspore::parse::Parser::ParseStatement


Process finished with exit code 1
```

2.3 脚本信息

```
from mindspore import nn
import mindspore as ms

ms.set_context(mode=ms.GRAPH_MODE)
class Model(nn.Cell):
    def construct(self, x, y):
        a = x + 1
        y = a + y
        del a
        return y

m = Model()
m(1, 2)
```

**3. 根因分析**

在Graph模式下，Python代码并不是由Python解释器去执行，而是将代码编译成静态计算图，然后执行静态计算图。

由于语法解析的限制，当前在编译构图时，支持的数据类型、语法以及相关操作并没有完全与Python语法保持一致，部分使用受限。

具体参考：https://www.mindspore.cn/docs/zh-CN/r1.8/note/static\_graph\_syntax\_support.html

出错的代码

https://gitee.com/mindspore/mindspore/blob/master/mindspore/ccsrc/pipeline/jit/parse/parse.cc

![](figures/zh-cn_image_0000002134921433.png)从说明文档和代码上都能看出del不被支持。

**4. 解决方案**

不用del，将变量置None。

```
from mindspore import nn
import mindspore as ms

ms.set_context(mode=ms.GRAPH_MODE)
class Model(nn.Cell):
    def construct(self, x, y):
        a = x + 1
        y = a + y
        a = None
        return y

m = Model()
m(1, 2)
```

