Repository: huggingface/diffusers

Issue:
[Tracker] change to posix for better Windows support
In https://github.com/huggingface/diffusers/pull/6564, @fabiorigano introduced the use of Posix to better support Windows compatibility. 

It'd be nice to change the instances of `os.path.join()` to `Path(...).as_posix()`. 

Feel free to open PRs for this and tag me. 

While opening PRs, please target only ONE script at a time. 

Let's go 🚀 



Discussion:
Hi @sayakpaul, I checked the mentioned PR and also understood the issue. This is a documentation change right? We need to change every instance of `os.path.join()` to `Path(...).as_posix()`?
> Hi @sayakpaul, I checked the mentioned PR and also understood the issue. This is a documentation change right? We need to change every instance of `os.path.join()` to `Path(...).as_posix()`?

Hey @Bhavay-2001 this is not a documentation change. Try going through this issue #6561 you'll understand why we are doing this.  
Hi @charchit7, yes I understood that this is to provide windows support for the adapter.py. I previously thought that it was a documentation change issue, however I have changed the file and opened the corresponding PR.
Thanks 
Hi, @sayakpaul! Does this issue request to change all os.path.join() instances in the whole Diffusers repo? Can I just take any script containing os.path.join() and change it?
I think so. 
@sayakpaul there are quite a few such instances in training examples. I will tackle a few. ok?
I think those are fine to leave as is because most of the training doesn't take place on Windows. 
@sayakpaul I searched across the entire diffusers repo and 111 files contain instance(s) of `os.path.join` however as you previously mentioned a lot of that is related to training. I then did a targeted search within `diffusers/src/diffusers` and this revealed a much smaller [subset](https://github.com/search?q=repo%3Ahuggingface%2Fdiffusers+os.path.join+path%3A%2F%5Esrc%5C%2Fdiffusers%5C%2F%2F&type=code) that contains 11 files and ~55 instances of `os.path.join`. One of these 11 files was addressed by Bhavay in this [PR](https://github.com/huggingface/diffusers/pull/6672). Would it be worth me going after the other 10 files, most of which are within `diffusers/src/diffusers/utils` and `diffusers/src/diffusers/pipelines`?
Yeah that works for me.
Hi @sayakpaul, could you please review my PR.
Thanks
Where is it?
Please find the [PR](https://github.com/huggingface/diffusers/pull/6672) here
Also, @Stepheni12 if you don't mind can we distribute the following tasks? 
Yes, @Bhavay-2001 that sounds good! There were 11 files in total and your PR already did one of them so we can just split the other 10 from this [subset](https://github.com/search?q=repo%3Ahuggingface%2Fdiffusers+os.path.join+path%3A%2F%5Esrc%5C%2Fdiffusers%5C%2F%2F&type=code). You can take the top 5 files which are:
>src/diffusers/utils/hub_utils.py
>src/diffusers/utils/constants.py
>src/diffusers/models/modeling_flax_utils.py
>src/diffusers/configuration_utils.py
>src/diffusers/utils/dynamic_modules_utils.py

and then I'll take the bottom half of the list which are:

>src/diffusers/pipelines/onnx_utils.py
>src/diffusers/pipelines/pipeline_flax_utils.py
>src/diffusers/models/modeling_utils.py
>src/diffusers/utils/testing_utils.py
>src/diffusers/pipelines/pipeline_utils.py
Sure @Stepheni12, I will update the mentioned files

Resolving patch:
diff --git a/src/diffusers/models/modeling_utils.py b/src/diffusers/models/modeling_utils.py
--- a/src/diffusers/models/modeling_utils.py
+++ b/src/diffusers/models/modeling_utils.py
@@ -20,6 +20,7 @@
 import re
 from collections import OrderedDict
 from functools import partial
+from pathlib import Path
 from typing import Any, Callable, List, Optional, Tuple, Union
 
 import safetensors
@@ -369,18 +370,18 @@ def save_pretrained(
         # Save the model
         if safe_serialization:
             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:
-            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:
             # Create a new empty model card and eventually tag it
             model_card = load_or_create_model_card(repo_id, token=token)
             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(
                 save_directory,


Test patch: