tributo-algorithms 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. tributo_algorithms-0.1.0.dist-info/METADATA +328 -0
  2. tributo_algorithms-0.1.0.dist-info/RECORD +110 -0
  3. tributo_algorithms-0.1.0.dist-info/WHEEL +4 -0
  4. tributo_algorithms-0.1.0.dist-info/entry_points.txt +57 -0
  5. tributo_algorithms-0.1.0.dist-info/licenses/LICENSE +202 -0
  6. tributo_algorithms_boosting/__init__.py +42 -0
  7. tributo_algorithms_boosting/algorithm.py +825 -0
  8. tributo_algorithms_boosting/checkpointing.py +441 -0
  9. tributo_algorithms_boosting/contracts.py +232 -0
  10. tributo_algorithms_boosting/data_config.py +59 -0
  11. tributo_algorithms_boosting/descriptor.py +124 -0
  12. tributo_algorithms_boosting/lightgbm.py +511 -0
  13. tributo_algorithms_boosting/lightgbm_contracts.py +186 -0
  14. tributo_algorithms_boosting/lightgbm_descriptor.py +112 -0
  15. tributo_algorithms_boosting/native.py +557 -0
  16. tributo_algorithms_boosting/stages.py +150 -0
  17. tributo_algorithms_catboost/__init__.py +5 -0
  18. tributo_algorithms_catboost/algorithm.py +379 -0
  19. tributo_algorithms_catboost/contracts.py +145 -0
  20. tributo_algorithms_catboost/descriptor.py +121 -0
  21. tributo_algorithms_catboost/exporter.py +106 -0
  22. tributo_algorithms_catboost/flavor.py +191 -0
  23. tributo_algorithms_causal_core/__init__.py +41 -0
  24. tributo_algorithms_causal_core/algorithm.py +1193 -0
  25. tributo_algorithms_causal_core/contracts.py +136 -0
  26. tributo_algorithms_causal_core/descriptor.py +270 -0
  27. tributo_algorithms_causal_core/exporter.py +52 -0
  28. tributo_algorithms_causal_discovery/__init__.py +23 -0
  29. tributo_algorithms_causal_discovery/algorithm.py +526 -0
  30. tributo_algorithms_causal_discovery/contracts.py +97 -0
  31. tributo_algorithms_causal_discovery/descriptor.py +130 -0
  32. tributo_algorithms_causal_discovery/exporter.py +43 -0
  33. tributo_algorithms_causal_dowhy/__init__.py +38 -0
  34. tributo_algorithms_causal_dowhy/algorithm.py +325 -0
  35. tributo_algorithms_causal_dowhy/contracts.py +209 -0
  36. tributo_algorithms_causal_dowhy/descriptor.py +106 -0
  37. tributo_algorithms_causal_dowhy/exporter.py +43 -0
  38. tributo_algorithms_causal_dowhy/gcm.py +634 -0
  39. tributo_algorithms_causal_dowhy/gcm_descriptor.py +110 -0
  40. tributo_algorithms_causal_dr/__init__.py +22 -0
  41. tributo_algorithms_causal_dr/algorithm.py +446 -0
  42. tributo_algorithms_causal_dr/contracts.py +94 -0
  43. tributo_algorithms_causal_dr/descriptor.py +104 -0
  44. tributo_algorithms_causal_xlearner/__init__.py +29 -0
  45. tributo_algorithms_causal_xlearner/algorithm.py +448 -0
  46. tributo_algorithms_causal_xlearner/contracts.py +97 -0
  47. tributo_algorithms_causal_xlearner/descriptor.py +120 -0
  48. tributo_algorithms_causal_xlearner/exporter.py +432 -0
  49. tributo_algorithms_causal_xlearner/flavor.py +120 -0
  50. tributo_algorithms_causal_xlearner/model.py +116 -0
  51. tributo_algorithms_classical/__init__.py +41 -0
  52. tributo_algorithms_classical/contracts.py +139 -0
  53. tributo_algorithms_classical/descriptors.py +370 -0
  54. tributo_algorithms_classical/exporter.py +166 -0
  55. tributo_algorithms_classical/isolation_forest.py +172 -0
  56. tributo_algorithms_classical/isolation_forest_descriptor.py +122 -0
  57. tributo_algorithms_classical/kmeans.py +315 -0
  58. tributo_algorithms_classical/kmeans_descriptor.py +147 -0
  59. tributo_algorithms_classical/linear_regression.py +206 -0
  60. tributo_algorithms_classical/logistic_regression.py +238 -0
  61. tributo_algorithms_classical/models.py +28 -0
  62. tributo_algorithms_classical/multinomial_nb.py +643 -0
  63. tributo_algorithms_classical/multinomial_nb_descriptor.py +183 -0
  64. tributo_algorithms_classical/pca.py +187 -0
  65. tributo_algorithms_classical/pca_descriptor.py +111 -0
  66. tributo_algorithms_classical/random_forest.py +304 -0
  67. tributo_algorithms_classical/sgd.py +331 -0
  68. tributo_algorithms_classical/sgd_contracts.py +121 -0
  69. tributo_algorithms_classical/sgd_descriptor.py +143 -0
  70. tributo_algorithms_classical/unsupervised_contracts.py +198 -0
  71. tributo_algorithms_classical/unsupervised_exporter.py +427 -0
  72. tributo_algorithms_classical/unsupervised_models.py +90 -0
  73. tributo_algorithms_graph_pyg/__init__.py +37 -0
  74. tributo_algorithms_graph_pyg/algorithm.py +883 -0
  75. tributo_algorithms_graph_pyg/contracts.py +260 -0
  76. tributo_algorithms_graph_pyg/descriptor.py +201 -0
  77. tributo_algorithms_multistage_torch/__init__.py +40 -0
  78. tributo_algorithms_multistage_torch/algorithm.py +532 -0
  79. tributo_algorithms_multistage_torch/contracts.py +220 -0
  80. tributo_algorithms_multistage_torch/descriptor.py +146 -0
  81. tributo_algorithms_multistage_torch/pretrain.py +570 -0
  82. tributo_algorithms_multistage_torch/pretrain_descriptor.py +153 -0
  83. tributo_algorithms_recsys_torch/__init__.py +35 -0
  84. tributo_algorithms_recsys_torch/contracts.py +295 -0
  85. tributo_algorithms_recsys_torch/descriptor.py +136 -0
  86. tributo_algorithms_recsys_torch/jagged.py +707 -0
  87. tributo_algorithms_recsys_torch/jagged_descriptor.py +130 -0
  88. tributo_algorithms_recsys_torch/recipe.py +192 -0
  89. tributo_algorithms_representation/__init__.py +20 -0
  90. tributo_algorithms_representation/contracts.py +117 -0
  91. tributo_algorithms_representation/descriptor.py +137 -0
  92. tributo_algorithms_representation/recipe.py +162 -0
  93. tributo_algorithms_tabular_torch/__init__.py +46 -0
  94. tributo_algorithms_tabular_torch/contracts.py +228 -0
  95. tributo_algorithms_tabular_torch/descriptor.py +223 -0
  96. tributo_algorithms_tabular_torch/priors.py +216 -0
  97. tributo_algorithms_tabular_torch/pu_metrics.py +269 -0
  98. tributo_algorithms_tabular_torch/pu_reducer.py +129 -0
  99. tributo_algorithms_tabular_torch/recipe.py +294 -0
  100. tributo_algorithms_timeseries/__init__.py +36 -0
  101. tributo_algorithms_timeseries/contracts.py +120 -0
  102. tributo_algorithms_timeseries/descriptor.py +137 -0
  103. tributo_algorithms_timeseries/recipe.py +195 -0
  104. tributo_algorithms_timeseries/rnn_contracts.py +170 -0
  105. tributo_algorithms_timeseries/rnn_descriptor.py +167 -0
  106. tributo_algorithms_timeseries/rnn_recipe.py +223 -0
  107. tributo_algorithms_transformers_nlp/__init__.py +20 -0
  108. tributo_algorithms_transformers_nlp/contracts.py +109 -0
  109. tributo_algorithms_transformers_nlp/descriptor.py +137 -0
  110. tributo_algorithms_transformers_nlp/recipe.py +235 -0
@@ -0,0 +1,260 @@
1
+ """Executable contracts for the official homogeneous PyG graph Wheel."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import hashlib
6
+ from collections.abc import Mapping
7
+ from typing import Any
8
+
9
+
10
+ def _digest(name: str) -> str:
11
+ return hashlib.sha256(f"tributo.graph-pyg.{name}.v2".encode()).hexdigest()
12
+
13
+
14
+ class GraphConfigValidator:
15
+ """Validate bounded full-neighborhood GraphSAGE configuration."""
16
+
17
+ api_version = 1
18
+ schema_digest = "1" * 64
19
+
20
+ def validate(self, value: Mapping[str, Any]) -> Mapping[str, Any]:
21
+ allowed = {"model", "output", "ray", "training"}
22
+ unknown = sorted(set(value) - allowed)
23
+ if unknown:
24
+ raise ValueError(f"unknown graph config keys: {unknown}")
25
+ normalized = dict(value)
26
+ for name in allowed:
27
+ item = normalized.get(name)
28
+ if item is not None and not isinstance(item, Mapping):
29
+ raise ValueError(f"{name} must be a mapping")
30
+ output = normalized.get("output")
31
+ if not isinstance(output, Mapping) or not isinstance(
32
+ output.get("bundle_uri"), str
33
+ ):
34
+ raise ValueError("output.bundle_uri is required")
35
+ training = normalized.get("training", {})
36
+ if not isinstance(training, Mapping):
37
+ raise ValueError("training must be a mapping")
38
+ epochs = training.get("epochs", 2)
39
+ if not isinstance(epochs, int) or isinstance(epochs, bool) or epochs < 1:
40
+ raise ValueError("training.epochs must be positive")
41
+ return normalized
42
+
43
+
44
+ class RelationalGraphConfigValidator(GraphConfigValidator):
45
+ api_version = 1
46
+ schema_digest = "5" * 64
47
+
48
+ def validate(self, value: Mapping[str, Any]) -> Mapping[str, Any]:
49
+ normalized = dict(super().validate(value))
50
+ model = normalized.get("model")
51
+ relations = model.get("num_relations") if isinstance(model, Mapping) else None
52
+ if (
53
+ not isinstance(relations, int)
54
+ or isinstance(relations, bool)
55
+ or relations < 1
56
+ ):
57
+ raise ValueError("R-GCN model.num_relations must be positive")
58
+ return normalized
59
+
60
+
61
+ class HomogeneousGraphInputValidator:
62
+ """Require separate node, edge, and labeled seed roles."""
63
+
64
+ api_version = 1
65
+ schema_digest = "2" * 64
66
+
67
+ def validate(self, value: Mapping[str, Any]) -> Mapping[str, Any]:
68
+ bindings = value.get("bindings")
69
+ descriptors = value.get("descriptors")
70
+ if not isinstance(bindings, list) or not isinstance(descriptors, Mapping):
71
+ raise ValueError("graph input requires bindings and descriptors")
72
+ if len(bindings) != 3 or any(
73
+ not isinstance(item, Mapping) for item in bindings
74
+ ):
75
+ raise ValueError("graph input bindings must contain three mapping roles")
76
+ names = [item.get("name") for item in bindings]
77
+ if any(not isinstance(name, str) or not name for name in names) or len(
78
+ set(names)
79
+ ) != len(names):
80
+ raise ValueError("graph input binding roles must be unique names")
81
+ by_role = {item["name"]: item for item in bindings}
82
+ if set(by_role) != {"edges", "nodes", "train"}:
83
+ raise ValueError(
84
+ "graph input requires exactly nodes, edges, and train roles"
85
+ )
86
+ if value.get("primary_role") != "train":
87
+ raise ValueError("graph train seeds must be the primary role")
88
+ if set(descriptors) != set(by_role):
89
+ raise ValueError("graph input descriptors do not match role bindings")
90
+ if not by_role["train"].get("label_name"):
91
+ raise ValueError("graph train seeds require labels")
92
+ if len(by_role["nodes"].get("feature_names", ())) < 2:
93
+ raise ValueError("node input requires node_id and at least one feature")
94
+ if len(by_role["edges"].get("feature_names", ())) != 2:
95
+ raise ValueError("edge input requires source and destination columns")
96
+ return value
97
+
98
+
99
+ class RelationalGraphInputValidator(HomogeneousGraphInputValidator):
100
+ api_version = 1
101
+ schema_digest = "6" * 64
102
+
103
+ def validate(self, value: Mapping[str, Any]) -> Mapping[str, Any]:
104
+ bindings = value.get("bindings")
105
+ descriptors = value.get("descriptors")
106
+ if not isinstance(bindings, list) or not isinstance(descriptors, Mapping):
107
+ raise ValueError("relational graph input requires bindings and descriptors")
108
+ if len(bindings) != 3 or any(
109
+ not isinstance(item, Mapping) for item in bindings
110
+ ):
111
+ raise ValueError(
112
+ "relational graph input bindings must contain three mapping roles"
113
+ )
114
+ names = [item.get("name") for item in bindings]
115
+ if any(not isinstance(name, str) or not name for name in names) or len(
116
+ set(names)
117
+ ) != len(names):
118
+ raise ValueError("relational graph binding roles must be unique names")
119
+ by_role = {item["name"]: item for item in bindings}
120
+ if set(by_role) != {"edges", "nodes", "train"}:
121
+ raise ValueError("R-GCN requires nodes, edges, and train roles")
122
+ if value.get("primary_role") != "train" or set(descriptors) != set(by_role):
123
+ raise ValueError("R-GCN role descriptors are inconsistent")
124
+ if not by_role["train"].get("label_name"):
125
+ raise ValueError("R-GCN train seeds require labels")
126
+ if len(by_role["nodes"].get("feature_names", ())) < 2:
127
+ raise ValueError("R-GCN nodes require node_id and features")
128
+ if len(by_role["edges"].get("feature_names", ())) != 3:
129
+ raise ValueError("R-GCN edges require source, destination, and relation")
130
+ return value
131
+
132
+
133
+ class GraphOutputValidator:
134
+ """Require a successfully published graph model Bundle."""
135
+
136
+ api_version = 1
137
+ schema_digest = "3" * 64
138
+
139
+ def validate(self, value: Mapping[str, Any]) -> Mapping[str, Any]:
140
+ if value.get("status") != "succeeded":
141
+ raise ValueError("graph training did not succeed")
142
+ outputs = value.get("outputs")
143
+ if (
144
+ not isinstance(outputs, Mapping)
145
+ or not isinstance(outputs.get("bundle_uri"), str)
146
+ or not outputs["bundle_uri"]
147
+ ):
148
+ raise ValueError("graph output requires bundle_uri")
149
+ return value
150
+
151
+
152
+ class GraphCoverageValidator:
153
+ """Require cross-worker seed coverage and synchronized topology state."""
154
+
155
+ api_version = 1
156
+ schema_digest = "4" * 64
157
+
158
+ def validate(self, value: Mapping[str, Any]) -> Mapping[str, Any]:
159
+ if (
160
+ value.get("input_complete") is not True
161
+ or value.get("distributed") is not True
162
+ ):
163
+ raise ValueError("graph seed coverage is incomplete")
164
+ workers = value.get("workers")
165
+ state = value.get("state")
166
+ if not isinstance(workers, list) or not isinstance(state, Mapping):
167
+ raise ValueError("graph execution evidence is missing")
168
+ if any(
169
+ not isinstance(worker, Mapping)
170
+ or not isinstance(worker.get("input_rows"), Mapping)
171
+ or int(worker["input_rows"].get("train", 0)) <= 0
172
+ or int(worker["input_rows"].get("nodes", 0)) <= 0
173
+ or int(worker["input_rows"].get("edges", 0)) <= 0
174
+ for worker in workers
175
+ ):
176
+ raise ValueError("graph role coverage is incomplete")
177
+ details = state.get("details")
178
+ if (
179
+ not isinstance(details, Mapping)
180
+ or details.get("sampling") != "full_neighborhood"
181
+ ):
182
+ raise ValueError("graph sampling evidence is missing")
183
+ return value
184
+
185
+
186
+ class RelationalGraphCoverageValidator(GraphCoverageValidator):
187
+ api_version = 1
188
+ schema_digest = "7" * 64
189
+
190
+ def validate(self, value: Mapping[str, Any]) -> Mapping[str, Any]:
191
+ validated = super().validate(value)
192
+ state = validated.get("state")
193
+ details = state.get("details") if isinstance(state, Mapping) else None
194
+ if (
195
+ not isinstance(details, Mapping)
196
+ or details.get("topology_kind") != "relational"
197
+ ):
198
+ raise ValueError("R-GCN relational topology evidence is missing")
199
+ return validated
200
+
201
+
202
+ class GraphSAGETorchInputValidator(HomogeneousGraphInputValidator):
203
+ api_version = 1
204
+ schema_digest = _digest("graphsage-input")
205
+
206
+ def validate(self, value: Mapping[str, Any]) -> Mapping[str, Any]:
207
+ validated = super().validate(value)
208
+ bindings = validated.get("bindings")
209
+ if not isinstance(bindings, list):
210
+ raise ValueError("graph input bindings are malformed")
211
+ for binding in bindings:
212
+ if (
213
+ isinstance(binding, Mapping)
214
+ and binding.get("sample_weight_name") is not None
215
+ ):
216
+ raise ValueError("GraphSAGE does not support sample-weight binding")
217
+ return validated
218
+
219
+
220
+ class RGCNTorchInputValidator(RelationalGraphInputValidator):
221
+ api_version = 1
222
+ schema_digest = _digest("rgcn-input")
223
+
224
+ def validate(self, value: Mapping[str, Any]) -> Mapping[str, Any]:
225
+ validated = super().validate(value)
226
+ bindings = validated.get("bindings")
227
+ if not isinstance(bindings, list):
228
+ raise ValueError("R-GCN input bindings are malformed")
229
+ for binding in bindings:
230
+ if (
231
+ isinstance(binding, Mapping)
232
+ and binding.get("sample_weight_name") is not None
233
+ ):
234
+ raise ValueError("R-GCN does not support sample-weight binding")
235
+ return validated
236
+
237
+
238
+ class GraphSAGETorchCoverageValidator(GraphCoverageValidator):
239
+ api_version = 1
240
+ schema_digest = _digest("graphsage-coverage")
241
+
242
+
243
+ class RGCNTorchCoverageValidator(RelationalGraphCoverageValidator):
244
+ api_version = 1
245
+ schema_digest = _digest("rgcn-coverage")
246
+
247
+
248
+ __all__ = [
249
+ "GraphConfigValidator",
250
+ "GraphSAGETorchCoverageValidator",
251
+ "GraphSAGETorchInputValidator",
252
+ "GraphCoverageValidator",
253
+ "GraphOutputValidator",
254
+ "HomogeneousGraphInputValidator",
255
+ "RelationalGraphConfigValidator",
256
+ "RelationalGraphCoverageValidator",
257
+ "RelationalGraphInputValidator",
258
+ "RGCNTorchCoverageValidator",
259
+ "RGCNTorchInputValidator",
260
+ ]
@@ -0,0 +1,201 @@
1
+ """Descriptors for GraphSAGE and R-GCN RayTorchAdapter algorithms."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import hashlib
6
+ from pathlib import Path
7
+ from typing import Any
8
+
9
+ from tributo.algorithms import AlgorithmBuilder
10
+ from tributo.algorithms.api import (
11
+ ContractBinding,
12
+ ContractBindingSet,
13
+ EnvironmentSpec,
14
+ ExecutionMode,
15
+ ExecutionProfile,
16
+ MetricReduction,
17
+ QualifiedReference,
18
+ SingleStageTorchPlan,
19
+ TorchDatasetRoute,
20
+ TorchPolicy,
21
+ TorchStageSpec,
22
+ WorkerRange,
23
+ WorkerResources,
24
+ )
25
+ from tributo.training.algorithm_spec import AlgorithmSpec, Capability, ProblemType
26
+
27
+ from tributo_algorithms_graph_pyg.contracts import (
28
+ GraphConfigValidator,
29
+ GraphOutputValidator,
30
+ GraphSAGETorchCoverageValidator,
31
+ GraphSAGETorchInputValidator,
32
+ RelationalGraphConfigValidator,
33
+ RGCNTorchCoverageValidator,
34
+ RGCNTorchInputValidator,
35
+ )
36
+
37
+ _PACKAGE = "tributo-algorithms"
38
+ _VERSION = "0.1.0"
39
+ _ROOT = Path(__file__).resolve().parent
40
+
41
+
42
+ def _code_digest() -> str:
43
+ return hashlib.sha256((_ROOT / "algorithm.py").read_bytes()).hexdigest()
44
+
45
+
46
+ def _binding(
47
+ contract_id: str, validator: type[Any], version: int = 2
48
+ ) -> ContractBinding:
49
+ return ContractBinding(
50
+ contract_id=contract_id,
51
+ schema_version=version,
52
+ schema_digest=str(validator.schema_digest),
53
+ validator_ref=QualifiedReference.parse(
54
+ f"tributo_algorithms_graph_pyg.contracts:{validator.__name__}"
55
+ ),
56
+ )
57
+
58
+
59
+ def _policy(*, relational: bool) -> TorchPolicy:
60
+ return TorchPolicy(
61
+ torch_runtime_api_version=1,
62
+ loop_owner="adapter",
63
+ parallelism_id="torch.ddp.replicated",
64
+ dataset_routing=(
65
+ TorchDatasetRoute("train", "split_exact", True, 1, 1, "reject"),
66
+ TorchDatasetRoute(
67
+ "nodes", "replicate", True, 1, 1, "reject", 1_000_000, 268_435_456
68
+ ),
69
+ TorchDatasetRoute(
70
+ "edges", "replicate", True, 1, 1, "reject", 5_000_000, 268_435_456
71
+ ),
72
+ ),
73
+ execution_plan=SingleStageTorchPlan(
74
+ stage=TorchStageSpec(
75
+ "train",
76
+ ("train", "nodes", "edges"),
77
+ )
78
+ ),
79
+ state_layout="replicated",
80
+ metric_reducers={
81
+ "train_loss": MetricReduction.SUM_COUNT,
82
+ "accuracy": MetricReduction.SUM_COUNT,
83
+ },
84
+ backend="auto",
85
+ max_replicated_bytes_per_worker=536_870_912,
86
+ )
87
+
88
+
89
+ def _spec(*, relational: bool) -> AlgorithmSpec:
90
+ name = "rgcn_node_classifier" if relational else "graphsage_node_classifier"
91
+ return AlgorithmSpec(
92
+ name=name,
93
+ trainer_cls=None,
94
+ version="1.0.0",
95
+ default_config={},
96
+ supported_tasks=("fit",),
97
+ operations=("fit",),
98
+ problem_types=(ProblemType.NODE_CLASSIFICATION,),
99
+ capabilities=(
100
+ Capability.DISTRIBUTED,
101
+ Capability.EXPORTABLE,
102
+ Capability.TUNABLE,
103
+ ),
104
+ learning_paradigm="supervised",
105
+ model_family="relational_gcn" if relational else "graphsage",
106
+ data_modalities=("relational_graph" if relational else "graph",),
107
+ lifecycle_kind="batch_fit",
108
+ allowed_execution_modes=(ExecutionMode.RAY_TRAIN_TORCH.value,),
109
+ config_contract_ref=(
110
+ "tributo.official.rgcn.config.v1"
111
+ if relational
112
+ else "tributo.official.graphsage.config.v1"
113
+ ),
114
+ input_contract_ref=(
115
+ "tributo.official.graph.relational-torch.v2"
116
+ if relational
117
+ else "tributo.official.graph.homogeneous-torch.v2"
118
+ ),
119
+ output_contract_ref=(
120
+ "tributo.official.rgcn.bundle.v1"
121
+ if relational
122
+ else "tributo.official.graphsage.bundle.v1"
123
+ ),
124
+ )
125
+
126
+
127
+ _ENVIRONMENT = EnvironmentSpec(
128
+ environment_id="tributo.official.graph-pyg.v2",
129
+ dependencies=(
130
+ "onnx>=1.16",
131
+ "onnxruntime>=1.20",
132
+ "safetensors>=0.4.3",
133
+ "torch>=2.5,<2.14",
134
+ "torch-geometric>=2.5",
135
+ "tributo>=1.1",
136
+ f"tributo-algorithms[graph-pyg]=={_VERSION}",
137
+ ),
138
+ )
139
+
140
+
141
+ def _descriptor(*, relational: bool) -> object:
142
+ spec = _spec(relational=relational)
143
+ input_validator = (
144
+ RGCNTorchInputValidator if relational else GraphSAGETorchInputValidator
145
+ )
146
+ coverage_validator = (
147
+ RGCNTorchCoverageValidator if relational else GraphSAGETorchCoverageValidator
148
+ )
149
+ implementation_id = (
150
+ "tributo.official.graph_pyg.rgcn"
151
+ if relational
152
+ else "tributo.official.graph_pyg.graphsage"
153
+ )
154
+ adapter = (
155
+ "tributo_algorithms_graph_pyg.algorithm:DistributedRGCN"
156
+ if relational
157
+ else "tributo_algorithms_graph_pyg.algorithm:DistributedGraphSAGE"
158
+ )
159
+ contracts = ContractBindingSet(
160
+ config=_binding(
161
+ spec.config_contract_ref or "",
162
+ RelationalGraphConfigValidator if relational else GraphConfigValidator,
163
+ 1,
164
+ ),
165
+ input=_binding(spec.input_contract_ref or "", input_validator),
166
+ output=_binding(spec.output_contract_ref or "", GraphOutputValidator, 1),
167
+ coverage=_binding(
168
+ "tributo.official.rgcn.torch-coverage.v2"
169
+ if relational
170
+ else "tributo.official.graphsage.torch-coverage.v2",
171
+ coverage_validator,
172
+ ),
173
+ )
174
+ return AlgorithmBuilder.from_torch_adapter(
175
+ spec=spec,
176
+ implementation_id=implementation_id,
177
+ implementation_version="2.0.0",
178
+ adapter=adapter,
179
+ environment=_ENVIRONMENT,
180
+ metric_reducers={
181
+ "train_loss": MetricReduction.SUM_COUNT,
182
+ "accuracy": MetricReduction.SUM_COUNT,
183
+ },
184
+ supported_worker_range=WorkerRange(2, 64),
185
+ supported_execution_profiles=(ExecutionProfile.LOCAL, ExecutionProfile.CLUSTER),
186
+ resources_per_worker=WorkerResources(num_cpus=1),
187
+ package_name=_PACKAGE,
188
+ package_version=_VERSION,
189
+ tributo_version_spec=">=1.1",
190
+ policy=_policy(relational=relational),
191
+ code_digest=_code_digest(),
192
+ contract_bindings=contracts,
193
+ descriptor_api_version=2,
194
+ is_default=True,
195
+ )
196
+
197
+
198
+ GRAPHSAGE_DESCRIPTOR = _descriptor(relational=False)
199
+ RGCN_DESCRIPTOR = _descriptor(relational=True)
200
+
201
+ __all__ = ["GRAPHSAGE_DESCRIPTOR", "RGCN_DESCRIPTOR"]
@@ -0,0 +1,40 @@
1
+ """Official finite multi-stage PyTorch algorithms with lazy runtime exports."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any
6
+
7
+ from tributo_algorithms_multistage_torch.descriptor import DISTILLATION_DESCRIPTOR
8
+ from tributo_algorithms_multistage_torch.pretrain_descriptor import (
9
+ PRETRAIN_FINETUNE_DESCRIPTOR,
10
+ )
11
+
12
+ _LAZY_EXPORTS = {
13
+ "DistributedDistillation": (
14
+ "tributo_algorithms_multistage_torch.algorithm",
15
+ "DistributedDistillation",
16
+ ),
17
+ "DistributedPretrainFinetune": (
18
+ "tributo_algorithms_multistage_torch.pretrain",
19
+ "DistributedPretrainFinetune",
20
+ ),
21
+ }
22
+
23
+
24
+ def __getattr__(name: str) -> Any:
25
+ target = _LAZY_EXPORTS.get(name)
26
+ if target is None:
27
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
28
+ import importlib
29
+
30
+ value = getattr(importlib.import_module(target[0]), target[1])
31
+ globals()[name] = value
32
+ return value
33
+
34
+
35
+ __all__ = [
36
+ "DISTILLATION_DESCRIPTOR",
37
+ "PRETRAIN_FINETUNE_DESCRIPTOR",
38
+ "DistributedDistillation",
39
+ "DistributedPretrainFinetune",
40
+ ]