From d75207057ade1914c4fdc15f54dbcf298c246c61 Mon Sep 17 00:00:00 2001 From: Ricardo Vieira Date: Sat, 23 Nov 2024 23:55:23 +0100 Subject: [PATCH] Disable GC on logp_dlogp function Related to https://github.com/pymc-devs/pymc/issues/7539 --- pymc/model/core.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pymc/model/core.py b/pymc/model/core.py index f3a0658cc36..e3c14e642da 100644 --- a/pymc/model/core.py +++ b/pymc/model/core.py @@ -32,7 +32,7 @@ import pytensor.tensor as pt import scipy.sparse as sps -from pytensor.compile import DeepCopyOp, Function, get_mode +from pytensor.compile import DeepCopyOp, Function, Mode, get_mode from pytensor.compile.sharedvalue import SharedVariable from pytensor.graph.basic import Constant, Variable, graph_inputs from pytensor.tensor.random.op import RandomVariable @@ -253,6 +253,14 @@ def __init__( ) inputs = grad_vars + # If default C-backend mode, create function without gc + if ( + "mode" not in kwargs + and pytensor.config.mode == "Mode" + and pytensor.config.linker == "cvm" + and pytensor.config.optimizer == "o4" + ): + kwargs["mode"] = Mode(linker="cvm_nogc", optimizer="o4") self._pytensor_function = compile_pymc(inputs, outputs, givens=givens, **kwargs) self._raveled_inputs = ravel_inputs