Repository: Lightning-AI/pytorch-lightning
Pull request: Fixed the load_from_checkpoint path detected as URL bug
## What does this PR do?

This PR fixes #2243 by both checking if string is a local file and parsing string to see if it's an URL.

# Before submitting

- [X] Was this discussed/approved via a Github issue? (no need for typos and docs improvements)
- [X] Did you read the [contributor guideline](https://github.com/PyTorchLightning/pytorch-lightning/blob/master/.github/CONTRIBUTING.md), Pull Request section?
- [X] Did you make sure your PR does only one thing, instead of bundling different changes together? Otherwise, we ask you create a separate PR for every change.
- [ ] Did you make sure to update the documentation with your changes?
- [X] Did you write any new necessary tests? 
- [x] Did you verify new and existing tests pass locally with your changes?
- [ ] If you made a notable change (that affects users), did you update the [CHANGELOG](https://github.com/PyTorchLightning/pytorch-lightning/blob/master/CHANGELOG.md)?

<!-- For CHANGELOG separate each item in unreleased section by a blank line to reduce collisions -->

## PR review    
Anyone in the community is free to review the PR once the tests have passed.     
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.

## Did you have fun?
Make sure you had fun coding 🙃


Problem statement:
Model.load_from_checkpoint tries to open file path as URL and fail
## 🐛 Bug
 load_from_checkpoint tries to classify if the input is a file path or an URL and detects the hard drive letter as a scheme and then classify wrongly the input because of this.
urllib.error.URLError: \<urlopen error unknown url type: d\>

My input:
D:\Prog\Projects\AceriNet\research_seed\checkpoints\acerinet\bnacerinet0_target=OVA_OK_penalized=None_loss_fn=ce_normalized=True_balanced=FalseFalse_seed=42_val_loss=0.374_val_auroc=0.9041_v0.ckpt

### To Reproduce

Steps to reproduce the behavior:
Use any path with a hard drive letter at the start (windows formatting) for pl.LightningModule().load_from_checkpoint(path)

Hints from issue discussion:
Hi! thanks for your contribution!, great first issue!
Ah I didn’t think about Windows when I implemented this. I’ll take a look if there’s a better way.
We could try to detect if the file exists with if os.path.isfile() or Path(path_of_chkpt).is_file() instead of checking for scheme

Commit message: Fixed the load_from_checkpoint path detected as URL bug

Patch to review:
diff --git a/pytorch_lightning/utilities/cloud_io.py b/pytorch_lightning/utilities/cloud_io.py
index b2f9ffa788541..317ceafb0da03 100644
--- a/pytorch_lightning/utilities/cloud_io.py
+++ b/pytorch_lightning/utilities/cloud_io.py
@@ -1,11 +1,12 @@
 import torch
 
+from Pathlib import Path
 from urllib.parse import urlparse
 
 
 def load(path_or_url: str, map_location=None):
     parsed = urlparse(path_or_url)
-    if parsed.scheme == '':
-        # local file
+    if parsed.scheme == '' or Path(path_or_url).is_file():
+        # no scheme or local file
         return torch.load(path_or_url, map_location=map_location)
     return torch.hub.load_state_dict_from_url(path_or_url, map_location=map_location)


Code review comments:
diff_hunk: @@ -1,11 +1,12 @@
 import torch
 
+from Pathlib import Path
path: pytorch_lightning/utilities/cloud_io.py
text: @user1:
`from pathlib import Path`