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.zeros/ones/full` #527

Closed x0w3n closed 3 months ago

x0w3n commented 3 months ago

Describe the bug

A crash is triggered when setting a negative value for parameter of jt.zeros/ones/full, resulting in error happend during compilation.

Full Log

zeros:

[i 0512 07:56:47.812575 32 compiler.py:956] Jittor(1.3.9.6) src: /jittor/python/jittor
[i 0512 07:56:47.814704 32 compiler.py:957] g++ at /usr/bin/g++(8.3.0)
[i 0512 07:56:47.814764 32 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:56:47.826690 32 __init__.py:412] Found addr2line(2.31.1) at /usr/bin/addr2line.
[i 0512 07:56:48.171551 32 __init__.py:227] Total mem: 15.43GB, using 5 procs for compiling.
[i 0512 07:56:48.397233 32 jit_compiler.cc:28] Load cc_path: /usr/bin/g++
Traceback (most recent call last):
  File "test.py", line 54, in <module>
    x = jt.zeros((2, -3))
  File "/jittor/python/jittor/__init__.py", line 518, in zeros
    return unary(0, dtype).broadcast(shape)
RuntimeError: Wrong inputs arguments, Please refer to examples(help(jt.broadcast)).

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

The function declarations are:
 VarHolder* broadcast_to(VarHolder* x,  NanoVector shape,  NanoVector dims=NanoVector())
 VarHolder* broadcast_to_(VarHolder* x, VarHolder* y,  NanoVector dims=NanoVector())

Failed reason:[f 0512 07:56:48.781391 32 broadcast_to_op.cc:86] Check failed v(-3) >= 0u(0) Shape should greater than 0.

ones:

[i 0512 07:57:06.555178 56 compiler.py:956] Jittor(1.3.9.6) src: /jittor/python/jittor
[i 0512 07:57:06.558078 56 compiler.py:957] g++ at /usr/bin/g++(8.3.0)
[i 0512 07:57:06.558192 56 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:57:06.561714 56 __init__.py:412] Found addr2line(2.31.1) at /usr/bin/addr2line.
[i 0512 07:57:06.783172 56 __init__.py:227] Total mem: 15.43GB, using 5 procs for compiling.
[i 0512 07:57:06.851099 56 jit_compiler.cc:28] Load cc_path: /usr/bin/g++
Traceback (most recent call last):
  File "test.py", line 56, in <module>
    x = jt.ones((2, -3))
  File "/jittor/python/jittor/__init__.py", line 487, in ones
    return unary(1, dtype).broadcast(shape)
RuntimeError: Wrong inputs arguments, Please refer to examples(help(jt.broadcast)).

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

The function declarations are:
 VarHolder* broadcast_to(VarHolder* x,  NanoVector shape,  NanoVector dims=NanoVector())
 VarHolder* broadcast_to_(VarHolder* x, VarHolder* y,  NanoVector dims=NanoVector())

Failed reason:[f 0512 07:57:06.963078 56 broadcast_to_op.cc:86] Check failed v(-3) >= 0u(0) Shape should greater than 0.

full:

[i 0512 07:59:05.006199 76 compiler.py:956] Jittor(1.3.9.6) src: /jittor/python/jittor
[i 0512 07:59:05.008881 76 compiler.py:957] g++ at /usr/bin/g++(8.3.0)
[i 0512 07:59:05.008952 76 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:59:05.013408 76 __init__.py:412] Found addr2line(2.31.1) at /usr/bin/addr2line.
[i 0512 07:59:05.233204 76 __init__.py:227] Total mem: 15.43GB, using 5 procs for compiling.
[i 0512 07:59:05.301923 76 jit_compiler.cc:28] Load cc_path: /usr/bin/g++
Traceback (most recent call last):
  File "test.py", line 58, in <module>
    x = jt.full(val=-3,shape=(3,-3))
  File "/jittor/python/jittor/__init__.py", line 550, in full
    return unary(val, dtype).broadcast(shape)
RuntimeError: Wrong inputs arguments, Please refer to examples(help(jt.broadcast)).

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

The function declarations are:
 VarHolder* broadcast_to(VarHolder* x,  NanoVector shape,  NanoVector dims=NanoVector())
 VarHolder* broadcast_to_(VarHolder* x, VarHolder* y,  NanoVector dims=NanoVector())

Failed reason:[f 0512 07:59:05.413957 76 broadcast_to_op.cc:86] Check failed v(-3) >= 0u(0) Shape should greater than 0.

Minimal Reproduce

zeros:

import jittor as jt
from jittor import *
a  = jt.randn([[ 2.7771e+38, -1.7855e+38]])

ones:

import jittor as jt
from jittor import *
x = jt.ones((2, -3))

full:

import jittor as jt
from jittor import *
x = jt.full(val=-3,shape=(3,-3))

Expected behavior

These boundary value cases need to be checked and should be replaced with runtime error instead of direct crash.