Skip to content

Commit

Permalink
Merge pull request #5546 from chengchengpei/cpei/refactor
Browse files Browse the repository at this point in the history
1, log exceptions in details; 2, check processor is None before calling it
  • Loading branch information
hiyouga authored Oct 8, 2024
2 parents 89ba451 + 2c6262c commit f8a2cc6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/llamafactory/model/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ def load_tokenizer(model_args: "ModelArguments") -> "TokenizerModule":
padding_side="right",
**init_kwargs,
)
except Exception as e:
raise OSError("Failed to load tokenizer") from e

if model_args.new_special_tokens is not None:
num_added_tokens = tokenizer.add_special_tokens(
Expand All @@ -97,12 +99,13 @@ def load_tokenizer(model_args: "ModelArguments") -> "TokenizerModule":
try:
processor = AutoProcessor.from_pretrained(model_args.model_name_or_path, **init_kwargs)
patch_processor(processor, config, tokenizer, model_args)
except Exception:
except Exception as e:
logger.warning("Failed to load processor. Error: {}".format(e))
processor = None

# Avoid load tokenizer, see:
# https://github.com/huggingface/transformers/blob/v4.40.0/src/transformers/models/auto/processing_auto.py#L324
if "Processor" not in processor.__class__.__name__:
if processor and "Processor" not in processor.__class__.__name__:
processor = None

return {"tokenizer": tokenizer, "processor": processor}
Expand Down
4 changes: 2 additions & 2 deletions src/llamafactory/train/tuner.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,5 @@ def export_model(args: Optional[Dict[str, Any]] = None) -> None:
model_args.export_hub_model_id, token=model_args.hf_hub_token
)

except Exception:
logger.warning("Cannot save tokenizer, please copy the files manually.")
except Exception as e:
logger.warning("Cannot save tokenizer, please copy the files manually. Error: {}".format(e))

0 comments on commit f8a2cc6

Please sign in to comment.