How it fits together
sequence_ai.network is the connection between a robot and the GPU its policy runs on. On the robot, connect()
applies the client-side components to one connection. On the server, one_write and ping wrap a uvicorn or a WebSocket server. sequence_ai.engine
is the inference layer on the GPU: sequence serve serves a policy with the server's side of both layers on, optimize
shortens one inference with the speed-ups that keep its outputs exactly the same, batcher and slack share a GPU among robots, and replicas runs one process per GPU. bench/ measures a link before anything is added to it.
Install
pip install sequence-ai
The same package goes on the GPU and on the robot: Python 3.10 or later, on Linux or macOS (a robot can connect() from
3.9). The speed-ups use your model's own torch (2.4 or later) or JAX (0.4.30 or later).
sequence-ai, the open-source framework, is Apache-2.0. The install brings sequence-cloud with it, the client of
General Sequences' platform, under a proprietary license: only the platform needs it.
Quick start
No account, no key, no GPU: serve the toy policy on this machine and get an action from it.
sequence serve toy-policy
serving toy-policy on port 8000: a robot connects with sequence_ai.connect("http://<this machine>:8000", token="b2Kq9vX0sLwT7yRzN4hPgA")
It makes a token each time it starts, so nobody else who can reach the port runs the policy. Then, in a second terminal,
with the token it printed:
import sequence_ai
with sequence_ai.connect("http://127.0.0.1:8000", token="...") as policy_user: # the token it printed
policy_user.observe({"state": [0.0], "target": [0.5]}) # where the arm is, and where it should go
print(policy_user.act()) # {'delta': [0.1]}: one step toward the target
SEQ_SERVE_TOKEN set in both terminals gives them one of your own, and neither is told it again.
Your own policy: on the GPU - a CPU serves this one too - save this as policy.py in a folder of its own:
import numpy as np
import seq
@seq.policy(hz=15, action_chunk_valid_len=8, action_chunk_replan_at=5)
class QuickstartPolicy_user:
@seq.sample
def sample_user(self):
observation_user = {"image": np.zeros((224, 224, 3), dtype=np.uint8), "state": np.zeros(7, dtype=np.float32)}
return [("observe", observation_user), ("act",)] * 3 # an observation, then an act, three times
@seq.infer
def infer_user(self, observation_user):
frame_user = observation_user["image"] # your model here: the next 10 steps, 7 joints each
return {"actions": np.full((10, 7), float(frame_user.mean()), dtype=np.float32)}
Then serve it from that folder:
sequence serve
serving quickstart-policy-user on port 8000, each robot held and seated by its time at 15 Hz: a robot connects with sequence_ai.connect("http://<this machine>:8000", token="b2Kq9vX0sLwT7yRzN4hPgA")
On the robot:
import numpy as np
import sequence_ai
with sequence_ai.connect("http://127.0.0.1:8000", token="...") as policy_user: # your GPU's address, its token
policy_user.wait_until_ready() # once, before the robot moves
frame_user = np.zeros((224, 224, 3), dtype=np.uint8) # your camera's frame, streamed as video
policy_user.observe({"image": sequence_ai.Video(frame_user), "state": np.zeros(7, dtype=np.float32)})
print(policy_user.act()["actions"].shape) # (10, 7)
The robot plays 15 steps a second (hz), uses the first 8 steps of each chunk (action_chunk_valid_len), and asks for
the next chunk at step 5 (action_chunk_replan_at). Quickstart has the whole loop. Names ending in
_user are yours to change.
- An official template:
sequence init pi05-libero my_pi05_user, then sequence serve in that folder
(how).
- Both halves on one machine: in a clone of this repository,
export SEQ_SERVE_TOKEN=my-token_user, then sequence serve examples/quickstart_policy & python examples/quickstart_robot.py.
- A server you already run: its parts, one file each.
- What is on by default: each part, and how to turn it off.
- GPUs run for you: deploy the same folder to General Sequences.
The problem, by layer
A robot policy built on a vision-language-action (VLA) model runs each inference on a GPU, and a robot without a
suitable GPU on board sends its observations over a WAN to a remote one. Each layer of that path has its own problem.
The model is most of the latency. Across thirteen model and network configurations, the model is 68 to 96% of a
request's latency. The time of one inference is therefore the main lever, and optimize shortens it without changing
the model's output.
One robot leaves its GPU mostly idle. One robot keeps a GPU busy 21 to 55% of the time, so several robots can share
one, provided that no robot's action chunk runs out while its request waits. batcher batches the requests that are
waiting, slack computes how long each may wait and how many robots a replica can serve, and replicas runs one
replica per GPU.
A robot pauses, and Linux restarts its connection. A robot executes a chunk between requests, and Linux restarts a
TCP connection's congestion window after an idle period. The upload after a pause then takes one extra round trip, at
every RTT measured from 12 ms up but the longest. window, ping and connect keep the window open.
A request carries more round trips and bytes than it needs. A response split across writes can wait a round trip
behind a tunnel, and a camera frame is 50 to 100 KB. one_write sends each response in one write, connect() sends each
camera as video and compresses a large array only when that shortens the upload, and frames resizes a frame before it
is sent.
GPUs are in short supply. Few are near any given robot, and every millisecond of round-trip time comes out of the
slack an action chunk leaves. Getting a GPU near the robot is the routing layer, which is outside this package.
Inference layer
| Component |
What it does |
To add it |
Requires |
sequence serve |
Serves a @seq.policy class to robots elsewhere: on a thread of its own, pings answered at once, a warm-up on its @seq.sample, pictures and compressed arrays restored, a @seq.concurrent policy's acts in batches. |
one command |
what pip install sequence-ai installs |
optimize |
Makes a policy faster on its GPU: each speed-up is kept only when its outputs on your observations stay exactly the same and acts are at least 10% faster. sequence serve runs it on the @seq.sample episode. The speed-ups that change the outputs run with the difference you accept. |
nothing with sequence serve, else one call |
torch 2.4 or later and a CUDA GPU, or JAX |
load |
Reads a model's weights onto the GPU from one contiguous file in parallel reads, through the page cache where memory holds it: in about 60% of the time of a checkpoint read tensor by tensor from a cold disk, every tensor the bytes it was packed with. |
one call to pack, one to load |
torch for a GPU, or JAX |
batcher |
Batches the calls waiting for a model into one call, in the batch sizes the model lists. |
one object, one await |
nothing |
replicas |
Runs replicas of a model, each in its own process on the GPU assigned to it, and replaces one that dies. |
one object, one await |
nothing |
slack |
Schedules by the slack an action chunk leaves: how many robots a replica can serve, each by its own round-trip time (RTT), how long a request may wait for a batch, and which requests are dispatched first. |
a few calls in your server's loop |
nothing |
from sequence_ai.engine import optimize, slack
from sequence_ai.engine.batcher import Batcher
from sequence_ai.engine.replicas import ReplicaPool
optimize(model_user, examples_user) # 32 or more of your robot's observations
batcher_user = Batcher(model_on_a_list_user, sizes=[1, 2, 4, 8], wait_ms=2.0)
pool_user = ReplicaPool(load_user, replicas=2, devices=[0, 1]) # one replica per GPU
table_user = slack.measure(forward_of_user, sizes=[1, 2, 4]) # forward_of_user(n): one forward pass of n requests
play_user = slack.playback(hz=20, valid_len=15, replan_at=8) # 15 valid steps, the next requested at the 8th
seating_user = slack.Seating(table_user, play_user["buffer_s"] * 1000, sizes=[1, 2, 4],
cycle_ms=(play_user["play_s"] - play_user["buffer_s"]) * 1000)
seats_user, over_user = seating_user.seat([("near-1", 30.0), ("near-2", 30.0), ("near-3", 30.0), ("near-4", 30.0),
("far", 60.0)]) # (robot, its RTT in ms)
optimize tries cuda_graphs on every module that repeats and whole_graph on a run's whole call, keeps
each where the outputs stay exactly the same and acts get faster, and reports why each is on or off.
torch_compile, fused_kernels, tensorrt and precision change the outputs and need tolerance=.
How do I make a policy faster without changing its outputs, and what does each switch change?
- Its graphs speed up PyTorch policies whose time goes to launching kernels. XLA already compiles each jitted
function of a JAX policy such as π0.5 whole and puts most of its work in command buffers, so on a JAX policy they are
tried only when you turn them on.
cuda_graphs replays each module called many times per run with the same shapes from CUDA graphs of its own eager
kernels, and checks each new shape against eager mode byte for byte. A shape whose capture fails or differs runs in eager mode from then on. The module stays the same
object of the same class, with its weights, state_dict and hooks unchanged.
How do I make a PyTorch robot policy faster without changing its outputs?
batcher dispatches a batch as soon as it is full, or wait_ms after its first call while the model is free.
While the model is busy, waiting calls accumulate and are dispatched together. Only the listed sizes are used, and a
batch in which the model raised is re-run call by call.
How many robots can one GPU serve?
replicas runs each replica in its own process on its own GPU, so a forward pass never blocks the server's
event loop. ReplicaError is the model's own error, and the replica takes the next call. ReplicaDied is a process
that has exited, and it is replaced.
Should I run two replicas of a policy on one GPU?
slack computes a replica's capacity from the playback time an action chunk leaves when its robot requests
the next one, each robot by its own RTT, and tells a server how long the open batch may wait.
slack: scheduling by the slack an action chunk leaves
How do I use the inference components with openpi, LeRobot or GR00T?
Network layer
"Client" is the robot's program and "server" is the policy server on the GPU.