✨ From vibe coding to vibe deployment. UBOS MCP turns ideas into infra with one message.

Learn more
Andrii Bidochko
  • Updated: January 18, 2026
  • 6 min read

ExecuTorch Ruby Integration Brings AI Capabilities to Ruby Developers

ExecuTorch Ruby is a Ruby gem that enables developers to run Meta’s lightweight ExecuTorch runtime and execute exported PyTorch models (.pte files) directly inside Ruby applications.

ExecuTorch Ruby Integration: A Complete News Summary for Ruby Developers

On GitHub the ExecuTorch Ruby repository has just been updated with new releases, documentation improvements, and community‑driven examples. This article distills the key features, installation steps, and real‑world use cases, while weaving in relevant resources from the UBOS homepage to help you accelerate AI‑powered Ruby projects.

Project Overview & Core Features

The ExecuTorch Ruby gem bridges the gap between Ruby’s expressive syntax and the high‑performance inference engine built by Meta. Below are the most compelling capabilities:

  • Native Ruby bindings for ExecuTorch’s C++ core, exposing Model and Tensor classes.
  • Support for multiple data types (float, double, int, long) and automatic shape inference.
  • Simple model loading from .pte files generated via PyTorch’s torch.export workflow.
  • Full GPU‑optional inference on edge devices where C++17 compilers are available.
  • Compatibility with Ruby 3.0+ on macOS and Linux, making it ideal for modern web services and background workers.

These features empower Ruby developers to embed sophisticated machine‑learning pipelines without leaving the Ruby ecosystem.

Installation & Quick‑Start Guide

Prerequisites

Before you begin, ensure you have the following:

  • Ruby 3.0 or newer
  • A C++17‑compatible compiler (gcc 9+, clang 10+)
  • Git and CMake installed
  • Access to a Linux or macOS development environment

Step‑by‑Step Installation

  1. Clone and build ExecuTorch:
    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
  2. Configure Bundler to locate ExecuTorch:
    bundle config set --local build.executorch --with-executorch-dir=vendor/executorch
  3. Add the gem to your Gemfile:
    gem "executorch"
  4. Install dependencies:
    bundle install

First Inference in Ruby

Once installed, running a model is a matter of a few lines of code:

require "executorch"

# Load the exported .pte model
model = Executorch::Model.new("model.pte")

# Create an input tensor (shape inferred automatically)
input = Executorch::Tensor.new([[1.0, 2.0, 3.0]])

# Perform inference
output = model.predict([input]).first

puts output.to_a   # => [[3.0, 5.0, 7.0]]

This snippet demonstrates the gem’s simplicity: load, tensorize, predict, and read the result.

Why Ruby Developers Should Care – Benefits & Real‑World Use Cases

Key Benefits

  • Speed on the Edge: ExecuTorch’s lightweight runtime reduces latency compared to full PyTorch installations.
  • Unified Stack: Keep your web API, background jobs, and ML inference in a single Ruby codebase.
  • Cost Efficiency: No need for heavyweight GPU servers; inference can run on modest CPUs.
  • Open‑Source Flexibility: Apache‑2.0 license lets you modify and redistribute the gem freely.

Typical Use Cases

  1. Real‑time recommendation engines embedded in Rails e‑commerce platforms.
  2. Edge‑device analytics for IoT gateways written in Ruby.
  3. Automated content moderation pipelines that score text or images before storage.
  4. Personalized email subject line generation using lightweight models served directly from a Rails worker.

For developers looking to combine AI with existing Ruby services, the ExecuTorch Ruby gem is a natural fit.

Illustration: Visualizing ExecuTorch Ruby Workflow

ExecuTorch Ruby workflow diagram

Figure: A high‑level diagram showing how a Ruby application loads an ExecuTorch model, creates tensors, and receives inference results.

Related UBOS Resources to Accelerate Your AI Projects

UBOS offers a suite of tools that complement the ExecuTorch Ruby workflow. Below are hand‑picked resources you can explore:

Deep Dive: Tensor Handling & Model Export

Understanding how tensors are marshaled between Ruby and the C++ ExecuTorch core is essential for performance tuning.

Creating Tensors

ExecuTorch Ruby infers shape automatically from nested Ruby arrays, but you can also specify shape explicitly for flat arrays:

# Implicit shape
tensor = Executorch::Tensor.new([[1.0, 2.0], [3.0, 4.0]])

# Explicit shape for a flat array
tensor = Executorch::Tensor.new([1, 2, 3, 4], shape: [2, 2], dtype: :long)

Exporting from PyTorch

Use the official torch.export API to generate a .pte file compatible with ExecuTorch:

import torch
from executorch.exir import to_edge

class SimpleModel(torch.nn.Module):
    def forward(self, x):
        return x * 2 + 1

model = SimpleModel()
example = torch.randn(1, 3)
et_program = to_edge(torch.export.export(model, (example,))).to_executorch()

with open("model.pte", "wb") as f:
    et_program.write_to_file(f)

Once you have model.pte, the Ruby side can load it instantly as shown earlier.

Troubleshooting & FAQ

“ExecuTorch installation not found”

Verify the path you passed to Bundler. The directory vendor/executorch/include/executorch must exist. Re‑run the build steps if the folder is missing.

Missing header errors

Make sure you built ExecuTorch with the required extensions:

cmake -B cmake-out \
  -DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
  -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
  -DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON

Undefined symbols at runtime

Link additional libraries via the EXECUTORCH_EXTRA_LIBS environment variable, e.g., portable_ops_lib,portable_kernels.

“The most common pitfall is forgetting to set the EXECUTORCH_DIR environment variable in CI pipelines. Adding it to your CI config resolves the issue instantly.” – Ruby AI resources

Get Started Today

If you’re a Ruby developer eager to embed AI, the ExecuTorch Ruby gem offers a production‑ready path. Combine it with UBOS’s low‑code platform, leverage pre‑built templates like the AI SEO Analyzer, and accelerate time‑to‑value.

Visit the official repository to clone the code, read the full documentation, and contribute back to the community.

Ready to power your Ruby apps with on‑device AI? Explore the UBOS partner program and start building smarter solutions today.


Andrii Bidochko

CTO UBOS

Andrii Bidochko is an AI entrepreneur and researcher focused on AI agents, reinforcement learning, and autonomous systems. He writes about the technologies shaping the future of machine intelligence, from frontier models and agent architectures to real-world AI applications.

Sign up for our newsletter

Stay up to date with the roadmap progress, announcements and exclusive discounts feel free to sign up with your email.

Sign In

Register

Reset Password

Please enter your username or email address, you will receive a link to create a new password via email.