Skip to content

Commit 3fb1724

Browse files
committed
add optimizer build to compile_from_config
1 parent bb068d2 commit 3fb1724

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

bayesflow/approximators/continuous_approximator.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@ def compile(
105105
return super().compile(*args, **kwargs)
106106

107107
def compile_from_config(self, config):
108-
return self.compile(**deserialize(config))
108+
self.compile(**deserialize(config))
109+
if hasattr(self, "optimizer") and self.built:
110+
# Create optimizer variables.
111+
self.optimizer.build(self.trainable_variables)
109112

110113
def compute_metrics(
111114
self,

bayesflow/approximators/model_comparison_approximator.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ def compile(
119119
return super().compile(*args, **kwargs)
120120

121121
def compile_from_config(self, config):
122-
return self.compile(**deserialize(config))
122+
self.compile(**deserialize(config))
123+
if hasattr(self, "optimizer") and self.built:
124+
# Create optimizer variables.
125+
self.optimizer.build(self.trainable_variables)
123126

124127
def compute_metrics(
125128
self,

0 commit comments

Comments
 (0)