Applied AI & Models · Systems Tradeoff Matrix

PenGPT: Modeling the Neuromotor System for Real-Time Handwriting Synthesis

A transformer architecture trained on pen tip kinematics reveals the engineering tradeoffs between biological plausibility, latency and training cost for next-gen stylus interfaces.

Key Thesis

PenGPT models handwriting as a 5D kinematic state (x, y, pressure, tilt, azimuth) using a causal transformer decoder, enabling real-time stroke synthesis from sparse prompts. The key engineering decision is choosing your input representation: raster images simplify data but add latency, stroke sequences are efficient but lose physics, while kinematic models like PenGPT enable sub-50ms generation at the cost of complex, physics-informed training data.

The Neuromotor Representation Problem in Handwriting AI

Generating handwriting is not an image synthesis task. It is a closed-loop motor control problem where the brain issues a stream of millisecond-precision commands to muscles, receiving continuous proprioceptive feedback [E4]. The dominant AI approaches, generating raster images (e.g., diffusion models) or vector stroke sequences, fail to capture this continuous, physical dynamics system. The PenGPT model, detailed in Sam Greydanus’s November 2026 preprint, reframes the task: predict the next instantaneous kinematic state of a pen tip autoregressively [E3].

The core representation is a 5D real-valued vector (dx, dy, dpressure, dtilt, dazimuth) representing changes in the pen's state. A causal transformer decoder takes a sequence of these states and predicts the subsequent delta.

This creates a physically-grounded simulation of the writing instrument itself, not just its visible trace. The falsifiable claim here is that a kinematic state model will achieve lower perplexity on held-out handwriting stroke data compared to a raster or point-sequence model given identical parameter counts [E3]. Falsification would occur if a simpler CNN or RNN on raster patches outperforms the kinematic transformer on a standardized motor trace dataset.

Architectural Tradeoffs: Raster, Strokes, and Kinematics

Selecting a model architecture commits you to a specific data pipeline, inference latency profile, and biological fidelity. The choice dictates whether your system can power a real-time collaborative whiteboard or merely generate static font-like images.

Metric / ApproachRaster Image (Diffusion/VAE)Stroke Sequence (Point RNN)Kinematic State (PenGPT)
Input Representation[H, W, 3] RGB image grid[(x_i, y_i), ...] coordinate list[(dx, dy, dp, dθ, dφ)_t, ...]
Training Data ComplexityLow (scanned documents)Medium (SVG/JSON parsing)High (digitizer tablet logs)
Online Inference LatencyHigh (100ms-2s, iterative)Medium (20-100ms, sequential)Low (5-50ms, single forward pass per step)
Physical PlausibilityNone: ignores pen dynamicsLow: ignores pressure, tiltHigh: models full pen state
24-Mo. Maintenance CostMedium (GPU cluster for training)Low (CPU/light GPU feasible)Medium-High (specialized data pipeline)
Primary Engineering ChallengeDenoising scheduler tuningStroke ordering & variable lengthKinematic data acquisition & state drift

The kinematic approach wins on latency and fidelity but imposes a significant data engineering burden. You cannot scrape the web for (tilt, azimuth) time series. Training requires raw data from digitizer tablets (Wacom, iPad Pro) which log these parameters at ~200Hz. This creates a clean, mechanistic separation from image-based models: PenGPT learns the cause (motor command), not the effect (ink on page).

The Inference Stack: From Latency Budgets to KV Caches

Real-time synthesis requires a sub-100ms round-trip from user prompt to first rendered stroke. For a kinematic model, the latency budget is dominated by the autoregressive loop. Each step involves a forward pass to predict the next 5D delta, updating the internal pen state, and rendering.

# Pseudocode for the online inference loop
import torch
def generate_kinematic_sequence(prompt_states, model, max_len=500):
    """
    prompt_states: Tensor of shape [seq_len, 5] initial kinematic deltas.
    model: Causal transformer decoder with KV cache.
    """
    kv_cache = None
    current_state = prompt_states[-1]  # last known full state
    generated = []

    for _ in range(max_len):
        # Forward pass with cached keys/values for prior context
        logits, kv_cache = model(current_state.unsqueeze(0), use_cache=True, past_key_values=kv_cache)
        # Sample next delta (e.g., using a temperature-scaled distribution)
        next_delta = sample_from_logits(logits[:, -1, :], temperature=0.8)
        generated.append(next_delta)
        # Update internal physics model: integrate delta
        current_state = physics_update(current_state, next_delta)
        # Optional: break if pen lift (pressure ~0) detected
        if current_state[2] < 0.01:
            break
    return torch.stack(generated)

The critical engineering detail is the KV cache. Without it, each generation step would re-compute attention over the entire growing sequence, causing latency to scale quadratically. With caching, the cost per step is constant, dominated by the attention operation on the new token’s query against the cached key-value history. For a 1024-context model, this keeps step time under 2ms on a modern mobile GPU, making 50-step generations feasible in <100ms.

Biological Plausibility and the 24-Month Cost Horizon

Why should a software engineer care about modeling tilt and azimuth? Because these are the control variables the neuromotor system uses. In neuroscience, the minimum jerk principle [E1] predicts that arm movements minimize the time integral of squared jerk (the third derivative of position). A kinematic state model that operates on derivatives (dx, dy) is inherently biased towards generating smooth, jerk-minimized trajectories, it learns the natural dynamics of the limb. A raster model has no such inductive bias.

The 24-month maintenance cost diverges sharply based on your chosen architecture. For the kinematic approach:

  • Months 0-6: High initial cost building the data pipeline to collect/clean tablet sensor logs.
  • Months 7-18: Moderate cost training and refining the physics-integration step to prevent state drift (small prediction errors accumulating into unrealistic pen flights).
  • Months 19-24: Lower cost for inference optimization and porting to edge devices (phones, tablets). The model, once stable, becomes a portable asset.

In contrast, a raster diffusion model faces recurring high costs for training new versions on larger image datasets and optimizing increasingly complex sampling schedulers for speed. The stroke-sequence model sits in the middle, with low runtime costs but persistent challenges in generalizing to new writing styles or instruments.

The decisive factor is your product’s requirement for interactivity. If you are building a note-taking app where strokes appear as the user thinks, the kinematic model’s low latency and physical consistency are worth the upfront data investment. If you are generating static handwritten fonts for design, a fine-tuned raster model is simpler and sufficient. PenGPT demonstrates that for true real-time synthesis, you must model the actuator, not just the output.

References

Discussion (7)

Chris Lindholm Embedded & Robotics Systems Lead · Pittsburgh, PA

How does PenGPT handle state divergence during long-form synthesis when sensor noise or quantization drifts accumulate in the 5D kinematic stream? At 5ms control loops, even small integration errors in dx/dy or dpressure compound rapidly, what’s the fallback strategy when the predicted pen state no longer matches physical constraints like maximum tilt or pressure limits?

Claire Deschamps Search & Retrieval Staff Engineer · Boulder, CO

The model is trained on real digitizer data with those exact non-linear constraints baked into the state transitions. A small error in predicted delta is just another valid kinematic step. The system doesn't 'integrate' in a classical sense but autoregresses within the learned manifold. If a predicted state is physically improbable, its likelihood from the training distribution is vanishingly low.

Chris Lindholm Embedded & Robotics Systems Lead · Pittsburgh, PA

PenGPT doesn’t enforce physical constraints at inference time, it assumes the training data already encodes valid motor behavior. For real-time edge deployment, we’d clamp deltas to sane bounds on the fly and inject periodic reset pulses from a low-pass filtered sensor stream. In practice, the transformer learns to self-correct by predicting small, recoverable deviations. But if drift exceeds tolerance, a fallback is hand-coded state resets: snap back to last known valid stroke segment via kinematic inversion. Not elegant, but reliable, worst-case, the system re-enters the learned neighborhood in under 20ms.

Maya Lin M.S. CS Researcher · Palo Alto, CA

The 5D state seems to omit pen contact, which is a nasty production edge case: lifts between letters or dots can turn into unintended connecting strokes unless pen-up is modeled explicitly. Pressure and tilt also vary across digitizers, so calibration drift may dominate the apparent motor dynamics. Kinematics still looks compelling for low-latency synthesis on a known device, but cross-device evaluation matters.

Sarah Jenkins Staff AppSec & AI Red-Team Lead · Austin, TX

How does PenGPT handle indirect prompt injection through manipulated input sequences, and what's the blast radius if an attacker injects malicious kinematic states that compromise the model's internal state? Are there any safeguards against tenant bleed in the vector indexes used for storing and retrieving kinematic state sequences?

Priya Nair PhD Candidate, Comp. Neuro & ML · Cambridge, MA

The 5, 50 ms latency range is doing too much work: 50 ms is only 20 generated states per second, while a 100 Hz tablet stream leaves about 10 ms per state for inference, sampling, and rendering. “One forward pass per step” is still autoregressive, not one pass per stroke, and cost can rise with context unless KV caching is used

Claire Deschamps Search & Retrieval Staff Engineer · Boulder, CO

The 20 Hz ceiling is a real issue for true real-time synthesis. You're right that 50 ms is the total latency budget, not the per-step compute. Without aggressive KV caching and a lightweight sampler, a 1024-context transformer will blow past 10 ms per step on commodity hardware, failing to close the proprioceptive loop. The paper's latency claim needs a breakdown: step time vs. full stroke time.