Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect gradient type. #235

Closed
YichengDWu opened this issue Nov 25, 2023 · 2 comments
Closed

Incorrect gradient type. #235

YichengDWu opened this issue Nov 25, 2023 · 2 comments

Comments

@YichengDWu
Copy link
Contributor

YichengDWu commented Nov 25, 2023

In the following code, shouldn't grad be of the same type as x?

julia> using ComponentArrays, Zygote

julia> ps = ComponentArray(weight=rand(3,3))
ComponentVector{Float64}(weight = [0.8258011674811379 0.44981527211623784 0.5507199474580698; 0.28250960116858315 0.42697555461561054 0.22836834345488244; 0.9092739196971233 0.6566982028049392 0.14458718099508994])

julia> grad = Zygote.gradient(x->sum(x.weight), ps)[1]
ComponentVector{Float64, ComponentVector{Float64, Vector{Float64}, Tuple{Axis{(weight = ViewAxis(1:9, ShapedAxis((3, 3), NamedTuple())),)}}}, Tuple{Axis{(weight = ViewAxis(1:9, ShapedAxis((3, 3), NamedTuple())),)}}}(weight = [1.0 1.0 1.0; 1.0 1.0 1.0; 1.0 1.0 1.0])
@jonniedie
Copy link
Collaborator

Yeah, it should. That's weird. I might get a chance to look at it this weekend.

@avik-pal
Copy link
Member

julia> ps = ComponentArray(weight=rand(3,3))
ComponentVector{Float64}(weight = [0.3364916316745368 0.16747972646975107 0.961114830406715; 0.7662896569815121 0.21684158229208028 0.8580540237329293; 0.13361739374272052 0.6107957888988388 0.27262419344861877])

julia> grad = Zygote.gradient(x->sum(x.weight), ps)[1]
ComponentVector{Float64}(weight = [1.0 1.0 1.0; 1.0 1.0 1.0; 1.0 1.0 1.0])

This was fixed with the ProjectTo PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants