# PB2 Hyper-parameters as Integers?

**URL:** <https://discuss.ray.io/t/pb2-hyper-parameters-as-integers/8822>\
**Category:** Uncategorized\
**Created:** [December 31, 2022, 6:34am UTC](https://discuss.ray.io/t/pb2-hyper-parameters-as-integers/8822 "2022-12-31T06:34:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![l-j-g](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/l-j-g/32/3656_2.png) [@l-j-g](https://discuss.ray.io/u/l-j-g)\
**Post date:** [December 31, 2022, 6:34am UTC](https://discuss.ray.io/t/pb2-hyper-parameters-as-integers/8822/1 "2022-12-31T06:34:35Z")

</div>

Hi,

I’m trying to use PB2 with hyper-parameters specified as follows:

```auto
search_space = {
    'fast_period': [3,30],
    'liquidate': [0,1],
    'should_cancel': [True, False],
}

pb2 = PB2(
    time_attr='training_iteration',
    perturbation_interval=perturbation_interval,
    require_attrs=False,
    hyperparam_bounds=search_space
    )

```

When i execute i run into an error because my trainable function requires parameters to be as integers.

Is there some way I can specify that the sampled hyperparameters should be integers when using the PB2 scheduler? I wasn’t able to find much in the docs.

with PBT i was able to specify integer perturbations like this :

```auto
hyperparams_mutations = {
    'fast_period': tune.qrandint(3,30,1),
    'liquidate': [0,1],
    'should_cancel': [True, False],
}

search_space = {
    'fast_period': tune.qrandint(3,30,1),
    'liquidate': tune.choice([0,1]),
    'should_cancel': tune.choice([True, False]),
}

```

---

<div class="post-metadata">

**Author:** ![justinvyu](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/justinvyu/32/4309_2.png) [@justinvyu](https://discuss.ray.io/u/justinvyu)\
**Post date:** [January 3, 2023, 5:26pm UTC](https://discuss.ray.io/t/pb2-hyper-parameters-as-integers/8822/2 "2023-01-03T17:26:13Z")

</div>

Hi @l-j-g,

It looks like PBT has a way to do this with a custom explore function that can be used to post-process perturbed values (i.e. casting to int if needed), but PB2 does not. This can be added to PB2 to have the same behavior. Feel free to create a github issue to track this request!

One way to get around this for now is to do the casting/conversion within your trainable function, when loading the hyperparameters from the config.

---

<div class="post-metadata">

**Author:** ![Amadou](https://avatars.discourse-cdn.com/v4/letter/a/71e660/32.png) [@Amadou](https://discuss.ray.io/u/Amadou)\
**Post date:** [February 2, 2023, 4:55pm UTC](https://discuss.ray.io/t/pb2-hyper-parameters-as-integers/8822/3 "2023-02-02T16:55:36Z")

</div>

Hello guys! I am interested in this issue aswell. I have been thinking abour modifying the source code by chaining the pb2\_explore with my own custom version. Does this github already exist?

---

<div class="post-metadata">

**Author:** ![justinvyu](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/justinvyu/32/4309_2.png) [@justinvyu](https://discuss.ray.io/u/justinvyu)\
**Post date:** [February 6, 2023, 9:10pm UTC](https://discuss.ray.io/t/pb2-hyper-parameters-as-integers/8822/4 "2023-02-06T21:10:15Z")

</div>

Hi @Amadou,

This will be added in [[Tune] Add support for nested hyperparams in PB2 by justinvyu · Pull Request #31502 · ray-project/ray · GitHub](https://github.com/ray-project/ray/pull/31502). I will ping back when this is merged and usable in the latest ray-nightly.

---

<div class="post-metadata">

**Author:** ![Amadou](https://avatars.discourse-cdn.com/v4/letter/a/71e660/32.png) [@Amadou](https://discuss.ray.io/u/Amadou)\
**Post date:** [February 23, 2023, 1:30pm UTC](https://discuss.ray.io/t/pb2-hyper-parameters-as-integers/8822/5 "2023-02-23T13:30:50Z")

</div>

Hello justinvyu, Thank you very much. I overlooked your message here, is why I am replying so late

---

<div class="post-metadata">

**Author:** ![justinvyu](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/justinvyu/32/4309_2.png) [@justinvyu](https://discuss.ray.io/u/justinvyu)\
**Post date:** [February 23, 2023, 9:07pm UTC](https://discuss.ray.io/t/pb2-hyper-parameters-as-integers/8822/6 "2023-02-23T21:07:46Z")

</div>

No worries! Feel free to mark this as resolved if no more questions 🙂
