reflop

module
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2026 License: Apache-2.0

README

reFLOP

CI Release

PyTorch C Go

Linux macOS

Lend your GPU as a calculator.

Guests send tensor math. Never code execution, never shell access.

Install · Quick Start · How it works · Security · Docs


Owner Guest
Has the GPU workstation (Linux) a laptop (macOS or Linux, no CUDA needed)
Runs reflopd their own PyTorch code, unchanged except for the device
Gets a GPU that stays busy, and a machine that stays theirs the GPU's FLOPs, and nothing else

Run your PyTorch code with a simple prefix.

reflop run python train.py    # device="cuda"

Or embed reflop in your code, and simply run python3 train.py.

import torch, reflop

dev = reflop.device()          # the GPU on the Owner's workstation
model = MyModel().to(dev)      # weights live on the server

for x, y in loader:
    loss = loss_fn(model(x.to(dev)), y.to(dev))
    loss.backward()
    opt.step(); opt.zero_grad()
    print(loss.item())         # only this number comes back

[!IMPORTANT] The server never runs Guest code. It accepts graphs over a closed set of 582 operators (571 PyTorch overloads, 11 reFLOP-native), validates them, and runs them in a sandboxed worker. No request can say "delete a file", "open a socket" or "start a process", so a Guest can't do any of those.

Install

Side Platform Needs
Owner installs reflopd Linux x86_64 or aarch64, glibc ≥ 2.28 nothing: no root, no Docker, no Python. NVIDIA driver ≥ 525 is optional (without a GPU, reflopd serves the CPU)
Guest installs reflop macOS (Apple Silicon or Intel) or Linux Python ≥ 3.10, PyTorch ≥ 2.6

Guest : reflop

Add the client to the environment your training code runs in

  • uv or pip
# Recommended
uv add reflop

# or
pip install reflop

This installs both the Python library (import reflop) and the reflop command in that environment.

  • Install script
curl -fsSL https://raw.githubusercontent.com/reflopai/reflop/main/install.sh | sh

The script installs into the active virtual environment if there is one, otherwise into an environment of its own.


Owner : reflopd

On the GPU workstation

  • Install script
curl -fsSL https://raw.githubusercontent.com/reflopai/reflop/main/install.sh | sh -s -- --server

reflopd goes to ~/.local/bin.

The download is checked against the release's SHA-256 sums, and the sums against a signature made with the project's offline release key (the check uses ssh-keygen, OpenSSH 8.1 or newer).


Update
reflop update      # Guest
reflopd update     # Owner

Each one updates only its own program to the newest release, after checking the release signature.

In a uv project, reflop update upgrades reflop in uv.lock and syncs, so uv run keeps the new version.

In a pip environment it installs the release's wheel. pip install -U reflop and uv lock --upgrade-package reflop && uv sync also work. The files on PyPI are the files of the signed GitHub release.

From the Releases tab

Download reflopd_0.2.2_linux_<arch>.tar.gz or reflop-0.2.2-py3-none-any.whl from Releases with checksums.txt and checksums.txt.sig. Check the signature, then the file:

echo 'reflop-release ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKqs9C0dx4nGfqCL1Vw0hgwleOGNaDOPYyMBCwYU3lsW' > allowed_signers
ssh-keygen -Y verify -f allowed_signers -I reflop-release -n reflop-release -s checksums.txt.sig < checksums.txt
sha256sum --check --ignore-missing checksums.txt

Then put reflopd on your PATH or pip install the wheel.

Build from source

Requires Go (see go.mod) and, for the client, Python 3.10+:

git clone https://github.com/reflopai/reflop.git && cd reflop
make build                                  # bin/reflopd, with the worker embedded
pip install ./client/python                 # the reFLOP client

Quick Start

Owner side reflopd

# 1) Set up and start (rootless).
reflopd up --listen <LAN-or-Tailscale-addr>:7460

# 2) One invite per Guest, prints the one-time pairing code
reflopd invite --name alice

Guest side reflop

# 3) Pair once (the server key gets pinned), then check
reflop pair reflop1-baaraai2b4…
reflop status

# 4) Train your model
python reflop_train.py          # Embed `reflop` in code
reflop run python train.py      # Or just add a prefix command

How it works

Usually your whole program is copied to the remote machine and Python runs there. With reFLOP, Python runs on your machine and only the tensor operations cross over, to a GPU in a sandbox.

Step Where What happens
1. Record Guest Every PyTorch operation on a reflop tensor is recorded instead of run. Shapes and dtypes are computed locally, so shape-dependent code needs no round trip.
2. Send Guest → Owner loss.item(), print(t) or .cpu() turns the recording into one graph. The graph is sent once; later steps send only its hash and the new inputs.
3. Validate Owner Strict decoding, the operator whitelist, schema and argument checks, shape inference on meta tensors, and a peak-memory estimate against the GPU's size, all before any GPU memory is allocated. Index arguments are bounds-checked before each kernel launches.
4. Run Owner One worker process per session, with no network, no exec, no fork, and no access to the Owner's files. Weights and optimizer state stay on the server between steps.
5. Return Owner → Guest Only what you asked for. Usually a few bytes: the loss.

What the Owner is protected from

A Guest tries to What happens
run a shell, a script, a pip package, a CUDA kernel there is no request type for it; only whitelisted operators exist
read ~/.ssh, the browser profile, other Guests' data the worker's Landlock domain covers only its own scratch directory
open a socket, connect to localhost, exec, fork, ptrace seccomp denies it after warm-up
index out of bounds to read GPU memory bounds are checked before the kernel launches
read stale GPU memory with torch.empty allocation-only operators return zeros
fill the disk or exhaust host RAM safety rails: disk keeps max(10%, 20 GiB) free, host RAM keeps 4 GiB
hog the GPU reflopd pause, kill, yield --auto; optional quotas
impersonate the server the client pins the server key at pairing and refuses a different one

[!TIP] reflopd doctor shows which protections are active on your machine, and reflopd selftest --security checks them on a live worker. Details: threat model.

Datasets

Decode and preprocess on your laptop, upload once, then send only batch indices:

reflop data build --from my_data:load --out ./cifar_pack   # runs your code locally
reflop data push ./cifar_pack --name cifar10               # resumable, verified per 4 MiB chunk
ds = reflop.dataset("cifar10")
for batch in ds.loader(batch_size=128, shuffle=True, seed=0):
    x = batch["images"].float() / 255     # gathered on the server
    y = batch["labels"]

Fast steady-state training

Eager mode records every operation each step, which costs tens of microseconds per operation on the client. For steps whose graph does not change, reflop.capture replays the step on the server without running your Python:

step = reflop.capture(train_step)     # train_step(x, y) -> loss
for x, y in data:
    loss = step(x, y)                 # one request per step after two warm-up calls

ResNet-18, CIFAR-10 shapes, batch 128, RTX 5070, client on the same machine over TLS:

Mode Throughput vs plain PyTorch on the same GPU
reflop.capture 74%
eager 19%

See the multi-model benchmark report for the matched native GPU comparison from a MacBook Pro over Tailscale TLS, including correctness limitations, and benchmark/ to reproduce it.

Steps whose Python numbers change every step (a non-capturable Adam's bias correction, a Python learning-rate schedule) are detected and refused; use capturable=True or tensor learning rates.

More Information

reflopd status · top · audit who is connected, live memory and FLOPs, the audit log
reflopd pause · resume · kill alice · say "…" Owner controls
reflopd revoke alice · users delete alice cut a Guest off; then remove them and their data
reflopd unpair alice · reflop unpair both of those in one step; the Guest's side, so they can pair again
reflopd yield --auto pause Guests while you use the GPU yourself
reflopd quota set alice --device-memory 6GiB optional quotas (none by default)
reflopd rails show · rails set --ram 8GiB safety rails (always on)
reflopd invite --name bob --via ssh --key "ssh-ed25519 …" reuse sshd: a forced-command pipe, never a shell
sudo reflopd install --system move reflopd into a dedicated system account
reflop data build · push · ls · rm datasets
reflop verify cross-check small graphs against your CPU
with reflop.placement("local"): run part of the program on the client

Guides: Owner guide (setup, exposure, Level 1, SSH mode, rails, quotas, troubleshooting) · Guest guide (API, capture, datasets, placement, what works and what doesn't) · C and C++ API (libreflop for non-Python programs)

Design: Threat model · Design decisions · Spike report · Operator set

[!WARNING] Limitations

  • The Owner can see Guests' data and models. reFLOP protects the Owner's machine from Guests, not the other way around.
  • No arbitrary CPU programs, custom CUDA or Triton kernels, or server-side image and text decoding.
  • GPU results can differ bitwise from local runs (TF32, non-deterministic kernels).
  • Killing a worker loses its session state, unless the Guest uses checkpoints, which the Owner must allow.

All limitations

reFLOP vs recom

Use it for Access
recom your own remote machine full shell over SSH
reFLOP a GPU shared with people you don't fully trust whitelisted tensor operators only

Development

make build              # bin/reflopd
make test               # Go tests (race) and Python tests
make lint               # gofmt, go vet, ruff, and the I1/I2 static check
make build-probes       # test build with isolation probes (never ship it)
make test-isolation     # run the probes inside real sandboxed workers
make clib               # libreflop and the C/C++ examples

See CONTRIBUTING.md, SECURITY.md and the Code of Conduct.

License

Apache-2.0

Directories

Path Synopsis
clib
go command
Command libreflop builds the reFLOP C API as a shared library:
Command libreflop builds the reFLOP C API as a shared library:
pkg
opset
Package opset exposes opset v1 (generated from opset/v1/opset.yaml, the single source of truth, invariant I10) to Go code: reflopd and libreflop.
Package opset exposes opset v1 (generated from opset/v1/opset.yaml, the single source of truth, invariant I10) to Go code: reflopd and libreflop.
sshhost
Package sshhost handles the sshd host keys that SSH invites carry, so the Guest's ssh trusts exactly the host the Owner paired them with (SEC_SWEEP L6).
Package sshhost handles the sshd host keys that SSH invites carry, so the Guest's ssh trusts exactly the host the Owner paired them with (SEC_SWEEP L6).
wire
Package wire implements reflop framing: a uint32 big-endian length prefix followed by a protobuf message.
Package wire implements reflop framing: a uint32 big-endian length prefix followed by a protobuf message.
Package server embeds the Python worker into reflopd so that a single binary carries everything the Owner needs (PLAN.md §4.2).
Package server embeds the Python worker into reflopd so that a single binary carries everything the Owner needs (PLAN.md §4.2).
reflopd/cmd/reflopd command
Command reflopd is the reFLOP server daemon.
Command reflopd is the reFLOP server daemon.
reflopd/internal/audit
Package audit keeps an append-only, per-identity log of what Guests did (PLAN.md §9.9): registrations, executes, transfers, validation failures, rail hits and kills.
Package audit keeps an append-only, per-identity log of what Guests did (PLAN.md §9.9): registrations, executes, transfers, validation failures, rail hits and kills.
reflopd/internal/auth
Package auth manages the server key, Guest identities, invites, and the challenge-response authentication of PLAN.md §15 (ADR-006).
Package auth manages the server key, Guest identities, invites, and the challenge-response authentication of PLAN.md §15 (ADR-006).
reflopd/internal/buildinfo
Package buildinfo carries version metadata injected at build time with -ldflags "-X github.com/reflopai/reflop/server/reflopd/internal/buildinfo.Version=...".
Package buildinfo carries version metadata injected at build time with -ldflags "-X github.com/reflopai/reflop/server/reflopd/internal/buildinfo.Version=...".
reflopd/internal/cgroup
Package cgroup manages worker cgroups inside a delegated cgroup v2 subtree (systemd user service or scope with Delegate=yes, or the Level 1 system unit).
Package cgroup manages worker cgroups inside a delegated cgroup v2 subtree (systemd user service or scope with Delegate=yes, or the Level 1 system unit).
reflopd/internal/cli
Package cli implements the reflopd command line (PLAN.md §16.1).
Package cli implements the reflopd command line (PLAN.md §16.1).
reflopd/internal/config
Package config holds reflopd settings.
Package config holds reflopd settings.
reflopd/internal/gpu
Package gpu detects NVIDIA GPUs and the driver without loading CUDA in reflopd (reflopd never touches the GPU, PLAN.md §9.1).
Package gpu detects NVIDIA GPUs and the driver without loading CUDA in reflopd (reflopd never touches the GPU, PLAN.md §9.1).
reflopd/internal/paths
Package paths decides every server-side location.
Package paths decides every server-side location.
reflopd/internal/rails
Package rails implements the always-on safety rails of PLAN.md §9.6: a disk free floor on the store filesystem and a host RAM floor.
Package rails implements the always-on safety rails of PLAN.md §9.6: a disk free floor on the store filesystem and a host RAM floor.
reflopd/internal/runtime
Package runtime installs the pinned compute runtime: a standalone CPython plus PyTorch wheels whose SHA-256 hashes are embedded in this reflopd build (lock.json, generated by codegen/lock_runtime.py).
Package runtime installs the pinned compute runtime: a standalone CPython plus PyTorch wheels whose SHA-256 hashes are embedded in this reflopd build (lock.json, generated by codegen/lock_runtime.py).
reflopd/internal/selfupdate
Package selfupdate replaces the running reflopd binary with a published GitHub release.
Package selfupdate replaces the running reflopd binary with a published GitHub release.
reflopd/internal/server
Package server is reflopd's daemon: listeners, authentication, sessions, workers, rails, Owner controls and audit (PLAN.md §9).
Package server is reflopd's daemon: listeners, authentication, sessions, workers, rails, Owner controls and audit (PLAN.md §9).
reflopd/internal/sshpipe
Package sshpipe manages SSH pipe mode (PLAN.md §4.4, §15.4): the Guest's key goes into authorized_keys with restrict and a forced command, so SSH is a pipe that can only run `reflopd serve --stdio`, never a shell.
Package sshpipe manages SSH pipe mode (PLAN.md §4.4, §15.4): the Guest's key goes into authorized_keys with restrict and a forced command, so SSH is a pipe that can only run `reflopd serve --stdio`, never a shell.
reflopd/internal/store
Package store keeps each identity's TensorPacks content-addressed under a server-chosen path: <root>/<identity>/blobs/<sha256> (invariant I7).
Package store keeps each identity's TensorPacks content-addressed under a server-chosen path: <root>/<identity>/blobs/<sha256> (invariant I7).
reflopd/internal/supervisor
Package supervisor spawns, watches and kills sandboxed workers: one process per (identity, session), invariant I5.
Package supervisor spawns, watches and kills sandboxed workers: one process per (identity, session), invariant I5.
reflopd/internal/suspend
Package suspend moves a worker's GPU memory to host RAM and back with the CUDA driver's process checkpoint API (ADR-030).
Package suspend moves a worker's GPU memory to host RAM and back with the CUDA driver's process checkpoint API (ADR-030).
reflopd/internal/usage
Package usage accounts how much compute each Guest identity has used.
Package usage accounts how much compute each Guest identity has used.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL