Skip to content

Commit

Permalink
Fix flax from_pretrained pytorch weight check (open-mmlab#603)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mishig Davaadorj authored Sep 21, 2022
1 parent fb2fbab commit f810060
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/diffusers/modeling_flax_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,16 +307,16 @@ def from_pretrained(
# Load model
if os.path.isdir(pretrained_model_name_or_path):
if from_pt:
if not os.path.join(pretrained_model_name_or_path, WEIGHTS_NAME):
if not os.path.isfile(os.path.join(pretrained_model_name_or_path, WEIGHTS_NAME)):
raise EnvironmentError(
f"Error no file named {WEIGHTS_NAME} found in directory {pretrained_model_name_or_path} "
)
model_file = os.path.join(pretrained_model_name_or_path, WEIGHTS_NAME)
elif os.path.isfile(os.path.join(pretrained_model_name_or_path, FLAX_WEIGHTS_NAME)):
# Load from a Flax checkpoint
model_file = os.path.join(pretrained_model_name_or_path, FLAX_WEIGHTS_NAME)
# At this stage we don't have a weight file so we will raise an error.
elif os.path.join(pretrained_model_name_or_path, WEIGHTS_NAME):
# Check if pytorch weights exist instead
elif os.path.isfile(os.path.join(pretrained_model_name_or_path, WEIGHTS_NAME)):
raise EnvironmentError(
f"{WEIGHTS_NAME} file found in directory {pretrained_model_name_or_path}. Please load the model"
" using `from_pt=True`."
Expand Down

0 comments on commit f810060

Please sign in to comment.