JuliaDiff / JuliaDiff/ForwardDiff.jl

use `HessianConfig` to calculate gradients?

Open
#734 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

Hello,

Recently i came across with a problem in which already had a hessian cache, (HessianConfig + DiffResults.HessianResult), but it seems there aren't any methods for calculating for using HessianConfig (and HessianResult) when calculating gradients (of the same function with the same number and type of arguments).

I did this dirty hack to allow calculating gradients with HessianConfig + HessianResult:

hresult,hconfig = cache    
h_jconfig = hconfig.jacobian_config
seeds = h_jconfig.seeds
duals = h_jconfig.duals[1]
gconfig = ForwardDiff.GradientConfig{Nothing,eltype(aux),length(seeds),typeof(duals)}(seeds,duals)
gresult = ForwardDiff.MutableDiffResult(result.value,(result.derivs[1],))

It works for me, but it could be generalized (by passing the adequate function argument, for example)

It would be much easier to just do ForwardDiff.gradient!(hresult,f,x,hconfig) instead.

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

Start by tracing the existing HessianConfig, DiffResults.HessianResult, GradientConfig, and gradient! entry points to understand how cached Jacobian configuration is used. Compare the proposed HessianConfig-to-gradient path with the existing gradient result handling, then verify that gradient!(hresult, f, x, hconfig) produces the same gradients while reusing the cache.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.