Skip to content

Feat(planner): add optional Bézier trajectory head as swappable planner#69

Merged
m-zain-khawaja merged 6 commits into
autowarefoundation:mainfrom
gcordova10:feat/gabriela-4features
Jun 22, 2026
Merged

Feat(planner): add optional Bézier trajectory head as swappable planner#69
m-zain-khawaja merged 6 commits into
autowarefoundation:mainfrom
gcordova10:feat/gabriela-4features

Conversation

@gcordova10

Copy link
Copy Markdown
Contributor

Description

This PR introduces an optional, swappable Bézier trajectory planner head into the AutoE2E architecture, aligning with the WG's requirements for trajectory smoothing and jerk reduction.

Key Changes

  • Implemented BezierPlanner under Model/model_components/trajectory_planning/ using a precomputed Bernstein basis (zero scipy dependency).
  • Integrated PLANNER_REGISTRY to support modular, swappable planners.
  • Maintained full backward compatibility with the existing AutoE2E contract (trajectory, ego_hidden, future_visual_features).
  • Follows unicycle dynamics (acceleration, curvature) as per the project's contract.
  • Verified with 15+ unit/integration tests ensuring gradient flow and output integrity.

Testing

  • Verified numerical stability of Bernstein expansion against analytical reference.
  • CI passed successfully (lint + unit tests).

Closes #45 (Relates to #51)

WG Alignment Note: This implementation aligns with the "fast/reactive" planning layer discussed in the WG meeting. It serves as one of the metric trajectory planner heads identified as a
requirement for the current reactive block, ensuring compatibility with the broader architectural goal of separating reactive trajectory planning from future "slow-thinking" reasoning modules.

@gcordova10 gcordova10 changed the title Ffeat(planner): add optional Bézier trajectory head as swappable planner Feat(planner): add optional Bézier trajectory head as swappable planner Jun 17, 2026
@gcordova10 gcordova10 force-pushed the feat/gabriela-4features branch from 4119613 to 502e382 Compare June 17, 2026 12:44

@m-zain-khawaja m-zain-khawaja left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi @gcordova10 - this looks good to me. I noticed that you added a compute_planner_loss function. We already have a losses folder with a trajectory loss - could you please therefore remove the planner loss from your bezier_planner.py and if you need to add further losses, could you please add them under the losses folder.

Also, have you tried a forward pass test with your planner, do the layers work correctly?

@gcordova10 gcordova10 force-pushed the feat/gabriela-4features branch from 502e382 to 1dc1ecc Compare June 22, 2026 09:22
gcordova10 added a commit to gcordova10/auto_fsd that referenced this pull request Jun 22, 2026
…Loss + add forward-pass tests

- compute_planner_loss now calls losses/TrajectoryImitationLoss instead of an
  inline F.mse_loss (removes torch.nn.functional import); the planner owns no
  loss logic of its own. The method stays because BasePlanner declares it abstract and
  AutoE2E.forward(mode='train') invokes it.
- add end-to-end forward-pass tests through AutoE2E(planner_mode='bezier') in
  train and infer modes + a direct compute_planner_loss test. 14/14 green.

Addresses review on autowarefoundation#69.

Signed-off-by: GABRIELA CORDOVA <100548769@alumnos.uc3m.es>
@gcordova10 gcordova10 force-pushed the feat/gabriela-4features branch from 74f88ef to 1dc1ecc Compare June 22, 2026 09:57
@gcordova10

Copy link
Copy Markdown
Contributor Author

Hi @zainkhawaja!
I have force-pushed to update this branch. The Bezier Planner is now fully refactored to comply with the new BasePlanner interface (separating forward for inference and compute_planner_loss for training), and I've integrated it cleanly via the Planner Registry.
Note on the CI: The make typecheck (mypy) step might fail on this branch due to the pre-existing typing issue in map.py I kept my branch strictly focused on the Bezier planner and didn't include a fix here.
The PR is ready for review!

@gcordova10 gcordova10 closed this Jun 22, 2026
@gcordova10 gcordova10 reopened this Jun 22, 2026
Adds Model/model_components/trajectory_planning/ with a BasePlanner contract
and a BezierPlanner that smooths the (acceleration, curvature) control
profiles via a fixed Bernstein basis (math.comb, no scipy). Selectable from
AutoE2E via planner='bezier'; default 'autoregressive' (TrajectoryPlanner)
is unchanged, preserving the (trajectory, ego_hidden, future) 3-tuple.

Relates to autowarefoundation#45 (optional/swappable planners).

Signed-off-by: GABRIELA CORDOVA <100548769@alumnos.uc3m.es>
Signed-off-by: GABRIELA CORDOVA <100548769@alumnos.uc3m.es>
Signed-off-by: GABRIELA CORDOVA <100548769@alumnos.uc3m.es>
Signed-off-by: GABRIELA CORDOVA <100548769@alumnos.uc3m.es>
…tibility

Signed-off-by: GABRIELA CORDOVA <100548769@alumnos.uc3m.es>
…Loss + add forward-pass tests

- compute_planner_loss now calls losses/TrajectoryImitationLoss instead of an
  inline F.mse_loss (removes torch.nn.functional import); the planner owns no
  loss logic of its own. The method stays because BasePlanner declares it abstract and
  AutoE2E.forward(mode='train') invokes it.
- add end-to-end forward-pass tests through AutoE2E(planner_mode='bezier') in
  train and infer modes + a direct compute_planner_loss test. 14/14 green.

Addresses review on autowarefoundation#69.

Signed-off-by: GABRIELA CORDOVA <100548769@alumnos.uc3m.es>
@gcordova10 gcordova10 force-pushed the feat/gabriela-4features branch from 1dc1ecc to 158539c Compare June 22, 2026 15:20

@m-zain-khawaja m-zain-khawaja left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approved, thanks @gcordova10

@m-zain-khawaja m-zain-khawaja merged commit 945480f into autowarefoundation:main Jun 22, 2026
1 check passed
@gcordova10

Copy link
Copy Markdown
Contributor Author

@ryotayamada @m-zain-khawaja — as suggested in #56, I put together a small planner benchmark harness that runs gru, flow_matching and bezier through the PLANNER_REGISTRY under identical conditions (same embed_dim/horizon/inputs/device).

What it measures now (no checkpoint/dataset/sim needed): inference latency, parameter count, and architectural smoothness on the (accel, curvature) output — jerk = Var(Δaccel), curvature = Var(Δcurvature).

Results (GPU, batch=1, random weights — see caveat):

planner params latency p50 (ms) jerk Var(Δaccel) curv Var(Δcurv)
gru (autoregressive) 829K 43.3 1.4e-04 3.8e-04
flow_matching (ODE) 988K 11.3 4.2e+00 2.0e+00
bezier (one-shot) 495K 0.39 5.0e-06 1.2e-06

So Bézier is ~28× faster than flow-matching and ~110× faster than GRU, the lightest, and the smoothest by construction (Bernstein basis) — relevant for the real-time R-Car target.

Honest caveat: these are untrained weights, so the smoothness/latency numbers are architectural; ADE/FDE, off-road rate, collision and closed-loop stability are NOT comparable yet — they need a trained checkpoint + dataset (KITScenes/L2D) + a simulator (NAVSIM/Bench2Drive). The harness has hooks for those.

@m-zain-khawaja — since you're leading this comparison, happy to fold the harness into this PR or move it to a separate one, whatever you prefer. I can also help wire the trained ADE/FDE + closed-loop metrics once the training loop (#78/#67) is in place.

@zainkhawaja

zainkhawaja commented Jun 22, 2026 via email

Copy link
Copy Markdown

@m-zain-khawaja

Copy link
Copy Markdown
Member

Thank you @gcordova10 - these results are encouraging. Could you please add this in a separate PR 👍

m-zain-khawaja pushed a commit that referenced this pull request Jun 23, 2026
… for gru/flow_matching/bezier

Compares the registered planners under identical conditions: inference latency
(p50/p99/jitter), param count, and architectural smoothness (Var(Δaccel),
Var(Δcurvature)) on the (accel, curvature) unicycle output. ADE/FDE, off-road,
collision and closed-loop are left as documented hooks (need trained checkpoint
+ dataset/simulator). Addresses @m-zain-khawaja's request in #69 / #56.

Signed-off-by: GABRIELA CORDOVA <100548769@alumnos.uc3m.es>
@gcordova10 gcordova10 deleted the feat/gabriela-4features branch June 30, 2026 15:30
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.

Proposal: Diffusion decoder with flow matching as optional trajectory planner

3 participants