somaticio / tensorflow.rb

tensorflow for ruby
BSD 3-Clause "New" or "Revised" License
829 stars 63 forks source link

FFI backend #90

Open headius opened 7 years ago

headius commented 7 years ago

This is for #89.

I have taken the approach of simply swapping the FFI bindings in for the ext bindings and replacing any C wrappers around the TensorFlow API with Ruby+FFI versions of the same code.

So far things are working ok, but I'm stuck with a segfault (0x00 mem access) that I can't figure out. A call to TF_SetAttrTensor with a tensor created by the wrapper String_encoder method seems to be improperly initialized, later blowing up somewhere near Status::SlowCopyFrom in TensorFlow itself via a 0x0 pointer access.

There's also a small tweak to the generated code to modify the TF_StringEncode binding to have an out parameter for the destination. This will need some tweaks to ffi_gen to avoid, and there are likely other cases.

The segv I get is here...maybe someone will be able to help: https://gist.github.com/headius/752eb916bd3a9d39f2574a5a5f06d1f5

Obviously a lot more work to do here but I'm pleased with how far I got.

arafatkatze commented 7 years ago

@headius Thanks a lot for doing this.
I will look at this tomorrow and see if I come up with something.
I have faced the exact same issue that you are referring to and it bugged me a lot so I will try to see it.

Thanks again, This is cool.

pavel-jurasek commented 7 years ago

I will look at that

nusco commented 5 years ago

Any news on this? It's a pity that this project is falling back, and FFI seems like the way forward.

illtellyoulater commented 5 years ago

Or maybe this is the way to go?

TensorStream, a pure ruby machine learning framework (with OpenCL support) based on TensorFlow.

https://github.com/jedld/tensor_stream

https://medium.com/@joseph.dayo/tensorstream-bringing-machine-learning-to-ruby-114582060e3d

headius commented 3 years ago

TensorStream, a pure ruby machine learning framework (with OpenCL support) based on TensorFlow.

I never noticed this comment but I wanted to point out that TensorStream is not actually wrapping TensorFlow like this library does, and only supports the OpenCL backend on CRuby anyway (pure-Ruby on other impls).

akostadinov commented 1 year ago

How about https://github.com/ankane/tensorflow-ruby ?