Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions ext/TensorOperationsChainRulesCoreExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ using LinearAlgebra

# Cannot free intermediate tensors when using AD
# Thus we change the forward passes: `istemp=false` and `tensorfree!` is a no-op
function ChainRulesCore.rrule(
::typeof(TensorOperations.tensorfree!), allocator = DefaultAllocator()
)
function ChainRulesCore.rrule(::typeof(TensorOperations.tensorfree!), C)
tensorfree!_pullback(Δargs...) = (NoTangent(), NoTangent())
return nothing, tensorfree!_pullback
end
function ChainRulesCore.rrule(::typeof(TensorOperations.tensorfree!), C, allocator)
tensorfree!_pullback(Δargs...) = (NoTangent(), NoTangent(), NoTangent())
return nothing, tensorfree!_pullback
end
function ChainRulesCore.rrule(
::typeof(TensorOperations.tensoralloc), ttype, structure,
istemp, allocator = DefaultAllocator()
Expand Down
1 change: 1 addition & 0 deletions ext/TensorOperationsEnzymeExt/TensorOperationsEnzymeExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ using Enzyme.EnzymeCore
using Enzyme.EnzymeCore: EnzymeRules

@inline EnzymeRules.inactive(::typeof(TensorOperations.tensorfree!), ::Any) = true
@inline EnzymeRules.inactive(::typeof(TensorOperations.tensorfree!), ::Any, ::Any) = true
@inline EnzymeRules.inactive_type(v::Type{<:AbstractBackend}) = true
@inline EnzymeRules.inactive_type(v::Type{DefaultAllocator}) = true
@inline EnzymeRules.inactive_type(v::Type{<:CUDAAllocator}) = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Mooncake.tangent_type(::Type{ManualAllocator}) = Mooncake.NoTangent
@zero_derivative DefaultCtx Tuple{typeof(TensorOperations.promote_add), Any}

Mooncake.@from_rrule Mooncake.DefaultCtx Tuple{typeof(TensorOperations.tensorfree!), Any}
Mooncake.@from_rrule Mooncake.DefaultCtx Tuple{typeof(TensorOperations.tensorfree!), Any, Any}
Mooncake.@from_rrule Mooncake.DefaultCtx Tuple{typeof(TensorOperations.tensoralloc), Any, Any, Any, Any}

Mooncake.@is_primitive DefaultCtx Tuple{typeof(tensorcontract!), AbstractArray, AbstractArray, Index2Tuple, Bool, AbstractArray, Index2Tuple, Bool, Index2Tuple, Number, Number, Vararg{Any}}
Expand Down
Loading