Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refactored the torch layer hierarchy. The main goals were making it easier to define custom semirings and cleaning up the deep method dispatch chains.
Layer hierarchy (before → after):
CircuitLayerwas a god-class with_scatter_forward,_scatter_backward,_safe_exp,_scatter_logsumexp_forwardall baked in. Now it's a thin wrapper aroundtorch.scatter_reducethat just takes areduce: str.LogSumExpLayersubclassesCircuitLayerand overridesforward— instead of the old runtimeif reduce == "logsumexp"branching.ProbabilisticCircuitLayerwas also tangled intoCircuitLayer. Now it's a separate branch underAbstractCircuitLayer, withProbabilisticSumLayerandProbabilisticLogSumLayeras clean subclasses (no moreif log_spacebranching orreduce_fncallables).GatherCircuitLayerfor custom reductions: pads groups into a 2D tensor so users just provide a standard torch reduction (e.g.torch.nanmean) + a fill value. No scatter knowledge needed.Custom semirings:
(sum_reduce, prod_reduce, zero, one, negate)where reduces are strings (forscatter_reduce-backed ops) or callables (for custom gather-based ops). No more passing layer constructors.("amin", "sum", float('inf'), 0.0, tropical_negate)for tropical semiring.Utilities:
scatter_logsumexpandgather_indicesintoutils.py.Performance:
nan_to_num_calls.Tests & benchmarks:
klay.torch.tests/test_benchmarks.pyusing pytest-benchmark for per-commit regression tracking.