Skip to content

Problem in jitting methods of a class #23975

Answered by jakevdp
mtagliazucchi asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks for the question – we have a FAQ entry on this topic here, and it looks like you're already using the pytree approach, which is great.

This class is almost okay, but I noticed that the method update_params returns a new instance of the class with the updated parameters and it does not modify the parameters of the original instance.

This is working as expected: JIT-compiled functions must be pure, and cannot operate via side-effects. By design, the input to the function will not be mutated as a result of executing the function because this is a side-effect (see JAX sharp bits: pure functions for some discussion of this).

I would like to avoid to generate a new class instance ever…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@mtagliazucchi
Comment options

Answer selected by mtagliazucchi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants