Repository navigation
nav: the belief net — .cvcnm version 2, C-channel risk patches, the patch crop and the gate in training (B3) - #746
Merged
Conversation
The deployed drive steers the material policy and an external force together (drive_step_material_ext with an ext_force: cvcdbg's RF/comm force), but the material trainer trained the material heads with no such force present. material_ext (material.h) puts it in every material training rollout, joined as the deployed drive joins it: - the surrogate adds it to ftot (a point mass: steer has nothing to act on); - the bicycle and the dynamic vehicle add it last to F = F_bar + F_goal + F_mat, and with steer to the steering bias (F_rep + F_mat + F_ext) . left; - a null channel is the rollout without one, bit for bit (conditional adds). Sources, exactly one: K force patches per agent on the rollout patch's grid with a per-step schedule (a force that depends only on the agent's position, e.g. fixed radios and jammers switching on and off; J is the patch's gradient), per-step values with an optional J, or a C++ callback with hold. The VJPs chain J^T dL/dF_ext into the position adjoint (a held window's sum at its sampled step) and return dL/dF_ext per step. detail/material_ext.h holds the per-step sampler and the reverse's window. material_batch::ext carries it through material_loss / material_loss_and_grad; L_multi leaves it out; with it the surrogate runs on the CPU. pycvc: optional trailing ext_patch / ext_patch_of_step / ext_F / ext_J / ext_steer on nav_integrate_surrogate_material, nav_integrate_bicycle_material(_vjp) (want_g_fext returns g_fext) and nav_material_trainer_step / _loss, checked with the GIL held. Tests: nav_material_ext_test (null and zero force bit-identical on all three integrators; the coefficient gradients through a scheduled force patch and through a held callback against finite differences; dL/dF_ext; a callback giving the patch is the patch; steer; malformed channels; NavMaterialExt.Golden writes tests/data/material_ext_golden.json for GRL-SNAM's torch twins), nav_material_train_test's full chain with an external force (surrogate and bicycle), and test_pycvc_nav_train's test_external_force (the bindings reproduce the golden to 4e-9). Also: sim_world.h's set_ext_force comment said the ext force had no effect on the material path; step() fuses them through drive_step_material_ext.
…r a torch twin trainer material_loss and material_loss_and_grad take an optional material_loss_parts: L, each unweighted term (traj, vel, fric, clear, nav, lreg, multi) and the CVaR eta, for a twin trainer's parity and for logging. TheLossPartsAddUpToTheLoss checks they sum to L on both entry points. TorchTrainerGolden runs the native trainer for 3 Adam steps on the fixture batch with a scheduled external force patch, and with CVC_MATERIAL_TRAIN_GOLDEN_DIR set writes the golden GRL-SNAM's torch material trainer is held to: the config, batch and force (JSON), the weights before and after (.cvcnm), step 0's weight gradients (float32) and each step's loss terms. Not committed (2.5 MB).
Comments and docs only: ext_force is a hook for a caller's own force, and the golden is for a torch twin of the loss; no downstream user is named.
…ittable downstream build_test_model takes the header's widths (d_tok, nhead, num_layers, d_risk); the table at the default widths is the fixed one (TestModelTableAtDefaultWidths), so every existing test and golden is unchanged. The golden test is now a helper: TorchTrainerGolden as before (loss 42.952275 -> 25.870981, eta 33.5428), and TorchTrainerGoldenSmall at d_tok 16, 2 heads, 1 layer, d_risk 16 on a batch of 4 with a 9x9 rollout patch: 59,542 parameters, about 0.8 MB written, small enough for a torch twin's CI to commit.
# Conflicts: # docs/NAV_MATERIAL.md
…atch crop and the gate in training (B3) B3 of docs/roadmap/NAV-BELIEF-MATERIAL-ROADMAP.md, with §9's recommended column: - .cvcnm version 2 for a 3-channel net ([r~, hard, seen]): the version-1 layout plus a belief block after eps, <IIfIIff> (risk_channels, seen_rule, unknown_risk, unknown_hard, unknown_gate_hard, material_range_m, patch_extent_m), the layout GRL-SNAM's matnet_export writes. A 2-channel net is still version 1, byte for byte. coef_energy_net::risk_channels() / belief_header() / set_belief_header() / meta(). - The loader checks every known tensor's shape against the hyperparams and the risk encoder's channels against the header, bounds-checks every read, and keeps the meta trailer, which serialize() now writes back (it used to drop it). - The CPU and CUDA forward and backward and the trainer take C = risk_channels() channels: material_batch::risk_patch is [B*C*P*P]. - material_batch::gate_active ([B] u8, null = ungated): each agent's lam_soft enters every rollout times its bit, and its gradient through the rollout is gated the same way; L_lreg reads the head's own lam_soft (as GRL-SNAM's torch trainer does). - material_patch_belief (belief_material.h): the model's 3-channel patch, cropped from belief planes around an agent; BIT, op order pinned in the header. - pycvc: nav_material_patch_belief; nav_material_trainer_risk_channels; a trailing gate_active on nav_material_trainer_step / _loss; nav_matnet_forward and the trainer take (B,C,P,P) patches. Tests: - nav_belief_material_net_test: version 1 round-trips byte for byte with its meta; version 2 carries the block at the right offsets and round-trips; the loader refuses a 3-channel version 1, an unknown version, a bad block, a mismatched d_tok and truncation; a zero seen channel is the 2-channel net in the forward and backward; the crop at cell centres, off the map, unseen, and between cells. - nav_material_train_test: the full-chain gradcheck on the belief net with the gate (surrogate dir_rel 3.8e-5, bicycle 4.4e-4); the gate on is ungated byte for byte; TorchTrainerGoldenBelief (golden 3: the small golden's widths with 3 channels, patches cropped from golden 1, the gate on agents 0 and 2; loss 49.43 -> 41.69). The 2-channel small golden is byte-identical to before. - nav_coef_energy_cuda_test: the 3-channel forward (3e-7) and backward (1.2e-4, cos 1) match the CPU on a GTX 1650. - test_pycvc_nav_train: the belief net trains with the gate and saves as version 2; the crop matches its numpy twin byte for byte.
…erial-net # Conflicts: # bindings/pycvc/pycvc_nav.i # bindings/pycvc/test_pycvc_nav_train.py # inc/cvc/nav/material_train.h # src/cvc/nav/material_train.cpp # src/cvc/tests/coef_energy_test_model.h # src/cvc/tests/nav_material_train_test.cpp
transfix
added a commit
to CVC-Lab/GRL-SNAM
that referenced
this pull request
Oct 20, 2026
…r both trainers (#131) The torch side of libcvc's B3 (transfix/libcvc#746) for belief (observed) material: - grl_snam/belief_material.py: material_patch_belief, the model's 3-channel [r~, hard, seen] patch cropped from belief planes around an agent (r~ bilinear, hard and seen from the nearest cell, the pinned values where it is unseen or off the map), bit-identical to libcvc's kernel. - material_train_native.MaterialTrainer passes a batch's gate_active to the native trainer (HAS_MATERIAL_TRAINER_GATE), and reports risk_channels. - tests/fixtures/material_train_golden_belief: libcvc's TorchTrainerGoldenBelief (the small golden's widths with the 3-channel net, patches cropped from golden 1, the gate on agents 0 and 2; .cvcnm version 2 weights). Tests: - test_material_train_torch: the belief golden in the step-0, three-Adam-step and terms tests (CPU, float32 and float64, the small golden's tolerances), and a live torch-vs-native comparison of the belief net with the gate on the surrogate and the bicycle. - test_belief_material_parity: the crop reproduces the golden's four patches byte for byte, pins unseen and off-map samples, and matches pycvc's nav_material_patch_belief.
This was referenced Oct 20, 2026
transfix
added a commit
that referenced
this pull request
Oct 21, 2026
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.
This is B3 of
docs/roadmap/NAV-BELIEF-MATERIAL-ROADMAP.md: the belief net. It adds a 3-channel[r~, hard, seen]risk patch,.cvcnmversion 2, the crop that builds that patch from belief planes, and the witness gate in training. It follows §9's recommended column, and everything is additive: a 2-channel net and an ungated batch behave exactly as before.On top of #734, merged as f7930c0. master is merged in (376e91a), so the diff is B3's change alone, and the full CI/CD runs on it.
.cvcnmeps,<IIfIIff>: risk_channels, seen_rule, unknown_risk, unknown_hard, unknown_gate_hard, material_range_m, patch_extent_m. That is the layout GRL-SNAM'smatnet_exportalready writes (belief material (T2, part 1): a 3-channel net, .cvcnm v2, the gate in training CVC-Lab/GRL-SNAM#129).serialize()now writes back (it used to drop it).risk_channels(),belief_header(),set_belief_header(),meta().The net and the trainer
C = risk_channels()channels;material_batch::risk_patchis[B*C*P*P].material_batch::gate_active([B]u8, null = ungated): each agent'slam_softenters every rollout times its bit, and so does its gradient through the rollout.L_lregreads the head's own value, matching the torch trainer.material_patch_belief(belief_material.h) is the model's patch for one agent. It takes P×P samples overextent_m: r~ bilinear, hard and seen from the nearest cell, and the pinned values where that cell is unseen or off the map. It is BIT, with the op order pinned in the header.nav_material_patch_belief;nav_material_trainer_risk_channels;gate_activeonnav_material_trainer_step/_loss;(B,C,P,P)patches innav_matnet_forwardand the trainer.Tests
.cvcnmversion 1 with metad_tokand truncationdir_rel3.8e-5 (surrogate), 4.4e-4 (bicycle)nav_coef_energy(4),nav_coef_energy_grad(6),nav_material_optim(3),nav_material_train(16), the CUDA suites (4 + 4),test_pycvc_nav_trainGolden 3 is
NavMaterialTrain.TorchTrainerGoldenBelief, written withCVC_MATERIAL_TRAIN_GOLDEN_DIR, like the small golden. It uses:material_patch_belieffrom golden 1's full planes (the JSON records the crop inputs);Its
_w0/_w3files are.cvcnmversion 2. The loss goes 49.43 → 41.69 over 3 steps. A numpy twin of the crop reproduces its four patches bit for bit; they are 92%, 100%, 0% and 51% seen.