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.
- tributo_algorithms-0.1.0.dist-info/METADATA +328 -0
- tributo_algorithms-0.1.0.dist-info/RECORD +110 -0
- tributo_algorithms-0.1.0.dist-info/WHEEL +4 -0
- tributo_algorithms-0.1.0.dist-info/entry_points.txt +57 -0
- tributo_algorithms-0.1.0.dist-info/licenses/LICENSE +202 -0
- tributo_algorithms_boosting/__init__.py +42 -0
- tributo_algorithms_boosting/algorithm.py +825 -0
- tributo_algorithms_boosting/checkpointing.py +441 -0
- tributo_algorithms_boosting/contracts.py +232 -0
- tributo_algorithms_boosting/data_config.py +59 -0
- tributo_algorithms_boosting/descriptor.py +124 -0
- tributo_algorithms_boosting/lightgbm.py +511 -0
- tributo_algorithms_boosting/lightgbm_contracts.py +186 -0
- tributo_algorithms_boosting/lightgbm_descriptor.py +112 -0
- tributo_algorithms_boosting/native.py +557 -0
- tributo_algorithms_boosting/stages.py +150 -0
- tributo_algorithms_catboost/__init__.py +5 -0
- tributo_algorithms_catboost/algorithm.py +379 -0
- tributo_algorithms_catboost/contracts.py +145 -0
- tributo_algorithms_catboost/descriptor.py +121 -0
- tributo_algorithms_catboost/exporter.py +106 -0
- tributo_algorithms_catboost/flavor.py +191 -0
- tributo_algorithms_causal_core/__init__.py +41 -0
- tributo_algorithms_causal_core/algorithm.py +1193 -0
- tributo_algorithms_causal_core/contracts.py +136 -0
- tributo_algorithms_causal_core/descriptor.py +270 -0
- tributo_algorithms_causal_core/exporter.py +52 -0
- tributo_algorithms_causal_discovery/__init__.py +23 -0
- tributo_algorithms_causal_discovery/algorithm.py +526 -0
- tributo_algorithms_causal_discovery/contracts.py +97 -0
- tributo_algorithms_causal_discovery/descriptor.py +130 -0
- tributo_algorithms_causal_discovery/exporter.py +43 -0
- tributo_algorithms_causal_dowhy/__init__.py +38 -0
- tributo_algorithms_causal_dowhy/algorithm.py +325 -0
- tributo_algorithms_causal_dowhy/contracts.py +209 -0
- tributo_algorithms_causal_dowhy/descriptor.py +106 -0
- tributo_algorithms_causal_dowhy/exporter.py +43 -0
- tributo_algorithms_causal_dowhy/gcm.py +634 -0
- tributo_algorithms_causal_dowhy/gcm_descriptor.py +110 -0
- tributo_algorithms_causal_dr/__init__.py +22 -0
- tributo_algorithms_causal_dr/algorithm.py +446 -0
- tributo_algorithms_causal_dr/contracts.py +94 -0
- tributo_algorithms_causal_dr/descriptor.py +104 -0
- tributo_algorithms_causal_xlearner/__init__.py +29 -0
- tributo_algorithms_causal_xlearner/algorithm.py +448 -0
- tributo_algorithms_causal_xlearner/contracts.py +97 -0
- tributo_algorithms_causal_xlearner/descriptor.py +120 -0
- tributo_algorithms_causal_xlearner/exporter.py +432 -0
- tributo_algorithms_causal_xlearner/flavor.py +120 -0
- tributo_algorithms_causal_xlearner/model.py +116 -0
- tributo_algorithms_classical/__init__.py +41 -0
- tributo_algorithms_classical/contracts.py +139 -0
- tributo_algorithms_classical/descriptors.py +370 -0
- tributo_algorithms_classical/exporter.py +166 -0
- tributo_algorithms_classical/isolation_forest.py +172 -0
- tributo_algorithms_classical/isolation_forest_descriptor.py +122 -0
- tributo_algorithms_classical/kmeans.py +315 -0
- tributo_algorithms_classical/kmeans_descriptor.py +147 -0
- tributo_algorithms_classical/linear_regression.py +206 -0
- tributo_algorithms_classical/logistic_regression.py +238 -0
- tributo_algorithms_classical/models.py +28 -0
- tributo_algorithms_classical/multinomial_nb.py +643 -0
- tributo_algorithms_classical/multinomial_nb_descriptor.py +183 -0
- tributo_algorithms_classical/pca.py +187 -0
- tributo_algorithms_classical/pca_descriptor.py +111 -0
- tributo_algorithms_classical/random_forest.py +304 -0
- tributo_algorithms_classical/sgd.py +331 -0
- tributo_algorithms_classical/sgd_contracts.py +121 -0
- tributo_algorithms_classical/sgd_descriptor.py +143 -0
- tributo_algorithms_classical/unsupervised_contracts.py +198 -0
- tributo_algorithms_classical/unsupervised_exporter.py +427 -0
- tributo_algorithms_classical/unsupervised_models.py +90 -0
- tributo_algorithms_graph_pyg/__init__.py +37 -0
- tributo_algorithms_graph_pyg/algorithm.py +883 -0
- tributo_algorithms_graph_pyg/contracts.py +260 -0
- tributo_algorithms_graph_pyg/descriptor.py +201 -0
- tributo_algorithms_multistage_torch/__init__.py +40 -0
- tributo_algorithms_multistage_torch/algorithm.py +532 -0
- tributo_algorithms_multistage_torch/contracts.py +220 -0
- tributo_algorithms_multistage_torch/descriptor.py +146 -0
- tributo_algorithms_multistage_torch/pretrain.py +570 -0
- tributo_algorithms_multistage_torch/pretrain_descriptor.py +153 -0
- tributo_algorithms_recsys_torch/__init__.py +35 -0
- tributo_algorithms_recsys_torch/contracts.py +295 -0
- tributo_algorithms_recsys_torch/descriptor.py +136 -0
- tributo_algorithms_recsys_torch/jagged.py +707 -0
- tributo_algorithms_recsys_torch/jagged_descriptor.py +130 -0
- tributo_algorithms_recsys_torch/recipe.py +192 -0
- tributo_algorithms_representation/__init__.py +20 -0
- tributo_algorithms_representation/contracts.py +117 -0
- tributo_algorithms_representation/descriptor.py +137 -0
- tributo_algorithms_representation/recipe.py +162 -0
- tributo_algorithms_tabular_torch/__init__.py +46 -0
- tributo_algorithms_tabular_torch/contracts.py +228 -0
- tributo_algorithms_tabular_torch/descriptor.py +223 -0
- tributo_algorithms_tabular_torch/priors.py +216 -0
- tributo_algorithms_tabular_torch/pu_metrics.py +269 -0
- tributo_algorithms_tabular_torch/pu_reducer.py +129 -0
- tributo_algorithms_tabular_torch/recipe.py +294 -0
- tributo_algorithms_timeseries/__init__.py +36 -0
- tributo_algorithms_timeseries/contracts.py +120 -0
- tributo_algorithms_timeseries/descriptor.py +137 -0
- tributo_algorithms_timeseries/recipe.py +195 -0
- tributo_algorithms_timeseries/rnn_contracts.py +170 -0
- tributo_algorithms_timeseries/rnn_descriptor.py +167 -0
- tributo_algorithms_timeseries/rnn_recipe.py +223 -0
- tributo_algorithms_transformers_nlp/__init__.py +20 -0
- tributo_algorithms_transformers_nlp/contracts.py +109 -0
- tributo_algorithms_transformers_nlp/descriptor.py +137 -0
- tributo_algorithms_transformers_nlp/recipe.py +235 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"""Contracts for the official LightGBM integration."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Mapping
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class LightGBMConfigValidator:
|
|
10
|
+
"""Validate the bounded LightGBM configuration envelope."""
|
|
11
|
+
|
|
12
|
+
api_version = 1
|
|
13
|
+
schema_digest = "5" * 64
|
|
14
|
+
_MODEL_ALLOWED = {
|
|
15
|
+
"bagging_fraction",
|
|
16
|
+
"bagging_freq",
|
|
17
|
+
"feature_fraction",
|
|
18
|
+
"lambda_l1",
|
|
19
|
+
"lambda_l2",
|
|
20
|
+
"learning_rate",
|
|
21
|
+
"max_bin",
|
|
22
|
+
"max_depth",
|
|
23
|
+
"min_data_in_leaf",
|
|
24
|
+
"num_class",
|
|
25
|
+
"num_leaves",
|
|
26
|
+
"num_threads",
|
|
27
|
+
"objective",
|
|
28
|
+
"task",
|
|
29
|
+
"verbosity",
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
def validate(self, value: Mapping[str, Any]) -> Mapping[str, Any]:
|
|
33
|
+
allowed = {"data", "model", "output", "ray", "resource", "training"}
|
|
34
|
+
unknown = sorted(set(value) - allowed)
|
|
35
|
+
if unknown:
|
|
36
|
+
raise ValueError(f"unknown LightGBM config keys: {unknown}")
|
|
37
|
+
for name in allowed:
|
|
38
|
+
item = value.get(name)
|
|
39
|
+
if item is not None and not isinstance(item, Mapping):
|
|
40
|
+
raise ValueError(f"{name} must be a mapping")
|
|
41
|
+
data = value.get("data")
|
|
42
|
+
if (
|
|
43
|
+
not isinstance(data, Mapping)
|
|
44
|
+
or not isinstance(data.get("label_col"), str)
|
|
45
|
+
or not data["label_col"]
|
|
46
|
+
):
|
|
47
|
+
raise ValueError("LightGBM data.label_col is required")
|
|
48
|
+
feature_columns = data.get("feature_columns")
|
|
49
|
+
if feature_columns is not None and (
|
|
50
|
+
not isinstance(feature_columns, (list, tuple))
|
|
51
|
+
or not feature_columns
|
|
52
|
+
or any(not isinstance(name, str) or not name for name in feature_columns)
|
|
53
|
+
):
|
|
54
|
+
raise ValueError("LightGBM data.feature_columns must be non-empty names")
|
|
55
|
+
model = value.get("model", {})
|
|
56
|
+
if not isinstance(model, Mapping):
|
|
57
|
+
raise ValueError("LightGBM model must be a mapping")
|
|
58
|
+
unknown_model = sorted(set(model) - self._MODEL_ALLOWED)
|
|
59
|
+
if unknown_model:
|
|
60
|
+
raise ValueError(f"unknown LightGBM model keys: {unknown_model}")
|
|
61
|
+
task = model.get("task")
|
|
62
|
+
if task is not None and task not in {"classification", "regression"}:
|
|
63
|
+
raise ValueError("LightGBM model.task must be classification or regression")
|
|
64
|
+
objective = model.get("objective")
|
|
65
|
+
if objective is not None and objective not in {
|
|
66
|
+
"binary",
|
|
67
|
+
"multiclass",
|
|
68
|
+
"multiclassova",
|
|
69
|
+
"multiclassova2",
|
|
70
|
+
"regression",
|
|
71
|
+
}:
|
|
72
|
+
raise ValueError("LightGBM model.objective is outside the supported subset")
|
|
73
|
+
if task == "classification" and objective == "regression":
|
|
74
|
+
raise ValueError(
|
|
75
|
+
"LightGBM classification conflicts with regression objective"
|
|
76
|
+
)
|
|
77
|
+
if task == "regression" and objective in {
|
|
78
|
+
"binary",
|
|
79
|
+
"multiclass",
|
|
80
|
+
"multiclassova",
|
|
81
|
+
"multiclassova2",
|
|
82
|
+
}:
|
|
83
|
+
raise ValueError(
|
|
84
|
+
"LightGBM regression conflicts with classification objective"
|
|
85
|
+
)
|
|
86
|
+
num_class = model.get("num_class")
|
|
87
|
+
if num_class is not None and (
|
|
88
|
+
not isinstance(num_class, int)
|
|
89
|
+
or isinstance(num_class, bool)
|
|
90
|
+
or num_class < 2
|
|
91
|
+
):
|
|
92
|
+
raise ValueError("LightGBM model.num_class must be at least two")
|
|
93
|
+
if objective in {"multiclass", "multiclassova", "multiclassova2"} and (
|
|
94
|
+
num_class is None
|
|
95
|
+
):
|
|
96
|
+
raise ValueError("multiclass LightGBM requires model.num_class")
|
|
97
|
+
if objective == "binary" and num_class is not None and num_class != 2:
|
|
98
|
+
raise ValueError("binary LightGBM requires model.num_class=2")
|
|
99
|
+
training = value.get("training", {})
|
|
100
|
+
if not isinstance(training, Mapping):
|
|
101
|
+
raise ValueError("LightGBM training must be a mapping")
|
|
102
|
+
num_rounds = training.get("num_rounds", 10)
|
|
103
|
+
if (
|
|
104
|
+
not isinstance(num_rounds, int)
|
|
105
|
+
or isinstance(num_rounds, bool)
|
|
106
|
+
or not 1 <= num_rounds <= 10000
|
|
107
|
+
):
|
|
108
|
+
raise ValueError("LightGBM training.num_rounds must be in [1, 10000]")
|
|
109
|
+
ray = value.get("ray")
|
|
110
|
+
if (
|
|
111
|
+
not isinstance(ray, Mapping)
|
|
112
|
+
or not isinstance(ray.get("storage_path"), str)
|
|
113
|
+
or not ray["storage_path"]
|
|
114
|
+
):
|
|
115
|
+
raise ValueError("LightGBM ray.storage_path is required")
|
|
116
|
+
output = value.get("output")
|
|
117
|
+
if (
|
|
118
|
+
not isinstance(output, Mapping)
|
|
119
|
+
or not isinstance(output.get("bundle_uri"), str)
|
|
120
|
+
or not output["bundle_uri"]
|
|
121
|
+
):
|
|
122
|
+
raise ValueError("LightGBM output.bundle_uri is required")
|
|
123
|
+
return dict(value)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
class LightGBMInputValidator:
|
|
127
|
+
"""Require one labeled Ray Data tabular input."""
|
|
128
|
+
|
|
129
|
+
api_version = 1
|
|
130
|
+
schema_digest = "6" * 64
|
|
131
|
+
|
|
132
|
+
def validate(self, value: Mapping[str, Any]) -> Mapping[str, Any]:
|
|
133
|
+
bindings = value.get("bindings")
|
|
134
|
+
descriptors = value.get("descriptors")
|
|
135
|
+
if not isinstance(bindings, list) or not isinstance(descriptors, Mapping):
|
|
136
|
+
raise ValueError("LightGBM input requires bindings and descriptors")
|
|
137
|
+
binding = next(
|
|
138
|
+
(
|
|
139
|
+
item
|
|
140
|
+
for item in bindings
|
|
141
|
+
if isinstance(item, Mapping) and item.get("name") == "train"
|
|
142
|
+
),
|
|
143
|
+
None,
|
|
144
|
+
)
|
|
145
|
+
if not isinstance(binding, Mapping) or not binding.get("feature_names"):
|
|
146
|
+
raise ValueError("LightGBM input requires train feature columns")
|
|
147
|
+
if not isinstance(binding.get("label_name"), str) or not binding["label_name"]:
|
|
148
|
+
raise ValueError("LightGBM input requires a label")
|
|
149
|
+
return value
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
class LightGBMOutputValidator:
|
|
153
|
+
"""Require successful Bundle-backed LightGBM output."""
|
|
154
|
+
|
|
155
|
+
api_version = 1
|
|
156
|
+
schema_digest = "7" * 64
|
|
157
|
+
|
|
158
|
+
def validate(self, value: Mapping[str, Any]) -> Mapping[str, Any]:
|
|
159
|
+
outputs = value.get("outputs")
|
|
160
|
+
if value.get("status") != "succeeded" or not isinstance(outputs, Mapping):
|
|
161
|
+
raise ValueError("LightGBM output requires successful execution")
|
|
162
|
+
if not outputs.get("bundle_uri"):
|
|
163
|
+
raise ValueError("LightGBM output requires bundle_uri")
|
|
164
|
+
return value
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
class LightGBMCoverageValidator:
|
|
168
|
+
"""Require complete framework-native distributed coverage."""
|
|
169
|
+
|
|
170
|
+
api_version = 1
|
|
171
|
+
schema_digest = "8" * 64
|
|
172
|
+
|
|
173
|
+
def validate(self, value: Mapping[str, Any]) -> Mapping[str, Any]:
|
|
174
|
+
if value.get("input_complete") is not True:
|
|
175
|
+
raise ValueError("LightGBM input coverage is incomplete")
|
|
176
|
+
if value.get("distributed") is not True:
|
|
177
|
+
raise ValueError("LightGBM execution did not prove distribution")
|
|
178
|
+
return value
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
__all__ = [
|
|
182
|
+
"LightGBMCoverageValidator",
|
|
183
|
+
"LightGBMConfigValidator",
|
|
184
|
+
"LightGBMInputValidator",
|
|
185
|
+
"LightGBMOutputValidator",
|
|
186
|
+
]
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"""Descriptor for official distributed LightGBM."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from tributo.algorithms import AlgorithmBuilder
|
|
6
|
+
from tributo.algorithms.api import (
|
|
7
|
+
ContractBinding,
|
|
8
|
+
ContractBindingSet,
|
|
9
|
+
DistributionStrategy,
|
|
10
|
+
EnvironmentSpec,
|
|
11
|
+
ExecutionMode,
|
|
12
|
+
ExecutionProfile,
|
|
13
|
+
FrameworkNativePolicy,
|
|
14
|
+
QualifiedReference,
|
|
15
|
+
WorkerRange,
|
|
16
|
+
WorkerResources,
|
|
17
|
+
)
|
|
18
|
+
from tributo.training.algorithm_spec import (
|
|
19
|
+
AlgorithmSpec,
|
|
20
|
+
Capability,
|
|
21
|
+
DataLoadingMode,
|
|
22
|
+
ProblemType,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
_PACKAGE = "tributo-algorithms"
|
|
26
|
+
_VERSION = "0.1.0"
|
|
27
|
+
_INPUT = "tributo.algorithm-input.ray-tabular.v1"
|
|
28
|
+
_OUTPUT = "tributo.official.lightgbm.onnx.v1"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _binding(contract_id: str, digest: str, validator: str) -> ContractBinding:
|
|
32
|
+
return ContractBinding(
|
|
33
|
+
contract_id=contract_id,
|
|
34
|
+
schema_version=1,
|
|
35
|
+
schema_digest=digest * 64,
|
|
36
|
+
validator_ref=QualifiedReference.parse(
|
|
37
|
+
f"tributo_algorithms_boosting.lightgbm_contracts:{validator}"
|
|
38
|
+
),
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
_SPEC = AlgorithmSpec(
|
|
43
|
+
name="lightgbm",
|
|
44
|
+
trainer_cls=None,
|
|
45
|
+
version="1.0.0",
|
|
46
|
+
default_config={},
|
|
47
|
+
problem_types=(
|
|
48
|
+
ProblemType.BINARY_CLASSIFICATION,
|
|
49
|
+
ProblemType.MULTI_CLASS_CLASSIFICATION,
|
|
50
|
+
ProblemType.REGRESSION,
|
|
51
|
+
),
|
|
52
|
+
capabilities=(Capability.DISTRIBUTED, Capability.EXPORTABLE, Capability.TUNABLE),
|
|
53
|
+
data_loading=DataLoadingMode.CANONICAL_DRIVER,
|
|
54
|
+
operations=("fit",),
|
|
55
|
+
learning_paradigm="supervised",
|
|
56
|
+
model_family="gradient_boosted_trees",
|
|
57
|
+
data_modalities=("tabular",),
|
|
58
|
+
lifecycle_kind="bounded_training",
|
|
59
|
+
allowed_execution_modes=(ExecutionMode.FRAMEWORK_NATIVE.value,),
|
|
60
|
+
config_contract_ref="tributo.algorithm-config.lightgbm.v1",
|
|
61
|
+
input_contract_ref=_INPUT,
|
|
62
|
+
output_contract_ref=_OUTPUT,
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
LIGHTGBM_DESCRIPTOR = AlgorithmBuilder.from_distributed_algorithm(
|
|
66
|
+
spec=_SPEC,
|
|
67
|
+
implementation_id="tributo.official.boosting.lightgbm",
|
|
68
|
+
implementation_version="1.0.0",
|
|
69
|
+
implementation="tributo_algorithms_boosting.lightgbm:DistributedLightGBM",
|
|
70
|
+
executable_factory="tributo_algorithms_boosting.lightgbm:create_algorithm",
|
|
71
|
+
distribution=_PACKAGE,
|
|
72
|
+
framework="lightgbm",
|
|
73
|
+
environment=EnvironmentSpec(
|
|
74
|
+
environment_id="tributo.official.boosting.lightgbm.v1",
|
|
75
|
+
dependencies=(
|
|
76
|
+
"lightgbm>=4.5,<5",
|
|
77
|
+
"onnxmltools>=1.13",
|
|
78
|
+
"tributo>=1.1",
|
|
79
|
+
f"tributo-algorithms[boosting]=={_VERSION}",
|
|
80
|
+
),
|
|
81
|
+
),
|
|
82
|
+
allowed_config_keys=("data", "model", "output", "ray", "resource", "training"),
|
|
83
|
+
strategy=DistributionStrategy.FRAMEWORK_NATIVE,
|
|
84
|
+
supported_worker_range=WorkerRange(2, 1024),
|
|
85
|
+
supported_execution_profiles=(ExecutionProfile.LOCAL, ExecutionProfile.CLUSTER),
|
|
86
|
+
resources_per_worker=WorkerResources(num_cpus=1),
|
|
87
|
+
policy=FrameworkNativePolicy(
|
|
88
|
+
framework="lightgbm-data-parallel",
|
|
89
|
+
evidence_collector_ref=(
|
|
90
|
+
"tributo_algorithms_boosting.lightgbm:DistributedLightGBM.collect_evidence"
|
|
91
|
+
),
|
|
92
|
+
),
|
|
93
|
+
package_name=_PACKAGE,
|
|
94
|
+
package_version=_VERSION,
|
|
95
|
+
tributo_version_spec=">=1.1",
|
|
96
|
+
exporter="tributo_algorithms_boosting.lightgbm:export_result",
|
|
97
|
+
flavor_id="onnx-runtime-v1",
|
|
98
|
+
contract_bindings=ContractBindingSet(
|
|
99
|
+
config=_binding(
|
|
100
|
+
_SPEC.config_contract_ref or "", "5", "LightGBMConfigValidator"
|
|
101
|
+
),
|
|
102
|
+
input=_binding(_INPUT, "6", "LightGBMInputValidator"),
|
|
103
|
+
output=_binding(_OUTPUT, "7", "LightGBMOutputValidator"),
|
|
104
|
+
coverage=_binding(
|
|
105
|
+
"tributo.official.lightgbm.coverage.v1", "8", "LightGBMCoverageValidator"
|
|
106
|
+
),
|
|
107
|
+
),
|
|
108
|
+
descriptor_api_version=2,
|
|
109
|
+
is_default=True,
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
__all__ = ["LIGHTGBM_DESCRIPTOR"]
|