ExecuTorch Ruby
Run PyTorch models in Ruby.
ExecuTorch is Meta's lightweight runtime for deploying PyTorch models on edge devices. This gem provides Ruby bindings so you can run exported models ( .pte files) directly in your Ruby applications.
Quick Start
require "executorch" # Load a model model = Executorch :: Model . new ( "model.pte" ) # Create input tensor input = Executorch :: Tensor . new ( [ [ 1.0 , 2.0 , 3.0 ] ] ) # Run inference output = model . predict ( [ input ] ) . first puts output . to_a # => [[3.0, 5.0, 7.0]]
Installation
Requirements: Ruby 3.0+, macOS or Linux, C++17 compiler
Step 1: Build ExecuTorch
ExecuTorch must be built from source. Follow the official guide, or use these commands:
git clone https://github.com/pytorch/executorch.git cd executorch ./install_requirements.sh cmake -B cmake-out \ -DCMAKE_INSTALL_PREFIX=vendor/executorch \ -DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \ -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \ -DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \ -DCMAKE_BUILD_TYPE=Release cmake --build cmake-out -j4 cmake --install cmake-out
... continue reading