JuliaDiff / JuliaDiff/ForwardDiff.jl

`gradient!` allocates for matrices but not for vectors

Open
#698 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
1k
Forks
160
PR merge metrics
No merged PRs in 30d

Description

Is it due to views?

julia> using ForwardDiff, Chairmarks

julia> g(x) = sum(abs2, x)
g (generic function with 1 method)

julia> @be (zeros(2), zeros(2), ForwardDiff.GradientConfig(g, zeros(2))) ForwardDiff.gradient!(_[1], g, _[2], _[3])
Benchmark: 3548 samples with 1255 evaluations
min    18.855 ns
median 19.215 ns
mean   19.753 ns
max    62.914 ns

julia> @be (zeros(2, 2), zeros(2, 2), ForwardDiff.GradientConfig(g, zeros(2, 2))) ForwardDiff.gradient!(_[1], g, _[2], _[3])
Benchmark: 2765 samples with 365 evaluations
min    67.745 ns (4 allocs: 160 bytes)
median 77.912 ns (4 allocs: 160 bytes)
mean   87.240 ns (4 allocs: 160 bytes)
max    220.408 ns (4 allocs: 160 bytes)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the vector and matrix benchmarks in the issue using ForwardDiff and Chairmarks. Start by tracing the gradient! call and comparing its behavior for vector and matrix inputs, especially whether views are involved. Done means identifying and addressing the matrix-only allocations, with the benchmark showing the resulting allocation behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
performance
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.