Giter VIP home page Giter VIP logo

Comments (1)

mcabbott avatar mcabbott commented on June 20, 2024 2

I can reproduce this, seems to be a bug. Thanks for the report! Slightly shorter version below:

julia> using Tullio, Zygote, CUDA, KernelAbstractions

julia> batchmul(A, B) = @tullio C[i,j,k] := A[i,k] * B[j,k];

julia> A = rand(Float32, 4, 2); B = rand(Float32, 4, 2);

julia> withgradient((a,b) -> sum(abs2, batchmul(a, b)), A, B)
(val = 5.032481f0, grad = (Float32[0.07354373 1.634892; 2.6971781 3.3456252; 1.6237329 3.0221555; 2.502201 1.6203384], Float32[0.99070925 2.647247; 1.6691209 0.9896178; 0.45123747 2.6089365; 1.6953326 2.0719757]))

julia> withgradient((a,b) -> sum(abs2, batchmul(a, b)), cu(A), cu(B))
(val = 5.0324807f0, grad = (Float32[0.010545072 0.6002646; 0.38673505 1.228375; 0.23281904 1.1096104; 0.35877827 0.59492123], Float32[0.00033122321 0.2761269; 0.00055803615 0.103224255; 0.00015086193 0.27213085; 0.0005667995 0.21612196]))

julia> bcmul(A, B) = reshape(A, size(A,1), 1, :) .* reshape(B, 1, size(B)...);

julia> bcmul(A, B)  batchmul(A, B)
true

julia> withgradient((a,b) -> sum(abs2, bcmul(a, b)), A, B)
(val = 5.032481f0, grad = (Float32[0.07354373 1.6348917; 2.6971781 3.3456252; 1.6237328 3.0221555; 2.502201 1.6203386], Float32[0.99070925 2.647247; 1.6691209 0.9896178; 0.45123744 2.6089365; 1.6953325 2.0719757]))

julia> withgradient((a,b) -> sum(abs2, bcmul(a, b)), cu(A), cu(B))
(val = 5.0324807f0, grad = (Float32[0.07354373 1.6348919; 2.6971781 3.345625; 1.6237328 3.0221558; 2.502201 1.6203384], Float32[0.9907092 2.647247; 1.6691209 0.9896178; 0.45123744 2.6089368; 1.6953325 2.0719757]))

If this is the function you actually need, then I stronly suggest that you write it as bcmul above, using Broadcasting not fancy packages.

from tullio.jl.

Related Issues (20)

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.