Add sparse relation-aware Graph Transformer signals#652
Draft
yliu2-sc wants to merge 7 commits into
Draft
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.
Scope of work done
This PR adds several opt-in Graph Transformer improvements that make the encoder more relation-aware without enabling the graph-edge hard attention mask path.
pairwise_nonmissing_indicesfor pairwise structural attention bias so missing pairs can be distinguished from nonmissing pairs without carrying an extra dense nonmissing mask.relation_attention_mode="edge_type_bilinear". Relation edges are represented as sparse(batch_idx, query_pos, key_pos, relation_idx)coordinates, withsource -> targetmapped toquery=target,key=source.relation_value_mode="sparse_residual_gate", a zero-initialized relation-specific value residual path that lets relation type affect message content without replacing the main SDPA attention implementation.edge_attr_attention_bias_mode="sparse_linear", an opt-in sparse edge-attribute-to-per-head-logit bias path with zero-initialized per-relation projections.Explicitly out of scope: graph-edge hard attention masking. That path is intentionally not included in this PR because the recent experiments showed runtime/memory issues that need a separate design pass.
Implementation notes
to_homogeneous().pairwise_biasstays unchanged; this PR only removes the extra dense NM-specific mask and uses sparse coordinates for the additional nonmissing bias.Where is the documentation for this feature?: N/A for this draft. I can add docs/changelog notes once we settle the final public interface names.
Did you add automated tests or write a test plan?
/Users/yliu2/Desktop/BAGL/.venv/bin/ruff check --config pyproject.toml gigl/transforms/graph_transformer.py gigl/nn/graph_transformer.py tests/unit/transforms/graph_transformer_test.py tests/unit/nn/graph_transformer_test.pyPYTHONPATH=/Users/yliu2/Desktop/BAGL/GiGL /Users/yliu2/Desktop/BAGL/.venv/bin/python -m unittest tests.unit.transforms.graph_transformer_test tests.unit.nn.graph_transformer_testUpdated Changelog.md? NO
Ready for code review?: NO - draft PR for design/API discussion first.