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

Make @non_differentiable not use ::Tuple #653

Closed
wants to merge 3 commits into from

Conversation

MasonProtter
Copy link
Contributor

@MasonProtter MasonProtter commented Jan 15, 2024

@oxinabox
Copy link
Member

Why does duplicating prevent ambiguities?

@MasonProtter
Copy link
Contributor Author

MasonProtter commented Jan 16, 2024

so first I tried without the duplication, and just putting in a ::Tuple for @scalar_rule but that was actually worse than than before, so I tried the duplication but that was also bad. I'm going to try now to remove the ::Tuple from @non_differentiable

Copy link

codecov bot commented Jan 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (77748b3) 93.79% compared to head (52c8bc6) 93.79%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #653   +/-   ##
=======================================
  Coverage   93.79%   93.79%           
=======================================
  Files          14       14           
  Lines         886      886           
=======================================
  Hits          831      831           
  Misses         55       55           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MasonProtter MasonProtter changed the title Make @scalar_rule use ::Tuple Make @non_differentiable not use ::Tuple Jan 16, 2024
@oxinabox
Copy link
Member

We needed that for #651

@MasonProtter
Copy link
Contributor Author

Ah I see, I guess that's what created this ambiguity problem in the first place. :(

@MasonProtter
Copy link
Contributor Author

I would have naively thought though that it'd be better to have @non_differentiable be lower-precendence than other methods, so that it's easier to override. If you have a differentiable method, you wouldn't want that to tie with the non-differentiable method

@oxinabox
Copy link
Member

I would have naively thought though that it'd be better to have @non_differentiable be lower-precendence than other methods, so that it's easier to override.

Yes, unfortunately julia does not have a way of saying "This method always loses ambiguity fights"
(I guess because then you would just have a later ambiguity fight if two methods had it)

@MasonProtter
Copy link
Contributor Author

MasonProtter commented Jan 16, 2024

Having the ::Tuple restriction on @non_differentiable makes it more specific though. Are we sure that #651 was the right way to solve those ambiguities?

Or maybe we should just solve this by dealing with the rules for zero and one differently.

We currently do

@non_differentiable one(::Any)
@non_differentiable zero(::Any)

and

@scalar_rule one(x) ZeroTangent()
@scalar_rule zero(x) ZeroTangent()

Maybe we should just be manually writing the rules for these functions to instead do

if x <: Number
    ZeroTangent()
else
    NoTangent()
end

?

@oxinabox
Copy link
Member

Are we sure that #651 was the right way to solve those ambiguities?

We are not.

I think maybe we should just delete:

@non_differentiable one(::Any)
@non_differentiable zero(::Any)

@oxinabox
Copy link
Member

oxinabox commented Jan 23, 2024

closing in favor of JuliaDiff/ChainRules.jl#770

@oxinabox oxinabox closed this Jan 23, 2024
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

Successfully merging this pull request may close these issues.

frules for one are ambiguous
2 participants