Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to pass config to call back into AD #222

Closed
rcalxrc08 opened this issue Oct 6, 2023 · 1 comment · Fixed by #239
Closed

Unable to pass config to call back into AD #222

rcalxrc08 opened this issue Oct 6, 2023 · 1 comment · Fixed by #239
Labels

Comments

@rcalxrc08
Copy link

I have the following:

function my_func(x)
	return sin(x)
end
using ChainRulesCore
using AbstractDifferentiation: derivative, jacobian
using Diffractor: DiffractorForwardBackend, DiffractorRuleConfig
function ChainRulesCore.frule(config::RuleConfig{>:HasForwardsMode}, (_, dx), ::typeof(my_func), x)
    res=my_func(x)
    _, der_fwd = ChainRulesCore.frule_via_ad(config, (ChainRulesCore.NoTangent(), dx), sin, x)
    @show "hello from fd with right config with calling back"
    return res, der_fwd
end

function my_func2(x)
	return sin(x)
end

function ChainRulesCore.frule((_, dx), ::typeof(my_func2), x)
    res=my_func2(x)
    _, der_fwd = ChainRulesCore.frule_via_ad(DiffractorRuleConfig(), (ChainRulesCore.NoTangent(), dx), sin, x)
    @show "hello from fd with wrong config with calling back"
    return res, der_fwd
end

derivative(DiffractorForwardBackend(), my_func, 1.0)
derivative(DiffractorForwardBackend(), my_func2, 1.0)

and I get the output just for the second call, in the first case the frule has something wrong. Is it supported this way of defining the rules for Diffractor.jl? Am I doing anything wrong?

@oxinabox
Copy link
Member

You are not, you are doing everything correct.
Its just that right now diffractor forward mode isn't using its config.
I am not sure why it was commented out.
See here: https://github.com/JuliaDiff/Diffractor.jl/blob/b3e4ee058ef0ae59bc5c7623ed6770b52b6324f2/src/stage1/forward.jl#L110C17-L110C37
Could be we can just uncomment it out and add a test and be good to go.
It might have just been commented out while investigating something and forgotten to undone.
Or it might be something more annoying like inference issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants