Change path to posix (modeling_utils.py) (#6781)
* Change path to posix * running isort * run style and quality checks --------- Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
This commit is contained in:
@@ -20,6 +20,7 @@ import os
|
|||||||
import re
|
import re
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
from pathlib import Path
|
||||||
from typing import Any, Callable, List, Optional, Tuple, Union
|
from typing import Any, Callable, List, Optional, Tuple, Union
|
||||||
|
|
||||||
import safetensors
|
import safetensors
|
||||||
@@ -367,18 +368,18 @@ class ModelMixin(torch.nn.Module, PushToHubMixin):
|
|||||||
# Save the model
|
# Save the model
|
||||||
if safe_serialization:
|
if safe_serialization:
|
||||||
safetensors.torch.save_file(
|
safetensors.torch.save_file(
|
||||||
state_dict, os.path.join(save_directory, weights_name), metadata={"format": "pt"}
|
state_dict, Path(save_directory, weights_name).as_posix(), metadata={"format": "pt"}
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
torch.save(state_dict, os.path.join(save_directory, weights_name))
|
torch.save(state_dict, Path(save_directory, weights_name).as_posix())
|
||||||
|
|
||||||
logger.info(f"Model weights saved in {os.path.join(save_directory, weights_name)}")
|
logger.info(f"Model weights saved in {Path(save_directory, weights_name).as_posix()}")
|
||||||
|
|
||||||
if push_to_hub:
|
if push_to_hub:
|
||||||
# Create a new empty model card and eventually tag it
|
# Create a new empty model card and eventually tag it
|
||||||
model_card = load_or_create_model_card(repo_id, token=token)
|
model_card = load_or_create_model_card(repo_id, token=token)
|
||||||
model_card = populate_model_card(model_card)
|
model_card = populate_model_card(model_card)
|
||||||
model_card.save(os.path.join(save_directory, "README.md"))
|
model_card.save(Path(save_directory, "README.md").as_posix())
|
||||||
|
|
||||||
self._upload_folder(
|
self._upload_folder(
|
||||||
save_directory,
|
save_directory,
|
||||||
|
|||||||
Reference in New Issue
Block a user