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

Remove frule for getindex(::Tuple, i) #680

Merged
merged 3 commits into from
Jul 4, 2023
Merged

Conversation

Keno
Copy link
Contributor

@Keno Keno commented Oct 12, 2022

Having this chain rule is sub-optimal, because it prevents early-SROA in Diffractor-like systems that would like to perform some optimizations before applying AD (but can't do any optimization on functions that have custom rules). By letting it go down to the getfield, regular SROA can apply. Any AD system should handle getfield anyway, so I don't think there's a strong reason to have this.

Similar reasoning applies to the reverse rules also, but they aren't currently actively causing me problems, so this PR only removes the frule, since I don't think many other packages are using them. We can revisit the rrules later.

@github-actions github-actions bot added the needs version bump Version needs to be incremented or set to -DEV in Project.toml label Oct 12, 2022
@Keno
Copy link
Contributor Author

Keno commented Oct 12, 2022

Probably makes sense to actually add an frule for getfield in the same breath.

Copy link
Member

@mcabbott mcabbott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will take your word for it, but right now this branch leads to the following failure:

julia> Diffractor.PrimeDerivativeFwd(x -> (x,2x,3x)[2])(1.0)
2.0

julia> Diffractor.PrimeDerivativeFwd(x -> sum((x,2x,3x)[1:2]))(1.0)
ERROR: type CompositeBundle has no field partials
Stacktrace:
  [1] getproperty
    @ ./Base.jl:37 [inlined]
  [2] (::Diffractor.∂☆{1})(f::Diffractor.UniformBundle{1, typeof(getfield), ZeroTangent}, x::Diffractor.CompositeBundle{1, Tuple{Float64, Float64, Float64}, Tuple{Diffractor.TangentBundle{1, Float64, Tuple{Float64}}, Diffractor.TangentBundle{1, Float64, Tuple{Float64}}, Diffractor.TangentBundle{1, Float64, Tuple{Float64}}}}, s::Diffractor.TangentBundle{1, Int64, Tuple{NoTangent}}, inbounds::Diffractor.UniformBundle{1, Bool, ZeroTangent})
    @ Diffractor ~/.julia/dev/Diffractor/src/stage1/forward.jl:165

@Keno
Copy link
Contributor Author

Keno commented Oct 12, 2022

I need to update Diffractor. We can hold this branch until I can push that.

@oxinabox
Copy link
Member

Can we rebase and merge this?

@Keno Keno force-pushed the kf/nofruletupgetindex branch from 8507e03 to d169a50 Compare May 27, 2023 00:07
@Keno Keno requested a review from oxinabox May 27, 2023 00:07
@Keno
Copy link
Contributor Author

Keno commented May 27, 2023

Rebased and also gave the same treatment to first,tail, which @staticfloat ran into having the same issue.

@oxinabox
Copy link
Member

oxinabox commented Jun 1, 2023

CI is failing,
not just because we haven't merged #718
even the 1.6 CI is failing.
This is because the tests haven't been deleted.
this PR should also delete the matching tests.

Probably makes sense to actually add an frule for getfield in the same breath.

This hasn't been done yet?

Keno added 2 commits June 30, 2023 20:19
Having this chain rule is sub-optimal, because it prevents early-SROA
in Diffractor-like systems that would like to perform some optimizations
before applying AD (but can't do any optimization on functions that
have custom rules). By letting it go down to the `getfield`, regular
SROA can apply. Any AD system should handle `getfield` anyway, so
I don't think there's a strong reason to have this.

Similar reasoning applies to the reverse rules also, but they
aren't currently actively causing me problems, so this PR only
removes the frule, since I don't think many other packages are
using them. We can revisit the rrules later.
For similar reasons as getindex, having a rule for first/tail is
suboptimal because it supresses early SROA. Tail is particularly
problematic, because it is used in the implementation of the
```
x, y... = abc
```
syntax, of which users expect early elimination.
@oscardssmith oscardssmith self-assigned this Jun 30, 2023
@Keno Keno force-pushed the kf/nofruletupgetindex branch from d169a50 to f5cab7d Compare June 30, 2023 21:48
@oscardssmith
Copy link
Member

I've deleted the unnecessary tests and added the getfield frule. Let's see if this works.

@oxinabox
Copy link
Member

oxinabox commented Jul 4, 2023

All CI failures were preexisting
This can be merged now

@oxinabox oxinabox merged commit 05ebb38 into main Jul 4, 2023
@oxinabox oxinabox deleted the kf/nofruletupgetindex branch July 4, 2023 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs version bump Version needs to be incremented or set to -DEV in Project.toml
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants