Issue:
When mismatching versions are installed, huggingface_hub calls filelock with deprecated parameter mode. This affects building resnet models e.g. timm.create_model(model_name, ..., pretrained=pretrained, ...) and other places where huggingface_hub is used.
e.g. see stack trace from CircleCI:
Loading pretrained weights from Hugging Face hub (timm/resnet50_gn.a1h_in1k)
HTTP Request: HEAD https://huggingface.co/timm/resnet50_gn.a1h_in1k/resolve/main/model.safetensors "HTTP/1.1 302 Found"
Exception ignored in: <function BaseFileLock.__del__ at 0x7fd7639c53f0>
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/filelock/_api.py", line 230, in __del__
self.release(force=True)
File "/usr/local/lib/python3.10/site-packages/filelock/_api.py", line 191, in release
with self._thread_lock:
AttributeError: 'UnixFileLock' object has no attribute '_thread_lock'
Traceback (most recent call last):
File "/home/circleci/circleci-demo-python-django/deeplabcut/pose_estimation_pytorch/registry.py", line 73, in build_from_cfg
return obj_cls(**filtered_args)
File "/home/circleci/circleci-demo-python-django/deeplabcut/pose_estimation_pytorch/models/backbones/resnet.py", line 52, in __init__
self.model = timm.create_model(
File "/home/circleci/.local/lib/python3.10/site-packages/timm/models/_factory.py", line 138, in create_model
model = create_fn(
File "/home/circleci/.local/lib/python3.10/site-packages/timm/models/resnet.py", line 1695, in resnet50_gn
return _create_resnet('resnet50_gn', pretrained, **dict(model_args, **kwargs))
File "/home/circleci/.local/lib/python3.10/site-packages/timm/models/resnet.py", line 791, in _create_resnet
return build_model_with_cfg(ResNet, variant, pretrained, **kwargs)
File "/home/circleci/.local/lib/python3.10/site-packages/timm/models/_builder.py", line 457, in build_model_with_cfg
load_pretrained(
File "/home/circleci/.local/lib/python3.10/site-packages/timm/models/_builder.py", line 226, in load_pretrained
state_dict = load_state_dict_from_hf(pretrained_loc, weights_only=True, cache_dir=cache_dir)
File "/home/circleci/.local/lib/python3.10/site-packages/timm/models/_hub.py", line 226, in load_state_dict_from_hf
cached_safe_file = hf_hub_download(
File "/home/circleci/.local/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py", line 89, in _inner_fn
return fn(*args, **kwargs)
File "/home/circleci/.local/lib/python3.10/site-packages/huggingface_hub/file_download.py", line 1032, in hf_hub_download
return _hf_hub_download_to_cache_dir(
File "/home/circleci/.local/lib/python3.10/site-packages/huggingface_hub/file_download.py", line 1247, in _hf_hub_download_to_cache_dir
with WeakFileLock(lock_path):
File "/usr/local/lib/python3.10/contextlib.py", line 135, in __enter__
return next(self.gen)
File "/home/circleci/.local/lib/python3.10/site-packages/huggingface_hub/utils/_fixes.py", line 92, in WeakFileLock
lock = FileLock(lock_file, timeout=log_interval, mode=0o664)
TypeError: BaseFileLock.__init__() got an unexpected keyword argument 'mode'
Proposed change:
explicitly include huggingface_hub>=0.23 in the dependencies, so that compatible versions are installed. This should resolve the problem.
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue:
When mismatching versions are installed, huggingface_hub calls filelock with deprecated parameter mode. This affects building resnet models e.g. timm.create_model(model_name, ..., pretrained=pretrained, ...) and other places where huggingface_hub is used.
e.g. see stack trace from CircleCI:
Loading pretrained weights from Hugging Face hub (timm/resnet50_gn.a1h_in1k) HTTP Request: HEAD https://huggingface.co/timm/resnet50_gn.a1h_in1k/resolve/main/model.safetensors "HTTP/1.1 302 Found" Exception ignored in: <function BaseFileLock.__del__ at 0x7fd7639c53f0> Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/filelock/_api.py", line 230, in __del__ self.release(force=True) File "/usr/local/lib/python3.10/site-packages/filelock/_api.py", line 191, in release with self._thread_lock: AttributeError: 'UnixFileLock' object has no attribute '_thread_lock' Traceback (most recent call last): File "/home/circleci/circleci-demo-python-django/deeplabcut/pose_estimation_pytorch/registry.py", line 73, in build_from_cfg return obj_cls(**filtered_args) File "/home/circleci/circleci-demo-python-django/deeplabcut/pose_estimation_pytorch/models/backbones/resnet.py", line 52, in __init__ self.model = timm.create_model( File "/home/circleci/.local/lib/python3.10/site-packages/timm/models/_factory.py", line 138, in create_model model = create_fn( File "/home/circleci/.local/lib/python3.10/site-packages/timm/models/resnet.py", line 1695, in resnet50_gn return _create_resnet('resnet50_gn', pretrained, **dict(model_args, **kwargs)) File "/home/circleci/.local/lib/python3.10/site-packages/timm/models/resnet.py", line 791, in _create_resnet return build_model_with_cfg(ResNet, variant, pretrained, **kwargs) File "/home/circleci/.local/lib/python3.10/site-packages/timm/models/_builder.py", line 457, in build_model_with_cfg load_pretrained( File "/home/circleci/.local/lib/python3.10/site-packages/timm/models/_builder.py", line 226, in load_pretrained state_dict = load_state_dict_from_hf(pretrained_loc, weights_only=True, cache_dir=cache_dir) File "/home/circleci/.local/lib/python3.10/site-packages/timm/models/_hub.py", line 226, in load_state_dict_from_hf cached_safe_file = hf_hub_download( File "/home/circleci/.local/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py", line 89, in _inner_fn return fn(*args, **kwargs) File "/home/circleci/.local/lib/python3.10/site-packages/huggingface_hub/file_download.py", line 1032, in hf_hub_download return _hf_hub_download_to_cache_dir( File "/home/circleci/.local/lib/python3.10/site-packages/huggingface_hub/file_download.py", line 1247, in _hf_hub_download_to_cache_dir with WeakFileLock(lock_path): File "/usr/local/lib/python3.10/contextlib.py", line 135, in __enter__ return next(self.gen) File "/home/circleci/.local/lib/python3.10/site-packages/huggingface_hub/utils/_fixes.py", line 92, in WeakFileLock lock = FileLock(lock_file, timeout=log_interval, mode=0o664) TypeError: BaseFileLock.__init__() got an unexpected keyword argument 'mode'Proposed change:
explicitly include huggingface_hub>=0.23 in the dependencies, so that compatible versions are installed. This should resolve the problem.