Skip to content

Fix custom generate from local directory#38916

Merged
manueldeprada merged 1 commit intohuggingface:mainfrom
manueldeprada:fix-custom-generate-local
Jun 20, 2025
Merged

Fix custom generate from local directory#38916
manueldeprada merged 1 commit intohuggingface:mainfrom
manueldeprada:fix-custom-generate-local

Conversation

@manueldeprada
Copy link
Copy Markdown
Contributor

@manueldeprada manueldeprada commented Jun 19, 2025

Passing a local folder to custom_generate via model.generate(**inputs, custom_generate="custom_generate_example", ...) fails because

  1. shutil.copy in src/transformers/dynamic_module_utils.py silently fails if the parent directory structure doesn't exist.
  2. The relative imports do not get correctly copied to the fresh submodule in .cache.

So, this PR does:

  1. Create parent dirs before copying files (custom_generate dir)
  2. Correctly copy relative import files to the submodule folder.
  3. Update docs.

@manueldeprada manueldeprada requested a review from gante June 19, 2025 15:11
@HuggingFaceDocBuilderDev
Copy link
Copy Markdown

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.

@manueldeprada manueldeprada force-pushed the fix-custom-generate-local branch from 4369eaa to df03945 Compare June 20, 2025 09:41
1. Create parent dirs before copying files (custom_generate dir)
2. Correctly copy relative imports to the submodule file.
3. Update docs.
@manueldeprada manueldeprada force-pushed the fix-custom-generate-local branch from df03945 to 114b57d Compare June 20, 2025 10:01
@manueldeprada manueldeprada requested a review from stevhliu June 20, 2025 10:03
@manueldeprada manueldeprada enabled auto-merge (squash) June 20, 2025 10:06
Copy link
Copy Markdown
Contributor

@gante gante left a comment

Choose a reason for hiding this comment

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

LGTM :)

Missing: a test. E.g. we can add a custom_generate folder in tests/fixtures and test we can run it in GenerationIntegrationTests

@manueldeprada manueldeprada merged commit 166e823 into huggingface:main Jun 20, 2025
20 checks passed
manueldeprada added a commit to manueldeprada/transformers that referenced this pull request Jun 24, 2025
manueldeprada added a commit that referenced this pull request Jun 26, 2025
…39015)

* create test for #38916 (custom generate from local dir with imports)
zaristei pushed a commit to zaristei/transformers that referenced this pull request Sep 9, 2025
…h imports) (huggingface#39015)

* create test for huggingface#38916 (custom generate from local dir with imports)
zaristei pushed a commit to zaristei/transformers that referenced this pull request Sep 9, 2025
…h imports) (huggingface#39015)

* create test for huggingface#38916 (custom generate from local dir with imports)
zaristei pushed a commit to zaristei/transformers that referenced this pull request Sep 9, 2025
…h imports) (huggingface#39015)

* create test for huggingface#38916 (custom generate from local dir with imports)
zaristei pushed a commit to zaristei/transformers that referenced this pull request Sep 9, 2025
…h imports) (huggingface#39015)

* create test for huggingface#38916 (custom generate from local dir with imports)
zaristei pushed a commit to zaristei/transformers that referenced this pull request Sep 9, 2025
…h imports) (huggingface#39015)

* create test for huggingface#38916 (custom generate from local dir with imports)
zaristei pushed a commit to zaristei/transformers that referenced this pull request Sep 9, 2025
…h imports) (huggingface#39015)

* create test for huggingface#38916 (custom generate from local dir with imports)
zaristei pushed a commit to zaristei/transformers that referenced this pull request Sep 9, 2025
…h imports) (huggingface#39015)

* create test for huggingface#38916 (custom generate from local dir with imports)
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