Skip to content

Commit

Permalink
Customize initial cost estimation of Exhaustive optimizer
Browse files Browse the repository at this point in the history
  • Loading branch information
mofeing committed Feb 14, 2024
1 parent 216e800 commit 7d60617
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Optimizers/Exhaustive.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The algorithm has a ``\mathcal{O}(n!)`` time complexity if `outer = true` and ``
metric::Function = flops
outer::Bool = false
strategy::Symbol = :breadth
init::Optimizer = Greedy()
end

function einexpr(config::Exhaustive, path::SizedEinExpr{L}; cost = BigInt(0)) where {L}
Expand All @@ -44,9 +45,9 @@ function einexpr(config::Exhaustive, path::SizedEinExpr{L}; cost = BigInt(0)) wh
else
BitSet
end
return exhaustive_breadthfirst(Val(config.metric), path, settype, config.outer)
return exhaustive_breadthfirst(Val(config.metric), path, settype, config.outer, config.init)
elseif config.strategy === :depth
init_path = einexpr(Naive(), path)
init_path = einexpr(config.init, path)
leader = Ref(
@compat (;
path = init_path,
Expand Down Expand Up @@ -94,11 +95,12 @@ function exhaustive_breadthfirst(
expr::SizedEinExpr{L},
::Type{SetType} = BitSet,
outer::Bool = false,
optimizer_init::Optimizer = Greedy(),
) where {L,Metric,SetType}
cost_fac = maximum(values(expr.size))

# make a initial guess using a fast optimizer like Greedy
greedy_path = einexpr(Greedy(), expr)
greedy_path = einexpr(optimizer_init, expr)
cost_max = mapreduce(Metric, +, Branches(greedy_path, inverse = true), init = BigInt(0))::BigInt

# number of input tensors
Expand Down

0 comments on commit 7d60617

Please sign in to comment.