Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Incorrect Gradient Computation when Nesting Zygote over TaylorDiff Description

未关闭
#92 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
julia
领域
devtools

调研方向

首先使用报告中的 Julia、TaylorDiff 和 Zygote 版本运行最小示例,重点关注嵌套在 Zygote.gradient 中的 TaylorDiff.derivative。跟踪这些入口点之间的交互,并为该示例添加回归测试。当计算出的梯度不再全为零,并且与预期的非零结果一致时,即视为完成。

由索引模型根据 Issue 内容生成。

描述

Bug Report: Incorrect Gradient Computation when Nesting Zygote over TaylorDiff

Description

When attempting to compute the gradient of a function that internally uses TaylorDiff for differentiation, Zygote returns incorrect results (all zeros).

Minimal Working Example

The following mwe demonstrates the issue:

import TaylorDiff
import Zygote

# Define a function
f(x) = sum(x .^ 2)

# Define function to return unit vectors
unit_vectors(x, i) = [j == i ? one(eltype(x)) : zero(eltype(x)) for j in 1:length(x)]

# Define input
x = Float64.(collect(1:5))

# Compute unit vectors for each direction to compute the gradient
e_vectors = [unit_vectors(x, i) for i in 1:length(x)]

# Define a function to compute gradient using TaylorDiff
∇f_taylor(f, x) = TaylorDiff.derivative.(Ref(f), Ref(x), e_vectors, Ref(Val(1)))

# Evaluate gradient
∇f_taylor(f, x) # Returns 5-element Vector{Float64}: 2.0 4.0 6.0 8.0 10.0 (correct)

# Define a simple function of the gradient with TaylorDiff
g_taylor(x) = sum(∇f_taylor(f, x))

# Evaluate gradient
g_taylor(x) # returns 30.0 (Correct)

# Compute gradient using Zygote
Zygote.gradient(g_taylor, x) # returns ([0.0, 0.0, 0.0, 0.0, 0.0],) (incorrect)

The function g_taylor(x) computes the sum of the gradient of f(x), which should return a nonzero result. Applying Zygote.gradient to g_taylor(x) should correctly compute the derivative.

Instead of returning the correct gradient, Zygote.gradient(g_taylor, x) returns all zeros.

Additional Information

Julia Version: 1.11.3
TaylorDiff Version: v0.3.1
Zygote Version: v0.6.75

主要语言
Julia
星标
83
派生
12
PR 合并指标
30 天内没有已合并 PR

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

JuliaDiff/TaylorDiff.jl 的其他 Issue

查看 JuliaDiff/TaylorDiff.jl 的全部 Issue

相似的 Issue

更多 Julia Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。