Repository navigation
Add a fixed-shape k-hop sequence layout for packed graph transformer tokens - #814
Queued
kmontemayor2-sc wants to merge 10 commits into
Queued
kmontemayor2-sc wants to merge 10 commits into
kmontemayor2-sc wants to merge 10 commits into
Conversation
…tokens Adds gigl/transforms/static_khop.py (khop_layout, pack_sequences, PackedSequences, KhopLayoutTooLargeError) and its tests. Nothing uses it yet; the attention module and the encoder integration follow in later PRs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 23, 2026
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
yliu2-sc
reviewed
Oct 29, 2026
yliu2-sc
reviewed
Oct 29, 2026
…e to packed_layout.py - khop_layout raises ValueError for a sampling_direction other than 'in' or 'out', instead of treating every other value as 'out'. - PackedSequences is renamed PackedLayout and, with pack_sequences, moves to gigl/transforms/packed_layout.py, since neither depends on how the sequences were built. static_khop.py keeps only the k-hop code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lace prioritize_hop_order with an ordering option
select_sequences dedupes each anchor's candidates (the lowest column of a node wins), orders them by an optional priority and cuts them at max_seq_len, returning the nodes, the source column of every token and the lengths. The k-hop layout generates candidates through the neighbour table and calls it. khop_layout takes ordering in {node_id, hop, input} instead of prioritize_hop_order.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The module holds the pieces shared by the per-anchor sequence builders (selection, the packed type and packing), not only the packed layout. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The builder pads each anchor's ragged PPR edges into a [anchors, edges] table and lets select_sequences order them by descending weight, then gathers the weights and relation features by the returned source column. select_sequences gains include_anchor (no anchor slot; the anchor stays if it is a candidate) and ties_by_column (priority ties keep column order instead of ascending node id). Output matches the previous builder on random PPR batches, and it is faster on CPU. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
svij-sc
approved these changes
Oct 30, 2026
The test counts unique graphs, which includes compiles from earlier tests in the same process. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SelectedSequences(nodes, source, lengths) and KhopLayout(layout, lengths, hop_bits) replace the bare tuples. select_sequences and pack_sequences get function-level examples; the test that runs the docstring examples came in with the previous commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kmontemayor2-sc
marked this pull request as ready for review
October 30, 2026 18:40
kmontemayor2-sc
requested review from
mkolodner-sc,
xgao4-sc and
zfan3-sc
as code owners
October 30, 2026 18:40
kmontemayor2-sc
enabled auto-merge
October 30, 2026 18:41
kmontemayor2-sc
disabled auto-merge
October 30, 2026 18:41
yliu2-sc
approved these changes
Nov 3, 2026
yliu2-sc
left a comment
Collaborator
There was a problem hiding this comment.
we'll have separate PR for PPR?
Collaborator
Author
Yes, and we will support many more GT configs. |
kmontemayor2-sc
added this pull request to the merge queue
Nov 3, 2026
Any commits made after this event will not be merged.
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.
PR 1/3 for Packed Attention in GT
Summary
GraphTransformerEncoderbackend needs, for every anchor, the list of neighbour tokens withinkhops andthe hop distance of each token. The existing sparse k-hop builders in
gigl/transforms/graph_transformer.pyproducethis with data-dependent shapes (sparse matmul,
coalesce,unique,nonzero, bool-mask indexing). That costs manyhost syncs and blocks
torch.compile.gigl/transforms/static_khop.py, which builds the same layout with fixed shapes and per-token hopdistance, and no all-pairs matrix.
kmonte/gt-packed-attention), then theencoder integration (Run supported GraphTransformerEncoder configs on packed tokens #811,
kmonte/gt-packed-backend). Nothing uses this module yet, so behavior is unchanged.Approach
[num_nodes + 1, width],-1padded,width= largest node degree) turns each hop into agather. Only sort, gather and scatter are used, so output shapes are known up front.
(node << hop_bits) | hop. The layout scatters and gathers one tensor, and consumers decodeit with a shift and a mask.
node id with
prioritize_hop_order), cut atmax_seq_len. The hop is the first-reach hop.O(num_anchors * width ** hop_distance), and one hub node setswidthfor the whole batch.khop_layoutcounts the cells (candidates plus the neighbour table) before allocating them and raises
KhopLayoutTooLargeErrorpast a 2^25-cell budget (
MAX_LAYOUT_CANDIDATES). The caller can then fall back to the padded path.pack_sequencesthe total token count.pack_sequencesturns the per-sequence lengths into flat gather indices andPackedSequences(int32cu_seqlensoffsets,
max_seq_len), which the attention PR consumes.User-facing changes
gigl/transforms/static_khop.py, all additive and unused so far:khop_layoutpack_sequencesPackedSequencesKhopLayoutTooLargeErrorMAX_LAYOUT_CANDIDATESkhop_layoutaccepts int32 or int64 edge indices and anchors.Verification
tests/unit/transforms/static_khop_test.py, 7 tests, pass (CPU):pack_sequencesoffsets are correct.static_khopdoctests: 9 examples pass.ruffandtyare clean.gt-split-ut-20261023-165324, one L4 (g2-standard-48,cuda:0), run on the final integration tree, whichcontains this PR's code unchanged:
static_khop_test7 tests pass. The same job ran the whole stack's tests, 181 intotal, all passing and none skipped.
🤖 Generated with Claude Code