microsoft / FLAML

A fast library for AutoML and tuning. Join our Discord: https://discord.gg/Cppx2vSPVP.
https://microsoft.github.io/FLAML/
MIT License
3.75k stars 495 forks source link

BlendSearch in UDF mode #1283

Open khosravym opened 4 months ago

khosravym commented 4 months ago

When I select the BlendSearch search algorithm, I consistently encounter the following warning, whereas it does not appear when using CFO:

You passed a space parameter to OptunaSearch that contained unresolved search space definitions. OptunaSearch should however be instantiated with fully configured search spaces only. To use Ray Tune's automatic search space conversion, pass the space definition as part of the param_space argument to tune.Tuner() instead.

Programmer-RD-AI commented 1 month ago

Union[ Dict[str, "OptunaDistribution"], List[Tuple], Callable[["OptunaTrial"], Optional[Dict[str, Any]]], ]

The above is the space parameter structure that is expected could you check with what you pass to BlendSearch? and if possible send it...?

Nevermetyou65 commented 1 week ago

I got the same warning. I used the code in this example https://github.com/microsoft/FLAML/blob/main/test/tune_example.py

Programmer-RD-AI commented 1 week ago

I belive that Passing the space definition as part of the param_space argument to tune.Tuner() when using BlendSearch with OptunaSearch in UDF mode should resolve this issue...

Nevermetyou65 commented 1 week ago

Sorry, But what argument are you referring to? I can not find anything about tune.Tuner() in the doc. Is it in this doc? https://microsoft.github.io/FLAML/docs/reference/tune/tune

Do you have any code example? Thanks

Programmer-RD-AI commented 1 week ago

Hi, I was thinking of something similar to the following code segment:


from flaml.tune import tune

# Define the parameter space for tuning
param_space = {
    "n_estimators": tune.randint(lower=4, upper=1024),
    "num_leaves": tune.randint(lower=4, upper=1024),
    "min_child_samples": tune.randint(lower=2, upper=100),
}

# Define the settings for the AutoML run
settings = {
    ...,
    "config": param_space,
}

# Run the AutoML search
automl.fit(X_train=X_train, y_train=y_train, **settings)```
Nevermetyou65 commented 1 week ago

Hmm...

I got the warning from this example: https://github.com/microsoft/FLAML/blob/main/test/tune_example.py It does not use automl.fit but tune.run() for a user-defined function. But looking at your code, I see it's the same thing. The dictionary setting should work the same as this line.

analysis = tune.run(
        train_lgbm,
        metric="mse",
        mode="min",
        config=config_search_space,
        low_cost_partial_config=low_cost_partial_config,
        points_to_evaluate=points_to_evaluate,
        time_budget_s=3,
        num_samples=-1,
    )

And that is where I got warning. Set search_alg = "CFO" as make waning gone though.