# Run best model off sweep?

**URL:** <https://community.wandb.ai/t/run-best-model-off-sweep/2423>\
**Category:** W&B Help\
**Tags:** sweeps, wandb\
**Created:** [May 16, 2022, 3:38am UTC](https://community.wandb.ai/t/run-best-model-off-sweep/2423 "2022-05-16T03:38:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![cyrilw](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@cyrilw](https://community.wandb.ai/u/cyrilw)\
**Post date:** [May 16, 2022, 3:38am UTC](https://community.wandb.ai/t/run-best-model-off-sweep/2423/1 "2022-05-16T03:38:22Z")

</div>

Hi,  
I am using Sweeps to run through different configuration models and I was told by the wandb chat support that to run the best model configuration off sweeps is to create a new sweep with the best performing parameter set and running off it.

But this is lot of tedious work, is there any other elegant way of quering wandb project for the best model configuration and running off it?

tldr: I run a sweep with different configuration, would like to run predictions off a specific set of parameters (or best performing set of parameters). How to do it with the sweep API?

---

<div class="post-metadata">

**Author:** ![\_scott](https://sea2.discourse-cdn.com/flex020/user_avatar/community.wandb.ai/_scott/32/95_2.png) [@\_scott](https://community.wandb.ai/u/_scott)\
**Post date:** [May 16, 2022, 10:11am UTC](https://community.wandb.ai/t/run-best-model-off-sweep/2423/2 "2022-05-16T10:11:09Z")

</div>

Hi @cyrilw

Thanks for persisting with this and posting it here, here is how you do it with the Api.

```auto
import wandb

api = wandb.Api()
sweep = api.sweep(f"_scott/project-name/sweeps/qwbwbwbz")

# Get best run parameters
best_run = sweep.best_run(order='validation/accuracy')
best_parameters = best_run.config
print(best_parameters)

```

Hope this helps 🪄

---

<div class="post-metadata">

**Author:** ![cyrilw](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@cyrilw](https://community.wandb.ai/u/cyrilw)\
**Post date:** [May 16, 2022, 2:52pm UTC](https://community.wandb.ai/t/run-best-model-off-sweep/2423/3 "2022-05-16T14:52:40Z")

</div>

Thank you for the reply.

in this,  
`best_run = sweep.best_run(order='validation/accuracy')`

do I need to change the validation/accuracy based on my sweep columns?

---

<div class="post-metadata">

**Author:** ![\_scott](https://sea2.discourse-cdn.com/flex020/user_avatar/community.wandb.ai/_scott/32/95_2.png) [@\_scott](https://community.wandb.ai/u/_scott)\
**Post date:** [May 16, 2022, 3:02pm UTC](https://community.wandb.ai/t/run-best-model-off-sweep/2423/4 "2022-05-16T15:02:05Z")

</div>

Yes, sorry I should have said that. `order` is the metric you want it to order by.

If you have set a goal in your Sweep config, it’ll use that if `order` is not given.

Here’s the source if you’re curious: [https://github.com/wandb/client/blob/a339333b3ee93864daf416f04c1501186dffac5c/wandb/apis/public.py#L2137](https://wandb/client)

---

<div class="post-metadata">

**Author:** ![cyrilw](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@cyrilw](https://community.wandb.ai/u/cyrilw)\
**Post date:** [May 16, 2022, 3:36pm UTC](https://community.wandb.ai/t/run-best-model-off-sweep/2423/5 "2022-05-16T15:36:04Z")

</div>

I see. Just to confirm, my current sweep configuration is;

```auto
method: random
metric:
  goal: minimize
  name: KL
parameters:
  K:
    distribution: int_uniform
    max: 15
    min: 3

```

since I do have the goal/metric set I don’t need to worry about order, right? but if not I do collect KL (column name is `KL`) score (kl-divergence) so I’d modify the code snipet as;

`best_run = sweep.best_run(order='KL')`

But in case of KL, the lower is better any recommendation on how to select best\_run based on it?

---

<div class="post-metadata">

**Author:** ![\_scott](https://sea2.discourse-cdn.com/flex020/user_avatar/community.wandb.ai/_scott/32/95_2.png) [@\_scott](https://community.wandb.ai/u/_scott)\
**Post date:** [May 16, 2022, 4:51pm UTC](https://community.wandb.ai/t/run-best-model-off-sweep/2423/6 "2022-05-16T16:51:05Z")

</div>

Because your configuration has a goal, you can leave `order` out.  
So you can just do:

```auto
best_run = sweep.best_run() 

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/wandb/original/1X/366b649231631dbab896843020da0056074ac79d.png) [@system](https://community.wandb.ai/u/system)\
**Post date:** [July 15, 2022, 4:51pm UTC](https://community.wandb.ai/t/run-best-model-off-sweep/2423/7 "2022-07-15T16:51:46Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
