Repository navigation
train-coef: fix the deterministic multi-start, the dropped penetration penalty, and the integrate_surrogate export - #113
Merged
Conversation
… audit multi_start_penalty drew no randomness (frac was a constant 0.9), so its ms_count=20 rollouts were one rollout repeated twenty times. Each start now moves a U(frac_range) fraction of the clearance toward the nearest obstacle, drawn per start and per sample. The default (0.8, 0.98) is centred on the old 0.9 so w_multi keeps its scale; (0.9, 0.9) reproduces the old value exactly and draws nothing; generator= makes it reproducible. A per-sample [B] robot_radius also crashed it whenever B != N (broadcast against the obstacle axis). Trainer.step_batch computed the penetration penalty and never added it to the loss (the line was commented out). It is now L += w_prox * pen, with explicit TrainCfg.w_prox = 0.1 / prox_tau = 0.05 (the values the commented-out getattr carried) and a --w_prox flag; 0 restores the old objective. grl_snam.integrate_surrogate exported the legacy explicit-Euler integrator while the trainer, the runtime stepper and cvc::nav all use the semi-implicit integrate_surrogate_v2. The export is now v2; the legacy one stays as train_coef_energy.integrate_surrogate_explicit for the version-1 trainer path. v2 itself crashed on its own default robot_radius=0.0 (indexed a 0-d tensor); it now takes a float or [B]. Regression tests: tests/test_training_loss_audit.py (14 of 15 fail on the parent commit; the 15th is a gradient guard).
transfix
added a commit
to transfix/libcvc
that referenced
this pull request
Oct 12, 2026
…rollout (#596) CVC-Lab/GRL-SNAM#113 made multi_start_penalty draw frac ~ U(frac_range) per start and per sample; the old fixed frac = 0.9 made its ms_count rollouts one rollout repeated. The native port mirrored that single start. multi_start_params now carries ms_count, frac_lo/frac_hi, seed and semi_implicit; the defaults are the old single explicit start, byte-identical to master (checked over 400 random batches). The draw is torch.rand's, bit for bit: std::mt19937(seed), low 24 bits, then the Python's lo + (hi - lo) * u with the same float rounding (multi_start_fracs). The ms_count rollouts run as one batch of ms_count*B agents; a degenerate range is evaluated once. A fixed seed is a fixed function, so the loss and gradient score the same starts and the finite-difference checks stay deterministic; the pycvc trainer's step k draws with seed + k and _loss scores the base seed. semi_implicit (forward + adjoint) selects GRL-SNAM's integrator, which has updated the velocity first since f5a015f; the default explicit order is the material fork's, which train_material.py imports. Without it, frac_range=(0.9, 0.9) matched native's start but not its rollout. Also fixes NaN coefficient grads for a padded agent with no valid obstacle: its start was o0 - frac * inf * 0, and the adjoint's 0 * NaN reached g_beta/g_gamma. It now contributes 0, like the Python's 1e6 sentinel. pycvc: nav_material_trainer_create takes trailing ms_count, frac_lo, frac_hi, seed and ms_semi_implicit, validated before any GIL-free step. Tests: rollout and multi-start FD gradchecks for both integrators and sampled starts at a fixed seed; determinism, degenerate-range, bad-range and no-obstacle cases; NavGeomRolloutParity pins the draw bit for bit and L/grads to ~3e-7 against torch autograd on GRL-SNAM #113 (gen_nav_geom_multistart_golden.py regenerates the goldens); full-chain trainer gradchecks with sampled starts; pycvc trainer arg coverage.
transfix
added a commit
that referenced
this pull request
Nov 7, 2026
* release: 0.3.0 95 commits since v0.2.1 (PRs #66 to #158), with new features, so the pre-1.0 minor version goes up. The main changes: - Ariadne hosts: GRL-SNAM's demos run as Python hosts of Ariadne documents (#147, #149, #153). `grl-snam ariadne cars` runs libcvc's multi-car template (#155), and fleet and live take its settings, worlds, plants, panels and log (#157). These need pycvc-gl 3.7.12. - Vehicle plants: capture, the demos, the fog-of-war stories and training run on kinematic, dynamic and Jolt plants (#119, #130, #143, #145, #154). - Torch twins of libcvc, held to its goldens: the material rollout (#118), terrain (#120), dyn_bike and dyn4 (#121, #123, #134-#136), the external force (#122, #124), the material trainer (#125), belief material (#128, #129, #131), U_nav (#133), and the port-Hamiltonian form, its energy books, wheel spin and compliant contact (#138, #139, #146). - The vehicle-plant port-Hamiltonian whitepaper (#137 to #158). - Training and evaluation: the base scorecard and selection (#82-#98), `grl-snam coef-train` (#102), the learned lam head and .cvcnav v2 (#94, #105), and the 2026-10 audit fixes (#113). - Data: grl-snam-weights, plus the Austin scene and Humvee as runtime dependencies, so `grl-snam demo` runs from a bare install (#72-#77). - The research core moves under grl_snam/ (#103). The world clock is shared with libcvc's (#116, #117). The version lives in pyproject.toml. The three cvcpkg columns mirror it in upstream_version and in the package.files dist-info path. cvc_revision goes back to 1 for the new upstream version. The publish job asks the server for the next revision in any case. * material_train_native: pass semi_implicit=False explicitly (libcvc #981) libcvc #981 (in 3.7.12) changed nav_material_trainer_create's ms_semi_implicit default from 0 to 1. MaterialTrainer left the L_multi sampling args out for the legacy single start, so on pycvc-gl 3.7.12 semi_implicit=False quietly ran semi-implicit Euler. #159's CI was the first run on 3.7.12, and four tests failed on cp311, cp312 and cp313: - test_sampled_multi_start_args: "semi_implicit did not reach the rollout", because the default and semi_implicit=True were now the same rollout; - test_live_native_trainer_agrees[legacy] and [legacy+ext], and test_live_native_trainer_agrees_on_the_belief_net[surrogate]: the explicit torch trainer and the native one differed by 1.3e-3 to 1.5e-3 (tolerance 1e-5). Now a binding that takes the args always gets them, so the integrator is the one asked for on any pycvc. An older binding still gets the legacy start through the old signature. GRL-SNAM's default stays explicit Euler. tests/test_material_train_native_args.py checks both bindings. Its new case fails without this change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes three defects in the CoefEnergyNet training path (
grl-snam train-coef/grl_snam.train_coef_energy) found by inspection on 2026-10-08 at1885bdb. Each one was confirmed with a failing test before it was fixed.origin/mainhas since moved tob934fcd(#112, recipes only), so the line numbers below are unchanged.Findings → confirmation → fix
1.
multi_start_penaltyis deterministic, so its 20 rollouts are identicalgrl_snam/surrogate_robust.py:188-217: the loop setsfrac = 0.9on every iteration and draws no randomness. With the trainer'sms_count=20, it runs one rollout twenty times at 20× the compute.frac ~ U(frac_range)of the clearance toward the nearest obstacle, drawn per start and per sample.(0.8, 0.98)is centred on the old 0.9, sow_multikeeps its scale.(f, f)draws nothing;(0.9, 0.9)reproduces the old value exactly.generator=makes the draw reproducible.[B]robot_radiuscrashed it wheneverB != N(it broadcast against the obstacle axis). That's fixed too.2. The penetration penalty is computed but never added to the loss
grl_snam/train_coef_energy.py:553-559:penis computed, but the line that adds it is commented out. It has been since the initial import.pen ≈ 9, yet the logged loss equals the sum of the other terms.L += w_prox * pen, with explicitTrainCfg.w_prox = 0.1andprox_tau = 0.05. These are the values the commented-outgetattrcarried. A--w_proxflag is added;w_prox=0restores the old objective.3.
grl_snam.integrate_surrogateexports the legacy explicit-Euler integratorgrl_snam/__init__.py:36-40pointed attrain_coef_energy.integrate_surrogate(:386-438), whose position step usesv_n. The trainer (:500), the DBG runtime stepper andcvc::navall integrate with the semi-implicitintegrate_surrogate_v2.o0 + dt·v0.integrate_surrogate_v2crashed on its own defaultrobot_radius=0.0(it indexed a 0-d tensor), so it could not have been dropped in as the export.grl_snam.integrate_surrogateis nowintegrate_surrogate_v2, which accepts a float or a[B]radius.train_coef_energy.integrate_surrogate_explicitand kept only for theversion != 2trainer path.Tests
tests/test_training_loss_audit.pyhas 15 tests. Onorigin/main, 14 fail and 1 passes (a gradient guard). On this branch all pass.Full suite on this box: 452 passed, 19 failed. The same 19 tests fail on an
origin/mainarchive (437 passed, 19 failed). They are this box's native-pycvc parity, missingmaterial_rasterdependencies, and the libm tripwire, and are unrelated to this change. black 26.5.1 (the CI pin) and ruff are clean.Did shipped weights or published results depend on these defects?
Nothing was re-run.
grl-snam-weights(coef_sdf.cvcnav/.pt, v1.0.0): not affected. It is produced bygrl-snam train(grl_snam/tools/train.py→sdf_navonly), which imports neithertrain_coef_energynormulti_start_penalty.share/cvc/nav/coef_mlp.cvcnav: not affected. It is the untrained bias-basin seed.train_coef_energy, i.e. CoefEnergyNet on the legacytrain-coeftrack, was affected by items 1 and 2. That includes the original research-code results, if any are still cited.cvc::nav::multi_start_penalty(src/cvc/nav/geom_rollout.cpp, used by the material trainer) is a faithful port of the old deterministic draw. It computes one start at 0.9, so it wasted no compute, and its value equals the old Python value. After this PR the Python default samples, andfrac_range=(0.9, 0.9)is the parity setting. Any.cvcnmfrom the native trainer used the deterministic start. Making libcvc sample too is a separate libcvc change.Shipping
The
grl-snam-cp31Xrecipe vendors the source, so this reaches the cvcpkg catalog only with acvc_revisionbump and a publish. Neither is done here.Do not merge without review.