fix UnboundLocalError (#834)

* When an exception has been assigned using as target, it is cleared at the end of the except clause.(https://docs.python.org/3/reference/compound_stmts.html#the-try-statement)

* Update loader.py

---------

Co-authored-by: xiaoyang <xiaoyang@youzan.com>
Co-authored-by: Daniel Han <danielhanchen@gmail.com>
This commit is contained in:
XiaoYang 2024-07-31 01:15:09 +08:00 committed by GitHub
commit 18900721c2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -155,14 +155,14 @@ class FastLanguageModel(FastLlamaModel):
try:
model_config = AutoConfig.from_pretrained(model_name, token = token, revision = revision)
is_model = True
except Exception as autoconfig_error:
autoconfig_error = str(autoconfig_error)
except Exception as error:
autoconfig_error = str(error)
is_model = False
try:
peft_config = PeftConfig .from_pretrained(model_name, token = token, revision = revision)
is_peft = True
except Exception as peft_error:
peft_error = str(peft_error)
except Exception as error:
peft_error = str(error)
is_peft = False
pass