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,220 @@
|
|
|
1
|
+
"""Executable contracts for finite Teacher-to-Student distillation."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import hashlib
|
|
6
|
+
import re
|
|
7
|
+
from collections.abc import Mapping
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
_SHA256_RE = re.compile(r"[0-9a-f]{64}\Z")
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class DistillationConfigValidator:
|
|
14
|
+
api_version = 1
|
|
15
|
+
schema_digest = "a" * 64
|
|
16
|
+
|
|
17
|
+
def validate(self, value: Mapping[str, Any]) -> Mapping[str, Any]:
|
|
18
|
+
allowed = {"model", "output", "ray", "training"}
|
|
19
|
+
if unknown := sorted(set(value) - allowed):
|
|
20
|
+
raise ValueError(f"unknown distillation config keys: {unknown}")
|
|
21
|
+
model = value.get("model")
|
|
22
|
+
if not isinstance(model, Mapping):
|
|
23
|
+
raise ValueError("distillation model config is required")
|
|
24
|
+
for name in ("input_features", "teacher_hidden", "student_hidden"):
|
|
25
|
+
item = model.get(name)
|
|
26
|
+
if not isinstance(item, int) or isinstance(item, bool) or item < 1:
|
|
27
|
+
raise ValueError(f"model.{name} must be positive")
|
|
28
|
+
output = value.get("output")
|
|
29
|
+
if (
|
|
30
|
+
not isinstance(output, Mapping)
|
|
31
|
+
or not isinstance(output.get("bundle_uri"), str)
|
|
32
|
+
or not output["bundle_uri"]
|
|
33
|
+
):
|
|
34
|
+
raise ValueError("output.bundle_uri is required")
|
|
35
|
+
ray = value.get("ray")
|
|
36
|
+
if not isinstance(ray, Mapping) or not ray.get("storage_path"):
|
|
37
|
+
raise ValueError("ray.storage_path is required")
|
|
38
|
+
return dict(value)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class DistillationInputValidator:
|
|
42
|
+
api_version = 1
|
|
43
|
+
schema_digest = hashlib.sha256(
|
|
44
|
+
b"tributo.distillation.dense-labeled-role-named.v2"
|
|
45
|
+
).hexdigest()
|
|
46
|
+
|
|
47
|
+
def validate(self, value: Mapping[str, Any]) -> Mapping[str, Any]:
|
|
48
|
+
bindings = value.get("bindings")
|
|
49
|
+
if not isinstance(bindings, list) or len(bindings) != 1:
|
|
50
|
+
raise ValueError("distillation requires one train binding")
|
|
51
|
+
binding = bindings[0]
|
|
52
|
+
if (
|
|
53
|
+
not isinstance(binding, Mapping)
|
|
54
|
+
or binding.get("name") != "train"
|
|
55
|
+
or not binding.get("feature_names")
|
|
56
|
+
or not binding.get("label_name")
|
|
57
|
+
or binding.get("sample_weight_name") is not None
|
|
58
|
+
):
|
|
59
|
+
raise ValueError("distillation requires dense features and label")
|
|
60
|
+
return value
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class DistillationOutputValidator:
|
|
64
|
+
api_version = 1
|
|
65
|
+
schema_digest = "c" * 64
|
|
66
|
+
|
|
67
|
+
def validate(self, value: Mapping[str, Any]) -> Mapping[str, Any]:
|
|
68
|
+
outputs = value.get("outputs")
|
|
69
|
+
if value.get("status") != "succeeded" or not isinstance(outputs, Mapping):
|
|
70
|
+
raise ValueError("distillation failed")
|
|
71
|
+
if not isinstance(outputs.get("bundle_uri"), str) or not outputs["bundle_uri"]:
|
|
72
|
+
raise ValueError("distillation requires Student Bundle")
|
|
73
|
+
return value
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class DistillationCoverageValidator:
|
|
77
|
+
api_version = 1
|
|
78
|
+
schema_digest = hashlib.sha256(b"tributo.distillation.coverage.v2").hexdigest()
|
|
79
|
+
|
|
80
|
+
def validate(self, value: Mapping[str, Any]) -> Mapping[str, Any]:
|
|
81
|
+
if (
|
|
82
|
+
value.get("input_complete") is not True
|
|
83
|
+
or value.get("distributed") is not True
|
|
84
|
+
):
|
|
85
|
+
raise ValueError("distillation coverage is incomplete")
|
|
86
|
+
state = value.get("state")
|
|
87
|
+
details = state.get("details") if isinstance(state, Mapping) else None
|
|
88
|
+
if not isinstance(details, Mapping):
|
|
89
|
+
raise ValueError("distillation stage evidence is missing")
|
|
90
|
+
if details.get("component_stages") != "teacher,student":
|
|
91
|
+
raise ValueError("distillation component stage set drifted")
|
|
92
|
+
for stage in ("teacher", "student"):
|
|
93
|
+
if int(details.get(f"stage.{stage}.rows", 0)) <= 0:
|
|
94
|
+
raise ValueError(f"distillation {stage} coverage is missing")
|
|
95
|
+
return value
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
class PretrainFinetuneConfigValidator:
|
|
99
|
+
api_version = 1
|
|
100
|
+
schema_digest = "e" * 64
|
|
101
|
+
|
|
102
|
+
def validate(self, value: Mapping[str, Any]) -> Mapping[str, Any]:
|
|
103
|
+
allowed = {"model", "output", "ray", "training"}
|
|
104
|
+
if unknown := sorted(set(value) - allowed):
|
|
105
|
+
raise ValueError(f"unknown pretrain-finetune config keys: {unknown}")
|
|
106
|
+
for name in allowed:
|
|
107
|
+
if not isinstance(value.get(name), Mapping):
|
|
108
|
+
raise ValueError(f"{name} config is required")
|
|
109
|
+
model = value["model"]
|
|
110
|
+
for name in ("input_features", "hidden_features"):
|
|
111
|
+
item = model.get(name)
|
|
112
|
+
if not isinstance(item, int) or isinstance(item, bool) or item < 1:
|
|
113
|
+
raise ValueError(f"model.{name} must be positive")
|
|
114
|
+
training = value["training"]
|
|
115
|
+
for name in ("pretrain_epochs", "finetune_epochs"):
|
|
116
|
+
item = training.get(name, 1)
|
|
117
|
+
if not isinstance(item, int) or isinstance(item, bool) or item < 1:
|
|
118
|
+
raise ValueError(f"training.{name} must be positive")
|
|
119
|
+
if not value["ray"].get("storage_path"):
|
|
120
|
+
raise ValueError("ray.storage_path is required")
|
|
121
|
+
if (
|
|
122
|
+
not isinstance(value["output"].get("bundle_uri"), str)
|
|
123
|
+
or not value["output"]["bundle_uri"]
|
|
124
|
+
):
|
|
125
|
+
raise ValueError("output.bundle_uri is required")
|
|
126
|
+
return dict(value)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
class PretrainFinetuneInputValidator:
|
|
130
|
+
api_version = 1
|
|
131
|
+
schema_digest = hashlib.sha256(
|
|
132
|
+
b"tributo.pretrain-finetune.dense-labeled-role-named.v2"
|
|
133
|
+
).hexdigest()
|
|
134
|
+
|
|
135
|
+
def validate(self, value: Mapping[str, Any]) -> Mapping[str, Any]:
|
|
136
|
+
bindings = value.get("bindings")
|
|
137
|
+
if not isinstance(bindings, list) or len(bindings) != 1:
|
|
138
|
+
raise ValueError("pretrain-finetune requires one train binding")
|
|
139
|
+
binding = bindings[0]
|
|
140
|
+
if (
|
|
141
|
+
not isinstance(binding, Mapping)
|
|
142
|
+
or binding.get("name") != "train"
|
|
143
|
+
or not binding.get("feature_names")
|
|
144
|
+
or not binding.get("label_name")
|
|
145
|
+
or binding.get("sample_weight_name") is not None
|
|
146
|
+
):
|
|
147
|
+
raise ValueError("pretrain-finetune requires dense features and label")
|
|
148
|
+
return value
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
class PretrainFinetuneOutputValidator:
|
|
152
|
+
api_version = 1
|
|
153
|
+
schema_digest = "0" * 64
|
|
154
|
+
|
|
155
|
+
def validate(self, value: Mapping[str, Any]) -> Mapping[str, Any]:
|
|
156
|
+
outputs = value.get("outputs")
|
|
157
|
+
if value.get("status") != "succeeded" or not isinstance(outputs, Mapping):
|
|
158
|
+
raise ValueError("pretrain-finetune failed")
|
|
159
|
+
if (
|
|
160
|
+
not isinstance(outputs.get("bundle_uri"), str)
|
|
161
|
+
or not outputs["bundle_uri"]
|
|
162
|
+
or not isinstance(outputs.get("composition_digest"), str)
|
|
163
|
+
or _SHA256_RE.fullmatch(outputs["composition_digest"]) is None
|
|
164
|
+
):
|
|
165
|
+
raise ValueError("pretrain-finetune requires Bundle and composition digest")
|
|
166
|
+
return value
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
class PretrainFinetuneCoverageValidator:
|
|
170
|
+
api_version = 1
|
|
171
|
+
schema_digest = hashlib.sha256(b"tributo.pretrain-finetune.coverage.v2").hexdigest()
|
|
172
|
+
|
|
173
|
+
def validate(self, value: Mapping[str, Any]) -> Mapping[str, Any]:
|
|
174
|
+
if (
|
|
175
|
+
value.get("input_complete") is not True
|
|
176
|
+
or value.get("distributed") is not True
|
|
177
|
+
):
|
|
178
|
+
raise ValueError("pretrain-finetune coverage is incomplete")
|
|
179
|
+
state = value.get("state")
|
|
180
|
+
details = state.get("details") if isinstance(state, Mapping) else None
|
|
181
|
+
if not isinstance(details, Mapping):
|
|
182
|
+
raise ValueError("pretrain-finetune stage evidence is missing")
|
|
183
|
+
if details.get("component_stages") != "pretrain,finetune":
|
|
184
|
+
raise ValueError("pretrain-finetune component stage set drifted")
|
|
185
|
+
for stage in ("pretrain", "finetune"):
|
|
186
|
+
if int(details.get(f"stage.{stage}.rows", 0)) <= 0:
|
|
187
|
+
raise ValueError(f"pretrain-finetune {stage} coverage is missing")
|
|
188
|
+
return value
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
class DistillationTorchInputValidator(DistillationInputValidator):
|
|
192
|
+
pass
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
class DistillationTorchCoverageValidator(DistillationCoverageValidator):
|
|
196
|
+
pass
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
class PretrainFinetuneTorchInputValidator(PretrainFinetuneInputValidator):
|
|
200
|
+
pass
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
class PretrainFinetuneTorchCoverageValidator(PretrainFinetuneCoverageValidator):
|
|
204
|
+
pass
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
__all__ = [
|
|
208
|
+
"DistillationConfigValidator",
|
|
209
|
+
"DistillationCoverageValidator",
|
|
210
|
+
"DistillationInputValidator",
|
|
211
|
+
"DistillationOutputValidator",
|
|
212
|
+
"DistillationTorchCoverageValidator",
|
|
213
|
+
"DistillationTorchInputValidator",
|
|
214
|
+
"PretrainFinetuneConfigValidator",
|
|
215
|
+
"PretrainFinetuneCoverageValidator",
|
|
216
|
+
"PretrainFinetuneInputValidator",
|
|
217
|
+
"PretrainFinetuneOutputValidator",
|
|
218
|
+
"PretrainFinetuneTorchCoverageValidator",
|
|
219
|
+
"PretrainFinetuneTorchInputValidator",
|
|
220
|
+
]
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"""Descriptor for the Core-orchestrated distillation Component plan."""
|
|
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
|
+
ComponentStageTorchPlan,
|
|
12
|
+
ContractBinding,
|
|
13
|
+
ContractBindingSet,
|
|
14
|
+
EnvironmentSpec,
|
|
15
|
+
ExecutionMode,
|
|
16
|
+
ExecutionProfile,
|
|
17
|
+
MetricReduction,
|
|
18
|
+
QualifiedReference,
|
|
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_multistage_torch.contracts import (
|
|
28
|
+
DistillationConfigValidator,
|
|
29
|
+
DistillationOutputValidator,
|
|
30
|
+
DistillationTorchCoverageValidator,
|
|
31
|
+
DistillationTorchInputValidator,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
_PACKAGE = "tributo-algorithms"
|
|
35
|
+
_VERSION = "0.1.0"
|
|
36
|
+
_ROOT = Path(__file__).resolve().parent
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _code_digest() -> str:
|
|
40
|
+
return hashlib.sha256((_ROOT / "algorithm.py").read_bytes()).hexdigest()
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _binding(contract_id: str, validator: type[Any], version: int) -> ContractBinding:
|
|
44
|
+
return ContractBinding(
|
|
45
|
+
contract_id=contract_id,
|
|
46
|
+
schema_version=version,
|
|
47
|
+
schema_digest=str(validator.schema_digest),
|
|
48
|
+
validator_ref=QualifiedReference.parse(
|
|
49
|
+
f"tributo_algorithms_multistage_torch.contracts:{validator.__name__}"
|
|
50
|
+
),
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
_SPEC = AlgorithmSpec(
|
|
55
|
+
name="teacher_student_distillation",
|
|
56
|
+
trainer_cls=None,
|
|
57
|
+
version="1.0.0",
|
|
58
|
+
default_config={},
|
|
59
|
+
supported_tasks=("fit",),
|
|
60
|
+
operations=("fit",),
|
|
61
|
+
problem_types=(ProblemType.BINARY_CLASSIFICATION,),
|
|
62
|
+
capabilities=(Capability.DISTRIBUTED, Capability.EXPORTABLE, Capability.TUNABLE),
|
|
63
|
+
learning_paradigm="knowledge_distillation",
|
|
64
|
+
model_family="teacher_student_mlp",
|
|
65
|
+
data_modalities=("tabular",),
|
|
66
|
+
lifecycle_kind="finite_multistage_fit",
|
|
67
|
+
allowed_execution_modes=(ExecutionMode.RAY_TRAIN_TORCH.value,),
|
|
68
|
+
config_contract_ref="tributo.official.distillation.config.v1",
|
|
69
|
+
input_contract_ref="tributo.official.distillation.dense-labeled.v2",
|
|
70
|
+
output_contract_ref="tributo.official.distillation.student-bundle.v1",
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
_POLICY = TorchPolicy(
|
|
74
|
+
torch_runtime_api_version=1,
|
|
75
|
+
loop_owner="adapter",
|
|
76
|
+
parallelism_id="torch.ddp.replicated",
|
|
77
|
+
dataset_routing=(TorchDatasetRoute("train", "split_exact", True, 1, 1, "reject"),),
|
|
78
|
+
execution_plan=ComponentStageTorchPlan(
|
|
79
|
+
stages=(
|
|
80
|
+
TorchStageSpec(
|
|
81
|
+
"teacher",
|
|
82
|
+
("train",),
|
|
83
|
+
),
|
|
84
|
+
TorchStageSpec(
|
|
85
|
+
"student",
|
|
86
|
+
("train",),
|
|
87
|
+
checkpoint_from_stage="teacher",
|
|
88
|
+
),
|
|
89
|
+
),
|
|
90
|
+
final_stage_id="student",
|
|
91
|
+
),
|
|
92
|
+
state_layout="component",
|
|
93
|
+
metric_reducers={
|
|
94
|
+
"teacher_loss": MetricReduction.SUM_COUNT,
|
|
95
|
+
"student_loss": MetricReduction.SUM_COUNT,
|
|
96
|
+
"train_loss": MetricReduction.SUM_COUNT,
|
|
97
|
+
},
|
|
98
|
+
backend="auto",
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
_CONTRACTS = ContractBindingSet(
|
|
102
|
+
config=_binding(_SPEC.config_contract_ref or "", DistillationConfigValidator, 1),
|
|
103
|
+
input=_binding(_SPEC.input_contract_ref or "", DistillationTorchInputValidator, 2),
|
|
104
|
+
output=_binding(_SPEC.output_contract_ref or "", DistillationOutputValidator, 1),
|
|
105
|
+
coverage=_binding(
|
|
106
|
+
"tributo.official.distillation.torch-component-coverage.v2",
|
|
107
|
+
DistillationTorchCoverageValidator,
|
|
108
|
+
2,
|
|
109
|
+
),
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
DISTILLATION_DESCRIPTOR = AlgorithmBuilder.from_torch_adapter(
|
|
113
|
+
spec=_SPEC,
|
|
114
|
+
implementation_id="tributo.official.multistage_torch.distillation",
|
|
115
|
+
implementation_version="2.0.0",
|
|
116
|
+
adapter="tributo_algorithms_multistage_torch.algorithm:DistributedDistillation",
|
|
117
|
+
environment=EnvironmentSpec(
|
|
118
|
+
environment_id="tributo.official.multistage-torch.v2",
|
|
119
|
+
dependencies=(
|
|
120
|
+
"onnx>=1.16",
|
|
121
|
+
"onnxruntime>=1.20",
|
|
122
|
+
"safetensors>=0.4.3",
|
|
123
|
+
"torch>=2.5",
|
|
124
|
+
"tributo>=1.1",
|
|
125
|
+
f"tributo-algorithms[multistage-torch]=={_VERSION}",
|
|
126
|
+
),
|
|
127
|
+
),
|
|
128
|
+
metric_reducers={
|
|
129
|
+
"teacher_loss": MetricReduction.SUM_COUNT,
|
|
130
|
+
"student_loss": MetricReduction.SUM_COUNT,
|
|
131
|
+
"train_loss": MetricReduction.SUM_COUNT,
|
|
132
|
+
},
|
|
133
|
+
supported_worker_range=WorkerRange(2, 64),
|
|
134
|
+
supported_execution_profiles=(ExecutionProfile.LOCAL, ExecutionProfile.CLUSTER),
|
|
135
|
+
resources_per_worker=WorkerResources(num_cpus=1),
|
|
136
|
+
package_name=_PACKAGE,
|
|
137
|
+
package_version=_VERSION,
|
|
138
|
+
tributo_version_spec=">=1.1",
|
|
139
|
+
policy=_POLICY,
|
|
140
|
+
code_digest=_code_digest(),
|
|
141
|
+
contract_bindings=_CONTRACTS,
|
|
142
|
+
descriptor_api_version=2,
|
|
143
|
+
is_default=True,
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
__all__ = ["DISTILLATION_DESCRIPTOR"]
|