gigl.distributed.utils.dist_sampler#
Sampler factory helpers shared across sampling producers.
Attributes#
Union of all supported sampler input types. |
|
Union of all supported GiGL sampler runtime types. |
Functions#
|
Create a GiGL sampler runtime for one channel on one worker. |
Module Contents#
- gigl.distributed.utils.dist_sampler.create_dist_sampler(*, data, sampling_config, worker_options, channel, sampler_options, degree_tensors, current_device)[source]#
Create a GiGL sampler runtime for one channel on one worker.
- Parameters:
data (graphlearn_torch.distributed.DistDataset) – The distributed dataset containing graph topology and features.
sampling_config (graphlearn_torch.sampler.SamplingConfig) – Configuration for sampling behavior (neighbors, edges, etc.).
worker_options (Union[graphlearn_torch.distributed.MpDistSamplingWorkerOptions, graphlearn_torch.distributed.RemoteDistSamplingWorkerOptions]) – Worker-level options (RPC settings, device placement, concurrency).
channel (graphlearn_torch.channel.ChannelBase) – The communication channel for passing sampled messages.
sampler_options (gigl.distributed.sampler_options.SamplerOptions) – Algorithm-specific options (k-hop or PPR).
degree_tensors (Optional[Union[torch.Tensor, dict[graphlearn_torch.typing.NodeType, torch.Tensor]]]) – Pre-computed degree tensors required by PPR sampling. Must not be
Nonewhensampler_optionsisPPRSamplerOptions.current_device (torch.device) – The device on which sampling will run.
- Returns:
A configured sampler runtime, either
DistNeighborSamplerorDistPPRNeighborSampler.- Raises:
NotImplementedError – If
sampler_optionsis an unsupported type.- Return type:
SamplerRuntime
Note
When
sampling_config.seedis unset we draw one here, per worker. The seed belongs to the process that samples rather than to the config: the config is shared across ranks in Graph Store mode and compared for equality, so a value drawn while building it would differ per rank and be rejected.A seed is a large performance win, not just a determinism knob. GLT’s
CPURandomSampler::UniformSamplereadsRandomSeedManager::getInstance().getSeed()on every call, and that call happens once per source row of a batch:The
std::mt19937it feeds isthread_local static, so after the first call the read is discarded – but it still runs. With no seed set,getSeed()constructs astd::random_deviceand draws from it, about 5 us of real work per source row for a value that is thrown away:For the production use case we see up to 7x speed up, and 29x speedup in local testing.
Passing the seed to the sampler is what sets it: GLT calls
RandomSeedManager::getInstance().setSeedfromNeighborSampler.__init__only when the seed is notNone. That manager is process-global and the generator it feeds isthread_local, so the first sampler built on a worker thread fixes that thread’s stream. Per-channel seeds therefore are not a determinism guarantee.TODO(kmonte): Drop this workaround if GLT ever hoists the
getSeed()call out ofCPURandomSampler::UniformSampleand into the engine initializer, so the unseeded path stops paying per-row entropy.