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

DiffResults objects are not re-aliased properly #696

Open
gdalle opened this issue Mar 15, 2024 · 2 comments
Open

DiffResults objects are not re-aliased properly #696

gdalle opened this issue Mar 15, 2024 · 2 comments
Labels

Comments

@gdalle
Copy link
Member

gdalle commented Mar 15, 2024

The DiffResults documentation clearly states that whenever a DiffResult object is used, it must be realiased at the end of the function call:

result = do_stuff!(result, args...)

See for instance the docstrings in https://juliadiff.org/DiffResults.jl/stable/#Mutating-a-DiffResult, or the issue DiffResults#17

This is not done by ForwardDiff, for instance here:

function gradient!(result::Union{AbstractArray,DiffResult}, f::F, x::AbstractArray, cfg::GradientConfig{T} = GradientConfig(f, x), ::Val{CHK}=Val{true}()) where {T, CHK, F}
result isa DiffResult ? require_one_based_indexing(x) : require_one_based_indexing(result, x)
CHK && checktag(T, f, x)
if chunksize(cfg) == length(x)
vector_mode_gradient!(result, f, x, cfg)
else
chunk_mode_gradient!(result, f, x, cfg)
end
return result
end

Am I right in deducing that it can lead to incorrectness?

@gdalle gdalle changed the title DiffResults objects are not realiased properly DiffResults objects are not re-aliased properly Mar 15, 2024
@gdalle
Copy link
Member Author

gdalle commented Mar 15, 2024

See also JuliaDiff/ReverseDiff.jl#251

@gdalle
Copy link
Member Author

gdalle commented Mar 15, 2024

I can't manage to get an actual bug out of this, presumably because the StaticArrays extension of ForwardDiff overloads the vulnerable parts I've tried. But for ReverseDiff this does lead to wrong behavior

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

No branches or pull requests

1 participant