-
-
Notifications
You must be signed in to change notification settings - Fork 24
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
Restructure is not type stable but could be made stable? #177
Comments
Can you elaborate on why you want |
Hi @ToucheSir ! The first reason is because Enzyme fails due to the instability. And the second reason is that I find it unusual to be type instable. |
Not quite. You are allowed to pass an array of a different eltype to
...but even if you weren't, the type instability would remain. The reason is because Functors uses an untyped IdDict internally to keep track of shared/aliased parameters: https://github.com/FluxML/Functors.jl/blob/2eddcb74f9589e61b847362c2a91d91bd90ef628/src/walks.jl#L170-L201 The fix here would be to tell P.S. since you're working with Enzyme and not Zygote, you may be interested in adapting the mutating |
Thanks for the tips. Let me try to explicitly set the return type of the reconstruct expression as you suggested. |
Hi, it seems like calling restructure is not stable by default. This is currently causing issues with
Enzyme.jl
(see this issue). Here is a MWE to illustrate the point:This returns:
where the return type
Model
is not stable in terms of its type parameters.This can be solved in a brute-force manner by defining
re::Restructure
(defined here) as:where we are informing the compiler that the return type will be the same as
re.model
. I think this is safe to assume, and this immediately resolves the instability. Any thoughts on this?The text was updated successfully, but these errors were encountered: