Skip to content

AVG

Action Value Gradient is an incremental actor-critic: after each environment step it makes one update on that single transition, with no replay buffer and no target network. It stays stable through normalisation instead: the observations are normalised, the networks' penultimate features are L2-normalised, and the TD error is divided by a running estimate of its scale.

Paper: Vasan et al., Deep Policy Gradient Methods Without Batch Updates, Target Networks, or Replay Buffers, 2024 (arXiv:2411.15370). Ajax follows its Algorithm 1 as the authors' code makes it, gauthamvasan/avg at 6b6822c.

When to use it

AVG suits an agent that must learn from each step as it comes, without storing past experience: on-device or real-time learning, or a memory budget too small for a replay buffer. Where a replay buffer fits, SAC reuses each transition many times.

Feature AVG
Discrete actions no
Continuous actions yes, a tanh-squashed Gaussian, mapped onto the environment's bounds
Memory (memory=) no: with one-transition updates, a memory block could learn nothing temporal
Environments gymnax, Brax, MuJoCo Playground
Image observations no
PID policy yes, actor_architecture=PIDPolicy(...) (Networks)
Several seeds in one call yes, train(seed=[...])
Offline training no: it keeps no replay
Extension phases pretrain, post_update, eval_metrics, observe, on_target, critic_loss, actor_loss, action, eval_action, transform_action, actuate, choose_warmup_action, track_memory (which extensions run)
Resume and checkpoints yes; a run split by a checkpoint equals the run left whole

Example

from ajax import AVG
from ajax.logging import LoggingConfig

agent = AVG("Pendulum-v1")  # one env, learning from its first step
logging = LoggingConfig(log_frequency=1_000, backends=())
state, evaluations = agent.train(seed=[0, 1], n_timesteps=2_000, logging_config=logging)
print(evaluations["Eval/episodic mean reward"])  # one row per seed

This budget only shows the call; Pendulum needs more steps to be solved.

Key hyperparameters

The defaults are the authors'. The API section lists every argument.

Argument Default What it does
n_envs 1 parallel environments
actor_learning_rate 6.3e-3 Adam step size of the actor
critic_learning_rate 8.7e-3 Adam step size of the critic
beta_1, beta_2 0, 0.999 Adam's moment decays (epsilon 1e-8, torch's)
actor_architecture, critic_architecture ("256", "leaky_relu", "256", "leaky_relu") hidden layers
gamma 0.99 discount
learning_starts 0 steps of uniform random actions; AVG learns from each step after them, never from one of these
alpha_init 0.07 the entropy weight, fixed for the whole run
num_critics 1 critics; with more, the actor and the target use their minimum
reward_scale 1.0 multiplies the rewards in the target
max_grad_norm None gradient clipping
episode_length, action_repeat None, 1 simulator steps per episode and per agent step, on Brax and Playground; None is 1,000 steps, or a mujoco: task's own time limit (Environments)
expert_policy None an expert the run tracks; each evaluation logs its return next to the agent's (Eval/expert bias)
extensions () research features (Extensions)

AVG keeps alpha fixed, as the authors' code does, so it has no alpha_learning_rate or target_entropy_per_dim. It always normalises its observations and never its rewards, so it has no normalize_observations or normalize_rewards argument.

Differences from the reference

  • Actions. The authors' code hands its tanh action to the environment as it is; Ajax maps it onto the environment's bounds. On a [-1, 1] box the two are the same.
  • Several environments. The paper trains on one environment. With n_envs > 1, each update uses the transitions of all the environments from the same step.
  • Update order. Algorithm 1 writes the critic update before the actor's; the authors' code builds both losses from the same parameters, then steps the actor and the critic. Ajax follows the code, which produced the paper's results: the actor's loss sees the critic before its step, and the critic's target the actor before its step.

Notes

  • TD-error scale. The critic minimises the squared TD error divided by sqrt(max(var(r) + E[G^2] var(gamma), 1e-4)), where r is the entropy-regularised reward, gamma the per-step discount (zero at a termination) and G the returns of the episodes that terminated, as the authors' TDErrorScaler does. The scale is 1 while that variance is at most 0.01 and no episode has terminated; on a task without terminations it follows the reward's variance alone. The statistics are updated after every step, warm-up included, and shared by all the environments.
  • Actor gradient. The actor loss is alpha log pi(a|s) - Q(s, a) at the action actually executed, reparameterised from its stored pre-squash sample, so the gradient flows through that action.
  • Time limits. Only a termination stops the bootstrap, as in the authors' code; a transition cut by a time limit bootstraps on its final observation.
  • Initialisation. As in the authors' code, every layer starts orthogonal with gain 1 and a zero bias, the mean and log-std heads included. So the first policy's mean and log-std are unit-scale projections of the normalised features, not a near-zero mean and a constant standard deviation.
  • Log-std head. As in the authors' code, whose MultivariateNormal takes it as the covariance's diagonal, the head's output is a log-variance: the standard deviation is exp(out / 2), and its clip to [-20, 2] bounds the log-variance.
  • Evaluation uses the mean action.

Results

The repository records no learning curves for AVG yet. A conformance check (tests/conformance/test_avg_original.py) makes one update of Ajax's AVG and of gauthamvasan/avg from the same state and transition, and compares the actor, the critic, their optimisers and the TD-error scaler: every leaf conforms, to within float32 rounding. It asserts the one difference from that code, the action handed to the environment. The probes (tests/probing) train it briefly on tiny environments with known answers: its target, discounting, time limits, observation normalisation, and a run split by a checkpoint matching the run left whole. Performance compares its speed with the other agents'.

API

ajax.agents.AVG.AVG.AVG dataclass

AVG(
    env_id,
    *,
    n_envs=1,
    env_params=None,
    weight_decay=0.0,
    episode_length=None,
    action_repeat=1,
    extensions=(),
    learning_starts=0,
    expose_recent_rollout=False,
    share_encoder=None,
    expert_policy=None,
    eval_expert_policy=None,
    max_grad_norm=None,
    policy_update_start=0,
    actor_learning_rate=0.0063,
    critic_learning_rate=0.0087,
    actor_architecture=(
        "256",
        "leaky_relu",
        "256",
        "leaky_relu",
    ),
    critic_architecture=(
        "256",
        "leaky_relu",
        "256",
        "leaky_relu",
    ),
    gamma=0.99,
    reward_scale=1.0,
    alpha_init=0.07,
    beta_1=0,
    beta_2=0.999,
    num_critics=1,
)

Bases: PolicyUpdateStart, GradientClipping, ExpertGuided, EncoderSharing, IncrementalAgent

AVG: an incremental soft actor-critic whose critic's TD error is divided by a running estimate of its scale (the module's update). It always normalises its observations, never its rewards, and squashes its actions; with learning_starts above 0 it acts uniformly until then.

Defaults are the authors' (gauthamvasan/avg): 256-256 leaky-ReLU networks with penultimate normalisation, Adam at 6.3e-3 (actor) and 8.7e-3 (critic) with beta_1 0, beta_2 0.999 and torch's eps 1e-8 (avg.py:116-117, torch >= 2.7.0), a fixed alpha of 0.07.

Parameters:

Name Type Description Default
alpha_init float

The entropy coefficient, which never steps.

0.07
beta_1 float

Adam's first-moment decay (AVG uses 0).

0
beta_2 float

Adam's second-moment decay.

0.999
num_critics int

The critics, whose minimum the target and the actor read.

1

alpha_args property

alpha_args

AVG keeps its entropy coefficient at alpha_init, as its reference code does (avg.py): the temperature's optimizer never steps.

init

init(key, context)

A squashed Gaussian actor, num_critics Q critics without targets, the fixed temperature and the TD-error scale's statistics.

update_step_statistics

update_step_statistics(agent_state, transition, context)

Add the step just taken to the statistics behind the TD-error scale: its entropy-regularised reward and discount and, where an episode ended, its return.

update

update(agent_state, transition, context)

One update on the step just taken: a critic and an actor step, both from the current parameters (the actor's loss sees the critic before its step, the critic's TD target the actor before its), the actor's kept from policy_update_start; alpha is not updated.

The official code's order (gauthamvasan/avg, AVG.update in incremental_rl/avg_ablation.py and in avg.py): both losses are built before popt.step(), then qopt.step(). Vasan et al. (2024), Algorithm 1, writes the critic's update line before the actor's; the paper's runs come from that code.

update_critic

update_critic(agent_state, transition, context)

The critic step on the scaled TD error of the step, at the action the step executed (a residual policy's executed one, or the expert's where an extension handed it the step).

update_actor

update_actor(agent_state, transition, context)

The actor step through the action taken; the extensions also read the env's own observations, the policy's mean action and the agent's expert's action from its state (which only an extension holding that expert reads: zeros without one).