Wrapping a graph in OpFromGraph breaks its gradient when it has an integer output
Los mantenedores suelen responder en 1 día
@atishay-kasliwal ya está trabajando en esto.
Desde el 24/11/2026.
- #2718 de @atishay-kasliwal — abierto
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 22/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- python
- Área
- machine-learning
Línea de trabajo
Start in pytensor/compile/builders.py at _build_and_cache_lop_op, where the cotangent placeholder is created from the output variable's own type — here an integer scalar — and the inner pytensor.grad call then rejects it. Reproduce with the snippet in the issue, then compare against the unwrapped graph to see how a float known_grad reaches the same inner grad. Read the linked discussion #2065 for the Scan case that sends zeros for an integer carry. Note an open pull request (#2718) already targets this, so check its state before starting; done means the wrapped graph differentiates and the float cotangent is handled for the integer output.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
pytensor.grad raises on an OpFromGraph with an integer output when that output receives a float cotangent, though the same graph without the wrapper differentiates. _build_and_cache_lop_op builds the placeholder for that cotangent with the output's integer type, and the inner grad call rejects it. Scan hits this whenever its step is an OpFromGraph with an integer carry, because it sends zeros for that carry, as discussed in #2065.
import pytensor
import pytensor.tensor as pt
from pytensor.compile.builders import OpFromGraph
x = pt.dvector("x")
k0 = pt.lscalar("k0")
known_grads = lambda c, k: {c: pt.ones_like(c), k: pt.zeros((), dtype="float64")}
c, k = x * 2, k0 + 1
pytensor.grad(None, x, known_grads=known_grads(c, k)) # works
ix, ik = x.type(), pt.lscalar()
c, k = OpFromGraph([ix, ik], [ix * 2, ik + 1])(x, k0)
pytensor.grad(None, x, known_grads=known_grads(c, k))
# TypeError: Gradients must always be NullType, DisconnectedType, or continuous,
# but grad was given a known_grad of type Scalar(int64, shape=())
- Lenguaje dominante
- Python
- Estrellas
- 655
- Forks
- 266
- Merge medio
- 3 d 23 h
- PR fusionados (30 d)
- 43
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de pymc-devs/pytensor
-
BUG: cumsum and cumprod keep bool and small integer dtypes, so cumsum(x > 0) is wrongPosiblemente ocupada @rishabhsai la tomó hace 1 día. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
Docs of mode still mentions C/CVM as the default with FAST_RUNPosiblemente ocupada @ADITYASINGH1206 la tomó hace 13 días. Abiertodocs
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
pymc-devs/pytensor#2641 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Update conditions page in docsPosiblemente ocupada @caxaxa la tomó hace 3 días. Abiertodocs
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Los mantenedores suelen responder en 1 día
-
BUG: geomspace returns wrong sign for the endpoints when start and stop are negativePosiblemente ocupada @mayuriphad la tomó hace 32 días. Abierto
Dificultad 2/5 Menos de una hora Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
Reciprocal.impl computes np.float32(1.0) / x: float32 precision for float64 scalars under NEP 50 (Python linker)Quizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
pymc-devs/pytensor#2430 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de pymc-devs/pytensor
Issues similares
-
triage
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100
kornia/kornia-rs#1416 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
ui
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
PolicyEngine/ai-inequality#64 ·
Los mantenedores suelen responder en 1 día
-
LinearGaussianStateSpace.dist splits states and observations wrongly when the transition varies over timePosiblemente ocupada @PabloRoque la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
pymc-devs/pymc-extras#839 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día