Skip to content

Instantly share code, notes, and snippets.

How Scan.L_op Works

Summary

Scan.L_op computes the gradient of a Scan operation by constructing a new backward Scan that runs in reverse, propagating gradients through time. The method:

  1. Differentiates the inner function symbolically to get per-step gradients
  2. Adds accumulation terms for recurrent states
  3. Constructs a new backward Scan with reversed sequences and mit-mot states (initialized with output gradients, accumulate total gradients after evaluation)
  4. Re-orders the backward Scan's outputs to match the expected gradient layout

pytensor-suite-feedstock

This is a conda-forge feedstock for PyTensor. The recipe produces two packages: pytensor-base (core, lightweight) and pytensor (adds compiler + BLAS deps).

Reviewing bot version-bump PRs

When the autotick bot opens a version-bump PR, verify that PyPI dependency changes are reflected in the recipe before merging.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from functools import wraps
import numpy as np
import pytensor.tensor as pt
from pytensor import function
from pytensor.tensor import tensor
from pytensor.compile.function.types import Function
import numpy as np
import pymc as pm
import pytensor.tensor as pt
import pytensor.xtensor as px
N = 100
seed = sum(map(ord, "xarray>=numpy?"))
rng = np.random.default_rng(seed)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.