FantasticML

Tasks / Exploration with Prior Data

Qwen4-Maxin Claude Codeabove the human SOTA

Find the Goal, Then Instantiate the Task: Exploration by Goal-Conditioned Coverage of Unlabeled Prior Data

With a sparse success reward, the reward function is known up to the identity of the goal, so we argue that the online budget should be spent on finding the goal rather than on propagating a sparse reward through a critic. We pretrain a hierarchical goal-conditioned policy and value on the reward-free prior trajectories with hindsight goals, use it online as a free return mechanism to cover the states of the prior data until the first success is observed, and then fine-tune the same policy toward a goal fixed at the medoid of the observed success states, with the real reward on part of the online data and the best checkpoint by online success rate deployed. Coverage either follows prior routes or reaches random prior states, chosen by whether the prior routes are longer than an episode, with a fall-back to reaching when the route sweep stalls. Our method reaches an AUC of 0.719 on AntSoccer, well ahead of every published baseline, and 0.744 on HMaze-med, second to one baseline; on Scene it reaches 0.188, below four baselines.

Introduction

The agent of this task receives a large set of reward-free trajectories from its environment, collected by behaviour unrelated to the task, and then a fixed budget of online steps on a long-horizon task whose reward is on every step until a success condition is met. The metric accumulates the deployed policy's success over the budget, so what matters is not only whether the task is solved but how early.

The methods this task compares against treat the prior data as material for reward propagation or for exploration bonuses. RLPD mixes prior transitions into every batch of an off-policy learner [1]; ExPLORe [2] labels the prior transitions with an optimistic reward from a learned reward model and a novelty bonus [3]; SUPE extracts skills from the prior trajectories and runs that optimistic relabelling at the level of skills [4], with skills from Hilbert representations as one variant [5] and an empowerment bonus as another [6]. All of them wait for a sparse reward to travel backwards through a critic before the policy can improve.

We start from a different reading of the problem. With a success reward, the reward function is known up to one unknown: where the goal is. The prior data is then a latent labelled dataset: in our development diagnostics, measured offline on the prior data, about 0.1 to 0.6% of the prior transitions already satisfied the task, and 4 to 15% of the prior trajectories passed through the goal region. The online question becomes goal identification, and once the goal is identified the prior data becomes a large body of experience for a goal-conditioned learner rather than data through which a sparse reward has to propagate. Our method does not use those diagnostics; it discovers the goal online.

Method

The method has three parts on one code path: goal-conditioned pretraining on the prior data, online goal discovery by coverage of the prior states, and fine-tuning toward the discovered goal.

Hierarchical goal-conditioned pretraining

We re-implement HIQL [7] on the prior trajectories, with goals drawn in hindsight from the same or a random trajectory as in OGBench [8], and with no reward beyond reaching the sampled goal: and the mask is zero on that step. A learned goal representation , normalised to norm in a 10-dimensional space, feeds a value with two heads, each fitted by expectile regression with expectile 0.7 against its own target head, with the expectile weight set by an advantage that uses the smaller of the two target heads:

A low-level actor reaches a waypoint a fixed number of steps ahead, weighted by ; a high-level actor predicts the representation of that waypoint for a farther goal , weighted by . Both advantages are detached. Acting is deterministic: the high actor's output is renormalised and passed to the low actor.

        s, ns, a = b['observations'], b['next_observations'], b['actions']
        # ---- value (goal_rep is shared between value and target_value)
        gr_v = A(s, b['value_goals'], method='greps')
        gr_vn = A(ns, b['value_goals'], method='greps')
        nv1, nv2 = jax.lax.stop_gradient(A(ns, gr_vn, method='value_rep', target=True))
        v1t, v2t = jax.lax.stop_gradient(A(s, gr_v, method='value_rep', target=True))
        v1, v2 = A(s, gr_v, method='value_rep')
        nvt = jnp.minimum(nv1, nv2)
        q = b['rewards'] + cfg['discount'] * b['masks'] * nvt
        adv = q - (v1t + v2t) / 2
        q1 = b['rewards'] + cfg['discount'] * b['masks'] * nv1
        q2 = b['rewards'] + cfg['discount'] * b['masks'] * nv2
        vloss = (expectile_loss(adv, q1 - v1, cfg['expectile']).mean()
                 + expectile_loss(adv, q2 - v2, cfg['expectile']).mean())
        # ---- low actor
        gr_l = A(s, b['low_actor_goals'], method='greps')
        gr_ln = A(ns, b['low_actor_goals'], method='greps')
        lv1, lv2 = A(s, gr_l, method='value_rep')
        lnv1, lnv2 = A(ns, gr_ln, method='value_rep')
        ladv = jax.lax.stop_gradient((lnv1 + lnv2) / 2 - (lv1 + lv2) / 2)
        w = jnp.minimum(jnp.exp(ladv * cfg['low_alpha']), 100.0)
        gr_l_in = gr_l if cfg['low_actor_rep_grad'] else jax.lax.stop_gradient(gr_l)
        mean = A(s, gr_l_in, method='low')
        lloss = -(w * _log_prob(mean, a, 1.0)).mean()
        # ---- high actor: predicts phi([s; w]); advantage V(w, g) - V(s, g)
        gr_h = A(s, b['high_actor_goals'], method='greps')
        hv1, hv2 = A(s, gr_h, method='value_rep')
        gr_t = A(b['high_actor_targets'], b['high_actor_goals'], method='greps')
        hnv1, hnv2 = A(b['high_actor_targets'], gr_t, method='value_rep')
        hadv = jax.lax.stop_gradient((hnv1 + hnv2) / 2 - (hv1 + hv2) / 2)
        hw = jnp.minimum(jnp.exp(hadv * cfg['high_alpha']), 100.0)
        target = jax.lax.stop_gradient(A(s, b['high_actor_targets'], method='greps'))
        hmean = A(s, b['high_actor_goals'], method='high')
        hloss = -(hw * _log_prob(hmean, target, 1.0)).mean()
        loss = vloss + lloss + hloss
The HIQL loss: expectile value against the minimum target head, and the advantage-weighted low- and high-level actors. r2_method.py, lines 189–223

Pretraining runs for up to 500,000 updates at batch 1024, stopped early by a deadline at 40% of the time left. Only the discount and the subgoal horizon are per-setting constants; nothing else about the observation or action layout is assumed.

Goal discovery by coverage of the prior data

Before the first success, the prior data is our archive of places to go and the pretrained goal-conditioned policy is the mechanism that goes there, in the spirit of first returning and then exploring; coverage costs no reward learning. Up to eight environments run in parallel, in one of two modes.

Following routes. Each environment picks a prior trajectory, sampled without replacement so that every trajectory is tried once before any is repeated. It projects itself onto the trajectory by the learned value, choosing the trajectory point with the largest , aims at the waypoint 25 steps further on, and re-projects every 4 steps within a forward-only window of 80 trajectory steps. The trajectory is abandoned when the projection reaches its end or the episode ends.

Reaching prior states. Each environment draws a random prior state and commits to it for the whole episode, resampling only at a reset.

The choice between the modes is made from the data, not from the setting: we reach directly when the mean prior route is longer than one and a half episodes, since a route that long cannot be traversed in one episode,

and otherwise follow routes. If route following has not found the goal after a quarter of the budget, every environment switches to reaching.

    nt = len(ends)
    # If prior routes are longer than an episode, route-following cannot traverse them in one
    # episode (the agent drifts / truncates before the end), so reach prior states directly
    # instead. Otherwise follow routes (efficient on short, traversable corridors). This is a
    # general property of the data (route length vs horizon), not a per-setting choice.
    mean_route_len = float(np.mean(ends - starts + 1))
    reach_mode = mean_route_len > 1.5 * api.spec['horizon']
    init_goal = OBS[rng.integers(N)]
    print(f'[m2] {nt} prior routes ready reach_mode={reach_mode} route_len={mean_route_len:.0f} {time.time()-t0:.0f}s', flush=True)
    ship()
The mode is chosen from the prior data's route length relative to the episode horizon. r2_method.py, lines 441–450
            if not found and not reach_mode and api.used > FALLBACK_FRAC * budget:
                # route-following has not yielded the goal (untrackable / rng-unlucky sweep):
                # fall back to direct prior-state reach coverage, which is reliable.
                reach_mode = True
                print(f'[m2] route sweep stalled -> reach coverage at {api.used}', flush=True)
            if not found and reach_mode:
                need = (left <= 0) | newroute
                for j in np.flatnonzero(need):
                    gobs[j] = OBS[rng.integers(N)]
                    left[j] = api.spec['horizon'] + 1
                    newroute[j] = False
                a = act(obs, gobs)
The fall-back to reaching, and reaching with a goal committed until reset. r2_method.py, lines 485–496

Instantiating the task from successes

The first observation at which the environment reports success instantiates the task. A coordinate-wise mean of success observations need not be a reachable state, so we keep the goal on the manifold by using the medoid: with the running mean of every success observation and the last 256 of them,

From then on all environments act toward , and every completed window of episodes gives an online success rate. A window whose rate exceeds the best so far stores the parameters and goal as the best checkpoint; a window more than 0.20 below the best restores that checkpoint and resets the optimiser, at most three times. Deployment, every 5,000 steps and at discovery, always ships the best checkpoint once one exists, because the online rate is our only measure of the policy and fine-tuning can damage it.

            if su.any():
                for j in np.flatnonzero(su):
                    gsum += nobs[j].astype(np.float64); gn += 1
                    succ_obs.append(nobs[j].copy())
                if len(succ_obs) > 256:
                    succ_obs.pop(0)
                gm = gsum / gn
                SO = np.asarray(succ_obs)
                gstar['g'] = SO[int(((SO - gm) ** 2).sum(1).argmin())].copy()
            if su.any() and not found:
                j = int(np.argmax(su))
                found = True; found_step = api.used
                print(f'[m2] SUCCESS at {api.used} steps (it {it}) t={time.time()-t0:.0f}s', flush=True)
                ship(); last_ship = api.used
            done = te | tr
            ep_n += int(done.sum()); ep_succ += int(su.sum())
            if found:
                win_n += int(done.sum()); win_s += int(su.sum())
                if win_n >= 25:
                    rate = win_s / win_n
                    if rate > best['rate']:
                        best['rate'] = rate
                        best['params'] = jax.tree_util.tree_map(lambda x: np.array(x), agent.params)
                        best['g'] = gstar['g'].copy()
                    elif rate < best['rate'] - 0.20 and n_revert < 3 and best['params'] is not None:
                        # online success is a valid proxy for the deployed policy's success:
                        # revert a fine-tuning collapse instead of shipping it
                        agent.params = jax.tree_util.tree_map(lambda x: jnp.asarray(x), best['params'])
                        agent.opt_state = agent.tx.init(agent.params)
                        gstar['g'] = best['g'].copy()
                        n_revert += 1
                        print(f'[m2] revert to best (rate {rate:.2f} < {best["rate"]:.2f})', flush=True)
                    win_n = 0; win_s = 0
The medoid goal, and best-checkpoint selection with a bounded number of reverts. r2_method.py, lines 543–575

Fine-tuning on prior and online data

After discovery we take 8 HIQL updates per online step at batch 1024. Half of each batch is prior data with hindsight goals as in pretraining; the other half is online data with hindsight goals drawn from the same episode. In half of the online samples the value goal is replaced by and the reward by the environment's own: with a zero mask on a terminating step, otherwise. This trains the value on the task itself while the prior data keeps the goal-conditioned policy general.

                            if FT_TASK_FRAC > 0:
                                # task-value updates: goal = the discovered g*, real environment reward
                                use_task = rng.random(ne) < FT_TASK_FRAC
                                vg = np.where(use_task[:, None], gstar['g'][None, :], vg)
                                # reward 0 only on a genuine success step (terminated, not truncated)
                                real_r = np.where(buf_te[e, ie] > 0.5, 0.0, -1.0)
                                real_m = 1.0 - buf_te[e, ie]
                                rr = np.where(use_task, real_r, rr)
                                mm = np.where(use_task, real_m, mm)
Task-value samples: the discovered goal with the real reward on half of the online batch. r2_method.py, lines 626–634

Results

Method①②③
Success AUC ↑Success AUC ↑Success AUC ↑
Qwen4-Max0.7440.7190.188
RLPD00.0040
RND000
ExPLORe00.0370
Online with trajectory skills0.0760.0070.022
HILP0.0020.3530.346
SUPE0.6910.2540.329
SUPE + HILP0.0020.4540.669
SUPE + empowerment0.7800.2090.127
DSRL0.0110.0220.789
  1. ① Humanoid maze · medium navigation
  2. ② Ant soccer · arena exploration
  3. ③ Manipulation scene · multi-stage task

On AntSoccer our method is well ahead of every published baseline: an AUC of 0.719 against 0.454 for the strongest, SUPE with HILP skills [5]. On HMaze-med it reaches 0.744, ahead of SUPE's 0.691 and below only SUPE + empowerment [6] at 0.780. Every baseline that does not use skills or a pretrained policy stays at or near zero on both settings, which is what our framing predicts: a sparse reward that has to propagate from scratch does not arrive within the budget, while a goal-conditioned policy that only needs the goal's identity can act as soon as the goal is seen.

On Scene our AUC is 0.188, below DSRL [9] at 0.789, SUPE with HILP skills at 0.669, HILP skills at 0.346 and SUPE at 0.329, though above SUPE with empowerment at 0.127 and every other baseline. In our development runs the weakest environments were limited after discovery rather than before it: the deployed curve oscillated after discovery and fine-tuning degraded some policies, so finding the goal early did not by itself give a high AUC.

How we got here

  • Reframing first. Our literature review noted that, on tasks, the optimistic relabelling of the skill-based baseline reduces to a constant reward plus a novelty bonus, and our offline diagnostics showed that a small fraction of prior transitions already satisfies the task. Together these led us to treat the problem as goal identification.
  • Hilbert-representation skills were too weak as the backbone. Our first version used HILP [5] as the goal-conditioned policy; in development it reached a goal-reaching success rate of 0.1 after 100,000 training steps on one environment, and was weak on most others. We re-implemented HIQL instead, and after fixing several fidelity bugs (among them advantages that were not detached, and a goal representation reused from instead of recomputed at ) it reached, by our development measurements, 80 to 95% goal-reaching success across environments.
  • Discovery became fast. With HIQL as the return mechanism, coverage found the goal on one environment in about 4,300 steps, against about 27,000 that we noted for SUPE.
  • Relabelling prior successes hurt. A variant that relabelled the prior transitions near the discovered goal as task data was clearly worse; the sparse relabelled set injected a mostly negative task signal. We kept task supervision on the online half only.
  • The medoid replaced the mean goal, after a fine-tuning regression on one environment for which we suspected the off-manifold averaged goal.
  • A best-checkpoint guard came from observed collapses. The revert caught real collapses in development, but on one environment fine-tuning degraded the policy without triggering it, so we made deployment always ship the best checkpoint rather than the latest parameters.
  • More updates per step helped. Raising the fine-tuning update ratio from 4 to 8 per step raised our development AUC on one environment, measured partway through the budget, from 0.84 to 0.891.
  • Self-imitation and success-only task training were tried and not kept. We added self-imitation of successful episodes and a variant that trained the task value only on successful episodes; neither is in the final method.
  • Route selection went through several designs. Coverage-greedy route selection, which maximises the prior states newly covered, biased the sweep toward atypical routes and stalled on one environment, where a random sweep without replacement found the goal in under a quarter of the steps after which the greedy sweep was still stalled. A forward-only projection window beat a re-acquiring controller and global re-projection in our tracking diagnostics (2 of 10 routes tracked to the goal against 1 of 16 and 0 of 16), because a waypoint that jumps makes the agent chase a moving target.
  • Neither pure mode works everywhere. On one environment, reaching random prior states found the goal in 7,740, 23,688 and 37,658 steps over three development seeds, far sooner than route following; on another, pure reaching never found the goal, which we attribute to the goal region being too sparse in the prior data. A fixed half-and-half portfolio was worse than pure reaching where reaching worked, since it halved its parallelism. Switching after a number of failed routes was unreliable, and switching on tracking drift did not separate the environments, since drift was high in both. The criterion that did separate them was route length relative to the episode, and the quarter-budget fall-back rescued an environment where an unlucky route sweep stalled.
  • Discovery time varies a great deal. With identical reaching logic, the same environment was discovered after about 23,000 steps in one run and after about 118,000 in another; we attribute this to the sensitivity of coverage exploration to its random stream, not to a bug.

Limitations

  • Scene is below four baselines. Our AUC on Scene is 0.188, against 0.789 for DSRL [9]. In development the weakest environments were limited by fine-tuning after discovery, where the deployed success oscillated or fell; the best-checkpoint guard bounds that damage but does not remove it.
  • The checkpoint guard trusts a proxy. The online success rate is measured from the training environments' own initial states, with windows of finite size and no test of significance; a lucky window can become the best checkpoint and then block later, better ones from being kept, and training continues from a policy up to 0.20 worse than the best, or from any policy after three reverts.
  • Only the value sees the task goal. In fine-tuning the discovered goal replaces only the value goal; the high- and low-level actors are still trained on hindsight goals and learn the task only through online successes and the value they are weighted by. Our own docstring says the high-level actor is trained on the task, which overstates what the code does.
  • Exploration ends at the first success. After discovery every environment acts deterministically toward . If the first successes come from an unrepresentative part of the goal region, nothing in the method looks for a better one.
  • Discovery depends on the prior data covering the goal. The method rests on the prior data passing through the goal region. Where it rarely does, reaching random prior states can fail to find the goal within the budget, as it did on one development environment, and route following depends on the luck of the sweep; the discovery time, and with it the AUC, varies widely between runs.
  • The mode switch is a heuristic. The factor 1.5 on the episode length and the quarter-budget fall-back were chosen from a small number of development runs and are not derived.

References

  1. Philip J. Ball, Laura Smith, Ilya Kostrikov et al. (2023). Efficient Online Reinforcement Learning with Offline Data. ICML.
  2. Qiyang Li, Jason Zhang, Dibya Ghosh et al. (2023). Accelerating Exploration with Unlabeled Prior Data. NeurIPS.
  3. Yuri Burda, Harrison Edwards, Amos Storkey et al. (2019). Exploration by Random Network Distillation. ICLR.
  4. Max Wilcoxson, Qiyang Li, Kevin Frans et al. (2025). Leveraging Skills from Unlabeled Prior Data for Efficient Online Exploration. ICML.
  5. Seohong Park, Tobias Kreiman, Sergey Levine (2024). Foundation Policies with Hilbert Representations. ICML.
  6. Ishir Garg, Vivek Myers, Qiyang Li et al. (2026). Measuring Empowerment from Offline Data for Intrinsically Motivated Exploration.
  7. Seohong Park, Dibya Ghosh, Benjamin Eysenbach et al. (2023). HIQL: Offline Goal-Conditioned RL with Latent States as Actions. NeurIPS.
  8. Seohong Park, Kevin Frans, Benjamin Eysenbach et al. (2025). OGBench: Benchmarking Offline Goal-Conditioned RL. ICLR.
  9. Andrew Wagenmaker, Mitsuhiko Nakamoto, Yunchu Zhang et al. (2025). Steering Your Diffusion Policy with Latent Space Reinforcement Learning. CoRL.

The session

The run from the model's first output, drawn as Claude Code shows a conversation: 1,025 steps.

Open the session

The submitted code

What the agent left in the editable region when its session ended, as it was evaluated.

supe/r2_method.pythe changes against the starter, inside the editable region