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

Suppress Warning from ForwardDiff Duals #74

Open
avik-pal opened this issue May 8, 2024 · 1 comment
Open

Suppress Warning from ForwardDiff Duals #74

avik-pal opened this issue May 8, 2024 · 1 comment

Comments

@avik-pal
Copy link

avik-pal commented May 8, 2024

Turns out ForwardDiff.jl already works with DynamicExpressions, but we would want to turn off the type mismatch warnings.

using ForwardDiff, DynamicExpressions

operators = OperatorEnum(; binary_operators=[+, -, *], unary_operators=[cos]);
x1 = Node(; feature=1)
x2 = Node(; feature=2)
expr = x1 * cos(x2 - 3.2)

X = rand(2, 5)

ForwardDiff.gradient(X) do X
    return sum(abs2, first(eval_tree_array(expr, X, operators)))
end
┌ Warning: Warning: eval_tree_array received mixed types: tree=Float32 and data=ForwardDiff.Dual{ForwardDiff.Tag{var"#13#14", Float64}, Float64, 10}.
└ @ DynamicExpressions.EvaluateModule /mnt/research/lux/DynamicExpressions.jl/src/Evaluate.jl:95
2×5 Matrix{Float64}:
  0.182636   0.882172   0.906966    0.161635    1.86929
 -0.020271  -0.363872  -0.0764073  -0.0126587  -0.331082
@MilesCranmer
Copy link
Member

MilesCranmer commented May 9, 2024

Awesome!

The warning indicates it is attempting to promote the value type of X as well as the AbstractExpressionNode. Converting the node can be exensive, especially if it’s a GraphNode, as it needs to make a copy of the whole tree.

I wonder if that means it’s also converting the Node{T} to Node{Dual{T}} and if that’s an issue at all. But if not an issue we could just disable the warning.

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

No branches or pull requests

2 participants