Task API
See Add a task for the constructor and metric declaration conventions.
TaskABC
Bases: ABC
Abstract task contract for training, evaluation, and metrics.
Implementations define the task-owned target contract, metric declaration,
compile behavior, fit wiring, and evaluation logic. By default,
:attr:name returns the implementing class name,
:meth:validate_config performs no validation, and
:meth:validate_model_outputs performs no output checks.
build_target_spec(bundle, task_config)
abstractmethod
Build the concrete target/output contract for one task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bundle
|
DatasetBundle
|
Normalized dataset package. |
required |
task_config
|
Any
|
Task-local configuration subtree. |
required |
Returns:
| Type | Description |
|---|---|
TargetSpec
|
Concrete target and output contract for model construction and validation. This is the task-owned contract returned by the task implementation for downstream task logic. |
metric_contract(target_spec, task_config)
abstractmethod
Describe task-defined metric availability.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_spec
|
TargetSpec
|
Task-owned target specification. |
required |
task_config
|
Any
|
Task-local configuration subtree. |
required |
Returns:
| Type | Description |
|---|---|
TaskMetricContract
|
Task-defined metric declaration consumed by orchestration code. |
compile_model(model, task_config, target_spec)
abstractmethod
Apply task-owned compile semantics to a model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
Uncompiled model returned by a model family. |
required |
task_config
|
Any
|
Task-local configuration subtree. |
required |
target_spec
|
TargetSpec
|
Task-owned target specification. |
required |
Returns:
| Type | Description |
|---|---|
None
|
The task implementation applies compile configuration to the passed
model using |
build_fit_plan(bundle, task_config, target_spec, *, mode, combine_train_val)
abstractmethod
Build task-owned model.fit(...) wiring.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bundle
|
DatasetBundle
|
Normalized dataset package. |
required |
task_config
|
Any
|
Task-local configuration subtree. |
required |
target_spec
|
TargetSpec
|
Task-owned target specification. |
required |
mode
|
('search', 'final')
|
Runner phase requesting the fit plan. |
"search"
|
combine_train_val
|
bool
|
Whether the task should fold the validation split into training for this plan. |
required |
Returns:
| Type | Description |
|---|---|
FitPlan
|
Task-owned fit wiring excluding runner-injected schedule policy. |
evaluate(model, split, task_config, target_spec)
abstractmethod
Evaluate a model on one split and return structured results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
Compiled or already-trained model. |
required |
split
|
DataSplit
|
Dataset split to evaluate. |
required |
task_config
|
Any
|
Task-local configuration subtree. |
required |
target_spec
|
TargetSpec
|
Task-owned target specification. |
required |
Returns:
| Type | Description |
|---|---|
EvaluationResult
|
Structured evaluation output. |
evaluate_predictions(predictions, split, task_config, target_spec)
abstractmethod
Evaluate normalized predictions for one split.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predictions
|
Any
|
Prediction payload already normalized into the task's expected shape. |
required |
split
|
DataSplit
|
Dataset split to evaluate. |
required |
task_config
|
Any
|
Task-local configuration subtree. |
required |
target_spec
|
TargetSpec
|
Task-owned target specification. |
required |
Returns:
| Type | Description |
|---|---|
EvaluationResult
|
Structured evaluation output. |
validate_config(task_config)
Validate task-local configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task_config
|
Any
|
Task-local configuration subtree. |
required |
Returns:
| Type | Description |
|---|---|
None
|
The default implementation intentionally performs no validation and accepts any config object. |
validate_model_outputs(model, target_spec)
Validate model outputs against the task contract.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
Built model to validate. |
required |
target_spec
|
TargetSpec
|
Task-owned target specification. |
required |
Returns:
| Type | Description |
|---|---|
None
|
The default implementation intentionally performs no checks and exists as an override hook for task-specific output validation. |
TargetSpec
dataclass
Concrete target and output contract for one task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task_type
|
str
|
Stable task-type label, such as |
required |
output_names
|
list[str]
|
Ordered output names produced by the model. |
required |
output_shapes
|
list[Any]
|
Ordered output-shape descriptors matching |
required |
metadata
|
dict[str, Any]
|
Task-owned metadata required by model construction or evaluation. |
dict()
|
Attributes:
| Name | Type | Description |
|---|---|---|
task_type |
str
|
Stable task-type label, such as |
output_names |
list[str]
|
Ordered output names produced by the model. |
output_shapes |
list[Any]
|
Ordered output-shape descriptors matching |
metadata |
dict[str, Any]
|
Task-owned metadata required by model construction or evaluation. |
TaskMetricContract
dataclass
Task-defined metric declaration shared with orchestration code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
available_metric_names
|
set[str]
|
Metric names the task can produce. |
set()
|
training_only_metric_names
|
set[str]
|
Metric names available only after training has completed. |
set()
|
nonnegative_metric_names
|
set[str]
|
Task metric names guaranteed to stay nonnegative. Shared score and prune validation uses this set to interpret negative sentinels as unavailable values. |
set()
|
primary_metric_names
|
set[str]
|
Informational headline metrics exposed by the task. These names do not override runner-owned objective configuration. |
set()
|
Attributes:
| Name | Type | Description |
|---|---|---|
available_metric_names |
set[str]
|
Metric names the task can produce. |
training_only_metric_names |
set[str]
|
Metric names available only after training has completed. |
nonnegative_metric_names |
set[str]
|
Task metric names guaranteed to stay nonnegative. Shared score and prune validation uses this set to interpret negative sentinels as unavailable values. |
primary_metric_names |
set[str]
|
Informational headline metrics exposed by the task. These names do not override runner-owned objective configuration. |
FitPlan
dataclass
Task-owned training plan for one model.fit(...) call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fit_kwargs
|
dict[str, Any]
|
Keyword arguments forwarded to |
dict()
|
callbacks
|
list[Any]
|
Callback objects or callback-like payloads owned by the task. |
list()
|
monitor_metric
|
str | None
|
Optional monitor metric name used by task-owned callbacks. |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
fit_kwargs |
dict[str, Any]
|
Keyword arguments forwarded to |
callbacks |
list[Any]
|
Callback objects or callback-like payloads owned by the task. |
monitor_metric |
str | None
|
Optional monitor metric name used by task-owned callbacks. |
EvaluationResult
dataclass
Structured task evaluation output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metrics
|
dict[str, Any]
|
Flat metric dictionary consumed by NAS, reporting, or other shared orchestration logic. |
dict()
|
artifacts
|
dict[str, Any] | None
|
Optional flat structured payload describing task-owned evaluation artifacts. This field is metadata-oriented and does not imply that files must be written during every evaluation call. |
None
|
predictions
|
Any | None
|
Optional predictions or prediction-like payloads needed by later task-owned analysis code. |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
metrics |
dict[str, Any]
|
Flat metric dictionary consumed by NAS, reporting, or other shared orchestration logic. |
artifacts |
dict[str, Any] | None
|
Optional flat structured payload describing task-owned evaluation artifacts. This field is metadata-oriented and does not imply that files must be written during every evaluation call. |
predictions |
Any | None
|
Optional predictions or prediction-like payloads needed by later task-owned analysis code. |
instantiate_task_component(task_name, config, task_config, *, checkpoint_path=None, early_stopping_patience=None)
Instantiate one task using the explicit runtime constructor contract.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task_name
|
str
|
Registered task name. |
required |
config
|
Any
|
Loaded runtime configuration. |
required |
task_config
|
Any
|
Task-local configuration subtree. |
required |
checkpoint_path
|
Path | None
|
Explicit checkpoint path override. |
None
|
early_stopping_patience
|
int | None
|
Explicit early-stopping patience override. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
Instantiated task component. |