Jittor / jittor

Jittor is a high-performance deep learning framework based on JIT compiling and meta-operators.
https://cg.cs.tsinghua.edu.cn/jittor/
Apache License 2.0
3.09k stars 311 forks source link

Crash with error happend during compilatio in `jt.nn.pool/Pool/Pool3d/pool3d` #522

Closed x0w3n closed 5 months ago

x0w3n commented 5 months ago

Describe the bug

When negative numbers are passed to the kernel_size and stride parameters of jt.nn.pool/Pool/Pool3d/pool3d, a compilation failure occurs, resulting in the code not running.

Full Log

pool:

[i 0508 14:00:47.274039 64 compiler.py:956] Jittor(1.3.9.6) src: /jittor/python/jittor
[i 0508 14:00:47.276847 64 compiler.py:957] g++ at /usr/bin/g++(8.3.0)
[i 0508 14:00:47.276907 64 compiler.py:958] cache_path: /root/.cache/jittor/jt1.3.9/g++8.3.0/py3.7.4/Linux-5.15.153x56/13thGenIntelRCx56/8c5a/master
[i 0508 14:00:47.280649 64 __init__.py:412] Found addr2line(2.31.1) at /usr/bin/addr2line.
[i 0508 14:00:47.503262 64 __init__.py:227] Total mem: 15.43GB, using 5 procs for compiling.
[i 0508 14:00:47.573697 64 jit_compiler.cc:28] Load cc_path: /usr/bin/g++
Traceback (most recent call last):
  File "test.py", line 22, in <module>
    a = jt.nn.pool(kernel_size=-1,stride=1,op=jt.random((1,3,4,5)),x=jt.random((1,3,4,5)))
  File "/jittor/python/jittor/pool.py", line 512, in pool
    return Pool(kernel_size, stride, padding, op=op)(x)
  File "/jittor/python/jittor/__init__.py", line 1184, in __call__
    return self.execute(*args, **kw)
  File "/jittor/python/jittor/pool.py", line 38, in execute
    use_code_op = self.op in ['maximum', 'minimum']
RuntimeError: Wrong inputs arguments, Please refer to examples(help(jt.__richcmp__)).

Types of your inputs are:
 self   = Var,
 b      = str,

The function declarations are:
 VarHolder* less(VarHolder* x, VarHolder* y)
 VarHolder* less_equal(VarHolder* x, VarHolder* y)
 VarHolder* greater(VarHolder* x, VarHolder* y)
 VarHolder* greater_equal(VarHolder* x, VarHolder* y)
 VarHolder* equal(VarHolder* x, VarHolder* y)
 VarHolder* not_equal(VarHolder* x, VarHolder* y)

Failed reason:[f 0508 14:00:47.704375 64 pyjt_jit_op_maker.cc:15628] Not a valid call.

Pool:

[i 0508 14:01:23.635467 72 compiler.py:956] Jittor(1.3.9.6) src: /jittor/python/jittor
[i 0508 14:01:23.638738 72 compiler.py:957] g++ at /usr/bin/g++(8.3.0)
[i 0508 14:01:23.638859 72 compiler.py:958] cache_path: /root/.cache/jittor/jt1.3.9/g++8.3.0/py3.7.4/Linux-5.15.153x56/13thGenIntelRCx56/8c5a/master
[i 0508 14:01:23.644249 72 __init__.py:412] Found addr2line(2.31.1) at /usr/bin/addr2line.
[i 0508 14:01:23.864345 72 __init__.py:227] Total mem: 15.43GB, using 5 procs for compiling.
[i 0508 14:01:23.934246 72 jit_compiler.cc:28] Load cc_path: /usr/bin/g++
Traceback (most recent call last):
  File "test.py", line 25, in <module>
    a = jt.nn.Pool(kernel_size=-1,stride=1,padding=-1,op=0)(jt.random((1,3,3,5)))# crash
  File "/jittor/python/jittor/__init__.py", line 1184, in __call__
    return self.execute(*args, **kw)
  File "/jittor/python/jittor/pool.py", line 184, in execute
    f"i3*{self.stride[1]}-{self.padding[1]}+i5", # Wid
RuntimeError: Wrong inputs arguments, Please refer to examples(help(jt.reindex)).

Types of your inputs are:
 self   = Var,
 args   = (list, list, ),

The function declarations are:
 VarHolder* reindex(VarHolder* x,  NanoVector shape,  vector<string>&& indexes,  float64 overflow_value=0,  vector<string>&& overflow_conditions={}, vector<VarHolder*>&& extras={})
 VarHolder* reindex_(VarHolder* x, vector<VarHolder*>&& indexes,  float64 overflow_value=0,  vector<string>&& overflow_conditions={})

Failed reason:[f 0508 14:01:24.074261 72 parallel_compiler.cc:331] Error happend during compilation:
 [Error] source file location:/root/.cache/jittor/jt1.3.9/g++8.3.0/py3.7.4/Linux-5.15.153x56/13thGenIntelRCx56/8c5a/master/jit/__opkey0_reindex__Tx_float32__XDIM_4__YDIM_6__OVERFLOW_itof_0x0___INDEX0_i0__INDEX1_i1__IN___hash_c67001a5e6ed8c7f_op.cc
Compile fused operator(1/2)failed:[Op(3:1:1:1:i1:o1:s0:g1,reindex->4),]

Reason: [f 0508 14:01:24.073435 24:C1 expr.cc:394] Op -- 1 1 not support

Pool3d:

[i 0508 14:02:18.992094 68 compiler.py:956] Jittor(1.3.9.6) src: /jittor/python/jittor
[i 0508 14:02:18.994802 68 compiler.py:957] g++ at /usr/bin/g++(8.3.0)
[i 0508 14:02:18.994864 68 compiler.py:958] cache_path: /root/.cache/jittor/jt1.3.9/g++8.3.0/py3.7.4/Linux-5.15.153x56/13thGenIntelRCx56/8c5a/master
[i 0508 14:02:18.998582 68 __init__.py:412] Found addr2line(2.31.1) at /usr/bin/addr2line.
[i 0508 14:02:19.217992 68 __init__.py:227] Total mem: 15.43GB, using 5 procs for compiling.
[i 0508 14:02:19.290748 68 jit_compiler.cc:28] Load cc_path: /usr/bin/g++
Traceback (most recent call last):
  File "test.py", line 28, in <module>
    a(jt.random((1,3,3,5,5))) #crash
  File "/jittor/python/jittor/__init__.py", line 1184, in __call__
    return self.execute(*args, **kw)
  File "/jittor/python/jittor/pool.py", line 373, in execute
    '''])
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 0508 14:02:19.420311 68 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,3,-3,-5,-5,]

pool3d:

[i 0508 14:02:48.070988 64 compiler.py:956] Jittor(1.3.9.6) src: /jittor/python/jittor
[i 0508 14:02:48.074452 64 compiler.py:957] g++ at /usr/bin/g++(8.3.0)
[i 0508 14:02:48.074508 64 compiler.py:958] cache_path: /root/.cache/jittor/jt1.3.9/g++8.3.0/py3.7.4/Linux-5.15.153x56/13thGenIntelRCx56/8c5a/master
[i 0508 14:02:48.079277 64 __init__.py:412] Found addr2line(2.31.1) at /usr/bin/addr2line.
[i 0508 14:02:48.311457 64 __init__.py:227] Total mem: 15.43GB, using 5 procs for compiling.
[i 0508 14:02:48.384500 64 jit_compiler.cc:28] Load cc_path: /usr/bin/g++
Traceback (most recent call last):
  File "test.py", line 30, in <module>
    a = jt.nn.pool3d(kernel_size=-1,stride=1,op=jt.random((1,3,4,5,5)),x=jt.random((1,3,4,5,5)))
  File "/jittor/python/jittor/pool.py", line 517, in pool3d
    return Pool3d(kernel_size, stride, padding, op=op)(x)
  File "/jittor/python/jittor/__init__.py", line 1184, in __call__
    return self.execute(*args, **kw)
  File "/jittor/python/jittor/pool.py", line 215, in execute
    use_code_op = self.op in ['maximum', 'minimum']
RuntimeError: Wrong inputs arguments, Please refer to examples(help(jt.__richcmp__)).

Types of your inputs are:
 self   = Var,
 b      = str,

The function declarations are:
 VarHolder* less(VarHolder* x, VarHolder* y)
 VarHolder* less_equal(VarHolder* x, VarHolder* y)
 VarHolder* greater(VarHolder* x, VarHolder* y)
 VarHolder* greater_equal(VarHolder* x, VarHolder* y)
 VarHolder* equal(VarHolder* x, VarHolder* y)
 VarHolder* not_equal(VarHolder* x, VarHolder* y)

Failed reason:[f 0508 14:02:48.508174 64 pyjt_jit_op_maker.cc:15628] Not a valid call.

Minimal Reproduce

pool:

import jittor as jt
from jittor import *
pool = jt.nn.pool(kernel_size=-1,stride=1,op=jt.random((1,3,4,5)),x=jt.random((1,3,4,5))) #crash
pool(jt.random((1,3,5,5,5)),0) 

Pool:

import jittor as jt
from jittor import *
Pool = jt.nn.Pool(kernel_size=-1,stride=1,padding=-1,op=0)(jt.random((1,3,3,5)))# crash

Pool3d:

Pool3d = jt.nn.Pool3d(kernel_size=-1,stride=-1)
Pool3d(jt.random((1,3,3,5,5))) #crash

pool3d:

pool3d = jt.nn.pool3d(kernel_size=-1,stride=1,op=jt.random((1,3,4,5,5)),x=jt.random((1,3,4,5,5)))
pool3d(jt.random((1,3,5,5,5)),0) #crash

Expected behavior

The main reason for these crashes may be that the same underlying processing function of the jt.nn.pool/Pool/Pool3d/pool3d does not do boundary detection for kernel_size=-1, stride=-1,padding=-1, etc.