Skip to content

Commit 63683d8

Browse files
authored
Fix a bug when vocab_file is None (#830)
* fix a bug when vocab_file is None * Prevent potential bug when resource_file is None
1 parent b9058c0 commit 63683d8

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

paddlenlp/transformers/model_utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,11 @@ def from_pretrained(cls, pretrained_model_name_or_path, *args, **kwargs):
222222
default_root = os.path.join(MODEL_HOME, pretrained_model_name_or_path)
223223
resolved_resource_files = {}
224224
for file_id, file_path in resource_files.items():
225-
path = os.path.join(default_root, file_path.split('/')[-1])
226225
if file_path is None or os.path.isfile(file_path):
227226
resolved_resource_files[file_id] = file_path
228-
elif os.path.exists(path):
227+
continue
228+
path = os.path.join(default_root, file_path.split('/')[-1])
229+
if os.path.exists(path):
229230
logger.info("Already cached %s" % path)
230231
resolved_resource_files[file_id] = path
231232
else:

paddlenlp/transformers/tokenizer_utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,10 +476,11 @@ def from_pretrained(cls, pretrained_model_name_or_path, *args, **kwargs):
476476
default_root = os.path.join(MODEL_HOME, pretrained_model_name_or_path)
477477
resolved_vocab_files = {}
478478
for file_id, file_path in vocab_files.items():
479-
path = os.path.join(default_root, file_path.split('/')[-1])
480479
if file_path is None or os.path.isfile(file_path):
481480
resolved_vocab_files[file_id] = file_path
482-
elif os.path.exists(path):
481+
continue
482+
path = os.path.join(default_root, file_path.split('/')[-1])
483+
if os.path.exists(path):
483484
logger.info("Already cached %s" % path)
484485
resolved_vocab_files[file_id] = path
485486
else:

0 commit comments

Comments
 (0)