-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
diffuser model load using model and path params (#264)
Co-authored-by: grajguru <[email protected]>
- Loading branch information
1 parent
1286f45
commit 7d37f27
Showing
2 changed files
with
32 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# DeepSpeed Team | ||
|
||
from mii.utils import is_aml, mii_cache_path | ||
|
||
|
||
def attempt_load(load_fn, model_name, model_path, cache_path=None, kwargs={}): | ||
try: | ||
value = load_fn(model_name, **kwargs) | ||
except Exception as ex: | ||
if is_aml(): | ||
print( | ||
f"Attempted load but failed - {str(ex)}, retrying using model_path={model_path}" | ||
) | ||
value = load_fn(model_path, **kwargs) | ||
else: | ||
cache_path = cache_path or mii_cache_path() | ||
print( | ||
f"Attempted load but failed - {str(ex)}, retrying using cache_dir={cache_path}" | ||
) | ||
value = load_fn(model_name, cache_dir=cache_path, **kwargs) | ||
return value |