fix: replace stderr with stdout for download messages in hub.py (#146475)

This PR addresses an issue where download logs in `hub.py` are sent to `stderr` instead of `stdout`. Hence, when running models with workers, these messages are incorrectly categorized as errors, leading to confusion.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/146475
Approved by: https://github.com/mikaylagawarecki
This commit is contained in:
yousoumar 2025-02-10 10:46:10 +00:00 committed by PyTorch MergeBot
parent 6667e5d786
commit c88ae00692

View file

@ -262,7 +262,7 @@ def _get_cache_or_reload(
try:
url = _git_archive_link(repo_owner, repo_name, ref)
sys.stderr.write(f'Downloading: "{url}" to {cached_file}\n')
sys.stdout.write(f'Downloading: "{url}" to {cached_file}\n')
download_url_to_file(url, cached_file, progress=False)
except HTTPError as err:
if err.code == 300:
@ -859,7 +859,7 @@ def load_state_dict_from_url(
filename = file_name
cached_file = os.path.join(model_dir, filename)
if not os.path.exists(cached_file):
sys.stderr.write(f'Downloading: "{url}" to {cached_file}\n')
sys.stdout.write(f'Downloading: "{url}" to {cached_file}\n')
hash_prefix = None
if check_hash:
r = HASH_REGEX.search(filename) # r is Optional[Match[str]]