"examples/pytorch/test_pytorch_examples.py" did not exist on "1381b6d01dca9c84c3cacd3eae5155cda8e03c18"
Unverified Commit 5e2f3737 authored by YouJiacheng's avatar YouJiacheng Committed by GitHub
Browse files

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: default avatarSylvain Gugger <35901082+sgugger@users.noreply.github.com>

* Remove private variable change check
Co-authored-by: default avatarSylvain Gugger <35901082+sgugger@users.noreply.github.com>
parent 0c183cc2
...@@ -106,12 +106,13 @@ def no_init_weights(_enable=True): ...@@ -106,12 +106,13 @@ def no_init_weights(_enable=True):
TODO(Patrick): Delete safety argument `_enable=True` at next major version. . TODO(Patrick): Delete safety argument `_enable=True` at next major version. .
""" """
global _init_weights global _init_weights
old_init_weights = _init_weights
if _enable: if _enable:
_init_weights = False _init_weights = False
try: try:
yield yield
finally: finally:
_init_weights = True _init_weights = old_init_weights
try: try:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment