Özer Cem KELAHMETKELAHMET
Tools · Reinforcement learning

TD3

TD3 (twin delayed DDPG) fixes value overestimation in DDPG with twin critics, delayed policy updates and target smoothing. Learn how it works and when to use it.

Overview

TD3, short for twin delayed deep deterministic policy gradient, is an off-policy reinforcement learning algorithm for continuous actions. It is a direct fix for DDPG. DDPG often fails because its critic overestimates action values, and the actor then chases those inflated values. TD3 adds three small changes that tackle this: two critics with a minimum, delayed policy updates, and noise added to the target action. Together they make learning far more stable.

The method is simple, has few moving parts, and learns a deterministic policy, which makes deployment easy: the same input always gives the same action. It is a close sibling of SAC. SAC is stochastic and entropy-regularized, while TD3 is deterministic and relies on added noise to explore. For work with tables, TD3 is a good learner for continuous control tasks, such as setpoint tuning, where a tabular model supplies forecasts and scores as the state.

What it is

TD3 is an off-policy actor-critic algorithm with these components:

  • A deterministic actor that maps a state directly to one action.
  • Two critics, each estimating the Q-value of a state and action.
  • Target copies of the actor and both critics, updated slowly.
  • A replay buffer of past transitions.
  • Exploration noise added to actions when collecting data.

The name sums up the three improvements over DDPG:

  • Twin: two critics are trained, and the smaller of their estimates is used in the target.
  • Delayed: the actor and the target networks are updated less often than the critics.
  • DDPG: the base algorithm, deep deterministic policy gradient.

An everyday analogy

Imagine two independent referees scoring a gymnast. If one referee is generous by accident, taking the lower of the two scores protects you from rewarding an inflated mark. Now imagine a coach who changes the training plan after every single score. The plan would swing wildly. A calmer coach waits for several scores before revising the plan, which is the idea behind delayed updates. Finally, imagine the referees see a slightly blurred video of each move, so that they do not over-reward one lucky, precise twist. That is target smoothing. Together these habits give steadier training.

Why DDPG needed fixing

In DDPG, the critic is trained to match a target built from the actor's best action. The actor is trained to climb the critic. If the critic has a small, accidental peak in value at some action, the actor will find it and exploit it. The critic then learns from that exploited action, and the error grows. This feedback loop is called overestimation bias. It is the same family of problem that DQN variants such as double Q-learning address in the discrete case.

Where it came from

TD3 builds on several earlier ideas:

  • Q-learning and deep Q-networks introduced replay buffers and target networks for stable value learning with neural networks.
  • Deterministic policy gradient (2014) gave a gradient formula for deterministic policies.
  • DDPG (2015) combined that gradient with DQN-style tricks to learn continuous control.
  • Double Q-learning (2010) and double DQN (2015) showed that using separate estimators for choosing and evaluating actions reduces overestimation.
  • TD3 (2018), described in the paper "Addressing Function Approximation Error in Actor-Critic Methods", analyzed the overestimation problem in actor-critic methods and proposed the three fixes.

In the same year, SAC was introduced. Both quickly became standard baselines for continuous control. On-policy alternatives such as PPO and TRPO remain popular when samples are cheap. For the broader field, see reinforcement learning.

How it works

Step 1: collect experience with exploration noise

The actor proposes an action for the current state. Gaussian noise is added to it for exploration, and the result is clipped to the allowed action range. The transition is stored in the replay buffer. Many implementations use purely random actions for the first few thousand steps to seed the buffer.

Step 2: sample a minibatch

A random minibatch of stored transitions is drawn. Random sampling breaks the correlation between consecutive steps.

Step 3: compute the target with smoothing

For each transition, take the target actor's action at the next state, add a small clipped noise, and clip again to the valid range:

next action = clip( target_actor(next state) + clip(noise, -c, c), low, high )

This is target policy smoothing. It makes the target value average over a small neighborhood of actions, so a sharp, accidental peak in the critic is smoothed out. The idea is that similar actions should have similar values.

Step 4: use the minimum of twin target critics

The target value is

y = reward + gamma * (1 - done) * min( Q1_target(next state, next action), Q2_target(next state, next action) )

Taking the minimum counters overestimation. The two critics are initialized separately and so make different errors. Their minimum is biased low if anything, which is much safer than biased high, because an underestimate is not exploited by the actor in the same destructive way.

Step 5: update both critics

Each critic minimizes the squared difference between its prediction and y. Both use the same target but have their own parameters.

Step 6: delayed actor and target updates

Every second critic update (the delay is usually two), the actor is updated by gradient ascent on the first critic's value of the actor's action:

maximize Q1(state, actor(state))

and the target networks are updated by Polyak averaging, moving a small fraction (often 0.005) toward the main networks. Waiting lets the critic settle before the actor reacts to it. This reduces the size of errors fed back into the actor.

Step 7: repeat

The cycle of acting, storing and updating continues for as many steps as the budget allows.

Why the pieces work together

  • Twin critics reduce the bias in the value target.
  • Smoothing reduces variance in the target and discourages sharp peaks.
  • Delay reduces how often the actor reacts to unsettled critics.

Each piece alone helps. Together the gains are larger, and ablation studies in the original paper support this.

Key concepts and terms

Term Meaning
Deterministic policy A policy that returns one action per state.
Overestimation bias Systematic upward error in value estimates.
Twin critics Two Q-functions trained in parallel.
Clipped double Q-learning Using the minimum of two critics for the target.
Delayed policy update Updating the actor less often than the critics.
Target policy smoothing Adding clipped noise to the target action.
Target network A slowly updated copy of a network for stable targets.
Polyak averaging Moving a target network a small step toward the main network.
Replay buffer A memory of past transitions.
Exploration noise Noise added to the actor's action while collecting data.
Off-policy Learning from data gathered by earlier policies.
Policy delay The number of critic updates per actor update.
Noise clip The bound on the target smoothing noise.

A worked example

A numeric walk-through of the target

Suppose gamma = 0.99, reward = 2.0, and the episode is not done. At the next state, the target actor proposes an action 0.40. A noise sample of 0.05 is added after clipping to the allowed noise range, giving the smoothed action 0.45. The target critics evaluate that action:

  • Q1_target = 15.0
  • Q2_target = 13.5

The minimum is 13.5. The target is y = 2.0 + 0.99 * 13.5 = 15.365. Both critics are trained toward 15.365.

If DDPG had been used with a single critic at the unsmoothed action 0.40, and that critic happened to read 15.0 because of a spurious peak, the target would be 2.0 + 0.99 * 15.0 = 16.85. Over many updates, such inflated targets accumulate. TD3's minimum and smoothing reduce this.

Why delay matters

Suppose the critic changes a lot between consecutive updates because new data arrives. If the actor takes a gradient step after each critic update, it follows a moving target and may zigzag. By updating the actor only every second step, the critic has more time to settle and the actor's gradient is more reliable.

A compact PyTorch sketch

This is a teaching sketch of the update step. The environment loop and buffer are omitted.

python
import copy
import torch
import torch.nn as nn
import torch.nn.functional as F

class Actor(nn.Module):
    def __init__(self, obs_dim, act_dim, max_action, hidden=256):
        super().__init__()
        self.net = nn.Sequential(
            nn.Linear(obs_dim, hidden), nn.ReLU(),
            nn.Linear(hidden, hidden), nn.ReLU(),
            nn.Linear(hidden, act_dim), nn.Tanh())
        self.max_action = max_action

    def forward(self, s):
        return self.max_action * self.net(s)

class Critic(nn.Module):
    def __init__(self, obs_dim, act_dim, hidden=256):
        super().__init__()
        def q():
            return nn.Sequential(
                nn.Linear(obs_dim + act_dim, hidden), nn.ReLU(),
                nn.Linear(hidden, hidden), nn.ReLU(),
                nn.Linear(hidden, 1))
        self.q1, self.q2 = q(), q()

    def forward(self, s, a):
        sa = torch.cat([s, a], -1)
        return self.q1(sa), self.q2(sa)

class TD3:
    def __init__(self, obs_dim, act_dim, max_action,
                 gamma=0.99, tau=0.005, policy_noise=0.2,
                 noise_clip=0.5, policy_delay=2, lr=3e-4):
        self.actor = Actor(obs_dim, act_dim, max_action)
        self.actor_t = copy.deepcopy(self.actor)
        self.critic = Critic(obs_dim, act_dim)
        self.critic_t = copy.deepcopy(self.critic)
        self.a_opt = torch.optim.Adam(self.actor.parameters(), lr=lr)
        self.c_opt = torch.optim.Adam(self.critic.parameters(), lr=lr)
        self.max_action, self.gamma, self.tau = max_action, gamma, tau
        self.policy_noise = policy_noise * max_action
        self.noise_clip = noise_clip * max_action
        self.policy_delay = policy_delay
        self.step = 0

    def update(self, batch):
        s, a, r, s2, d = batch
        self.step += 1
        with torch.no_grad():
            noise = (torch.randn_like(a) * self.policy_noise).clamp(
                -self.noise_clip, self.noise_clip)
            a2 = (self.actor_t(s2) + noise).clamp(-self.max_action, self.max_action)
            q1_t, q2_t = self.critic_t(s2, a2)
            y = r + self.gamma * (1 - d) * torch.min(q1_t, q2_t).squeeze(-1)

        q1, q2 = self.critic(s, a)
        c_loss = F.mse_loss(q1.squeeze(-1), y) + F.mse_loss(q2.squeeze(-1), y)
        self.c_opt.zero_grad(); c_loss.backward(); self.c_opt.step()

        if self.step % self.policy_delay == 0:
            a_loss = -self.critic(s, self.actor(s))[0].mean()
            self.a_opt.zero_grad(); a_loss.backward(); self.a_opt.step()
            with torch.no_grad():
                for net, tgt in ((self.actor, self.actor_t),
                                 (self.critic, self.critic_t)):
                    for p, pt in zip(net.parameters(), tgt.parameters()):
                        pt.mul_(1 - self.tau).add_(self.tau * p)

Adding exploration noise when acting

python
import numpy as np

def select_action(agent, state, max_action, expl_noise=0.1, act_dim=1):
    with torch.no_grad():
        a = agent.actor(torch.as_tensor(state, dtype=torch.float32)).numpy()
    a = a + np.random.normal(0, max_action * expl_noise, size=act_dim)
    return np.clip(a, -max_action, max_action)

A table-driven scenario

Consider a process where a continuous setpoint, such as a pressure level or discount depth, is adjusted every hour. A tabular model reads recent logs and outputs expected demand and a risk score. The state combines these with the current setpoint and a few counters. The reward is margin minus a penalty for violating limits. TD3 learns a deterministic mapping from this state to the next setpoint. Because the policy is deterministic, an operator can inspect it, test what it would do for a given state, and repeat the test with the same result.

Strengths and limitations

Strengths

  • Much more stable than DDPG. The three fixes tackle the main failure modes.
  • Sample efficient. The replay buffer lets each transition be reused many times.
  • Simple. Few components and few hyperparameters beyond the DDPG basics.
  • Deterministic policy. Easy to test, audit and deploy.
  • Competitive baseline. It performs well across many continuous control tasks.
  • Cheap per update. Compared with SAC, there is no entropy term and no temperature to tune.

Limitations

  • Continuous actions only. It does not apply directly to discrete choices.
  • Exploration by added noise. The noise scale is a hyperparameter, and fixed noise may be too little or too much at different stages. SAC's entropy term adapts automatically.
  • Sensitive to some choices. Noise scales, learning rates and reward scale still matter.
  • Can still overestimate or underestimate. The minimum of twin critics can introduce a mild underestimation bias.
  • Weak in sparse-reward tasks. Without extra exploration tools, it may fail to find rewards.
  • Off-policy risks. Reusing old data can cause errors, especially in offline settings without conservative corrections.

How it compares with alternatives

Method Policy type Data use Key fixes or ideas Typical strength Typical weakness
TD3 Deterministic Off-policy Twin critics, delay, smoothing Stable, simple Fixed exploration noise
DDPG Deterministic Off-policy Target networks, replay Simple ancestor Overestimation, brittle
SAC Stochastic Off-policy Entropy bonus, twin critics Robust, adaptive exploration More components
PPO Stochastic On-policy Clipped ratio Stable, simple Many samples
TRPO Stochastic On-policy KL trust region Careful updates Complex
A2C Stochastic On-policy Synchronous actor-critic Simple baseline Less stable
DQN Greedy over Q Off-policy Replay, target network Discrete actions Not for continuous

A short guide: use TD3 when you want a simple, deterministic, sample-efficient method for continuous control. Use SAC when you want more robustness and automatic exploration. Use PPO when you have a fast simulator and want a dependable default. Use DDPG only for historical comparison.

Role in tabular foundation models

TD3 is a decision algorithm and does not read tables. A tabular foundation model, by contrast, learns from raw tables: it handles row and column structure, mixed numeric and categorical columns and missing values, does not require column names, and is often pre-trained on synthetic tables, using in-context learning at prediction time. See TabPFN, /model/architecture and /model/research. The two connect as follows.

Features and forecasts for the state

Sequential decisions in business and industry depend on tables: sensor histories, order books, price lists. A tabular foundation model can convert the latest rows into forecasts, risk scores and class probabilities without retraining for each table, using labeled rows as context. Those outputs make a compact state for a TD3 agent. A small state means small networks, fast training and less overfitting. See predictive maintenance for an example domain.

A learned simulator from logs

When trial and error on the real system is risky or slow, a model fitted to logged tables can predict next state and reward for a given state and action. TD3 can then train against it. The danger is model error: a deterministic actor is good at finding exact action values that exploit simulator flaws. Target smoothing helps a little, but you should also use short rollouts, mix real and simulated data, and check the final policy on held-out real logs. This ties to digital twins.

Offline learning from tables

Many organizations have only a static table of past decisions and outcomes. Applying TD3 directly to such data is risky, because the critic may overvalue actions that never occur in the table. Offline variants add a behavior-cloning term, which keeps the actor close to the logged actions, and normalize the data. A tabular model can add uncertainty estimates to flag unfamiliar state and action pairs.

Missing values and imputation

Real state vectors have gaps. A tabular foundation model can fill a missing cell by predicting it from the rest of the row in context. The policy can then receive the imputed value together with a missingness flag. See imputation networks.

Anomaly scores as safety signals

An anomaly detection model trained on normal operation can score how unusual the current state is. That score can be a state feature, a reward penalty or a trigger for a rule-based fallback. This matters because a deterministic policy with added noise can produce odd actions when it meets unfamiliar states.

Synthetic data and pre-training

Tabular foundation models are often pre-trained on synthetic tables drawn from a prior over data-generating processes. Setting the prior's parameters is a design problem. It is usually handled by hand or with Bayesian optimization, and TD3 is an option only when many continuous settings must be adjusted sequentially. See synthetic data generation.

Continual learning

Deployed systems drift. A TD3 agent can control how often to refresh a model, how much to adapt and which data to replay, with a reward that balances accuracy and cost. Replay buffer management helps avoid forgetting by keeping a mix of old and new situations.

Sector and semantic classification

A tabular model can infer what a column means, or what sector a table belongs to, from values and statistics when names are missing. These inferred labels can select action bounds, reward weights or sub-policies, so one TD3 setup can serve several kinds of tables.

An honest boundary

If the aim is to predict a target column, use a tabular foundation model or a supervised learner. TD3 only fits when actions change future states and rewards are delayed.

Practical guidance and best practices

Typical hyperparameters

Setting Typical value
Discount (gamma) 0.99
Target smoothing (tau) 0.005
Learning rate 3e-4 for actor and critics
Batch size 256
Replay buffer size 1 million transitions
Hidden layers two layers of 256 units
Exploration noise std 0.1 of the action range
Target policy noise std 0.2 of the action range
Noise clip 0.5 of the action range
Policy delay 2
Initial random steps a few thousand

These are starting points to tune, not rules.

Normalize and scale

Scale observations with running statistics. Keep rewards in a moderate range. Normalize the action range to from minus one to one and rescale at the environment boundary.

Handle episode endings correctly

Separate true terminal states from time-limit truncation. For truncation, keep the bootstrap term. Mixing them biases the critics.

Anneal exploration if needed

A constant exploration noise can be fine, but some tasks improve with noise that decays over time. Evaluate with no noise.

Monitor the right signals

  • Episode return and length.
  • Critic losses for both critics.
  • Gap between the two critic estimates. A large persistent gap signals disagreement or instability.
  • Average Q-value magnitude. Explosive growth signals trouble.
  • Action saturation: the share of actions at the bounds.

Example configuration

yaml
algo: td3
env: example-setpoint-control
seed: 5
gamma: 0.99
tau: 0.005
lr: 0.0003
batch_size: 256
buffer_size: 1000000
start_steps: 5000
expl_noise: 0.1
policy_noise: 0.2
noise_clip: 0.5
policy_delay: 2
hidden_sizes: [256, 256]
normalize_obs: true
eval_every: 5000
log_dir: /var/log/example.internal/td3-runs

Evaluate properly

Use a separate environment copy for evaluation, no exploration noise, many episodes, and several seeds. Report the mean and the spread.

Governance for deployed policies

Because the policy is deterministic, you can test it exhaustively on a grid of states and review its decisions with domain experts. Keep action limits enforced outside the policy. Add a rule-based fallback. Roll out gradually and log state, action and policy version for every decision.

Variants and extensions

  • TD3 with behavior cloning (offline) adds a term that keeps the actor near logged actions.
  • Prioritized replay samples important transitions more often.
  • N-step returns speed up credit assignment, with care about off-policy bias.
  • Larger ensembles of critics extend the twin idea to more critics, with a smaller or averaged minimum.
  • Layer normalization in critics allows higher update ratios.
  • Recurrent TD3 adds memory for partially observed problems.

A debugging checklist

  1. Test on a simple environment where the best action is obvious.
  2. Confirm that target networks are not receiving gradients.
  3. Confirm that the actor update uses only the first critic.
  4. Confirm the delay logic: the actor and targets update only every second critic step.
  5. Confirm noise is clipped and then actions are clipped again.
  6. Check that actions are not stuck at the bounds.
  7. Compare both critics. If one diverges, check learning rates and reward scale.
  8. Check the replay buffer stores the correct done flags.
  9. Evaluate without exploration noise.
  10. Repeat with another seed to see how stable the result is.

Reading a TD3 training log

In a healthy run, the two critic losses are similar in size and decline over time, then plateau with noise. The average Q-values grow gradually and track the observed returns. The gap between the two critics stays small. Returns rise in steps rather than smoothly, because deterministic policies can change behavior sharply when a new strategy is found.

Warning signs:

  • One critic's loss is much larger than the other's. The learning rate or initialization may be at fault.
  • Q-values grow far above any achievable return. Check reward scale and done handling.
  • Returns collapse after a period of progress. Lower the learning rate, or increase the policy delay.
  • Actions sit at the bounds for most states. The actor has saturated, and output scaling or reward shaping may need attention.

Ablation intuition

Each of the three fixes can be removed in an experiment to see what it does.

Change Typical effect of removing it
Single critic instead of twin Higher value estimates and less stable returns
No policy delay More oscillation in the actor and more sensitivity to critic noise
No target smoothing Greater variance in targets and more exploitation of narrow peaks

The exact size of each effect depends on the task, so run your own comparison when a result matters.

Pre-deployment checks

  • Evaluate the policy on a grid of states and review the actions with domain experts.
  • Stress test with missing or delayed inputs.
  • Confirm that saved normalization statistics load with the policy.
  • Define a rollback path and a rule-based fallback.

Choosing between deterministic and stochastic policies

A deterministic policy is easy to audit and repeat. A stochastic policy gives built-in exploration and can represent several good behaviors at once. When a task has many equally good solutions, or when the environment is partly random, a stochastic policy as in SAC can be safer. When a task has a clear single best action for each state, and testability matters, a deterministic policy as in TD3 is attractive.

Common mistakes

  • Updating the actor every step. This removes the delay that gives stability.
  • Skipping target smoothing. Training becomes more sensitive to spiky critics.
  • Using the average instead of the minimum. This loses the overestimation fix.
  • Forgetting to clip. Unclipped noise can push actions outside the valid range.
  • Wrong done handling. Treating truncation as termination biases values.
  • Too little initial exploration. The first critics overfit to a narrow set of data.
  • Evaluating with exploration noise. This understates the policy's true performance.
  • Tiny replay buffers. The agent forgets older situations.
  • Ignoring reward scale. Very large or very small rewards harm critic learning.
  • Trusting a learned simulator blindly. Validate on held-out real logs.
  • Using TD3 for discrete actions. Use DQN or PPO.
  • Reporting a single seed. Run several and report the spread.

Frequently asked questions

What does TD3 stand for?

TD3 stands for twin delayed deep deterministic policy gradient. Twin refers to the two critics. Delayed refers to updating the actor and the target networks less often than the critics. Deep deterministic policy gradient is the base algorithm, DDPG, that TD3 improves.

How is TD3 different from DDPG?

TD3 keeps the DDPG structure of a deterministic actor, a critic, target networks and a replay buffer, and adds three fixes. It trains two critics and uses their minimum, delays the actor updates, and adds clipped noise to the target action. These changes reduce overestimation and make training much more stable.

Why does TD3 use two critics?

Single critics tend to overestimate values, because noise in the estimates is amplified when the actor seeks the highest value. Two critics trained from different initializations make different errors, and taking their minimum gives a more cautious target. This prevents the upward drift that destabilizes DDPG.

What is target policy smoothing?

Target policy smoothing adds a small amount of clipped noise to the target actor's action when computing the target value. It makes the target an average over nearby actions. That discourages the actor from exploiting narrow, accidental peaks in the critic and encodes the idea that similar actions should have similar values.

Why is the policy update delayed?

The critic is noisy at first, and the actor follows its gradient. If the actor updates after every critic step, it follows a moving and unreliable target. Waiting for a couple of critic updates lets the critic settle, so the actor's gradient is better and errors are less likely to feed back into the critic.

Is TD3 on-policy or off-policy?

TD3 is off-policy. It stores transitions in a replay buffer and learns from them repeatedly, even after the policy has changed. That makes it much more sample efficient than on-policy methods such as PPO and TRPO.

Should I choose TD3 or SAC?

Both are strong choices for continuous control. TD3 is simpler and deterministic, which can ease testing and deployment. SAC adds an entropy bonus with automatic temperature tuning, which often gives more robust exploration and less sensitivity across tasks. If you are unsure, try both and compare results over several seeds.

Can TD3 handle discrete actions?

Not directly. TD3 relies on a deterministic actor and gradients through a continuous action input to the critic. For discrete actions, use a value-based method such as DQN or a policy-gradient method such as PPO. There are tricks to relax discrete actions, but they are not the standard use.

How does TD3 relate to tabular foundation models?

TD3 learns continuous control decisions, whereas a tabular foundation model reads tables and predicts or imputes in context. The tabular model can provide state features, uncertainty, anomaly scores and a learned simulator, and TD3 can learn the policy that acts on them. They complement each other.

What exploration noise should I use?

A common default is Gaussian noise with a standard deviation of about a tenth of the action range. Start with that and adjust. If the agent gets stuck in a poor behavior, increase it. If the behavior is erratic and returns are noisy, decrease it or anneal it over time. Always evaluate without the noise.

Glossary

  • Actor: the network that outputs the action.
  • Clipped double Q-learning: using the minimum of two critics for the target.
  • Critic: a network estimating the value of a state and action.
  • Deterministic policy: a policy that gives one action for each state.
  • Exploration noise: random noise added to actions during data collection.
  • Off-policy: learning from data produced by earlier policies.
  • Overestimation bias: systematic upward error in value estimates.
  • Polyak averaging: smooth updating of target networks.
  • Policy delay: how many critic updates occur per actor update.
  • Replay buffer: a store of past transitions.
  • Target network: a slowly updated copy used to compute stable targets.
  • Target policy smoothing: adding clipped noise to target actions.
  • Twin critics: two Q-functions trained in parallel.

Summary

TD3 is a stable, off-policy, deterministic actor-critic algorithm for continuous control. It fixes the overestimation problem of DDPG with twin critics and a minimum, delays the actor and target updates, and smooths the target action with clipped noise. The result is a simple method that is sample efficient and far more reliable than its ancestor.

It is closely related to SAC, which uses a stochastic policy and an entropy bonus. Compared with on-policy methods such as PPO and TRPO, it needs fewer samples but handles only continuous actions.

For tabular foundation models, TD3 is the decision learner. The tabular model supplies state features, imputations, anomaly scores and learned simulators, and TD3 learns how to act on them. See /model/research, /model/architecture and /model/benchmarks for the model side.

It belongs to Reinforcement learning in my stack, under AI and machine learning. Others in the same group:

Type to search.
    ↑↓ navigate↵ open