DynamicBatchSampler
¶
DynamicBatchSampler(
dataset: Union[Dataset, Sequence[GraphData]],
max_num: int,
mode: str = "node",
shuffle: bool = False,
skip_too_big: bool = False,
num_steps: Optional[int] = None,
)
Batch sampler grouping graphs into batches with at most max_num
nodes (or edges) in total, so that batches use a bounded amount of memory.
Pass it as batch_sampler to Dataloader. A graph larger than
max_num on its own is either yielded alone in its batch, or skipped if
skip_too_big is set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
Union[Dataset, Sequence[GraphData]]
|
required | |
max_num
|
int
|
Maximum number of nodes (or edges) per batch. |
required |
mode
|
str
|
|
'node'
|
shuffle
|
bool
|
Whether to shuffle the graphs at the start of each epoch. Defaults to False |
False
|
skip_too_big
|
bool
|
Whether to skip graphs larger than |
False
|
num_steps
|
Optional[int]
|
Maximum number of batches per epoch. Defaults to None (all graphs are used). The length of the sampler is only defined when it is set. |
None
|
Example:
from mlx_graphs.loaders import Dataloader, DynamicBatchSampler
sampler = DynamicBatchSampler(dataset, max_num=1000, mode="node")
loader = Dataloader(dataset, batch_sampler=sampler)
Source code in mlx_graphs/loaders/samplers.py
from mlx_graphs.loaders import DynamicBatchSampler · mlx_graphs/loaders/samplers.py