Skip to content

First changes for faster ntfield planning - #12

Merged
Tass0sm merged 6 commits into
mainfrom
feature/faster-ntfields
Nov 16, 2026
Merged

Tass0sm merged 6 commits into
mainfrom
feature/faster-ntfields

Conversation

@Tass0sm

@Tass0sm Tass0sm commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

Add an interface for encoding the goal once and planning with that fixed goal.
Add an "accel" submodule with a function using some backend to produce an accelerated field that supports faster inference. Define the inference-form model for for TD-NTFields method.
Add the inference-form model for the P-NTFields method.
Add a TensorRT backend for the acceleration submodule.

Tass0sm and others added 6 commits November 12, 2026 19:42
- TravelTimeModel.encode_goal / travel_time_from_encoded_goal: T(·, q_g) from a goal encoded once. TD-NTFields
  keeps the goal embedding, P-NTFields [q_g, f(q_g)]; other models fall back to forward with the goal expanded.
- TrainedField.towards(goal) returns a GoalField with travel_time(q) and gradient(q). MPPI plans with it.
- check_method checks travel_time_from_encoded_goal against forward. On the UR5e benchmark MPPI goes from 92 to
  42 ms per plan (scenarios) and from 195 to 113 ms (random pairs), with the same paths up to float32 rounding.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… backends

- ntfields.inference: InferenceModel, the tensor-only functions backends build (encode_goal, travel_time,
  pair_travel_time and the optional gradient, pair_gradient), and autograd_inference for any model, which
  TrainedField.towards now uses. TravelTimeModel.inference_model returns a model's own form (None by default).
- TD-NTFields' inference form, from fast-ntfields: LipschitzLinear rescales, the duplicated sin(lin1(x)) and the
  block gates folded into constants, instance norm written out, and gradients in forward mode. It matches autograd
  through the model to ~1e-15 in float64; check_method checks this for any model that has an inference form.
- accelerate(field, "eager" | "compile", cuda_graphs) returns an AcceleratedField, with CUDA graphs per batch
  size around each function. Gradients the inference form leaves out are absent and raise.
- A Field protocol for the planners, benchmark_ur5e and travel_time_error, which now take either field.
- On the UR5e benchmark (RTX 3090), compile + CUDA graphs plans MPPI in 9 ms instead of 41 (scenarios) and 20 ms
  instead of 110 (random pairs), with the same success counts, and the bidirectional gradient planner in 1.4 ms
  instead of 36.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The goal is encoded once as [q_g, f(q_g)], and gradients are first-order forward-mode jets through the encoder and
  the generator (tau_jet without its second derivatives), then T = ‖q_g - q_s‖ / τ. At q_s = q_g the norm's
  derivative is taken as 0, as autograd does. All five functions match autograd to ~1e-15 in float64.
- With the pntfields_arm preset on the UR5e problem (random weights, RTX 3090), compile + CUDA graphs takes MPPI from
  0.58 to 0.25 ms per step and the bidirectional gradient planner from 0.67 to 0.08 ms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- A [tensorrt] extra (torch-tensorrt 2.14, Python 3.12+ by a marker, so the core stays on 3.11).
- accelerate(field, "tensorrt", precision, batch): one engine per inference function, built on its first call with a
  dynamic batch, inside the CUDA graphs. fp16 applies to travel_time and pair_travel_time of models with
  float16-capable inference forms (TD-NTFields); encode_goal and the gradients stay fp32, and fp32 builds disable
  TF32. On the UR5e field at B = 1024, fp32 is within 1e-6 of the original model on T and 3e-5 on dT/dq, fp16
  within 4e-3 on T.
- ntfields export: serialized engines with named bindings, the original model's reference inputs and outputs, and a
  versioned meta.json, for runtimes outside Python. A test runs them through the bare TensorRT runtime.
- On the UR5e benchmark (RTX 3090), TensorRT plans MPPI in 6.0-6.8 ms (scenarios) and 16-19 ms (random pairs),
  against compile's 7.7 and 19, and the gradient planner in 2.2 ms against 1.2: in Python, compile stays the default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Importing torch_tensorrt on CPU torch raises AssertionError, which
pytest.importorskip doesn't catch, so check for CUDA first. Drop
torch-tensorrt from the dev group and exclude the tensorrt extra in
install-cpu.sh: the runners can't use it, and its NVIDIA stub wheel
failed to build on 3.14.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Only the test jobs exclude it; pyright needs torch_tensorrt to check
ntfields.accel.tensorrt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Tass0sm

Tass0sm commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator Author

Also modify the CI workflow to skip installing the new TensorRT extra.

@Tass0sm
Tass0sm merged commit 3ae990a into main Nov 16, 2026
6 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