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

Fix #1630 #1631

Merged
merged 1 commit into from
Jul 21, 2024
Merged

Fix #1630 #1631

merged 1 commit into from
Jul 21, 2024

Conversation

danielwe
Copy link
Contributor

I think this fix is correct (copied the pattern on line 944), but I don't have a test case. The rules I was experimenting with when triggering the bug are incorrect and likely fundamentally misguided, and I don't understand the system well enough to create tests that should pass but don't because of this bug.

Including a stack trace below in case it can help someone write an appropriate test.

Stack trace
LoadError: UndefVarError: `N` not defined
Stacktrace:
  [1] enzyme_custom_setup_args(B::LLVM.IRBuilder, orig::LLVM.CallInst, gutils::Enzyme.Compiler.GradientUtils, mi::Core.MethodInstance, RT::Any, reverse::Bool, isKWCall::Bool)
    @ Enzyme.Compiler ~/.julia/packages/Enzyme/SiyIj/src/rules/customrules.jl:234
  [2] enzyme_custom_fwd(B::LLVM.IRBuilder, orig::LLVM.CallInst, gutils::Enzyme.Compiler.GradientUtils, normalR::Ptr{Ptr{LLVM.API.LLVMOpaqueValue}}, shadowR::Ptr{Ptr{LLVM.API.LLVMOpaqueValue}})
    @ Enzyme.Compiler ~/.julia/packages/Enzyme/SiyIj/src/rules/customrules.jl:367
  [3] (::Enzyme.Compiler.var"#28262#28263")(B::Ptr{LLVM.API.LLVMOpaqueBuilder}, OrigCI::Ptr{LLVM.API.LLVMOpaqueValue}, gutils::Ptr{Nothing}, normalR::Ptr{Ptr{LLVM.API.LLVMOpaqueValue}}, shadowR::Ptr{Ptr{LLVM.API.LLVMOpaqueValue}})
    @ Enzyme.Compiler ~/.julia/packages/Enzyme/SiyIj/src/rules/llvmrules.jl:1228
  [4] EnzymeCreateForwardDiff(logic::Enzyme.Logic, todiff::LLVM.Function, retType::Enzyme.API.CDIFFE_TYPE, constant_args::Vector{Enzyme.API.CDIFFE_TYPE}, TA::Enzyme.TypeAnalysis, returnValue::Bool, mode::Enzyme.API.CDerivativeMode, width::Int64, additionalArg::Ptr{Nothing}, typeInfo::Enzyme.FnTypeInfo, uncacheable_args::Vector{Bool})
    @ Enzyme.API ~/.julia/packages/Enzyme/SiyIj/src/api.jl:170
  [5] enzyme!(job::GPUCompiler.CompilerJob{Enzyme.Compiler.EnzymeTarget, Enzyme.Compiler.EnzymeCompilerParams}, mod::LLVM.Module, primalf::LLVM.Function, TT::Type, mode::Enzyme.API.CDerivativeMode, width::Int64, parallel::Bool, actualRetType::Type, wrap::Bool, modifiedBetween::Tuple{Bool, Bool}, returnPrimal::Bool, expectedTapeType::Type, loweredArgs::Set{Int64}, boxedArgs::Set{Int64})
    @ Enzyme.Compiler ~/.julia/packages/Enzyme/SiyIj/src/compiler.jl:3725
  [6] codegen(output::Symbol, job::GPUCompiler.CompilerJob{Enzyme.Compiler.EnzymeTarget, Enzyme.Compiler.EnzymeCompilerParams}; libraries::Bool, deferred_codegen::Bool, optimize::Bool, toplevel::Bool, strip::Bool, validate::Bool, only_entry::Bool, parent_job::Nothing)
    @ Enzyme.Compiler ~/.julia/packages/Enzyme/SiyIj/src/compiler.jl:5867
  [7] codegen
    @ ~/.julia/packages/Enzyme/SiyIj/src/compiler.jl:5143 [inlined]
  [8] _thunk(job::GPUCompiler.CompilerJob{Enzyme.Compiler.EnzymeTarget, Enzyme.Compiler.EnzymeCompilerParams}, postopt::Bool)
    @ Enzyme.Compiler ~/.julia/packages/Enzyme/SiyIj/src/compiler.jl:6674
  [9] _thunk
    @ ~/.julia/packages/Enzyme/SiyIj/src/compiler.jl:6674 [inlined]
 [10] cached_compilation
    @ ~/.julia/packages/Enzyme/SiyIj/src/compiler.jl:6712 [inlined]
 [11] (::Enzyme.Compiler.var"#28595#28596"{DataType, DataType, Enzyme.API.CDerivativeMode, Tuple{Bool, Bool}, Int64, Bool, Bool, UInt64, DataType})(ctx::LLVM.Context)
    @ Enzyme.Compiler ~/.julia/packages/Enzyme/SiyIj/src/compiler.jl:6781
 [12] JuliaContext(f::Enzyme.Compiler.var"#28595#28596"{DataType, DataType, Enzyme.API.CDerivativeMode, Tuple{Bool, Bool}, Int64, Bool, Bool, UInt64, DataType}; kwargs::@Kwargs{})
    @ GPUCompiler ~/.julia/packages/GPUCompiler/Y4hSX/src/driver.jl:52
 [13] JuliaContext(f::Function)
    @ GPUCompiler ~/.julia/packages/GPUCompiler/Y4hSX/src/driver.jl:42
 [14] #s2010#28594
    @ ~/.julia/packages/Enzyme/SiyIj/src/compiler.jl:6732 [inlined]
 [15] var"#s2010#28594"(FA::Any, A::Any, TT::Any, Mode::Any, ModifiedBetween::Any, width::Any, ReturnPrimal::Any, ShadowInit::Any, World::Any, ABI::Any, ::Any, ::Type, ::Type, ::Type, tt::Any, ::Type, ::Type, ::Type, ::Type, ::Type, ::Any)
    @ Enzyme.Compiler ./none:0
 [16] (::Core.GeneratedFunctionStub)(::UInt64, ::LineNumberNode, ::Any, ::Vararg{Any})
    @ Core ./boot.jl:602
 [17] autodiff(::ForwardMode{FFIABI}, f::Const{typeof(objective)}, ::Type{BatchDuplicatedNoNeed}, args::BatchDuplicated{Vector{Float64}, 2})
    @ Enzyme ~/.julia/packages/Enzyme/SiyIj/src/Enzyme.jl:415
 [18] autodiff
    @ ~/.julia/packages/Enzyme/SiyIj/src/Enzyme.jl:321 [inlined]
 [19] gradient(::ForwardMode{FFIABI}, f::Function, x::Vector{Float64}; shadow::Tuple{Vector{Float64}, Vector{Float64}})
    @ Enzyme ~/.julia/packages/Enzyme/SiyIj/src/Enzyme.jl:1092
 [20] gradient(::ForwardMode{FFIABI}, f::Function, x::Vector{Float64})
    @ Enzyme ~/.julia/packages/Enzyme/SiyIj/src/Enzyme.jl:1088

@codecov-commenter
Copy link

codecov-commenter commented Jul 11, 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 2 lines in your changes missing coverage. Please review.

Project coverage is 67.81%. Comparing base (4da44dd) to head (32bbd18).
Report is 2 commits behind head on main.

Files Patch % Lines
src/rules/customrules.jl 0.00% 2 Missing ⚠️

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

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1631       +/-   ##
===========================================
- Coverage   96.30%   67.81%   -28.49%     
===========================================
  Files           8       38       +30     
  Lines         406    12622    +12216     
===========================================
+ Hits          391     8560     +8169     
- Misses         15     4062     +4047     

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

@wsmoses
Copy link
Member

wsmoses commented Jul 11, 2024

@danielwe I think the test would simply be making a batched version of

@testset "Mixed activity rule" begin
if you also want to try?

@wsmoses wsmoses merged commit 87338e4 into EnzymeAD:main Jul 21, 2024
35 of 54 checks passed
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