Skip to content

grl-snam train: why the SDF retrain diverged, the fix, and the learning measure again - #179

Merged
transfix merged 2 commits into
mainfrom
fix/sdf-trainer-divergence
Nov 14, 2026
Merged

transfix merged 2 commits into
mainfrom
fix/sdf-trainer-divergence

Conversation

@transfix

Copy link
Copy Markdown
Contributor

Base GRL-SNAM's SDF retrain (grl-snam train) clipped every optimizer step and did not descend its own loss (#172). This finds why, fixes it, and runs #172's learning measure again. The record is docs/learning-validation.md §8.

Why it diverged

Two faults. The measurements are in experiments/learning_proof/gradient_source.py and §8.1.

1. The backward ran through all 28 rollout steps, and on Austin those steps are chaotic.

  • Austin's SDF is normalized at 1 unit = 300 m. The physics constants were set on the procedural city, where 1 unit = 20 m.
  • So in units, rr is one SDF cell, a step crosses 5.5 cells, and 99% of the map lies inside the barrier band.
  • Near walls, one step's Jacobian has norm ~15. Two things do it: the barrier's curvature, and the wall normal turning from cell to cell. With both off it is 1.0.
  • The gradient grows ~1.65× per step of backward. Median norm: 0.42 / 2.2 / 57 / 7.8e4 at windows 2 / 7 / 14 / 28.
  • The same objective on the city: 0.22, never clips.
  • Does base GRL-SNAM's policy learn? The coef_sdf learning check, and E1 (planted dissipation) #172's guesses do not fix it:
    • ipc_piecewise's clamp: still 100% clipped;
    • nsub 3: 95% clipped.

2. The collision term had no gradient. sdf_rollout detaches the clearance, so 3·col was a constant to the optimizer. With a clean gradient of the rest, training weakens the barrier and the loss rises: 3.96 → 5.40 in 1500 steps.

The fix (new defaults of grl-snam train)

  • --bptt-window 7: the backward is truncated every 7 steps (sdf_eval.loss_terms). Seven is coef-train's own window.
  • --col-grad: sdf_rollout(clr_grad=True) keeps the clearance's gradient.
  • Neither changes a forward value.
  • --bptt-window 0 --no-col-grad is the old trainer. It still reproduces the published coef_sdf.pt bit for bit (checked).
  • --grad-terms-every N records each loss term's gradient norm in the history (grad_norm.terms.<term>). The weights are unchanged.
  • tests/test_sdf_train_divergence.py uses a small field in Austin's frame. On main it fails: median pre-clip norm 864, every step clipped.

The measure again (§8.3–8.8)

Five seeds × 4000 steps, the same split and arms as §7, plus constant_final (a constant net at the final net's own mean coefficients). Paired bootstrap CIs, and learn-report.

Now true:

  • Every seed descends its training and held-out loss.
  • 13–16% of steps clip (was 100%).
  • The seeds agree: barrier ↑, goal spring ↓, damping ↑.

Criterion 1 (held-out per-term losses) passes on the loss. On 5120 held-out pairs, the trained net's objective is lower than every arm's:

arm trained − arm
untrained −0.81 [−0.92, −0.69]
published −0.73
constant −0.77
constant at its own mean −0.16 [−0.21, −0.12]

The collision term passes too. The goal and reg terms get worse: that is the trade the objective makes.

The net uses what it sees. On held-out Austin pairs it reaches more than a constant at its own mean: +0.7* on its own plant, +1.4* on libcvc's sim_world. On coef's ice-band city it penetrates 92% less than every arm.

Criterion 2 (task metric) still fails, now the other way.

  • Against the untrained net it reaches fewer held-out goals:
    • Austin: −1.2 [−1.8, −0.6] on its own plant, −1.7 [−2.7, −0.7] on sim_world;
    • city scorecard: −3.4*.
  • It keeps +5.7 m of clearance in exchange.
  • The reach pick is step 0 on every seed.
  • The cause is the objective: its collision margin is 0.02 units, which is 6 m on Austin and 0.4 m in the city. The next step is an objective that is the task, in metres (§8.8).

grl-snam-weights is not republished: the final nets reach fewer goals than what ships.

Files

  • grl_snam/tools/train.py, tools/sdf_eval.py, sdf_nav.py (clr_grad), learning_history.py (term_grads), cli.py
  • Tests: tests/test_sdf_train_divergence.py, and one assertion in test_sdf_train_instruments.py
  • experiments/learning_proof/gradient_source.py; sdf_arms.py and objective_arms.py gain constant_final
  • docs/learning-validation.md §8, and docs/learning-validation/fixed/ (histories, curves, arms, objective, scorecards, arms-eval tables, learn-report)

Testing

  • Locally (torch 2.13): 928 passed.
  • Two failures also fail on main in this venv: test_coph_golden::test_torch_rounds_g2s_exp_and_expm1_correctly (torch-version rounding) and test_plant_capture::test_plant_names (a pycvc build missing a feature).
  • black 26.5.1 and ruff are clean on CI's scope.

… term that has one

Truncate the backward every 7 rollout steps (--bptt-window) and let the collision term carry
gradient (--col-grad). Neither changes a forward value; --bptt-window 0 --no-col-grad is the
trainer before the fix and still reproduces the published coef_sdf.pt. --grad-terms-every records
each loss term's gradient norm in the history (grad_norm.terms.<term>).
…nd the measure again

The source (gradient_source.py), the pilot of each half of the fix, the five-seed retrain, every
arm on held-out Austin pairs, the procedural city and arms-eval's cases, and learn-report.
sdf_arms.py and objective_arms.py gain the constant_final arm (a constant at the final net's own
mean coefficients).
@transfix
transfix merged commit b1bd445 into main Nov 14, 2026
5 checks passed
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