Skip to content

Commit d853fa5

Browse files
added api changes
Signed-off-by: Shashank Mittal <[email protected]>
1 parent 8d266f0 commit d853fa5

File tree

1 file changed

+99
-45
lines changed

1 file changed

+99
-45
lines changed

docs/proposals/parameter-distribution.md

Lines changed: 99 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,119 @@
44
The goal of this project is to enhance the existing Katib Experiment APIs to support various parameter distributions such as uniform, log-uniform, and qlog-uniform. Then extend the suggestion services to be able to configure distributions for search space using libraries provided in each framework.
55

66
## Motivation
7-
Currently, Katib is limited to supporting only uniform distribution for integer, float, and categorical hyperparameters. By introducing additional distributions, Katib will become more flexible and powerful in conducting hyperparameter optimization tasks.
7+
Currently, [Katib](https://github.com/kubeflow/katib) is limited to supporting only uniform distribution for integer, float, and categorical hyperparameters. By introducing additional distributions, Katib will become more flexible and powerful in conducting hyperparameter optimization tasks.
8+
9+
A Data Scientist requires Katib to support multiple hyperparameter distributions, such as log-uniform, normal, and log-normal, in addition to the existing uniform distribution. This enhancement is crucial for more flexible and precise hyperparameter optimization. For instance, learning rates often benefit from a log-uniform distribution because small values can significantly impact performance. Similarly, normal distributions are useful for parameters that are expected to vary around a central value.
10+
11+
### Goals
12+
- Add `Distribution` field to `ParameterSpec` alongside `ParameterType`.
13+
- Support for the log-uniform, normal, and log-normal Distributions.
14+
- Update the Experiment and gRPC API to support `Distribution`.
15+
- Update logic to handle the new parameter distributions for each suggestion service (e.g., Optuna, Hyperopt).
16+
- Extend the Python SDK to support the new `Distribution` field.
17+
### Non-Goals
18+
- This proposal do not aim to create new version for CRD APIs.
19+
- No changes will be made to the core optimization algorithms beyond supporting new distributions.
820

921
## Proposal
1022

11-
### Maintaining two versions of CRD APIs
12-
- Introduce `v1beta2` API version
13-
- The (conversion webhook)[https://book.kubebuilder.io/multiversion-tutorial/conversion.html] will serve as a critical component in managing transitions between different API versions (`v1beta1` to `v1beta2`).
14-
- TODO
15-
> I will create a correspondence table between v1beta1 and v1beta2. Maybe, we only need to create a table for the `ParameterType` and the `FeasibleSpace`.
16-
Look into this.
17-
- A specific field will be added to the katib-config `katib/pkg/util/v1beta1/katibconfig/config.go` to handle different gRPC client versions required by the suggestion controller. (One approach could be this for maintaining two versions of gRPC APIs).
18-
- TODO Based on this comment here:
19-
https://github.com/kubeflow/katib/pull/2059#discussion_r1049329229
20-
Look how to maintain two versions of gRPC APIs
21-
22-
### Experiment API changes
23+
### Parameter Distribution Comparison Table
24+
| Distribution Type | Hyperopt | Optuna | Ray Tune |
25+
|-------------------------------|-----------------------|--------------------------------------|-----------------------|
26+
| **Uniform Continuous** | `hp.uniform` | `FloatDistribution` | `tune.uniform` |
27+
| **Quantized Uniform** | `hp.quniform` | `DiscreteUniformDistribution`(deprecated) Use `FloatDistribution` instead. | `tune.quniform` |
28+
| **Log Uniform** | `hp.loguniform` | `LogUniformDistribution`(deprecated) Use `FloatDistribution` instead. | `tune.loguniform` |
29+
| **Uniform Integer** | `hp.randint` or quantized distributions with step size `q` set to 1 | `IntDistribution` | `tune.randint` |
30+
| **Categorical** | `hp.choice` | `CategoricalDistribution` | `tune.choice` |
31+
| **Quantized Log Uniform** | `hp.qloguniform` | Custom Implementation Use `FloatDistribution` instead. | `tune.qloguniform` |
32+
| **Normal** | `hp.normal` | (Not directly supported) | `tune.randn` |
33+
| **Quantized Normal** | `hp.qnormal` | (Not directly supported) | `tune.qrandn` |
34+
| **Log Normal** | `hp.lognormal` | (Not directly supported) | (Use custom transformation in `tune.randn`) |
35+
| **Quantized Log Normal** | `hp.qlognormal` | (Not directly supported) | (Use custom transformation in `tune.qrandn`) |
36+
| **Quantized Integer** | `hp.quniformint` | `IntUniformDistribution`(deprecated) Use `IntDistribution` instead. | |
37+
| **Log Integer** | | `IntLogUniformDistribution`(deprecated) Use `IntDistribution` instead. | `tune.lograndint` |
38+
39+
### How is Nevergrad implementing Hyperopt?
40+
Nevergrad maps parameter types (like p.Scalar, p.Log, p.Choice, etc.) from Nevergrad to corresponding Hyperopt search space definitions (hp.uniform, hp.loguniform, hp.choice, etc.).
41+
```python
42+
def _get_search_space(param_name, param):
43+
if isinstance(param, p.Scalar):
44+
...
45+
return hp.uniform(param_name, param.bounds[0][0], param.bounds[1][0])
46+
elif isinstance(param, p.Log):
47+
...
48+
return hp.loguniform(param_name, np.log(param.bounds[0][0]), np.log(param.bounds[1][0]))
49+
elif isinstance(param, p.Choice):
50+
...
51+
return hp.choice()
52+
```
53+
The `_get_search_space` function constructs a search space that represents the entire parameter space defined by Nevergrad.
54+
55+
## Experiment API changes
2356
Scope: `pkg/apis/controller/experiments/v1beta1/experiment_types.go`
24-
- Modifying the `ParameterSpec` struct to include a new field called Distribution.
57+
- Adding new field `Distribution` to `ParameterSpec`
2558

2659
```go
2760
type ParameterSpec struct {
28-
Name string `json:"name,omitempty"`
29-
Distribution Distribution `json:"distribution,omitempty"`
30-
FeasibleSpace FeasibleSpace `json:"feasibleSpace,omitempty"`
61+
Name string `json:"name,omitempty"`
62+
ParameterType ParameterType `json:"parameterType,omitempty"`
63+
Distribution Distribution `json:"distribution,omitempty"` // Added Distribution field
64+
FeasibleSpace FeasibleSpace `json:"feasibleSpace,omitempty"`
3165
}
3266
```
3367

34-
- Renaming Parameters
35-
68+
- Defining `Distribution` type
3669
```go
3770
type Distribution string
3871

3972
const (
4073
CategoricalDistribution Distribution = "categorical"
41-
IntUniformDistribution Distribution = "intUniform"
42-
IntLogUniformDistribution Distribution = "intLogUniform"
43-
FloatUniformDistribution Distribution = "floatUniform"
74+
UniformDistribution Distribution = "uniform"
75+
LogUniformDistribution Distribution = "logUniform"
76+
NormalDistribution Distribution = "normal"
77+
LogNormalDistribution Distribution = "logNormal"
4478
)
4579
```
80+
- The `Step` field can be used to define quantization steps for uniform or log-uniform distributions, effectively covering q-quantization requirements.
81+
```go
82+
type FeasibleSpace struct {
83+
Max string `json:"max,omitempty"`
84+
Min string `json:"min,omitempty"`
85+
List []string `json:"list,omitempty"`
86+
Step string `json:"step,omitempty"` // Step can be used to define q-quantization
87+
}
88+
```
4689

47-
### Suggestion Service Logic
90+
## gRPC API changes
91+
Scope: `pkg/apis/manager/v1beta1/api.proto`
92+
- Add the `Distribution` field to the `ParameterSpec` message
93+
```
94+
/**
95+
* Config for a hyperparameter.
96+
* Katib will create each Hyper parameter from this config.
97+
*/
98+
message ParameterSpec {
99+
string name = 1; /// Name of the parameter.
100+
ParameterType parameter_type = 2; /// Type of the parameter.
101+
FeasibleSpace feasible_space = 3; /// FeasibleSpace for the parameter.
102+
Distribution distribution = 4; // Distribution of the parameter.
103+
}
104+
```
105+
- Define the `Distribution` enum
106+
```
107+
/**
108+
* Distribution types for HyperParameter.
109+
*/
110+
enum Distribution {
111+
CATEGORICAL = 0;
112+
UNIFORM = 1;
113+
LOG_UNIFORM = 2;
114+
NORMAL = 3;
115+
LOG_NORMAL = 4;
116+
}
117+
```
118+
119+
## Suggestion Service Logic
48120
- For each suggestion service (e.g., Optuna, Hyperopt), the logic will be updated to handle the new parameter distributions.
49121
- This involves modifying the conversion functions to map Katib distributions to the corresponding framework-specific distributions.
50122

@@ -67,33 +139,15 @@ scope: `pkg/suggestion/v1beta1/optuna/base_service.py`
67139
return search_space
68140
```
69141

70-
#### Chocolate
71-
ref: https://chocolate.readthedocs.io/en/latest/api/space.html
72-
73142
#### Goptuna
74143
ref: https://github.com/c-bata/goptuna/blob/2245ddd9e8d1edba750839893c8a618f852bc1cf/distribution.go
75144

76145
#### Hyperopt
77146
ref: http://hyperopt.github.io/hyperopt/getting-started/search_spaces/#parameter-expressions
78147

79-
#### Scikit Optimize
80-
ref: https://scikit-optimize.github.io/stable/modules/classes.html#module-skopt.space.space
81-
82-
#### Parameter Distribution Table
83-
| Distribution Type | Hyperopt | Optuna | Ray Tune |
84-
|-------------------------------|-----------------------|--------------------------------------|-----------------------|
85-
| **Uniform Continuous** | `hp.uniform` | `FloatDistribution` | `tune.uniform` |
86-
| **Quantized Uniform** | `hp.quniform` | `DiscreteUniformDistribution`(deprecated) Use `FloatDistribution` instead. | `tune.quniform` |
87-
| **Log Uniform** | `hp.loguniform` | `LogUniformDistribution`(deprecated) Use `FloatDistribution` instead. | `tune.loguniform` |
88-
| **Uniform Integer** | `hp.randint` | `IntDistribution` | `tune.randint` |
89-
| **Categorical** | `hp.choice` | `CategoricalDistribution` | `tune.choice` |
90-
| **Quantized Log Uniform** | `hp.qloguniform` | | `tune.qloguniform` |
91-
| **Quantized Integer** | `hp.quniformint` | `IntUniformDistribution`(deprecated) Use `IntDistribution` instead. | |
92-
| **Log Integer** | | `IntLogUniformDistribution`(deprecated) Use `IntDistribution` instead. | `tune.lograndint` |
93-
| **Normal** | `hp.normal` | | `tune.randn` |
94-
148+
#### Ray-tune
149+
ref: https://docs.ray.io/en/latest/tune/api/search_space.html
95150

96-
### Testing
97-
- Write unit tests for the conversion webhook to ensure all fields are correctly converted.
98-
- Write unit tests for the new parameter distributions to ensure they are processed correctly by the controller.
151+
## Python SDK
152+
Extend the Python SDK to support the new `Distribution` field.
99153

0 commit comments

Comments
 (0)