def some_function( x, y, param2: int = PyParam(2, int, "func", "b"), param3: float = PyParam(3, scope="func"), param4: int = PyParam(value=4, dtype=int, scope="func"), param5=PyParam(5, dtype=int, scope="func"), param6=PyParam(6, int, scope="func") ) -> int: print("test") return param5
def get() -> tf.train.Optimizer: lr: float = PyParam(value=0.01, scope="adam") beta1: float = PyParam(value=0.9, scope="adam") beta2: float = PyParam(value=0.995, scope="adam") epsilon: float = PyParam(value=1e-8, scope="adam") optimizer = tf.train.AdamOptimizer( learning_rate=lr, beta1=beta1, beta2=beta2, epsilon=epsilon ) return optimizer
def nested_function( x, y, np1: int = PyParam(2, int, "np", "b"), ): def nested_function2( x, y, np2: int = PyParam(2, int, "np", "b"), ) -> bool: np3: int = PyParam(2, int, "np", "b") pass np4: int = PyParam(2, int, "np", "b") return nested_function2
def sum_numbers(): """Sum numbers """ s = 0 max_iters: int = PyParam(6, int, "loop", "max number of iterations") for i in range(start_index, max_iters): s += i return s
def get() -> tf.train.Optimizer: lr: float = PyParam(0.01, scope="adamw") weight_decay: float = PyParam(value=5e-6, scope="adamw") beta1: float = PyParam(value=0.9, scope="adamw") beta2: float = PyParam(value=0.995, scope="adamw") epsilon: float = PyParam(value=1e-8, scope="adamw") optimizer = tf.contrib.opt.AdamWOptimizer( weight_decay=weight_decay, learning_rate=lr, beta1=beta1, beta2=beta2, epsilon=epsilon, ) return optimizer
class SomeClass: param1: int = PyParam(value=1, scope="class") param2 = PyParam(2, scope="class") param3: int = PyParam(3, scope="class") param4: int = PyParam(value=4, dtype=int, scope="class") param5: int = PyParam(5, dtype=int, scope="class") param6: int = PyParam(6, int, scope="class", desc="last param") def class_func( self, arg1: float = PyParam(value=1.1, scope="class/func/arg"), arg2=PyParam(value=2.2, scope="class/func/arg"), ) -> bool: return self.param1 + self.param2 + arg1 + arg2
from pyparams import PyParam param1: int = PyParam(value=1, dtype=int, scope="loop", desc="a") param2: int = PyParam(2, int, "loop", "b") param3: int = PyParam(3, scope="loop") param4: int = PyParam(value=4, dtype=int, scope="loop2") param5: int = PyParam(5, dtype=int, scope="loop2") param6: int = PyParam(6, int, scope="loop")
from pyparams import PyParam version: str = PyParam(dtype=str, value="1.0", desc="model version") foo1: int = PyParam(dtype=int, value=1, scope="model", desc="foo1") foo2: float = PyParam(dtype=float, value=2, scope="model", desc="foo2") image_foo1: float = PyParam(dtype=float, value=2, scope="image", desc="") image_foo2: tuple = PyParam(dtype=tuple, value=(64, 64), scope="image", desc="shape of the image") image_foo3: tuple = PyParam(dtype=tuple, value=(32, 32), scope="image/shape", desc="shape of some image") bar1: list = PyParam(dtype=list, value=[64, 64], scope="", desc="something") y = foo1 + foo2
from pyparams import PyParam start_index: int = PyParam(1, scope="loop", desc="summation start index") def sum_numbers(): """Sum numbers """ s = 0 max_iters: int = PyParam(6, int, "loop", "max number of iterations") for i in range(start_index, max_iters): s += i return s print(sum_numbers())
def matmul(matrix: np.ndarray, x: np.ndarray): """matrix multiplication with magic""" bias: float = PyParam(1.1, float, "matmul") beta: float = PyParam(1.2, float, "matmul") return beta * matrix @ x + bias
def class_func( self, arg1: float = PyParam(value=1.1, scope="class/func/arg"), arg2=PyParam(value=2.2, scope="class/func/arg"), ) -> bool: return self.param1 + self.param2 + arg1 + arg2
def some_function( x, y, param2: int = PyParam(2, int, "func", "b"), param3: float = PyParam(3, scope="func"), param4: int = PyParam(value=4, dtype=int, scope="func"), param5=PyParam(5, dtype=int, scope="func"), param6=PyParam(6, int, scope="func") ) -> int: print("test") return param5 result = some_function( 0, 1, param2=PyParam(12, int, "func_call", "b"), param3=PyParam(13, scope="func_call"), ) @dataclass class SomeClass: param1: int = PyParam(value=1, scope="class") param2 = PyParam(2, scope="class") param3: int = PyParam(3, scope="class") param4: int = PyParam(value=4, dtype=int, scope="class") param5: int = PyParam(5, dtype=int, scope="class") param6: int = PyParam(6, int, scope="class", desc="last param") def class_func( self,
def matmul(matrix: np.ndarray, x: np.ndarray) -> np.ndarray: """matrix multiplication with magic""" offset: float = PyParam(1.0, float, "matmul") alpha: float = PyParam(1.0, float, "matmul") return alpha * matrix @ x + offset
from pyparams import PyParam param1: int = PyParam(value=1, dtype=int, scope="loop", desc="summation start index") param2: int = PyParam(2, int, "loop", "max number of iterations") param3: int = PyParam(3, scope="loop") param4: int = PyParam(value=4, dtype=int, scope="loop") param5: int = PyParam( 5, dtype=int, scope="loop", desc="'Note: some very long description, which should break line in " "the yaml file: `f1_score`: `0.333`'") param6: int = PyParam( 6, int, scope="loop", desc="some very long description, which should " "break line in the yaml file: Is it long enough?", )
def nested_function2( x, y, np2: int = PyParam(2, int, "np", "b"), ) -> bool: np3: int = PyParam(2, int, "np", "b") pass
# Template definition of model parameters from pyparams import PyParam version: str = PyParam(dtype=str, value="1.0", desc="model version") base_num_filters: int = PyParam(4, scope="feature_extractor") include_root: bool = PyParam(False, scope="feature_extractor") regularize_depthwise: bool = PyParam(False, scope="feature_extractor") activation_fn_in_separable_conv: bool = PyParam(False, scope="feature_extractor") entry_flow_blocks: tuple = PyParam( (1, 1, 1), dtype=tuple, scope="feature_extractor", desc="Number of units in each bock in the entry flow.", ) middle_flow_blocks: tuple = PyParam( (1, ), dtype=tuple, scope="feature_extractor", desc="Number of units in the middle flow.", ) X: int = 3
from pyparams import PyParam foo1_dict: dict = PyParam( dtype=dict, value={"a": 1, "b": 2}, scope="model", desc="foo1" ) foo2_dict: dict = PyParam( dtype=dict, value={"a": [1, 1, 2]}, scope="model", desc="foo2" ) foo3_dict: dict = PyParam( dtype=dict, value={"a": {"aa": 3, "ab": [1, 3]}, "b": [1, 2, 3], "c": "test"}, scope="model", desc="foo2", ) foo4_dict: dict = PyParam( dtype=list, value=[ {"a": {"aa": 3, "ab": [1, 3]}, "b": [1, 2, 3], "c": "test"}, {"A": {"AA": 15., "AB": [1]}, "B": [2, 3], "C": "TEST"} ], scope="model", desc="foo4 nested dict in list", )