Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions gigl/distributed/base_sampler.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import asyncio
from collections import defaultdict
from dataclasses import dataclass
from threading import Thread
from typing import Optional, Union

import torch
import uvloop
from graphlearn_torch.channel import SampleMessage
from graphlearn_torch.distributed import DistNeighborSampler as GLTDistNeighborSampler
from graphlearn_torch.distributed.dist_neighbor_sampler import ensure_device
from graphlearn_torch.distributed.dist_feature import DistFeature
from graphlearn_torch.distributed.event_loop import wrap_torch_future
from graphlearn_torch.sampler import (
Expand Down Expand Up @@ -91,6 +95,18 @@ class BaseDistNeighborSampler(GLTDistNeighborSampler):
sampling strategy (e.g., k-hop neighbor sampling, PPR-based sampling).
"""

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._loop.close()
self._loop = uvloop.new_event_loop()
self._runner_t = Thread(target=self._run_loop)
self._runner_t.daemon = True
self._loop.call_soon_threadsafe(ensure_device, self.device)

def _run_loop(self):
asyncio.set_event_loop(self._loop)
self._loop.run_forever()

def _prepare_sample_loop_inputs(
self,
inputs: NodeSamplerInput,
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ dependencies = [
# When updating to a new tensorflow version, please ensure that the version changes align with
# `transform` deps listed below. Package versions for `apache-beam`, `tensorflow-transform`, etc
"tensorflow~=2.16",
"uvloop",
]


Expand Down