Restore _init_weights value in no_init_weights (#18504)
* Recover _init_weights value in no_init_weights For potential nested use. In addition, users might modify private no_init_weights as well. * Apply suggestions from code review Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com> * Remove private variable change check Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
This commit is contained in:
parent
0c183cc2f4
commit
5e2f373705
|
@ -106,12 +106,13 @@ def no_init_weights(_enable=True):
|
|||
TODO(Patrick): Delete safety argument `_enable=True` at next major version. .
|
||||
"""
|
||||
global _init_weights
|
||||
old_init_weights = _init_weights
|
||||
if _enable:
|
||||
_init_weights = False
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
_init_weights = True
|
||||
_init_weights = old_init_weights
|
||||
|
||||
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue