<@U06RKAMK0UC> sample of running optuna hyperparam...
# ask-ai
s
@ancient-wolf-19325 sample of running optuna hyperparameter tuning on flyte
a
To run Optuna hyperparameter tuning on Flyte, you can use the Flyte Optuna plugin to parallelize trials efficiently. Define an objective function as a Flyte task, then orchestrate the optimization using the Optimizer class, specifying the number of trials and concurrency. Each trial runs as an isolated Flyte task, and the process is observable and fault-tolerant in the Flyte UI. No external experiment tracking is needed—Flyte handles caching, retries, and recovery automatically. See the code sample below for a minimal example using the Flyte Python SDK and Optuna plugin.
Copy code
import flytekit as fl
from flytekitplugins.optuna import Optimizer, suggest

image = fl.ImageSpec(packages=["flytekitplugins.optuna"])

@fl.task(container_image=image)
async def objective(x: float, y: int, z: int, power: int) -> float:
    import math
    return math.log((((x - 5) ** 2) + (y + 4) ** 4 + (3 * z - 3) ** 2)) ** power

@fl.eager(container_image=image)
async def train(concurrency: int, n_trials: int) -> float:
    optimizer = Optimizer(objective=objective, concurrency=concurrency, n_trials=n_trials)
    await optimizer(
        x=suggest.float(low=-10, high=10),
        y=suggest.integer(low=-10, high=10),
        z=suggest.category([-5, 0, 3, 6, 9]),
        power=2,
    )
    print(optimizer.study.best_value)
You can register and run this workflow using Flyte's CLI. Would you like a step-by-step breakdown or more details on customizing the search space or integrating with other ML frameworks? Sources: - flytekit-optuna README - Flyte HPO Tutorial 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
s
@ancient-wolf-19325 what is fl.eager?
a
fl.eager
is a decorator in Flyte that enables "eager workflows," allowing you to write async Python functions that execute Flyte tasks and subworkflows with immediate, materialized outputs, rather than Flyte Promises. This lets you use native Python constructs (like
await
, loops, and conditionals) for highly flexible workflow logic, leveraging Python's
asyncio
API for true parallelism and local development convenience. Eager workflows are not compiled into workflow specs but are executed as Flyte tasks using the FlyteRemote interface for orchestration and authentication, and are especially useful for rapid iteration and debugging. Would you like more detail or examples of how to use
fl.eager
in practice? Sources: - flytekit-optuna README - Eager workflows user guide - Flyte 1.10 release blog 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.