💯 Default Values
👉 Setting default values
Some configs are unlikely to ever change. In such cases, a default value can be specified.
The default needs to be propagated to the generated code. Hence, we'll add the default to the protobuf schema.
The default value will be added to the generated code.
In this case, all values have a default, so it is possible to instantiate the class without specifying any values.
🔠Enums
Enum values can be specified using the name of the enum value.
// default_enum.proto
syntax = "proto3";
package defaults_enum;
import "py_gen_ml/extensions.proto";
// Activation function
enum Activation {
// Rectified Linear Unit
RELU = 0;
// Gaussian Error Linear Unit
GELU = 1;
}
// Linear layer
message Linear {
// Number of input features
int32 in_features = 1;
// Number of output features
int32 out_features = 2;
// Activation function
Activation activation = 3 [(pgml.default).enum = "GELU"];
}
# Autogenerated code. DO NOT EDIT.
import enum
import py_gen_ml as pgml
class Activation(str, enum.Enum):
"""Activation function"""
RELU = "RELU"
"""Rectified Linear Unit"""
GELU = "GELU"
"""Gaussian Error Linear Unit"""
class Linear(pgml.YamlBaseModel):
"""Linear layer"""
in_features: int
"""Number of input features"""
out_features: int
"""Number of output features"""
activation: Activation = Activation.GELU
"""Activation function"""
🚧 Limitations
It is currently only possible to specify defaults for built-ins such as string
, float
, int
, etc. For message
fields, you cannot specify a default value. We leave this feature for future work.