jittor.nn.MaxPool2d的kernel_size接受非法参数异常
PhyllisJi opened this issue · 0 comments
PhyllisJi commented
关键错误信息
-
当kernel_size小于0时,这里测试取-1,该层不会对此抛出异常,而是会将非法输出传递到底层算子,调用. jt.code() 时出现错误,并返回异常信息。
- 当kernel_size等于0时,初始化模型时不会报任何错误,但在初始化中stride参数会设置为kernel_size。当传递数据进模型中,计算h和w时会除以stride,报除0错误.
预期行为
jittor.nn. MaxPool2d的kernel_size非法时,在初始化模型时应该拒绝该参数,并抛出正确的异常信息提醒用户,以防止底层算子出现未知问题,并不影响其他正常运算。
错误日志
1.当kernel为负数
Traceback (most recent call last):
File "D:\课件\研究生\项目\2023-7-5 bug标注\models\jttest.py", line 8, in <module>
output = maxpool(input)
File "D:\myvscode\environment\python3.9\lib\site-packages\jittor\__init__.py", line 1172, in __call__
return self.execute(*args, **kw)
File "D:\myvscode\environment\python3.9\lib\site-packages\jittor\pool.py", line 541, in execute
return self._layer(x)
File "D:\myvscode\environment\python3.9\lib\site-packages\jittor\__init__.py", line 1172, in __call__
return self.execute(*args, **kw)
File "D:\myvscode\environment\python3.9\lib\site-packages\jittor\pool.py", line 108, in execute
out = jt.code(return_shapes, return_dtypes, [x],
RuntimeError: Wrong inputs arguments, Please refer to examples(help(jt.ops.code)).
Types of your inputs are:
self = module,
args = (list, NanoString, list, ),
kwargs = {cuda_header=str, cuda_src=str, cuda_grad_src=list, cpu_header=str, cpu_src=str, cpu_grad_src=list, },
The function declarations are:
VarHolder* code(NanoVector shape, NanoString dtype, vector<VarHolder*>&& inputs={}, string&& cpu_src="", vector<string>&& cpu_grad_src={}, string&& cpu_header="", string&& cuda_src="", vector<string>&& cuda_grad_src={}, string&& cuda_header="", DataMap&& data={})
vector_to_tuple<VarHolder*> code_(vector<NanoVector>&& shapes, vector<NanoString>&& dtypes, vector<VarHolder*>&& inputs={}, string&& cpu_src="", vector<string>&& cpu_grad_src={}, string&& cpu_header="", string&& cuda_src="", vector<string>&& cuda_grad_src={}, string&& cuda_header="", DataMap&& data={})
vector_to_tuple<VarHolder*> code__(vector<VarHolder*>&& inputs, vector<VarHolder*>&& outputs, string&& cpu_src="", vector<string>&& cpu_grad_src={}, string&& cpu_header="", string&& cuda_src="", vector<string>&& cuda_grad_src={}, string&& cuda_header="", DataMap&& data={})
Failed reason:[f 0719 21:57:51.387000 96 code_op.cc:25] Check failed: (i == 0) ^ (v[i] >= 0) Something wrong... Could you please report this issue?
Vary shape should only occur in the first dimension: [1,1,-6,-6,]
Process finished with exit code 1
-
kernel为0
Traceback (most recent call last): File "D:\myvscode\softWare\PyCharm 2022.3.2\plugins\python\helpers\pydev\pydevd.py", line 1496, in _exec pydev_imports.execfile(file, globals, locals) # execute the script File "D:\myvscode\softWare\PyCharm 2022.3.2\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "D:\课件\研究生\项目\2023-7-5 bug标注\models\jttest.py", line 8, in <module> output = maxpool(input) File "D:\myvscode\environment\python3.9\lib\site-packages\jittor\__init__.py", line 1172, in __call__ return self.execute(*args, **kw) File "D:\myvscode\environment\python3.9\lib\site-packages\jittor\pool.py", line 541, in execute return self._layer(x) File "D:\myvscode\environment\python3.9\lib\site-packages\jittor\__init__.py", line 1172, in __call__ return self.execute(*args, **kw) File "D:\myvscode\environment\python3.9\lib\site-packages\jittor\pool.py", line 36, in execute h = (H+self.padding[0]*2-self.kernel_size[0])//self.stride[0]+1 ZeroDivisionError: integer division or modulo by zero python-BaseException Process finished with exit code 1
最小复现
maxpool = nn.MaxPool2d(0)
input = jt.randn(1, 1, 6, 6)
output = maxpool(input)
print(output.shape)
maxpool = nn.MaxPool2d(-1)
input = jt.randn(1, 1, 6, 6)
output = maxpool(input)
print(output.shape)