MCPcopy Create free account
hub / github.com/alibaba/GraphScope / GsFeatureStore

Class GsFeatureStore

python/graphscope/learning/gs_feature_store.py:29–216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27
28
29class GsFeatureStore(FeatureStore):
30 def __init__(self, config) -> None:
31 super().__init__()
32 self.config = config
33 self.tensor_attrs: Dict[Tuple[NodeType, str], TensorAttr] = {}
34
35 assert config is not None
36 config = json.loads(
37 base64.b64decode(config.encode("utf-8", errors="ignore")).decode(
38 "utf-8", errors="ignore"
39 )
40 )
41 self.node_features = config["node_features"]
42 self.node_labels = config["node_labels"]
43 self.edges = config["edges"]
44
45 assert self.node_features is not None
46 self.node_types = set()
47 for node in self.node_features:
48 self.node_types.add(node)
49
50 for edge in self.edges:
51 self.node_types.add(edge[0])
52 self.node_types.add(edge[-1])
53
54 for node_type in self.node_types:
55 self.tensor_attrs[(node_type, "x")] = TensorAttr(node_type, "x")
56
57 assert self.node_labels is not None
58 for node_type, node_label in self.node_labels.items():
59 self.tensor_attrs[(node_type, node_label)] = TensorAttr(
60 node_type, node_label
61 )
62
63 @staticmethod
64 def key(attr: TensorAttr) -> KeyType:
65 return (attr.group_name, attr.attr_name, attr.index)
66
67 def _put_tensor(self, tensor: FeatureTensorType, attr: TensorAttr) -> bool:
68 r"""To be implemented by :class:`GsFeatureStore`."""
69 raise NotImplementedError
70
71 def _get_tensor(self, attr: TensorAttr) -> Optional[Tensor]:
72 r"""Obtains a :class:`torch.Tensor` from the remote server.
73
74 Args:
75 attr(`TensorAttr`): Uniquely corresponds to a node/edge feature tensor .
76
77 Raises:
78 ValueError: If the attr can not be found in the attrlists of feature store.
79
80 Returns:
81 feature(`torch.Tensor`): The node/edge feature tensor.
82 """
83
84 group_name, attr_name, index = self.key(attr)
85 if not self._check_attr(attr):
86 raise ValueError(

Callers 1

graphlearn_torchMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected