Skip to content

Fix huggingface_hub and filelock dependency issue#3204

Merged
MMathisLab merged 3 commits intomainfrom
jaap/update_filelock_dependencies
Feb 10, 2026
Merged

Fix huggingface_hub and filelock dependency issue#3204
MMathisLab merged 3 commits intomainfrom
jaap/update_filelock_dependencies

Conversation

@deruyter92
Copy link
Copy Markdown
Collaborator

@deruyter92 deruyter92 commented Feb 10, 2026

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.

@deruyter92 deruyter92 marked this pull request as ready for review February 10, 2026 09:47
@MMathisLab MMathisLab merged commit 508c8db into main Feb 10, 2026
11 checks passed
@MMathisLab MMathisLab deleted the jaap/update_filelock_dependencies branch February 10, 2026 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants