Load model from HuggingFace if model_directory unset in config YAML

- Do not save/load the model to/from disk when model_directory unset
in config.yml
- Add symmetric search default config to cli.py
This commit is contained in:
Debanjum Singh Solanky
2022-01-14 17:32:45 -05:00
parent 510faa1904
commit c64e0c2965
2 changed files with 15 additions and 6 deletions

View File

@@ -39,14 +39,15 @@ def merge_dicts(priority_dict, default_dict):
def load_model(model_name, model_dir, model_type):
"Load model from disk or huggingface"
# Construct model path
model_path = join(model_dir, model_name.replace("/", "_"))
model_path = join(model_dir, model_name.replace("/", "_")) if model_dir is not None else None
# Load model from model_path if it exists there
if resolve_absolute_path(model_path).exists():
if model_path is not None and resolve_absolute_path(model_path).exists():
model = model_type(get_absolute_path(model_path))
# Else load the model from the model_name
else:
model = model_type(model_name)
model.save(model_path)
if model_path is not None:
model.save(model_path)
return model