Prune zero polynomial zonotope terms - #187
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e713eb5df8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| if torch is not None and isinstance(value, torch.Tensor): | ||
| if atol == 0.0: | ||
| return bool(torch.all(value == 0).item()) |
There was a problem hiding this comment.
Avoid per-term CUDA synchronization during pruning
When a PZ uses CUDA coefficients, .item() here forces a device-to-host synchronization for every term on every constructor call; since arithmetic paths rebuild PolynomialZonotope objects, large GPU-backed propagations will serialize around these checks even when no term is zero. Consider deferring/skipping pruning for non-CPU tensors or batching it so GPU work is not synchronized per monomial.
Useful? React with 👍 / 👎.
Motivation
Description
_is_zero_coeff(value, *, atol=0.0)that detects exact-zero coefficients for torch tensors, nested fallback tuples, and scalars while allowing explicit tolerance viaatolonly when opt-in.PolynomialZonotope.__init__by summing duplicate canonical exponent coefficients and skipping terms whose merged coefficient is exactly zero, avoiding scattered pruning across arithmetic helpers.Testing
pytest -q tests/test_polynomial_zonotope.py, which passed (all tests in that file passed).python -m pytest -q, which completed successfully with all tests passing (158 passed,1 warning).Codex Task