From cb8d51e150b74c5b55c052a5dfc21341f3757854 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 94756e6c061..a430f9c963c 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