Skip to content

Support AD on CUDA #376

Open
Open

Description

@Ryo-wtnb11

Hi developers.

I have recently noticed that the new version of TensorKit supports running on CUDA, and I got a massive speed up when I tried. It's wonderful!
However, when combining GPU-backed TensorMaps with AD (Zygote), the backward pass fails because several pullback functions assume CPU arrays due to scalar indexing.

using TensorKit
using Zygote
using CUDA
using cuTENSOR
using Adapt


V = Rep[U₁](1//2 => 2, -1//2 => 2)
A = randn(ComplexF64, V ← V)
A_gpu = adapt(CuArray, A)

# Forward works
D, U = eigh_trunc((A_gpu + A_gpu') / 2; trunc = truncrank(2))

@show D

# Backward fails
Zygote.gradient(A_gpu) do a
    D, U = eigh_trunc((a + a') / 2; trunc = truncrank(2))
    return real(tr(D))
end

And the essentially same issue occurs in many of functions for tensor manipulation, such as flip() and twist().
Maybe the scalar indexing is the best way to go on CPU with help of Strided.jl, so we may need to implement special pullbacks for CUDA extensions? It'd be annoying...

Activity

  1. lkdvos commented on Feb 18, 2026

    @lkdvos
    Member

    Hi Ryo, as you have noticed this is definitely something that is under active development right now. We are working on combining many of these new and upcoming features (shout-out to @kshyatt for a lot of this amazing work!), but unfortunately we are not entirely there yet, which is exactly why this has not been widely advertised just about yet.

    However, do feel free to keep reporting the missing parts, it is very helpful to have a list of things that we need to verify, as the problem space is quite large

  2. Ryo-wtnb11 commented on Feb 19, 2026

    @Ryo-wtnb11
    Author

    Cool. I'm really looking forward to see working.
    Yes, I know you all are enthusiastic on development AD functions especially in moving forward to Mooncake.jl at the moment.
    I wonder what's actual advantage of Mooncake.jl ? I looked into this library, but I can only understand it's good to support primitive manipulations more than Zygote. More crucially, it looks having issues on CUDA support so far!

  3. kshyatt commented on Feb 19, 2026

    @kshyatt
    Member

    We are also planning to add support for Enzyme (which has more robust CUDA support) and the Mooncake CUDA effort is also ongoing :)

  4. wsmoses commented on Feb 20, 2026

    @wsmoses

    I'd also recommend here trying to use Reactant for high performance GPU usage (with or without AD). At least for ML, climate science, and astrophysics applications the speedup has been quite dramatic

  5. lkdvos commented on Feb 20, 2026

    @lkdvos
    Member

    I did see the JuliaCon talk, and while it looks amazing I was not entirely sure if it would apply to the typical workflows we have, which are usually dominated by calls to either BLAS gemm or LAPACK SVD. Do you know if we should be expecting differences there too? (Also note that we has our own LAPACK wrappers, so I'm not sure if that's relevant ?)

  6. wsmoses commented on Feb 22, 2026

    @wsmoses

    I would actually expect more of an impact on code with multiple calls to linear algebra libraries [as we can potentially optimize usage thereof]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions