Repository navigation
Run PPR sequences on packed tokens in GraphTransformerEncoder - #859
Draft
kmontemayor2-sc wants to merge 12 commits into
Draft
kmontemayor2-sc wants to merge 12 commits into
kmontemayor2-sc wants to merge 12 commits into
Conversation
…r_sequence_grids Move the PPR block of tensors_to_graph_transformer_input into build_ppr_sequence_grids, which returns a PprSequenceGrids: node index, valid mask, ppr_weight, ppr_relation_features, and the ppr_is_expanded token bitmask. The packed encoder path can then build PPR sequences with the same code as the padded path. No behavior change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sequence_construction_method="ppr" ran only on padded sequences. The packed path now builds the PPR layout with build_ppr_sequence_grids, the padded path's builder, and packs it with pack_sequences. So both paths see the same tokens, PPR features and relation filter. - ppr_weight and ppr_relation_features go into the layout's token_attrs, and the anchor-relative feature lookup reads any attribute the layout has, with several columns for ppr_relation_features. hop_distance in PPR mode is read from its CSR matrix, as on the padded path. - Relation edges in PPR mode use the ppr_is_expanded bitmask and ppr_relation_channel_masks instead of the k-hop frontier. - Sinusoidal sequence positions are added per token at layout.position. - hop_distance > 4 keeps a config padded only for k-hop sequences. Tests: packed vs padded forward on CPU for 12 PPR configs, untyped and typed, over three batches (atol 1e-6), training gradients (atol 1e-5), a check that the ppr_is_expanded filter changes the output, and CUDA tests of training gradients and inference against the CPU padded path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> # Conflicts: # CHANGELOG.md
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…x a moved comment The docstring now has a one-line summary and says that the result has one key per grid cell. The comment in build_ppr_sequence_grids named homo_x, which is not in scope there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Conflicts resolved: CHANGELOG.md (kept the PR 7 entry with the readout and khop wording).
- Route dtypes the varlen kernel does not support (float64) to the padded path. - Return an empty embedding for a PPR batch with no anchors on the padded path. - Say what is wrong when ppr_relation_features is requested with max_seq_len=1. - Build the homogeneous edge index only for khop; drop an unreachable raise. - Correct the Notes, CHANGELOG and docstrings: PPR hop_distance comes from the batch, host reads of pairwise and PPR configs, what training means for the padded-grid backend, dropout in the anchor-only layer, CUDA-only routing. - Add hetero PPR parity, PPR hop-embedding, no-anchor and max_seq_len=1 tests; replace the PPR construction test that asserted the config was unsupported. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Resolved: gigl/nn/graph_transformer.py (imports; kept this branch's PPR code in the token-attr lookup and relation-edge lookup, with public helper names), gigl/transforms/graph_transformer.py (kept this branch's removal of the inline PPR block). Also in this commit: validate_ppr_sequence_input made public with a docstring, _PACKED_KERNEL_DTYPES typed as Final[tuple[torch.dtype, ...]].
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
GraphTransformerEncoderransequence_construction_method="ppr"only on the padded path, so PPR configs spent attention work on padding. This change lets them run on packed tokens (one[tokens, dim]buffer and the varlen kernel) on CUDA, with the same sequences and the same outputs as the padded path.Approach
tensors_to_graph_transformer_inputis nowbuild_ppr_sequence_grids, returning aPprSequenceGridstuple (node ids, valid mask,ppr_weight,ppr_relation_features, and theppr_is_expandedtoken mask). The padded and packed paths call it, so both see the same tokens, features and relation filter.pack_sequences.ppr_weightandppr_relation_featurestravel in the layout'stoken_attrs, so they work as an attention bias and as an anchor-relative input;_packed_anchor_relative_featuresreads any attribute intoken_attrsfrom the layout and looks up the rest in their sparse matrices.ppr_is_expandedtoken mask and the typed-PPR relation-channel masks so edges of tokens the anchor did not expand are dropped. The k-hop frontier-key code moved to_packed_khop_frontier_keys._packed_unsupported_reasonsnow rejects only k-hop withhop_distance > 4; PPR sequences do not grow withhop_distance.User-facing changes
ppr_weight,ppr_relation_featuresand sinusoidal positions, run on packed tokens on CUDA; they fell back to the padded path before. CPU is unchanged. Withpprsequences the packed path readshop_distancefrom the batch's sparse matrix, like the padded path; onlykhopsequences derive it from the layout..any()and anonzeroper bias, and the PPR sequence builder reads the longest candidate list and uses boolean masks. These configs and everypprconfig have no fixed host-read count and do not whole-encoder compile.anchor_only, to that backend.hop_distanceembedding size check applies tokhopconfigs only (see Run supported GraphTransformerEncoder configs on packed tokens #811).pprbatch with no anchors returns an empty embedding on the padded path instead of raising. Requestingppr_relation_featureswithmax_seq_len=1raises an error that namesmax_seq_len.gigl.transforms.graph_transformer.build_ppr_sequence_gridsand thePprSequenceGridstuple.Verification
make check_format_py,make check_format_mdandmake type_checkpass (at 02bfa30). At the tip,ruff check,ruff format --checkand a CPU run ofpacked_graph_transformer_testandtransforms/graph_transformer_testpass (the five GT test modules: 418 ran, 82 CUDA skips).tests/unit/nn/packed_graph_transformer_test.py: a heterogeneous PPR packed-vs-padded parity test, a PPR config with a two-entryhop_distanceembedding, a no-anchor batch, amax_seq_len=1error test, and the dtype routing decision. Over 12 PPR configs: supported-config check; packed vs padded output (untyped and typed PPR, 3 seeds); training gradient parity; CUDA vs CPU for inference and training gradients; and a test that theppr_is_expandedfilter changes the packed output.Performance
Synthetic PPR batches on one L4, torch 2.8.0+cu128, random weights, 3 layers, hidden 512, 8 heads, max_seq_len 256, anchor_only readout, hop_distance 2; each anchor has 32 to 300 PPR targets from a 20000-node pool. Inference: 512 anchors, fp32 with TF32, mean of 20 batches after 8 warmup. Training: 128 anchors, bf16 autocast, AdamW, mean of 20 steps. "Compile" is each layer under
torch.compile. Cells are ms per batch or step / peak MiB, padded vs packed. Measured at 2a96c1b, the PPR code commit; the later commits are base merges and comment fixes.ppr_weightbiasppr_weightbias +ppr_relation_featuresinput🤖 Generated with Claude Code