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 Step 2: Install the Gem Tell Bundler where ExecuTorch is installed (only needed once per project): bundle config set --local build.executorch --with-executorch-dir=vendor/executorch Add to your Gemfile: gem "executorch" Then: bundle install CI/CD: Use the environment variable instead: EXECUTORCH_DIR=/path/to/executorch bundle install Usage Tensors Create tensors from nested arrays (shape is inferred): # 2D tensor, shape [2, 3] tensor = Executorch :: Tensor . new ( [ [ 1.0 , 2.0 , 3.0 ] , [ 4.0 , 5.0 , 6.0 ] ] ) # With explicit dtype tensor = Executorch :: Tensor . new ( [ [ 1 , 2 ] , [ 3 , 4 ] ] , dtype : :long ) # Inspect tensor . shape # => [2, 3] tensor . dtype # => :float tensor . to_a # => [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]] Or from flat arrays with explicit shape: tensor = Executorch :: Tensor . new ( [ 1.0 , 2.0 , 3.0 , 4.0 ] , shape : [ 2 , 2 ] ) Supported dtypes: :float (default), :double , :int , :l...
First seen: 2026-01-14 01:07
Last seen: 2026-01-14 01:07