Skip to content

Conversation

@shashi
Copy link
Collaborator

@shashi shashi commented Aug 13, 2019

needs this patch on ForwardDiff.jl (along with commenting out Dual ops supported by ChainRules)

diff --git a/src/dual.jl b/src/dual.jl
index 0746bd5..a344b76 100644
--- a/src/dual.jl
+++ b/src/dual.jl
@@ -59,13 +59,17 @@ tag can be extracted, so it should be used in the _innermost_ function.
     return Dual{T}(convert(C, value), convert(Partials{N,C}, partials))
 end
 
+# we intend for the right cassette context to
+# intercept calls to dualtag
+dualtag() = nothing
+
 @inline Dual{T}(value, partials::Tuple) where {T} = Dual{T}(value, Partials(partials))
 @inline Dual{T}(value, partials::Tuple{}) where {T} = Dual{T}(value, Partials{0,typeof(value)}(partials))
 @inline Dual{T}(value) where {T} = Dual{T}(value, ())
 @inline Dual{T}(x::Dual{T}) where {T} = Dual{T}(x, ())
 @inline Dual{T}(value, partial1, partials...) where {T} = Dual{T}(value, tuple(partial1, partials...))
 @inline Dual{T}(value::V, ::Chunk{N}, p::Val{i}) where {T,V,N,i} = Dual{T}(value, single_seed(Partials{N,V}, p))
-@inline Dual(args...) = Dual{Nothing}(args...)
+@inline Dual(args...) = Dual{typeof(dualtag())}(args...)
 
 # we define these special cases so that the "constructor <--> convert" pun holds for `Dual`
 @inline Dual{T,V,N}(x::Dual{T,V,N}) where {T,V,N} = x

dualtest.jl is now a disaster, we need to remove all the old tag tests.

Edit: updated patch

@shashi shashi changed the title Tagging WIP: Tagging Aug 15, 2019


@inline function overdub(ctx::TaggedCtx{T}, f, args...) where {T}
if length(args) > 4
Copy link
Collaborator

Choose a reason for hiding this comment

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

Comment for why this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

just speeds things up, we don't have frules longer than that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Add that comment to the source code

shashi added 7 commits August 15, 2019 07:42
Before:

```julia

julia> @time D(x -> x * D(y -> x + y, 1), 1)
 41.852295 seconds (127.60 M allocations: 6.823 GiB, 5.71% gc time)
1
julia> @time D(x -> x * D(y -> x + y, 1), 1)
  1.962306 seconds (5.69 M allocations: 311.423 MiB, 6.14% gc time)
1
```

after

```julia
julia> @time D(x -> x * D(y -> x + y, 1), 1)
 12.301352 seconds (40.46 M allocations: 2.227 GiB, 4.98% gc time)
1

julia> @time D(x -> x * D(y -> x + y, 1), 1)
  0.467172 seconds (1.62 M allocations: 91.768 MiB, 5.42% gc time)
1
```
@shashi shashi mentioned this pull request Aug 18, 2019
@shashi shashi mentioned this pull request Oct 7, 2019
@shashi shashi closed this Oct 7, 2019
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.

4 participants