You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Traceback (most recent call last):
File "run_glue.py", line 610, in <module>
main()
File "run_glue.py", line 503, in main
trainer = ORTTrainer(
File "/workspace/optimum/onnxruntime/trainer.py", line 144, in __init__
super().__init__(
File "/usr/local/lib/python3.8/dist-packages/transformers/trainer.py", line 569, in __init__
self.scaler = ShardedGradScaler()
UnboundLocalError: local variable 'ShardedGradScaler' referenced before assignment
Expected behavior
ShardedGradScaler was firstly imported as global variable
Hello @JingyaHuang, thank you for bringing this to the notice with detailed steps and possible solutions 🤗. Can you try the above draft PR and see if that fixes the issue?
System Info
transformers
version: 4.21.0Who can help?
@pacman100 @sgugger
Information
Tasks
examples
folder (such as GLUE/SQuAD, ...)Reproduction
Running the
run_glue
(optimum version) with the distributed launcherError message:
Expected behavior
ShardedGradScaler
was firstly imported as global variabletransformers/src/transformers/trainer.py
Line 190 in da503ea
Then it was imported as a local variable for fsdp with the same name
transformers/src/transformers/trainer.py
Line 568 in da503ea
And it won't fall back to the global
ShardedGradScaler
, even when the local one is not imported leading, to an UnboundLocalError.P.S. However I don't have problem running the
run_glue.py
in transformers, the problem seems to occur when using classes inherited fromTrainer
.Possible solution: use different name / both import locally
REF:
https://docs.python.org/3/faq/programming.html#why-am-i-getting-an-unboundlocalerror-when-the-variable-has-a-value
https://stackoverflow.com/questions/58750517/why-unboundlocalerror-occurs-when-importing-inside-function
The text was updated successfully, but these errors were encountered: