Skip to main content
ByKlemens Flöge
Expert demonstrations go into TabPFN’s context. At every control step, one predict call returns the next action. No training. Behaviour cloning learns a policy from an expert’s (state, action) pairs. Usually you train a network on those pairs. With TabPFN, the pairs are the context: fit stores them, and predict maps a new state to an action. This notebook runs two examples:
  1. Lunar Lander (Gymnasium Box2D): TabPFN copies Gymnasium’s hand-written landing controller. 8 state values in, 2 engine commands out.
  2. HalfCheetah (MuJoCo): TabPFN copies a pretrained TD3 policy. 17 state values in, 6 joint torques out.
The speed tricks come from duckpfn by Niki Kilbertus, where TabPFN walks a simulated Microduck robot at 50 Hz.

Setup

A GPU runtime, the packages, and access to the TabPFN 3.5 weights.
  1. In Colab, select Runtime > Change runtime type > T4 GPU.
  2. The TabPFN 3.5 weights are gated. Open the model page on Hugging Face and accept the terms.
  3. Create a Hugging Face read token under Settings > Access Tokens. In Colab, add it as a secret named HF_TOKEN (key icon in the left bar) and switch on notebook access. Outside Colab, set the HF_TOKEN environment variable. If neither is set, the notebook asks for the token.
swig must be installed first, because the Box2D physics engine builds from source.
Download the TabPFN 3.5 Fast checkpoint. It is the smallest TabPFN 3.5 model and the fastest at prediction time.

Make TabPFN fast enough for a control loop

Three settings keep one prediction in the range of tens of milliseconds.
  • fit_mode="fit_with_cache": TabPFN encodes the context once, in fit. Each predict call then only processes the new rows.
  • n_estimators=1 with the TabPFN 3.5 Fast checkpoint: one forward pass per call.
  • One call for all outputs. TabPFNRegressor predicts one number per row, but the robots need 2 or 6 numbers per step. PooledRegressor repeats each state once per output and adds an output-id column. One table holds all outputs, so one predict call answers all of them. This is the duckpfn trick.
PooledRegressor also standardizes each output and records the time of every predict call.

Example 1: Lunar Lander

TabPFN copies Gymnasium’s hand-written landing controller. LunarLanderContinuous-v3 has an 8-value state (position, velocity, angle, angular velocity, leg contacts) and 2 continuous engine commands. Gymnasium ships a hand-written heuristic controller for it; that is our expert. An episode that scores 200 or more counts as solved. run_episode flies one episode with any policy and logs the states and actions.
Log the expert’s demonstrations and put them into TabPFN’s context.
Fly new episodes with TabPFN and with the expert, on seeds that are not in the context.
Watch one TabPFN landing.
Example 1: Lunar Lander

Example 2: HalfCheetah

TabPFN copies a pretrained TD3 policy and runs a MuJoCo robot with 6 joints. HalfCheetah-v5 has a 17-value state (joint angles and velocities) and 6 joint torques. The reward is mostly forward speed. The expert is sb3/td3-HalfCheetah-v3, a TD3 policy from the Stable-Baselines3 model zoo. Make the environment and roll out with optional action noise. With noise > 0, the robot executes a perturbed action but we log the expert’s clean action. The context then also shows how to recover from small mistakes. For the GIF, the camera follows the robot (camera_name="track"). The default floor is 80 m long and the cheetah runs further, so we make the floor 50 times longer. MuJoCo prints a harmless deprecation warning about settotalmass each time it loads the model.
Load the expert. It was saved with the old gym package, so we pass the spaces.
Log noisy expert demonstrations and keep a random subset as the context. Each transition becomes 6 rows, one per joint.
Run TabPFN and the expert for 1,000 steps each, on new seeds.
Watch TabPFN run for 300 steps (15 s of simulated time), shown in real time.
Example 2: HalfCheetah

Results

On a T4 GPU with Python 3.12, the whole notebook ran in 409 s. The pip install took 146 s of that. TabPFN gets close to both experts with no training. One predict call answers all joints in about 40 ms, which is less than HalfCheetah’s 50 ms control step. The test sets are small (10 and 3 runs), so read the results as “TabPFN matches the expert”, not as an exact ranking. Your numbers change with the GPU and the package versions.

Run longer

The defaults keep the notebook short. To get tighter numbers or a harder test:
  • Raise TESTS in either example. Each Lunar Lander episode adds a few hundred predict calls, and each HalfCheetah run adds 1,000.
  • Change DEMOS and CONTEXT to see how much demonstration data TabPFN needs. Fewer rows make each call faster.
  • Without a GPU, set DEVICE = "cpu". Each call is then much slower.

Next steps

  • A planner that needs many predictions per control step should put them into one predict call, not one call each.
  • Try a harder robot: Ant, Humanoid, or a model from MuJoCo Menagerie.
  • For a full walking robot at 50 Hz, see duckpfn.