Skip to content

feat: add accelerated compiled graph backends and WGPU support#1

Merged
leafyoung merged 6 commits into
mainfrom
review-fixes
May 11, 2026
Merged

feat: add accelerated compiled graph backends and WGPU support#1
leafyoung merged 6 commits into
mainfrom
review-fixes

Conversation

@leafyoung

Copy link
Copy Markdown
Owner

Summary

  • add compiled graph IR, reusable workspaces/buffers, backend capability reports, and graph/tape execution utilities
  • add backend-ready batch/device abstractions plus scalar, SIMD, mock-device, and feature-gated WGPU execution paths
  • add the first real WGPU backend skeleton with explicit device buffers/transfers, conservative exact-safe native compute eligibility, and native-vs-fallback execution tracing

Details

  • compiled IR, flat instructions, backend capability validation, metadata, and auto-dispatch helpers
  • scalar/SIMD batch compute and gradient execution, including AVX/SSE paths and scalar-lane fallback coverage for the current opcode set
  • device planning APIs, mock-device execution buffers, transfer plans, backend diagnostics, and graph-level helpers
  • feature-gated backend-wgpu support with real adapter/device initialization, GPU buffers/transfers, restricted exact-safe native batch compute, and host fallback for unsupported graphs/batches and gradients
  • README/examples/tests/benchmarks updated to cover the new APIs and backend behavior

Validation

  • cargo fmt --check
  • RUSTC_WRAPPER= CC=gcc cargo test --all-features
  • RUSTC_WRAPPER= CC=gcc cargo test --examples --all-features
  • RUSTC_WRAPPER= CC=gcc cargo clippy --all-targets --all-features -- -D warnings
  • RUSTC_WRAPPER= CC=gcc cargo bench --no-run

Copilot AI review requested due to automatic review settings May 10, 2026 15:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR significantly expands petite-ad beyond the legacy tuple-graph APIs by introducing reusable graph/tape/compiled-IR execution, adding forward-mode differentiation utilities, extending the mono/multi op sets and Hessian support (exact and finite-difference), and wiring in feature-gated backend infrastructure (including an initial WGPU skeleton).

Changes:

  • Added a reusable Graph/Tape API plus compiled IR/workspace abstractions and backend capability reporting.
  • Added forward-mode AD utilities (ForwardAD) and expanded mono/multi operation support (incl. checked-domain evaluation and higher-order Hessian methods).
  • Added optimizer utilities (Gradient Descent, Adam), new examples/benchmarks, and CI/dev tooling updates.

Reviewed changes

Copilot reviewed 43 out of 47 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/optim.rs Adds simple optimizers (GD/Adam) with basic validation and tests.
src/multi/tests.rs Adds Hessian and Hessian-row tests for multivariate tuple graphs.
src/multi/parser.rs Introduces a small expression parser that builds reusable Graphs.
src/multi/op_rules.rs Centralizes scalar + first/second-derivative local rules for MultiAD ops.
src/multi/multi_hessian_common.rs Shared dual-number Hessian algorithm for FR/RF exact methods.
src/multi/multi_ad_rf.rs Implements/exposes exact RF Hessian API + tests.
src/multi/multi_ad_fr.rs Implements/exposes exact FR Hessian API + tests.
src/multi/builder.rs Extends builder with node-handle graph construction + legacy compatibility.
src/multi.rs Re-exports compiled/graph/backends and wires in new modules.
src/mono/types.rs Adds a Dual type for forward-mode/higher-order internals.
src/mono/tests.rs Adds tests for finite-difference Hessian + new mono ops.
src/mono/tests_ho.rs Adds higher-order (RR/FR/RF) test coverage and cross-method consistency checks.
src/mono/mono_hessian_common.rs Shared utilities for mono FR/RF Hessian computations.
src/mono/mono_ad.rs Extends mono op set + adds checked evaluation and finite-difference Hessian helpers.
src/mono/mono_ad_rf.rs Adds mono RF exact Hessian API built on shared utilities.
src/mono/mono_ad_fr.rs Adds mono FR exact Hessian API built on shared utilities.
src/mono.rs Wires mono module exports, including higher-order APIs and tests.
src/main.rs Updates demo binary to showcase Hessian computations.
src/macros.rs Extends macros for new mono ops and higher-order mono op enums; extends multi ops list.
src/lib.rs Updates crate-level docs and re-exports for new APIs (graph/tape/compiled/forward/optim).
src/forward.rs Adds public forward-mode AD API for mono expressions, tuple graphs, and reusable graphs.
src/error.rs Extends error model with InvalidGraph and DomainError helpers.
examples/wasm_demo.html Adds a sketch HTML file documenting a potential WASM demo shape.
examples/optimizer_adam.rs Adds an Adam optimization example using Graph.
examples/newton_method.rs Adds a Newton’s method example using exact Hessians.
examples/hessian_performance.rs Adds a simple timing comparison example for exact Hessian methods.
examples/hessian_demo.rs Demonstrates approximate vs exact Hessian methods and their accuracy differences.
examples/graph_api.rs Demonstrates the new reusable Graph and ExprGraph APIs.
examples/gradient_descent.rs Adds a basic gradient descent example using Graph.
Cargo.toml Adds feature flags (serde, backend-wgpu) + new deps and profile tuning.
benches/hessian_benchmark.rs Adds benchmarks for RR/FR/RF Hessian computation and scalability.
benches/compute_benchmark.rs Extends benchmarks to cover graphs/tapes/compiled IR, SIMD batch paths, and checked mode.
AGENTS.md Adds contributor/agent guidance, commands, and conventions.
.pre-commit-config.yaml Updates pre-commit hooks and adds generic file hygiene checks.
.gitignore Ignores Cargo.lock for the library repository.
.github/workflows/ci.yml Adds CI workflow for formatting/clippy/tests/bench compile + coverage + audit.
.cargo/config.toml Adds mold linker config and registry settings.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/forward.rs
Comment thread src/forward.rs
Comment thread src/multi/builder.rs
Comment thread src/optim.rs Outdated
Comment thread .github/workflows/ci.yml

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request significantly expands the library's capabilities by introducing exact second-order automatic differentiation (Hessian computation) using Reverse-over-Reverse, Forward-over-Reverse, and Reverse-over-Forward methods for both univariate and multivariate functions. It also adds a public forward-mode AD API, a reusable graph and tape API for repeated evaluations, compiled IR for batch execution with SIMD and prototype GPU backends, and built-in optimizers like Adam and Gradient Descent. Extensive documentation and benchmarks have been added to support these features. Feedback focuses on optimizing performance by reducing heap allocations in the forward-mode and Hessian accumulation loops, avoiding redundant arithmetic in value-only passes and Hessian matrix construction, and handling numerical edge cases such as power operations with a zero base.

Comment thread src/forward.rs Outdated
Comment thread src/forward.rs Outdated
Comment thread src/multi/multi_ad_rr.rs
Comment thread src/multi/multi_ad_rr.rs Outdated
Comment thread src/multi/op_rules.rs Outdated
Comment thread src/forward.rs Outdated

@leafyoung leafyoung left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

All 5 issues addressed in fc182e9. Thanks for the review!

@leafyoung leafyoung left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

5 of 6 issues addressed in fc182e9 (value-only forward pass deferred as follow-up). Thanks for the review!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 45 out of 49 changed files in this pull request and generated 3 comments.

Comment thread src/forward.rs
Comment thread src/forward.rs
Comment thread src/multi/builder.rs

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 45 out of 49 changed files in this pull request and generated 5 comments.

Comment thread src/optim.rs
Comment thread src/optim.rs
Comment thread .cargo/config.toml Outdated
Comment thread .cargo/config.toml Outdated
Comment thread src/mono/types.rs

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 45 out of 49 changed files in this pull request and generated 1 comment.

Comment thread src/mono/tests.rs

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 45 out of 49 changed files in this pull request and generated 3 comments.

Comment thread .pre-commit-config.yaml Outdated
Comment thread .pre-commit-config.yaml
Comment thread src/mono/tests.rs
leafyoung added 6 commits May 11, 2026 20:25
Add exact second-order automatic differentiation using
Reverse-over-Reverse, Forward-over-Reverse, and Reverse-over-Forward
methods for both univariate and multivariate functions.
Add reusable Graph and Tape APIs, forward-mode differentiation
utilities, checked-domain evaluation, multi-output graphs, tape
workspace reuse, and expanded mono/multi operation support.
Add compiled instruction IR for acceleration-ready execution,
batch compute/gradient APIs, reusable batch buffers, graph
serialization and parser utilities, optimizers (GD, Adam),
and stable math helpers (Log1pExp, LogAddExp).
Add flat backend IR with OpCode/FlatInstruction, SIMD backends
(f64x2 SSE2, f64x4 AVX), scalar-lane fallback coverage for all
opcodes, automatic backend dispatch, support diagnostics, device
batch planning, and mock-device execution harness.
Add real WGPU backend with device initialization, GPU buffer
allocation/upload/download, native WGSL compute kernel for
exact-safe batch value computation, execution tracing, and
host fallback for unsupported graphs and gradients.
Add 863 tests achieving 89.7% line coverage (LLVM engine).
Fix arity validation, Adam overflow, pow zero-base NaN, Hessian
perf, CI --all-features, value-only forward pass, mold linker
config, and pre-commit hook cleanliness.
@leafyoung
leafyoung merged commit 19c9d36 into main May 11, 2026
4 checks passed
@leafyoung
leafyoung deleted the review-fixes branch May 11, 2026 12: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.

2 participants