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

Dense instead of sparse matrix returned during differentiation #1537

Open
vboussange opened this issue Nov 3, 2024 · 1 comment
Open

Dense instead of sparse matrix returned during differentiation #1537

vboussange opened this issue Nov 3, 2024 · 1 comment
Labels
CUDA All things GPU

Comments

@vboussange
Copy link

vboussange commented Nov 3, 2024

Hi there,
I found an inconsistent behaviour when differentiating a function which takes in an AbstractCuSparseArray versus the same function differentiating an AbstractSparseArray

using CUDA
using Zygote
using SparseArrays

logpos(a) = a > 0 ? log(a) : zero(a)
l(A) = sum(logpos.(A))

A = sprandn(Float32, 10,10,0.4)

dA = gradient(l, A)[1] # returns a sparse array, as expected

Acu = sparse(CuArray(A))
dAcu = gradient(l, Acu)[1] # returns a dense CuArray

Maybe someone here has an idea of where could this come from?

@vboussange vboussange changed the title CuArray instead of SparseCuArray returned during differentiation Dense instead of sparse matrix returned during differentiation Nov 3, 2024
@ToucheSir
Copy link
Member

I suspect the issue is with missing rule(s) in ChainRules since Zygote has almost nothing in the way of machinery for diffing sparse arrays. What happens if you set CUDA.allowscalar(false) before running the MWE?

@ToucheSir ToucheSir added the CUDA All things GPU label Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CUDA All things GPU
Projects
None yet
Development

No branches or pull requests

2 participants