Vectorise the tensor conversion layer - #13
Open
rodvals wants to merge 1 commit into
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.
Dependency
Stacked on #9 and targets
fix/multiple-fixes, because it must preserve the parsing semantics that pull request establishes: stored zeros are not edges, weights are kept, edge direction is not reversed, and isolated nodes survive. Merge after its parent, then rebase ontomasterand retarget.It shares no commits with #12 and can merge before or after it.
Problem
Six conversion functions in
utils/parsing.pystepped over one sparse entry at a time in Python, calling.item()per entry, so the cost was dominated by crossing the Python and torch boundary rather than by the work itself. Aggregation also carried three near identical branches forsum,maxandmin.Changes
coo_matrix(...).tocsr()forsum, and a sort plusreduceatformaxandmin; three branches become oneadd_edge_listcall per layer with a weight property, reciprocal edges collapsed by sortingTensor.index_add_, accumulated in float64 and cast backNo conversion changes what it returns.
Verification
tests/test_parsing_vectorisation.py: Every conversion is compared against a reference implementation carrying the original per-entry algorithm, so equivalence is demonstrated rather than assumed.sum323.1 ms to 2.2 ms,max371.3ms to 3.4ms,min361.9ms to 8.4ms, Laplacian 853.2ms to 5.9ms