Repository navigation
Support relation message modes on the packed GraphTransformerEncoder path - #852
Draft
kmontemayor2-sc wants to merge 29 commits into
Draft
kmontemayor2-sc wants to merge 29 commits into
kmontemayor2-sc wants to merge 29 commits into
Conversation
…path Factor the relation-message math (per-relation transforms, scatter-softmax, mean aggregation) into one edge-list core shared by the padded layouts and the packed layout. Packed layers take relation edges as flat token rows with host-side per-relation segments, so no layer reads the device. The encoder matches edges on the khop layout with the existing edge matcher and the layout-derived frontier, and routes each packed layer through an overridable _run_packed_layer hook for checkpointing. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
… scatter, more tests Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…on edge matching and read segment bounds once Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…utput_size on repeat_interleave, docs Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…n-message Conflicts resolved as in bc6d2af, which merged the same two heads. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d-relation-message # Conflicts: # tests/unit/nn/packed_graph_transformer_test.py
…d-relation-message
…d-relation-message Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d-relation-message
…n-message Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
No behavior change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n-message # Conflicts: # gigl/nn/graph_transformer.py
…relation-message Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d-relation-message
…n-message Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rap the CHANGELOG entry No behavior change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n-message Conflicts resolved: CHANGELOG.md (kept both the relation message and readout notes).
Anchor self-loops survived the frontier filter, so the no_edges_into_anchors case never took the branch it targets. Drop self-loops from its batch and assert the branch runs. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…n-message Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…n-message Resolved: gigl/nn/graph_transformer.py (import list)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Summary
GraphTransformerEncodercan now runrelation_message_mode="edge_type_linear"and"edge_type_attention"on packed tokens. Before this PR, any relation message mode sent the batch down the padded path, so relation-aware models paid padding FLOPs and memory for every sequence.relation_attention_modestill has to be"none"on the packed path.Approach
PackedRelationEdgescarries each relation edge as packed rows (target, source, relation) plus host-side(relation, start, end)segments.GraphTransformerEncoderLayer.forward_packedtakes it asrelation_edges, which is required when a message mode is set._aggregate_relation_messagesis the new layout-independent core. The padded_compute_relation_messagesand_compute_relation_attention_messagesnow call it too, so both paths share one implementation of per-relation transforms, mean or softmax weighting, and scatter-add.lookup_pairwise_relation_indicessends all relation edges through the token-pair matcher in one call instead of one call per relation. Host syncs per forward therefore no longer grow with the number of relations or layers._match_directed_edges_to_token_pairsalso returns the matched edge index, andrepeat_interleavecalls passoutput_sizeto avoid extra syncs.anchor_onlyreadout, the last layer keeps only edges into each sequence's first token.User-facing changes
relation_message_modeinedge_type_linearoredge_type_attention(andrelation_attention_mode="none") now run on packed tokens on CUDA. Embeddings and gradients match the padded path up to float error.GraphTransformerEncoder.Verification
ruff check,ruff format --checkanddprint checkpass at this tip.make unit_test_py(CPU) forpacked_attention_test.py(4 ran, 3 CUDA skips),packed_graph_transformer_test.py(93 ran, 12 CUDA skips),graph_transformer_test.py(125 ran, 1 skip),static_khop_test.py(14 ran): all pass, includingtype_check.PackedRelationMessageTestcompares packed against padded outputs and gradients (truncation, edgeless batches, filtered edges, hetero graphs, checkpointing). Theno_edges_into_anchorsgradient case has no anchor self-loops and asserts that the packed path takes the all-filtered branch. CUDA-only tests check parity with CPU and that the number of host syncs does not depend on layers or relations.Performance
One L4, torch 2.8.0+cu128, random weights, 3 layers, hidden 512, 8 heads,
anchor_onlyreadout,edge_type_linear, max_seq_len 256. Padded vs packed. Inference: 512 anchors, fp32 with TF32, mean of 40 batches. Training: bf16 autocast, mean of 24 steps. Times are ms per batch or step.These were measured before later PRs in the stack, so numbers at this tip may differ slightly.
🤖 Generated with Claude Code