Skip to content

[AutoModel] Fix bug with subfolders and local model paths when loading custom code#13197

Merged
DN6 merged 2 commits intomainfrom
dynamic-module
Mar 2, 2026
Merged

[AutoModel] Fix bug with subfolders and local model paths when loading custom code#13197
DN6 merged 2 commits intomainfrom
dynamic-module

Conversation

@DN6
Copy link
Collaborator

@DN6 DN6 commented Feb 28, 2026

What does this PR do?

When loading custom code from a local path with AutoModel, the subfolder argument is not properly handled in get_cached_module_file. This results in this check for a valid file path failing and a local path being passed to hf_hub_download, which throws an error.

if os.path.isfile(module_file_or_url):

e.g. This currently fails

model = AutoModel.from_pretrained("<my_local_path>", subfolder="transformer", trust_remote_code=True)

but this works because the full local path is provided.

model = AutoModel.from_pretrained("<my_local_path>/transformer", trust_remote_code=True)

This PR adds a check to handle subfolder properly when fetching local files.

Fixes # (issue)

Before submitting

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@DN6 DN6 requested a review from yiyixuxu February 28, 2026 06:33
@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Collaborator

@yiyixuxu yiyixuxu left a comment

Choose a reason for hiding this comment

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

thanks!

@DN6 DN6 merged commit e7fe4ce into main Mar 2, 2026
12 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.

3 participants