julia> using Zygote
julia> using TensorOperations
julia> function f(x)
@tensor b[i,k] := x[i,j]*x[j,k]
sum(b)
end
f (generic function with 1 method)
julia> a=rand(10,10);
julia> gradient(f,a)
ERROR: Can't differentiate gc_preserve_end expression $(Expr(:gc_preserve_end, %77)).
You might want to check the Zygote limitations documentation.
https://fluxml.ai/Zygote.jl/latest/limitations
This isn’t built-in, but the gradients are again tensor expressions which are fairly simple to derive. One version is wrapped up as TensorRules.jl (maybe the story starts here…).