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:
- Lunar Lander (Gymnasium Box2D): TabPFN copies Gymnasium’s hand-written landing controller. 8 state values in, 2 engine commands out.
- HalfCheetah (MuJoCo): TabPFN copies a pretrained TD3 policy. 17 state values in, 6 joint torques out.
Setup
A GPU runtime, the packages, and access to the TabPFN 3.5 weights.- In Colab, select Runtime > Change runtime type > T4 GPU.
- The TabPFN 3.5 weights are gated. Open the model page on Hugging Face and accept the terms.
- 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 theHF_TOKENenvironment variable. If neither is set, the notebook asks for the token.
swig must be installed first, because the Box2D physics engine builds from source.
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, infit. Eachpredictcall then only processes the new rows.n_estimators=1with the TabPFN 3.5 Fast checkpoint: one forward pass per call.- One call for all outputs.
TabPFNRegressorpredicts one number per row, but the robots need 2 or 6 numbers per step.PooledRegressorrepeats each state once per output and adds an output-id column. One table holds all outputs, so onepredictcall 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.
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.
gym package, so we pass the spaces.
Results
On a T4 GPU with Python 3.12, the whole notebook ran in 409 s. Thepip 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
TESTSin either example. Each Lunar Lander episode adds a few hundred predict calls, and each HalfCheetah run adds 1,000. - Change
DEMOSandCONTEXTto 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
predictcall, 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.