Skip to content

Commit

Permalink
Allow loading if a preset doesn't have preprocessor.json.
Browse files Browse the repository at this point in the history
  • Loading branch information
SamanehSaadat committed Apr 10, 2024
1 parent 069303c commit f772e41
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions keras_nlp/models/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,21 @@ def from_preset(
f"Received: backbone={kwargs['backbone']}."
)

# Load preprocessor from preset.
preprocessor_preset_cls = check_config_class(
preset, PREPROCESSOR_CONFIG_FILE
)
if not issubclass(preprocessor_preset_cls, Preprocessor):
raise ValueError(
f"`{PREPROCESSOR_CONFIG_FILE}` in `{preset}` should be a subclass of `Preprocessor`."
if not get_file(preset, PREPROCESSOR_CONFIG_FILE):
# Load tokenizer and create a preprocessor based on that.
preprocessor = cls.preprocessor_cls(
tokenizer=cls.preprocessor_clstokenizer_cls.from_preset(preset)
)
preprocessor = preprocessor_preset_cls.from_preset(preset)
else:
# Load preprocessor from preset.
preprocessor_preset_cls = check_config_class(
preset, PREPROCESSOR_CONFIG_FILE
)
if not issubclass(preprocessor_preset_cls, Preprocessor):
raise ValueError(
f"`{PREPROCESSOR_CONFIG_FILE}` in `{preset}` should be a subclass of `Preprocessor`."
)
preprocessor = preprocessor_preset_cls.from_preset(preset)

# Backbone case.
backbone_preset_cls = check_config_class(preset)
Expand Down

0 comments on commit f772e41

Please sign in to comment.