Danny Vilela
12/16/2021, 10:22 PMEvaluateModelOnMetric(model: Model = …, metric: Metric = …)
that evaluates a single model against a single metric and lists models: List[Model] = [model_a, model_b, model_c]
and metrics: List[Metric] = [precision, recall, f1_score]
.
It’s pretty simple to design a task EvaluateModelsOnMetrics(models: List[Model] = …, metrics: List[Metric] = …)
that uses itertools.product
internally and delegates to a EvaluateModelOnMetric
, but I’m wondering if prefect has something like this out of the box 🙂Kevin Kho
Anna Geller
Danny Vilela
12/17/2021, 1:16 AMProductMapTask
. Thank you @Anna Geller!Danny Vilela
01/05/2022, 11:25 PMitertools.product
work with task checkpointing? This example is a bit incomplete, but I think it shows what I’m trying to do:
import itertools
from typing import Any
from typing import Dict
from typing import List
from prefect import task
from prefect import Flow
from prefect.engine.state import State
@task()
def product_map(data: Dict[str, Any]) -> List[Dict[str, Any]]:
keys: List[str] = [*data.keys()]
vals: List[Any] = [*data.values()]
return [dict(zip(keys, pair)) for pair in itertools.product(*vals)]
@task()
def print_abc(a: int, b: str, c: str) -> str:
print(a, b, c)
return f"a={a}, b={b}, c={c}"
params: Dict[str, Any] = dict(
a=[1, 2],
b=["foo", "bar"],
c=["hello", "world"]
)
with Flow(name="test") as flow:
mapped_params = product_map(data=params)
print_abc.map(mapped_params) # Note: this does not work!
flow_state: State = flow.run()
assert flow_state.is_successful()
print(flow_state.result[mapped_params].result)
mapped_params
is a list of dictionaries, where each dictionary represents a product of all values of params
values (e.g., [{'a': 1, 'b': 'foo', 'c': 'hello'}, {'a': 1, 'b': 'foo', 'c': 'world'}, …]
). But I’m not sure [how/if it’s possible] to tell Prefect that each dictionary should be expanded into the print_abc
method’s keyword arguments? Am I missing something?
I assume that if I can get each individual dictionary’s a
, b
, and c
mapped to a task, then checkpointing could work as expected.Anna Geller