Skip to content

Differentiable generic functions and type constraints #5749

Answered by saipraveenb25
MangoSister asked this question in Q&A
Discussion options

You must be logged in to vote

Thank you for opening a discussion on this! I understand that having gradients disappear silently can be very annoying to track down. We do have a gradient data-flow analysis pass to warn about these cases (i.e. requires the 'no_diff' modifier when calling a non-differentiable function with differentiable inputs). It looks like this case doesn't get detected because the function is marked [Differentiable]

This is a slightly tricky situation. You are correct in that its confusing that

[Differentiable]
T sqr<T>(T x)
    where T : __BuiltinArithmeticType { return x * x; }

is allowed but silently returns a 0 since __BuiltinArithmeticType is non-differentiable.

One fix is to warn users if the…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@saipraveenb25
Comment options

@MangoSister
Comment options

Answer selected by MangoSister
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants