How to use the "until" function required for conditional ending of scan in PyTensor

Hello All,

I am trying to use the conditional ending of the scan function in PyTensor as mentioned in the pytensor docs. The code I am running (below) is exactly same as mentioned in the PyTensor docs. But I am getting the error “‘function’ object has no attribute ‘utils’”. Please suggest how may I fix the error.


import pytensor
import pytensor.tensor as at

def power_of_2(previous_power, max_value):
return previous_power * 2, pytensor.scan.utils.until(previous_power * 2 > max_value)

max_value = at.scalar()
values, _ = pytensor.scan(power_of_2,
outputs_info = at.constant(1.),
non_sequences = max_value,
n_steps = 1024)

f = pytensor.function([max_value], values)


The error I get is

Python version - 3.10.9
Pytensor version - 2.8.11

Thanks for all the help!

There’s a difference between scan the function (which you get by default after import pytensor) and scan the submodule (which you don’t get), so you have to expressly import the the until function with: from pytensor.scan.utils import until

1 Like