Skip to content

cvc::nav coef_trainer: learning history, checkpoint blobs, pre-clip grad norm - #1141

Merged
transfix merged 4 commits into
masterfrom
feat/nav-learning-instruments
Nov 14, 2026
Merged

transfix merged 4 commits into
masterfrom
feat/nav-learning-instruments

Conversation

@transfix

@transfix transfix commented Nov 11, 2026 •

Copy link
Copy Markdown
Owner

A falling training loss does not show that the nav policy learned anything. coef_trainer already scores checkpoints on a fitness: typically reach_on_plant on validation seeds, with the untrained policy included and rollback. It then ends on the best. Nothing else was recorded:

  • the global gradient norm adam_step computes was dropped;
  • the loss went to the console every 50 steps;
  • nothing read the heads one by one;
  • the scored checkpoints were never written out.

This adds those instruments, all opt-in. It is the cvc::nav side of the same instruments on the GRL-SNAM trainers.

What it adds

New train_config fields, all off by default:

  • history_path: a JSON-lines history.
    • A header.
    • Per outer step: the windows' mean loss and the last window's, the learning rate, and the pre-clip gradient norm (mean and max over the step's Adam steps, and the share that clipped).
    • Per checkpoint (step 0, every checkpoint_every, and the last; recorded with or without a fitness):
      • the fitness, whether it is the best so far, and whether it rolled back;
      • per head (alpha, beta, gamma, each the output layer's row): its mean and spread over a fixed probe batch of the scene's agents, and its ||Δθ||/||θ|| since the last checkpoint and since the start;
      • the trunk (the hidden layers) alongside.
    • An end record: the selected step, the rollbacks, the episodes.
  • checkpoint_prefix: each checkpoint's policy, as it was scored (before any rollback), saved as <prefix>.stepNNNNNN.cvcnav (coef_checkpoint_path).
  • probe_agents, probe_seed (256, 0x5eed): the probe batch, drawn once from the scene. It only feeds the head numbers and selects nothing.
  • coef_trainer::last_grad_norm() and last_lr().

Scope: the CPU coef_trainer::train only; train_coef_mlp_cuda ignores the new fields. docs/NAV_TRAINING.md documents them under "Recording what training does" and in the hyperparameter table.

Defaults unchanged: the evidence

  • Same training as origin/master. I built origin/master (ddf8585) and this branch: Release, no CUDA. A driver linked against each ran four configs on city_scene(64): surrogate and bicycle rollouts, each without a fitness and with a fitness, checkpoint_every 10 and rollback_drop 0.05. All four give identical output on both builds: the trained parameters' hash, every checkpoint score to 9 digits, the selected step, and the rollbacks.
  • The instruments only read. LearningInstrumentsDoNotChangeTraining turns both instruments on in a run with a fitness and rollback, and in one without a fitness. The trained parameters, checkpoint scores, selection, rollbacks and last grad norm all match the plain run exactly.
  • Off by default. LearningInstrumentsAreOffByDefault: a default train_config has both paths empty, so train() takes no instrument branch.

Tests (in nav_coef_train_test)

  • LearningHistoryRecordsStepsCheckpointsAndBlobs:
    • the record counts (header, 20 steps, 5 checkpoints, end);
    • the best and rolled-back flags land on the right checkpoints;
    • each checkpoint blob reloads to exactly the policy the fitness scored, including the one that then rolled training back.
  • LearningHistoryHeadsMoveOnlyWhenTrained:
    • at lr = 0 every head's Δθ is 0 and the head numbers repeat at every checkpoint;
    • a trained run moves all three heads and the trunk;
    • the probe spread is non-zero.
  • LastGradNormIsBeforeTheClip: a known gradient's norm is reported above a tiny clip.
  • UnwritableHistoryThrows: an unwritable history throws before any parameter changes.

Locally (Linux, GCC 13, Release, no CUDA): all 36 nav_coef_train_test cases pass. That includes the existing gradcheck, convergence, checkpoint selection and rollback tests. CI's clang-format reports nothing on the changed lines.

…clip grad norm

A falling training loss does not show the policy learned anything. The trainer
already scores checkpoints on a fitness (reach on the plant, the untrained
policy included) and ends on the best. It recorded nothing else: the global
gradient norm adam_step computes was dropped, the per-step loss went to the
console every 50 steps, nothing read the heads one by one, and the scored
checkpoints were never written out.

train_config gains (all off by default; CPU trainer only):
- history_path: a JSON-lines history. A header; per outer step the windows'
  mean loss, the last window's, the learning rate, and the pre-clip gradient
  norm (mean and max over the step's Adam steps, the share that clipped); per
  checkpoint (step 0, every checkpoint_every, the last; with or without a
  fitness) the fitness, best-so-far and rollback flags, and per head (alpha,
  beta, gamma: the output layer's row) its mean and spread over a fixed probe
  batch of the scene's agents and its ||dtheta||/||theta|| since the last
  checkpoint and since the start, the trunk alongside; an end record.
- checkpoint_prefix: each checkpoint's policy, as scored (before any
  rollback), saved as <prefix>.stepNNNNNN.cvcnav.
- probe_agents / probe_seed: the probe batch (it selects nothing).

coef_trainer::last_grad_norm() / last_lr() expose the last Adam step's.

Training is unchanged, bit for bit: the instruments only read the parameters.
Tests pin that (same parameters, checkpoint scores, selection and rollbacks
with them on, with and without a fitness), and the history's contents.
…N-escaped)

On Windows the checkpoint path has backslashes, which the history escapes as a
JSON string must; the test looked for the raw path and failed on every Windows
lane. Compare against the escaped form.
@transfix
transfix merged commit 4239741 into master Nov 14, 2026
58 of 60 checks passed
@transfix
transfix deleted the feat/nav-learning-instruments branch November 14, 2026 19:34
transfix added a commit that referenced this pull request Nov 15, 2026
Master's #1217 keeps nothing per thread in state_exec: a native's context (call_args::context())
carries its group, registry and stream, async_host::call and begin_external take it, and the pool
drops in_pump_all() and the one-argument run_on_host.

- async_host.h: begin_external takes the context, as on master, and keeps this branch's note that
  a call is finished through the host it was made on.
- script_engine.cpp: the sliced form finds the calling program's group from the call's context
  (exec_group::current(ctx)), else group 0, and reads its data step from the context.
- ariadne.cpp: file-pick opens its picker through run_on_host for the group its verbs were bound
  for (the env's, as its host is), and inline in group 0 and the init lane.
- exec_pool: in_pump_all() is back, for the host-thread calls' debug assertion and
  ScriptLane::run's refusal, read from the pool's calls (their callers' and pumpers' thread ids)
  under its mutex rather than from thread-locals.
- ariadne_runtime_test: the init lane's cycles test no longer compares against the calling
  thread's own registry, which master removed; it is AriadneInit.RunsAScriptThatLeavesCycles.
- ci.yml: the sanitizer's required list names the test by its new name.
- STATE_EXEC_THREADED.md: B29-B31 and the file-pick and sliced-call notes name the context-based
  calls.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant