gigl.distributed.utils.fused_feature#
Fetching a raw feature matrix, its packed sidecar and node labels with one request per partition.
A node or edge type can store its columns in a raw float matrix, in a packed uint8 sidecar (feature quantization),
or in both, and a node type can also have integer node labels. Fetching each store through its own DistFeature costs one
RPC per store per remote partition for every batch. FusedFeatureStore serves whichever stores a type has as one row
of bytes (the node label columns, the float columns reinterpreted as bytes, then the sidecar columns) and
FusedDistFeature is a DistFeature over such stores, so one lookup is one request per partition for every type.
FusedDistFeature.async_get resolves to the raw matrix, the sidecar rows and the node label rows, the latter two
None for a type without them.
All stores are CPU stores: GiGL builds every Feature with with_gpu=False.
Classes#
A |
|
A raw float store, a packed sidecar and/or node labels, served to other partitions as one |
Functions#
|
Builds a |
Module Contents#
- class gigl.distributed.utils.fused_feature.FusedDistFeature(num_partitions, partition_idx, local_feature, feature_pb, rpc_router, device=None)[source]#
Bases:
graphlearn_torch.distributed.dist_feature.DistFeatureA
DistFeaturewhose local stores areFusedFeatureStoreobjects.GLT’s
DistFeaturelooks up local rows and answers remote requests by indexing its local stores with ids, whichFusedFeatureStoresupports; only the constructor checks the store type, so it is repeated here without that check.async_getresolves to the raw float matrix, the packed sidecar rows and theint64node label rows, stitched straight from the local rows and the received byte rows. The sidecar and node label rows areNonefor a type without them.- Parameters:
num_partitions (int) – Number of data partitions.
partition_idx (int) – Data partition of the current process.
local_feature (Union[FusedFeatureStore, dict[Union[graphlearn_torch.typing.NodeType, graphlearn_torch.typing.EdgeType], FusedFeatureStore]]) – A fused store, or one per node/edge type for heterogeneous data.
feature_pb (Union[graphlearn_torch.partition.PartitionBook, dict[Union[graphlearn_torch.typing.NodeType, graphlearn_torch.typing.EdgeType], graphlearn_torch.partition.PartitionBook]]) – Partition book of the entities, or one per type for heterogeneous data.
rpc_router (graphlearn_torch.distributed.rpc.RpcDataPartitionRouter) – Router used to reach the other partitions.
device (Optional[torch.device]) – Device used for computing.
- async_get(ids, input_type=None)[source]#
Looks up the raw float rows, packed sidecar rows and node label rows of ids.
- Parameters:
ids (jaxtyping.Int64[torch.Tensor, num_ids]) – Ids to look up.
input_type (Optional[Union[graphlearn_torch.typing.NodeType, graphlearn_torch.typing.EdgeType]]) – Node or edge type of the ids for heterogeneous data.
- Returns:
A future of the
[len(ids), raw_dim]raw matrix, the[len(ids), packed_dim]sidecar rows and the[len(ids), label_dim]node label rows. The sidecar rows areNoneif the type has no sidecar and the node label rows areNoneif it has no labels.- Return type:
torch.futures.Future[tuple[jaxtyping.Float[torch.Tensor, num_ids raw_dim], Optional[jaxtyping.UInt8[torch.Tensor, num_ids packed_dim]], Optional[jaxtyping.Int64[torch.Tensor, num_ids label_dim]]]]
- class gigl.distributed.utils.fused_feature.FusedFeatureStore(raw, packed, node_labels=None)[source]#
A raw float store, a packed sidecar and/or node labels, served to other partitions as one
uint8row per entity.A served row holds the node label columns (
int64) as bytes, then the raw float columns as bytes, then the sidecar columns, then zero padding up to a multiple of the widest dtype’s size (the raw dtype, or 8 bytes with node labels). The node labels come first and the padding keeps every row aligned, so the node label and raw columns of a received row can be read without a copy.A missing or zero-width store contributes no columns. Without a raw store the raw dtype is
float32, the dtype the raw matrix is later rebuilt as. Without a sidecar the row is the raw bytes alone, which need no padding. A row is never narrower than one raw element, so a type with no columns at all is served as one zero element.All stores must be CPU stores.
Example
A
float32raw store with 3 columns (12 bytes) and a 2-columnuint8sidecar make 14 bytes, padded to 16. Bytes 0-11 are the raw floats, bytes 12-13 the sidecar and bytes 14-15 zero padding.>>> raw = Feature(torch.ones(4, 3), id2index=torch.arange(4), with_gpu=False) >>> packed = Feature( ... torch.full((4, 2), 7, dtype=torch.uint8), ... id2index=torch.arange(4), ... with_gpu=False, ... dtype=torch.uint8, ... ) >>> store = FusedFeatureStore(raw, packed) >>> rows = store.cpu_get(torch.tensor([0, 2])) >>> rows.shape torch.Size([2, 16]) >>> rows[0, 12:].tolist() [7, 7, 0, 0] >>> raw_rows, packed_rows, node_label_rows = store.split(rows) >>> raw_rows.shape, packed_rows.shape, node_label_rows.shape (torch.Size([2, 3]), torch.Size([2, 2]), torch.Size([2, 0]))
With one
int64node label column the row grows by 8 bytes, and the node label bytes come first.>>> node_labels = Feature( ... torch.arange(4).unsqueeze(1), ... id2index=torch.arange(4), ... with_gpu=False, ... dtype=torch.int64, ... ) >>> rows = FusedFeatureStore(raw, packed, node_labels).cpu_get(torch.tensor([0, 2])) >>> rows.shape torch.Size([2, 24]) >>> FusedFeatureStore(raw, packed, node_labels).split(rows)[2].tolist() [[0], [2]]
- Parameters:
raw (Optional[graphlearn_torch.data.Feature]) – Raw float feature store, or
Noneif the type has none.packed (Optional[graphlearn_torch.data.Feature]) – Packed
uint8sidecar store with the same ids and id mapping asraw, orNone.node_labels (Optional[graphlearn_torch.data.Feature]) –
int64node label store with the same ids and id mapping asraw, orNone.
- Raises:
ValueError – If all stores are
None.
- cpu_get(ids)[source]#
Served rows of ids from the CPU tensors, as
[len(ids), row_bytes]bytes, for answering remote requests.Each store is gathered straight into its columns of the output, so every value is copied once.
- Parameters:
ids (jaxtyping.Int64[torch.Tensor, num_ids])
- Return type:
jaxtyping.UInt8[torch.Tensor, num_ids row_bytes]
- lazy_init_with_ipc_handle()[source]#
Materializes the stores after an IPC transfer.
- Return type:
None
- split(rows)[source]#
Views served byte rows as the raw float matrix, the sidecar rows and the node label rows, without copying.
The views have zero columns for a missing store.
- Parameters:
rows (jaxtyping.UInt8[torch.Tensor, num_rows row_bytes])
- Return type:
tuple[jaxtyping.Float[torch.Tensor, num_rows raw_dim], jaxtyping.UInt8[torch.Tensor, num_rows packed_dim], jaxtyping.Int64[torch.Tensor, num_rows label_dim]]
- gigl.distributed.utils.fused_feature.build_fused_dist_feature(num_partitions, partition_idx, raw_features, packed_features, feature_pb, rpc_router, device=None, node_labels=None)[source]#
Builds a
FusedDistFeatureover every entity type that has a raw store, a packed sidecar, node labels, or any mix.- Parameters:
num_partitions (int) – Number of data partitions.
partition_idx (int) – Data partition of the current process.
raw_features (Optional[Union[graphlearn_torch.data.Feature, dict[Union[graphlearn_torch.typing.NodeType, graphlearn_torch.typing.EdgeType], graphlearn_torch.data.Feature]]]) – Raw float store, or one per type.
packed_features (Optional[Union[graphlearn_torch.data.Feature, dict[Union[graphlearn_torch.typing.NodeType, graphlearn_torch.typing.EdgeType], graphlearn_torch.data.Feature]]]) – Packed sidecar store, or one per type.
feature_pb (Union[graphlearn_torch.partition.PartitionBook, dict[Union[graphlearn_torch.typing.NodeType, graphlearn_torch.typing.EdgeType], graphlearn_torch.partition.PartitionBook]]) – Partition book of the entities, or one per type.
rpc_router (graphlearn_torch.distributed.rpc.RpcDataPartitionRouter) – Router used to reach the other partitions.
device (Optional[torch.device]) – Device used for computing.
node_labels (Optional[Union[graphlearn_torch.data.Feature, dict[Union[graphlearn_torch.typing.NodeType, graphlearn_torch.typing.EdgeType], graphlearn_torch.data.Feature]]]) –
int64node label store, or one per type, with the same ids and id mapping as the features.
- Returns:
Noneif there are no stores at all.- Return type:
Optional[FusedDistFeature]