Skip to content

fix: keep keyword-only kwargs in select_compatible_kwargs - #2039

Merged
jlarson4 merged 1 commit into
TransformerLensOrg:devfrom
nurlanmnn-open-source:fix-hf-kwonly-kwargs
Nov 19, 2026
Merged

jlarson4 merged 1 commit into
TransformerLensOrg:devfrom
nurlanmnn-open-source:fix-hf-kwonly-kwargs

Conversation

@nurlanmnn

Copy link
Copy Markdown

Description

utils.download_file_from_hf was quietly throwing away options like revision and local_files_only, so asking for a pinned revision still downloaded the latest file. The helper that filters the kwargs only looked at positional parameters, and those options are keyword-only in hf_hub_download. This switches the helper to inspect.signature, which sees keyword-only parameters and follows the decorator on hf_hub_download. Unknown keys are still dropped like before.

Fixes #2038

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (none needed)
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have not rewritten tests relating to key interfaces which would affect backward compatibility

Tests: uv run pytest tests/unit/utilities/test_hf_utils.py gives 30 passed. The 3 new tests (keyword-only params kept, functools.wraps followed, download_file_from_hf forwards revision/local_files_only to a mocked hf_hub_download) fail on dev and pass with this change. No network is used. isort/black are clean, and mypy on the two files shows no new errors (the 2 __func__ errors at test_hf_utils.py:147/149 are already on dev).

I used an AI coding assistant to help find and fix this, and I reviewed and tested the change myself.

🤖 Generated with Claude Code

select_compatible_kwargs filtered on inspect.getfullargspec(...).args,
which lists only positional-or-keyword parameters and does not follow
functools.wraps. In huggingface_hub, hf_hub_download takes revision,
local_files_only, token and the rest as keyword-only, so
download_file_from_hf silently dropped all of them.

Filter on inspect.signature(...).parameters and keep both
positional-or-keyword and keyword-only names.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@jlarson4 jlarson4 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for putting this together @nurlanmnn! It is approved, assuming it passes CI. I will keep an eye on it and ping you if anything comes up that needs your attention. If nothing comes up, I will merge.

@jlarson4
jlarson4 merged commit 065bbcc into TransformerLensOrg:dev Nov 19, 2026
31 checks passed
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