LaurentMazare / ocaml-torch

OCaml bindings for PyTorch
Apache License 2.0
412 stars 38 forks source link

Tensor.randn fails for small matrices #46

Closed crackcomm closed 4 years ago

crackcomm commented 4 years ago

Hi. I have a problem with creating small matrices using randn:

let t = Tensor.randn [ 3; 4 ] in
Tensor.print t

It does not work for sizes smaller than 16. Built with libtorch 1.5.0 that's linked in README.

Strace:

openat(AT_FDCWD, "/dev/urandom", O_RDONLY) = 3
read(3, "N*\273\201\7\204\226z", 8)     = 8
close(3)                                = 0
--- SIGILL {si_signo=SIGILL, si_code=ILL_ILLOPN, si_addr=0x7fdd32008823} ---
+++ killed by SIGILL +++
Illegal instruction

Entire valgrind log.

In the meantime I can do that successfully:

let from = 0.0 and to_ = 1.0 in
Tensor.zeros ~requires_grad:false [ 3 ]
|> Tensor.uniform_ ~from ~to_
|> Tensor.print

Also a question, how can I run tests in ocaml-torch?

Edit: It's highly likely that the libtorch is compiled with SSE4 or other that my CPU doesn't support.

LaurentMazare commented 4 years ago

I've never encountered this kind of error but "illegal instruction" usually refers to your cpu not supporting some extension used by the library (as per your edit). Maybe you should recompile pytorch from source or try on another platform?

crackcomm commented 4 years ago

I will close since it seems like it was a library compiled with unsupported instructions.