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

Add internal forward-mode rules for ranges #1655

Merged
merged 8 commits into from
Jul 22, 2024

Conversation

ChrisRackauckas
Copy link
Contributor

This is part 1 one solving #274. It does the forward mode rules as those are simpler. A separate PR will do the WIP reverse mode rules as that seems to be a bit more complex.

This is part 1 one solving EnzymeAD#274. It does the forward mode rules as those are simpler. A separate PR will do the WIP reverse mode rules as that seems to be a bit more complex.

Add missing `@test`

don't forget the rule
# operations as this is not directly differentiable

getval(x) = hasproperty(x, :val) ? x.val : x
function EnzymeRules.forward(func::Const{Colon}, ::Type{<:Duplicated}, start::Union{Const, Active}, step::Union{Const, Active}, stop::Union{Const, Active})
Copy link
Member

Choose a reason for hiding this comment

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

Can you remove the union{const,active} restriction, make Type{<:Duplicated} more general, and in doing so add batchduplicated/duplicatednoneed?

See

function EnzymeRules.forward(
/
function EnzymeRules.forward(
for example

@ChrisRackauckas
Copy link
Contributor Author

How's that?

# operations as this is not directly differentiable

getval(x) = hasproperty(x, :val) ? x.val : x
function EnzymeRules.forward(func::Const{Colon}, RT::Type{<:Union{Const, DuplicatedNoNeed, Duplicated}}, start, step, stop)
Copy link
Member

Choose a reason for hiding this comment

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

this still needs to add batchduplicated/batchduplicatednoneed/etc , but otherwise almost there!


getval(x) = hasproperty(x, :val) ? x.val : x
function EnzymeRules.forward(func::Const{Colon}, RT::Type{<:Union{Const, DuplicatedNoNeed, Duplicated}}, start, step, stop)
ret = func.val(getval.((start, step, stop))...)
Copy link
Member

Choose a reason for hiding this comment

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

Since it's three things can you just do .val for all of them [there isn't a question that they would have the property all Enzyme.Annotation values have .val\

@codecov-commenter
Copy link

codecov-commenter commented Jul 21, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 0% with 27 lines in your changes missing coverage. Please review.

Project coverage is 71.63%. Comparing base (c0caf9a) to head (ef5c0ba).

Files Patch % Lines
src/internal_rules.jl 0.00% 27 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1655      +/-   ##
==========================================
- Coverage   73.26%   71.63%   -1.64%     
==========================================
  Files          40       31       -9     
  Lines       13442    13046     -396     
==========================================
- Hits         9848     9345     -503     
- Misses       3594     3701     +107     

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

@ChrisRackauckas
Copy link
Contributor Author

How's this? Is there anything like this batchsize utility?

@wsmoses
Copy link
Member

wsmoses commented Jul 21, 2024

You should be able to just call width(..). Also per above you should probably do something like

ntuple(Val(width(RT))) do i
Base.@_inline_meta
Thing
End

There are several examples of this in this file

@wsmoses wsmoses merged commit 3aa6a5a into EnzymeAD:main Jul 22, 2024
33 of 54 checks passed
@ChrisRackauckas ChrisRackauckas deleted the ranges_forward branch July 22, 2024 14:10
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.

3 participants