gigl.common.data.parquet_loader#

Loads node and edge tensors from Parquet files.

ParquetDataLoader reads the files of one entity (one node type or one edge type) under SerializedTFRecordInfo.parquet_uri_prefix. Column names and types are defined in gigl.common.data.parquet_format.

An entity directory:

<parquet_uri_prefix>/
    _row_counts.json                  the manifest
    part-00000-of-00003.parquet       row groups of 100000, 100000, 523 rows
    part-00001-of-00003.parquet       row groups of 100000, 4100 rows
    part-00002-of-00003.parquet       one row group of 61 rows

_row_counts.json:
    {"version": 2,
     "files": {"part-00000-of-00003.parquet": {"row_groups": [100000, 100000, 523], "size_bytes": 81234567},
               "part-00001-of-00003.parquet": {"row_groups": [100000, 4100], "size_bytes": 41733312},
               "part-00002-of-00003.parquet": {"row_groups": [61], "size_bytes": 25821}}}

One node file:

part-00000-of-00003.parquet
+-- row group 0 (100000 rows)
|     column chunk  node_id               int64
|     column chunk  features              fixed_size_list<float32>[feature_dim]  optional
|     column chunk  <packed_feature_key>  fixed_size_binary[packed_feature_dim]  optional
|     column chunk  <label key>           float32 or fixed_size_list<float32>    optional, one per label
+-- row group 1 (100000 rows)             same column chunks
+-- row group 2 (523 rows)                same column chunks
+-- footer
      schema
      per row group: row count, byte range of each column chunk

Edge files have the same layout with src and dst (int64) in place of node_id.

The writer (gigl.src.data_preprocessor.lib.transform.parquet_writer) targets:

  • row groups of 100,000 rows for nodes and 1,000,000 rows for edges (the last row group of a file is smaller),

  • files of 1 GB of uncompressed data. Files are zstd-compressed and also end when a Beam bundle ends, so many files are much smaller than this.

Terms:

  • Row group: a block of consecutive rows, stored column by column. pyarrow can read one row group without the others but not part of one, so it is the unit of work here.

  • Column chunk: one column’s values within one row group. Only the requested columns’ chunks are read. pyarrow also reads a gap of up to 8 KiB between two requested chunks instead of making a second request.

  • Footer: the schema and, per row group, the row count and the byte range of each column chunk. Reading it costs storage requests, so only the footers of files this rank reads from are fetched.

  • Manifest: _row_counts.json, the row count of every row group of every file and the file’s byte size (see gigl.common.data.parquet_manifest). Every rank computes its row range from it without reading other ranks’ footers. Loading fails if it is missing, does not list exactly the files found, or lists a size that differs from the directory listing. Each rank also checks the manifest’s row counts against the footers of the files it reads. Files with no rows are read by no rank, so only their sizes are checked; rank 0 logs a warning when there are any. The files must not change after the manifest is written. The data preprocessor writes each directory once, under a per-job prefix.

  • Row range: the rank’s contiguous slice of all rows, counted in sorted file order. Rank r of world_size keeps rows [r * total // world_size, (r + 1) * total // world_size).

  • Read task / plan: the plan is a list of _ReadTask, one per row group that overlaps the row range:

    • file_index: index into the sorted file list.

    • row_group: row group of that file.

    • row_offset: first row of the row group to keep (0 unless the range starts inside it).

    • num_rows: rows of the row group to keep.

    • out_offset: output row that the first kept row is written to.

    Tasks write disjoint output rows, so the copies need no lock.

  • Shared handle: one open file handle per file, used by all of that file’s tasks (see _SharedHandles).

ParquetDataLoader.load_as_torch_tensors:

list .parquet files (sorted) -> read manifest -> row range -> plan tasks
    -> read footers of this rank's files
    -> allocate each output tensor once, at its final size
    -> thread pool: read each task's row group, copy its columns into the outputs at out_offset
    -> LoadedEntityTensors

Example: a directory holds three Parquet files, in sorted order part-0.parquet, part-1.parquet and part-2.parquet. Their row groups hold [4, 4], [2] and [4] rows, so there are 14 rows in total. part-0[1] names row group 1 of part-0.parquet. With 2 ranks, rank 0 keeps rows [0, 7) and rank 1 keeps rows [7, 14). Row group part-0[1] straddles the boundary, so both ranks read it:

global rows    0    1    2    3    4    5    6    7    8    9    10   11   12   13
row group      part-0[0]           part-0[1]           part-1[0] part-2[0]
rank 0         x    x    x    x    x    x    x
rank 1                                            x    x    x    x    x    x    x

(file_index, row_group, row_offset, num_rows, out_offset)
rank 0: (0, 0, 0, 4, 0)  (0, 1, 0, 3, 4)
rank 1: (0, 1, 3, 1, 0)  (1, 0, 0, 2, 1)  (2, 0, 0, 4, 3)

Here file_index 0, 1 and 2 are part-0.parquet, part-1.parquet and part-2.parquet.

Rank 0 reads only the footer of part-0.parquet.

Outputs are allocated with gigl.utils.share_memory.allocate_preshared, which picks the tensor’s final home:

  • a file-backed tensor in GIGL_TENSOR_SPILL_DIR if that is set and the tensor is at least GIGL_TENSOR_SPILL_MIN_BYTES (2 GiB by default),

  • an ordinary in-memory tensor if it is smaller than that threshold,

  • otherwise a tensor in POSIX shared memory. Allocation fails if the shared-memory mount lacks the room.

So large outputs are never copied into shared memory later, and no per-row-group batches are kept to concatenate. Columns are copied as numpy arrays into numpy views of the outputs, which write straight into the tensors’ memory.

The loader runs in the per-entity process that gigl.common.data.load_torch_tensors starts with spawn, like the TFRecord loader.

Attributes#

Classes#

ParquetDataLoader

Loads one entity (node, edge, positive label or negative label) of one type from Parquet files.

Module Contents#

class gigl.common.data.parquet_loader.ParquetDataLoader(rank, world_size, num_threads=None)[source]#

Loads one entity (node, edge, positive label or negative label) of one type from Parquet files.

Produces the same LoadedEntityTensors as TFRecordDataLoader.load_as_torch_tensors for the same data.

TFRecordDataLoader gives each rank whole files. Dataflow ends files early at bundle boundaries, so file sizes vary and whole-file assignment gives uneven ranks. This loader instead gives each rank a contiguous range of rows, so ranks differ by at most one row. The module docstring describes how a rank’s range is planned, read and copied into its outputs.

Creates a loader for one rank.

Parameters:
  • rank (int) – Rank of the current machine.

  • world_size (int) – Number of machines.

  • num_threads (Optional[int]) – Number of reader threads. Defaults to the CPU count, at most 64.

load_as_torch_tensors(serialized_tf_record_info)[source]#

Loads this rank’s share of the Parquet files at parquet_uri_prefix as torch tensors.

Parameters:

serialized_tf_record_info (SerializedTFRecordInfo) – How the entity is stored. Must have parquet_uri_prefix set.

Returns:

The (ids, features, packed features, labels) of this rank’s rows.

Packed features are the uint8 [rows, packed_feature_dim] packed bytes and are None unless packed_feature_key is set.

Return type:

LoadedEntityTensors

Raises:
  • ValueError – If parquet_uri_prefix is not set, or the manifest is malformed, has an unknown version, does not list exactly the files found, lists a size that differs from a file’s listed size, or lists row counts that differ from a file’s footer.

  • FileNotFoundError – If the manifest is missing.

  • OSError – If listing the files or reading a footer or row group still fails after the retries.

gigl.common.data.parquet_loader.logger[source]#