Skip to content

Why remat modules must take a different name #2251

Answered by cgarciae
sanchit-gandhi asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @sanchit-gandhi! What you are describing is not related to remat or even Flax at all, its just how Python non local variables work inside functions:

A = 1

def f(x):
  A = A + 1
  return x * A

print(f(2))

This yields the same error:

Traceback (most recent call last):
  File "tmp/test_reasign_python_variables.py", line 9, in <module>
    print(f(2))
  File "tmp/test_reasign_python_variables.py", line 6, in f
    A = A + 1
UnboundLocalError: local variable 'A' referenced before assignment

Given python will force you to choose a 3rd name anyway, you can get creative, I've used something like RematOrNet1 in the past.

Good luck!

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@sanchit-gandhi
Comment options

Answer selected by marcvanzee
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