pullback drops cotangents when f repeats a variable or contains wrt, breaking pushforward

Abierto
#2,700 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
python
Área
backend

Línea de trabajo

The bug is in pullback in pytensor/gradient.py, which keeps one cotangent per repeated variable and lets output cotangents override gradients from other outputs; pushforward in the same module depends on it. Start by running the reproduction snippets in the issue and checking which inputs explicit_graph_inputs returns. Done means all three pushforward cases return both tangents and the pullback cases return every cotangent, without breaking existing gradient tests.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug gradients

pytensor.gradient.pushforward drops tangents through Add and Sub, so the directional derivative of a + b depends on only one of the two tangents. The cause is pullback, which keeps only one cotangent per variable when f repeats a variable. It also lets the cotangent of a variable in f override the gradient reaching it through the other outputs. The default pushforward pulls back through a first pullback whose outputs for Add are the output cotangent itself, so it hits both cases.

import pytensor.tensor as pt
from pytensor.gradient import pullback, pushforward
from pytensor.graph.traversal import explicit_graph_inputs

x = pt.dscalar("x")
y_bar_1 = pt.dscalar("y_bar_1")
y_bar_2 = pt.dscalar("y_bar_2")
y = x**2

list(explicit_graph_inputs(pullback([y, y], x, [y_bar_1, y_bar_2])))      # [x, y_bar_2], expected [x, y_bar_1, y_bar_2]
list(explicit_graph_inputs(pullback([x, 2 * x], x, [y_bar_1, y_bar_2])))  # [y_bar_1], expected [y_bar_1, y_bar_2]

a = pt.dscalar("a")
b = pt.dscalar("b")
a_dot = pt.dscalar("a_dot")
b_dot = pt.dscalar("b_dot")

list(explicit_graph_inputs(pushforward(a + b, [a, b], [a_dot, b_dot])))      # [b_dot], expected [a_dot, b_dot]
list(explicit_graph_inputs(pushforward(a - b, [a, b], [a_dot, b_dot])))      # [a_dot], expected [a_dot, b_dot]
list(explicit_graph_inputs(pushforward(a + 2 * b, [a, b], [a_dot, b_dot])))  # [a_dot], expected [a_dot, b_dot]

This came up while computing sparse Jacobians from colored pushforwards for #2578.

Lenguaje dominante
Python
Estrellas
654
Forks
258
Merge medio
3 d 41 min
PR fusionados (30 d)
42

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de pymc-devs/pytensor

Todos los issues de pymc-devs/pytensor

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.