Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Program Crash on generating simple data. #3082

Open
mytechnotalent opened this issue Jun 19, 2024 · 1 comment
Open

[BUG] Program Crash on generating simple data. #3082

mytechnotalent opened this issue Jun 19, 2024 · 1 comment
Labels
bug Something isn't working mojo-repo Tag all issues with this label

Comments

@mytechnotalent
Copy link

mytechnotalent commented Jun 19, 2024

Bug description

main

fn main() raises:
    try:
        # generate simple dataset
        var simple_data = generate_simple_data(100)
        var X = simple_data [0]
        var y = simple_data [1]
    except e:
        print("Error during execution:", e)
        raise e

calling function

fn generate_simple_data(num_samples: Int) -> (PythonObject, PythonObject):
   try:
       var numpy = Python.import_module("numpy")
       var torch = Python.import_module("torch")

       # Generate random X and y
       var X = numpy.random.rand(num_samples, 2).astype(numpy.float32)  # Random 2D points
       var y = numpy.random.randint(0, 2, num_samples, dtype=numpy.int64)  # Random integer labels (0 or 1)

       var X_tensor = torch.tensor(X)
       var y_tensor = torch.tensor(y)

       return (X_tensor, y_tensor)

   except e:
       print("Error generating simple data:", e)
       var the_number: Int = 0
       var the_py_object = PythonObject(the_number)
       return the_py_object, the_py_object
       ```

### Steps to reproduce

`mojo main.mojo`
```mojo main.mojo
Please submit a bug report to https://github.com/modularml/mojo/issues and include the crash backtrace along with all the relevant source codes.
Stack dump:
0. Program arguments: mojo main.mojo
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0 mojo 0x0000000100e28c24 llvm_strlcpy + 51480
1 mojo 0x0000000100e26f10 llvm_strlcpy + 44036
2 mojo 0x0000000100e292c4 llvm_strlcpy + 53176
3 libsystem_platform.dylib 0x000000018fc5f584 _sigtramp + 56
4 Python 0x000000010acafa30 PyObject_ClearWeakRefs + 428
5 libtorch_python.dylib 0x000000010ccad8ec THPVariable_subclass_dealloc(_object*) + 116
6 libtorch_python.dylib 0x0000000300078110 THPVariable_subclass_dealloc(_object*) + 8375806104
7 mojo 0x00000001011bd530 __jit_debug_register_code + 1041480
8 mojo 0x0000000100d8956c
9 mojo 0x0000000100d88f60
10 mojo 0x0000000100d71960
11 dyld 0x000000018f8a60e0 start + 2360
mojo crashed!
Please file a bug report.
[43289:1154932:20240619,181329.323794:WARNING in_range_cast.h:38] value -97304226 out of range
[43289:1154932:20240619,181329.327035:WARNING crash_report_exception_handler.cc:257] UniversalExceptionRaise: (os/kern) failure (5)
zsh: segmentation fault mojo main.mojo```

### System information

```shell
- What OS did you do install Mojo on MAC M3
- Provide version information for Mojo by pasting the output of `mojo 24.4.0 (2cb57382)`
- Provide Modular CLI version by pasting the output of `modular 0.8.0 (39a426b5)`
@mytechnotalent mytechnotalent added bug Something isn't working mojo-repo Tag all issues with this label labels Jun 19, 2024
@soraros
Copy link
Contributor

soraros commented Jun 19, 2024

Smaller repro:

from python import Python, PythonObject

def f() -> Tuple[PythonObject]:
    var np = Python.import_module("numpy")
    return np.array([0])

def main():
    var t = f()
    var y = t[0]
    print(y)

I doubt if NumPy is relevant, however, I wasn't able reduce it away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mojo-repo Tag all issues with this label
Projects
None yet
Development

No branches or pull requests

2 participants