From cb3fc610ddf0df5e52fbae35bc2fae5d90a0d391 Mon Sep 17 00:00:00 2001 From: LarsKue Date: Mon, 7 Apr 2025 19:18:05 -0400 Subject: [PATCH 1/5] remove width and depth argument in MLP --- bayesflow/networks/mlp/mlp.py | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/bayesflow/networks/mlp/mlp.py b/bayesflow/networks/mlp/mlp.py index 2522153ff..ea3459a3f 100644 --- a/bayesflow/networks/mlp/mlp.py +++ b/bayesflow/networks/mlp/mlp.py @@ -20,10 +20,8 @@ class MLP(keras.Layer): def __init__( self, + widths: Sequence[int], *, - depth: int = None, - width: int = None, - widths: Sequence[int] = None, activation: str = "mish", kernel_initializer: str = "he_normal", residual: bool = False, @@ -46,15 +44,8 @@ def __init__( Parameters ---------- - depth : int, optional - Number of layers in the MLP when `widths` is not explicitly provided. Must be - used together with `width`. Default is 2. - width : int, optional - Number of units per layer when `widths` is not explicitly provided. Must be used - together with `depth`. Default is 256. widths : Sequence[int], optional - Explicitly defines the number of hidden units per layer. If provided, `depth` and - `width` should not be specified. Default is None. + Defines the number of hidden units per layer, as well as the number of layers to be used. activation : str, optional Activation function applied in the hidden layers, such as "mish". Default is "mish". kernel_initializer : str, optional @@ -76,17 +67,6 @@ def __init__( super().__init__(**keras_kwargs(kwargs)) - if widths is not None: - if depth is not None or width is not None: - raise ValueError("Either specify 'widths' or 'depth' and 'width', not both.") - else: - if depth is None or width is None: - # use the default - depth = 2 - width = 256 - - widths = [width] * depth - self.res_blocks = [] for width in widths: self.res_blocks.append( From 411532a153e0d78bde1a20dfcf1a831c1cfe66a5 Mon Sep 17 00:00:00 2001 From: LarsKue Date: Tue, 8 Apr 2025 11:55:13 -0400 Subject: [PATCH 2/5] fix missing default --- bayesflow/networks/mlp/mlp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bayesflow/networks/mlp/mlp.py b/bayesflow/networks/mlp/mlp.py index ea3459a3f..d35d35c4d 100644 --- a/bayesflow/networks/mlp/mlp.py +++ b/bayesflow/networks/mlp/mlp.py @@ -20,7 +20,7 @@ class MLP(keras.Layer): def __init__( self, - widths: Sequence[int], + widths: Sequence[int] = (256, 256), *, activation: str = "mish", kernel_initializer: str = "he_normal", From f0217c02e445d4673be948e52ec909c9f7689563 Mon Sep 17 00:00:00 2001 From: LarsKue Date: Tue, 8 Apr 2025 11:56:55 -0400 Subject: [PATCH 3/5] fix remaining usage of depth and width for MLP --- bayesflow/experimental/cif/conditional_gaussian.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bayesflow/experimental/cif/conditional_gaussian.py b/bayesflow/experimental/cif/conditional_gaussian.py index 435fc7f77..c553dda91 100644 --- a/bayesflow/experimental/cif/conditional_gaussian.py +++ b/bayesflow/experimental/cif/conditional_gaussian.py @@ -1,3 +1,4 @@ +from collections.abc import Sequence import keras from keras.saving import register_keras_serializable import numpy as np @@ -33,8 +34,8 @@ def __init__(self, depth: int = 4, width: int = 128, activation: str = "swish", """ super().__init__(**keras_kwargs(kwargs)) - self.means = MLP(depth=depth, width=width, activation=activation) - self.stds = MLP(depth=depth, width=width, activation=activation) + self.means = MLP([width] * depth, activation=activation) + self.stds = MLP([width] * depth, activation=activation) self.output_projector = keras.layers.Dense(None) def build(self, input_shape: Shape) -> None: From f0065e46809c839ca34a4125851adac8b42df71e Mon Sep 17 00:00:00 2001 From: LarsKue Date: Tue, 8 Apr 2025 11:59:47 -0400 Subject: [PATCH 4/5] run linter --- bayesflow/experimental/cif/conditional_gaussian.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bayesflow/experimental/cif/conditional_gaussian.py b/bayesflow/experimental/cif/conditional_gaussian.py index c553dda91..4e55dcdf4 100644 --- a/bayesflow/experimental/cif/conditional_gaussian.py +++ b/bayesflow/experimental/cif/conditional_gaussian.py @@ -1,4 +1,3 @@ -from collections.abc import Sequence import keras from keras.saving import register_keras_serializable import numpy as np From fbd9a8ba1e0bcf73831b5b5a1b8419d05c20e34b Mon Sep 17 00:00:00 2001 From: LarsKue Date: Tue, 8 Apr 2025 12:13:16 -0400 Subject: [PATCH 5/5] fix flow matching fixture --- tests/test_networks/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_networks/conftest.py b/tests/test_networks/conftest.py index 48cd79ed2..5d646d9ee 100644 --- a/tests/test_networks/conftest.py +++ b/tests/test_networks/conftest.py @@ -22,7 +22,7 @@ def flow_matching(): from bayesflow.networks import FlowMatching return FlowMatching( - subnet_kwargs={"widths": None, "width": 64, "depth": 2}, + subnet_kwargs={"widths": [64, 64]}, integrate_kwargs={"method": "rk45", "steps": 100}, )