Skip to content

feat: add GRU transition model for latent-space dynamics prediction (OP#363)#3

Open
sahreen-haider wants to merge 7 commits into
mainfrom
1-feat-gru-transition-model-for-latent-space-dynamics
Open

feat: add GRU transition model for latent-space dynamics prediction (OP#363)#3
sahreen-haider wants to merge 7 commits into
mainfrom
1-feat-gru-transition-model-for-latent-space-dynamics

Conversation

@sahreen-haider

@sahreen-haider sahreen-haider commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

Implements a GRU-based transition model that predicts the next JEPA latent state
given the current latent and the action taken. This closes the loop between
perception (DINO ViT encoder) and planning by learning vessel dynamics directly
in latent space. Includes a full unit + smoke test suite and supporting fixes.

Changes

New: models/transition_model.py

  • GRUTransitionModel: single-layer GRU operating on (z_t ‖ a_t)z_t+1
  • Input dim: 389 (387 latent + 2 thruster commands), hidden dim: 256, output: 387
  • Includes init_hidden() for clean batch-compatible zero-state initialisation

main.py

  • Instantiates and runs GRUTransitionModel each step after env interaction
  • Fixes velocity obstacle avoidance to use the correct 2D velocity vector
    ([speed·cos(hdg), speed·sin(hdg)]) instead of the previous [speed, 0]
  • Saves transition model checkpoint alongside the world model
  • Logs z_t+1 norm in the step printout for a quick sanity check

env/maritime_env.py

  • Added get_vessel_state() returning (speed, heading_deg) for latent augmentation

config.yaml

  • Changed device: mpsdevice: cuda

perception/waste_detector.py

  • Added missing import numpy as np

utils/checkpoint.py

  • Added weights_only=True to torch.load to suppress PyTorch's upcoming
    security default change

New: tests/ — full test suite (52 tests, 0 failures)

File Tests Covers
tests/test_transition_model.py 14 Shapes, init_hidden, hidden state propagation, determinism, backward pass
tests/test_maritime_env.py 17 get_vessel_state, speed formula, heading wrap [0–360), step contract, done conditions
tests/test_jepa_world_model.py 14 Output dim, vessel state embedding, all 4 cardinal heading encodings, frozen encoder
tests/test_smoke.py 6 Full 5-step pipeline, checkpoint save/load, hidden context carry-over
  • pytest.ini added with testpaths = tests and pythonpath = .
  • tests/conftest.py stubs timm at the module level to work around a
    torchvision binary mismatch (torchvision::nms operator missing at
    registration time); individual fixtures monkeypatch timm.create_model
    to return a lightweight FakeEncoder returning the correct VISUAL_DIM

docs/gru_training_data_requirements.md (untracked — see note)

  • Full data spec: transition tuple schema, data volumes, collection policy,
    .npz storage format, normalisation, episode-level splits, MSE training
    loss, and real-vessel telemetry pipeline for future fine-tuning

Notes

  • checkpoints/ should be added to .gitignore — currently untracked but
    not ignored, .pth files will appear as untracked after any run
  • docs/ is excluded by .gitignore; remove that line if the data
    requirements doc should be versioned with the code

Test plan

  • 52 unit + smoke tests passing (python -m pytest tests/ -v)
  • Run main.py end-to-end on a CUDA machine; confirm z_t+1 norm
    logs a non-zero value each step
  • Confirm both checkpoints are written to checkpoints/ on episode end

OP#363

@sahreen-haider sahreen-haider linked an issue Jun 24, 2026 that may be closed by this pull request
6 tasks
@sahreen-haider sahreen-haider self-assigned this Jun 24, 2026
@sahreen-haider sahreen-haider added the enhancement New feature or request label Jun 24, 2026
@sahreen-haider sahreen-haider changed the title feat: add GRU transition model for latent-space dynamics prediction feat: add GRU transition model for latent-space dynamics prediction (OP#363) Jul 1, 2026

@ChinarCypher ChinarCypher left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overall integration looks great. It will be great if we can consider one smoke test that runs the real encoder (even on a tiny input) so we are not exclusively testing against FakeEncoder. Can we also confirm if the GRU hidden state is intended to persist across env steps within an episode and reset on done (tests mention carry-over).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: GRU Transition Model for Latent Space Dynamics

2 participants