GithubHelp home page GithubHelp logo

giggleliu / backwardslinalg.jl Goto Github PK

View Code? Open in Web Editor NEW
29.0 5.0 2.0 685 KB

Auto differentiation over linear algebras (a Zygote extension)

License: Other

Julia 100.00%
machine-learning linear-algebra autodiff flux

backwardslinalg.jl's Introduction

Hi there ๐Ÿ‘‹

github contribution grid snake animation

GiggleLiu's GitHub stats Top Langs

backwardslinalg.jl's People

Contributors

giggleliu avatar hamletwanttocode avatar juliatagbot avatar roger-luo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

backwardslinalg.jl's Issues

Working with QR gradients

Hi @GiggleLiu,

I was wondering about this use case

using Zygote
using BackwardsLinalg
gradient(x -> sum(qr(x).Q), rand(3,3)) 

but this gives an error

julia> gradient(x -> qr(x).Q |> sum, rand(3,3))
ERROR: MethodError: no method matching getindex(::Tuple{Array{Float64,2},Array{Float64,2}}, ::Symbol)
Closest candidates are:
  getindex(::Tuple, ::Int64) at tuple.jl:24
  getindex(::Tuple, ::Real) at tuple.jl:25
  getindex(::Tuple, ::AbstractUnitRange{#s66} where #s66<:Real) at range.jl:288
  ...
Stacktrace:
 [1] adjoint at /home/meach/.julia/packages/Zygote/fuj2C/src/lib/lib.jl:81 [inlined]
 [2] _forward at /home/meach/.julia/packages/Zygote/fuj2C/src/lib/grad.jl:44 [inlined]
 [3] _forward(::Zygote.Context, ::typeof(Zygote.literal_getproperty), ::Tuple{Array{Float64,2},Array{Float64,2}}, ::Val{:Q}) at /home/meach/.julia/packages/Zygote/fuj2C/src/lib/lib.jl:174
 [4] #19 at ./REPL[14]:1 [inlined]
 [5] _forward(::Zygote.Context, ::getfield(Main, Symbol("##19#20")), ::Array{Float64,2}) at /home/meach/.julia/packages/Zygote/fuj2C/src/compiler/interface2.jl:0
 [6] _forward(::Function, ::Array{Float64,2}) at /home/meach/.julia/packages/Zygote/fuj2C/src/compiler/interface.jl:31
 [7] forward(::Function, ::Array{Float64,2}) at /home/meach/.julia/packages/Zygote/fuj2C/src/compiler/interface.jl:37
 [8] gradient(::Function, ::Array{Float64,2}) at /home/meach/.julia/packages/Zygote/fuj2C/src/compiler/interface.jl:46
 [9] top-level scope at REPL[14]:1

Is there any way to fix this?

QR with pivoting?

Does this support qr! with pivoting for complex, non-square matricies?

using BackwardsLinalg
f(x) = qr!(x, val(true)).Q
A = rand(4,8) .+ 1.5*im
f'(A)

Merge into ChainRules?

It's great to see someone taking AD + linear algebra seriously. @GiggleLiu would you be open to merging this stuff into ChainRules at some point in the not too distant future? It would be a great help!

References

lapack exception (2) backward qr diff

While random matrices work, I get lapack exceptions in trtrs when using it in my application.
fpeps.zip

`using Zygote,BackwardsLinalg,fpeps

width = 4;height = 4;
D = 2;d = 2;chi = 5;

peps = Array{Array{ComplexF64,5},2}(undef,width,height);
for i = 1:width
for j = 1:height
peps[i,j] = rand(ComplexF64,D,D,D,D,d);
end
end

boundaries = fpeps.gen_boundaries(peps,chi);
n1 = boundaries[1][1]; n2 = boundaries[1][2];

fun(a) = real(sum(sum.(fpeps.north_vomps(n1,peps[1,:],a))))
fun'(n2)`

Is there anything I should know about numerical stability problems (assuming the lapack error means that trtrs didn't converge). How can I go about debugging this further? The matrix passed to trtrs did became spectacularly quite ill-conditioned in my example... I can try to reduce this further to a smaller minimal example?

If I set the parameters to make sure that we are effectively working with 1x1 matrices then I get errors later on with zygote (I'm assuming it's unrelated to this package but I'm not sure as the stacktrace effectively says nothing).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.