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.07k stars 307 forks source link

Crash with error happend during compilatio in `jt.nn.ReflectionPad2d/ReplicationPad2d` #525

Closed x0w3n closed 3 months ago

x0w3n commented 3 months ago

Describe the bug

The padding parameter of jt.nn.ReflectionPad2d/ReplicationPad2d accepts negative values and causes a crash

Full Log

ReflectionPad2d:

[i 0512 07:46:40.913512 64 compiler.py:956] Jittor(1.3.9.6) src: /jittor/python/jittor
[i 0512 07:46:40.915434 64 compiler.py:957] g++ at /usr/bin/g++(8.3.0)
[i 0512 07:46:40.915489 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 0512 07:46:40.926834 64 __init__.py:412] Found addr2line(2.31.1) at /usr/bin/addr2line.
[i 0512 07:46:41.259475 64 __init__.py:227] Total mem: 15.43GB, using 5 procs for compiling.
[i 0512 07:46:41.490990 64 jit_compiler.cc:28] Load cc_path: /usr/bin/g++
Traceback (most recent call last):
  File "test.py", line 35, in <module>
    jt.nn.ReflectionPad2d(padding=-83538626022206)(jt.random((1,3,4,5)))
  File "/jittor/python/jittor/__init__.py", line 1184, in __call__
    return self.execute(*args, **kw)
  File "/jittor/python/jittor/nn.py", line 1657, in execute
    f"i3<{l} ? {l}-i3 : i3 > {r} ? {w-1+r}-i3 : i3-{l}",
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 0512 07:46:41.883687 64 nano_vector.h:107] Check failed: s<10 && next_offset<=64  Something wrong... Could you please report this issue?

ReplicationPad2d:

[i 0512 07:47:03.425915 00 compiler.py:956] Jittor(1.3.9.6) src: /jittor/python/jittor
[i 0512 07:47:03.427885 00 compiler.py:957] g++ at /usr/bin/g++(8.3.0)
[i 0512 07:47:03.428018 00 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 0512 07:47:03.431493 00 __init__.py:412] Found addr2line(2.31.1) at /usr/bin/addr2line.
[i 0512 07:47:03.649032 00 __init__.py:227] Total mem: 15.43GB, using 5 procs for compiling.
[i 0512 07:47:03.717101 00 jit_compiler.cc:28] Load cc_path: /usr/bin/g++
Traceback (most recent call last):
  File "test.py", line 39, in <module>
    jt.nn.ReplicationPad2d(padding=-83538626022206)(jt.random((1,3,4,5)))
  File "/jittor/python/jittor/__init__.py", line 1184, in __call__
    return self.execute(*args, **kw)
  File "/jittor/python/jittor/nn.py", line 1725, in execute
    f"i3<{l} ? 0 : i3 > {r} ? {w-1} : i3-{l}"
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 0512 07:47:03.834228 00 nano_vector.h:107] Check failed: s<10 && next_offset<=64  Something wrong... Could you please report this issue?

Minimal Reproduce

ReflectionPad2d:

import jittor as jt
from jittor import *
jt.nn.ReflectionPad2d(padding=-83538626022206)(jt.random((1,3,4,5)))

ReplicationPad2d:

import jittor as jt
from jittor import *
jt.nn.ReplicationPad2d(padding=-83538626022206)(jt.random((1,3,4,5)))

Expected behavior

The padding parameter of jt.nn.ReflectionPad2d/ReplicationPad2d needs to be checked for boundary values and should be replaced with runtime error instead of direct crash.

LDYang694 commented 3 months ago

Thanks for the advice. We have fixed it in our latest code.