-
Notifications
You must be signed in to change notification settings - Fork 7
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
Handle new variables being created inside a traced loop #303
Conversation
CI succeeds (?) but running the tests locally, I get a failure for the sinkhorn control flow test.
The block arguments of cond_fn = ((var"##i#444179", var"##v#444181", ν, μ, K, u) -> begin
local num_iters = div(10 - 1, 1, RoundDown)
local num_iters = Reactant.promote_to(Reactant.TracedRNumber{Int64}, num_iters)
var"##i#444179" < num_iters + 1
end)
body_fn = ((var"##i#444179", var"##v#444181", ν, μ, K, u) -> begin
local step_ = 1
local start_ = 1
local _ = start_ + var"##i#444179" * step_
begin
v = ν ./ (K' * u)
u = μ ./ (K * v)
end
!(var"##v#444181" isa ReactantCore.MissingTracedValue) && (var"##v#444181" = v)
(var"##i#444179" + 1, var"##v#444181", ν, μ, K, u)
end) %12:6 = "stablehlo.while"(%11, %10, %1, %0, %7#0, %9) ({
^bb0(%arg9: tensor<i64>, %arg10: tensor<5xf32>, %arg11: tensor<5xf32>, %arg12: tensor<10xf32>, %arg13: tensor<10x5xf32>, %arg14: tensor<10xf32>):
// ...
"stablehlo.return"(%64) : (tensor<i1>) -> ()
}, {
^bb0(%arg3: tensor<5xf32>, %arg4: tensor<i64>, %arg5: tensor<5xf32>, %arg6: tensor<10xf32>, %arg7: tensor<10x5xf32>, %arg8: tensor<10xf32>):
// ...
"stablehlo.return"(%60, %44#0, %arg5, %arg6, %arg7, %58#0) : (tensor<i64>, tensor<5xf32>, tensor<5xf32>, tensor<10xf32>, tensor<10x5xf32>, tensor<10xf32>) -> ()
}) : (tensor<i64>, tensor<5xf32>, tensor<5xf32>, tensor<10xf32>, tensor<10x5xf32>, tensor<10xf32>) -> (tensor<i64>, tensor<5xf32>, tensor<5xf32>, tensor<10xf32>, tensor<10x5xf32>, tensor<10xf32>) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have another possible solution in Pangoraw@32853eb. I think there might be edge cases though.
let | ||
args = $(args_init) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this changes the scope of args
here, is it on purpose?
filter!(∉(SPECIAL_SYMBOLS), body_symbols.assignments) | ||
filter!(∉(SPECIAL_SYMBOLS), body_symbols.references) | ||
|
||
potentially_undefined = setdiff(body_symbols.assignments, body_symbols.references) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think all body_symbols.assignments are potentially undefined here. ExpressionExplorer already takes care of not adding references after an assignment.
julia> ss = ExpressionExplorer.compute_symbols_state(quote
x = x
y = x
y, x
end)
SymbolsState(Set([:x]), Set([:y, :x]), Set{FunctionName}(), Dict{FunctionNameSignaturePair, SymbolsState}(), Set{FunctionName}())
julia> ss.assignments
Set{Symbol} with 2 elements:
:y
:x
julia> ss.references
Set{Symbol} with 1 element:
:x
@@ -172,6 +196,7 @@ function trace_for(mod, expr) | |||
local start_ = $start | |||
local $induction = start_ + $counter * step_ | |||
$body |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does it needs something before the body (opposite of updates) ?
!($def isa $(MissingTracedValue)) && ($arg = $def)
$body
!($def isa $(MissingTracedValue)) && ($def = $arg)
Thanks for the review @Pangoraw! I like the simplicity of your approach way better, though. I can close this pr and we can go with your branch. One consideration I have is for
|
oh right, I missed that one. thank you! I opened #310. I think it would maybe better to use the |
Yeah agreed, it doesn't change much but seems a bit nicer. |
closed in favor of #310 |
RE #301