Skip to content

[docs] Regional compilation docs #11556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 15, 2025
Merged

[docs] Regional compilation docs #11556

merged 6 commits into from
May 15, 2025

Conversation

sayakpaul
Copy link
Member

What does this PR do?

huggingface/accelerate#3529

the repeated blocks of the provided `nn.Module`.

```py
# Make sure you're on the latest `accelerate`: `pip install -U accelerate`.
Copy link
Member Author

Choose a reason for hiding this comment

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

Merge after accelerate new version is released this week.

Copy link
Member

Choose a reason for hiding this comment

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

released !

@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.

Comment on lines 85 to 87
Enabling regional compilation might require simple yet intrusive changes to the
modeling code. However, 🤗 Accelerate provides a utility [`compile_regions()`](https://huggingface.co/docs/accelerate/main/en/usage_guides/compilation#how-to-use-regional-compilation) which automatically _only_ compiles
the repeated blocks of the provided `nn.Module`.
Copy link
Member

Choose a reason for hiding this comment

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

no we actually compile the rest of the model as well 😅 I found out in my post that some people thought only the encoder/decoder block will be compiled in regional, which is not true.
I changed the docs to be more explicit huggingface/accelerate#3572 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

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

👁️ But https://docs.pytorch.org/tutorials/recipes/regional_compilation.html suggests a completely different recipe no? No full compilation but only regional and I always thought that is what should be done.

What am I missing?

Copy link
Member

@IlyasMoutawwakil IlyasMoutawwakil May 15, 2025

Choose a reason for hiding this comment

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

regional compilation is simply: cut into regions and then compile those regions. I didn't compare the two approaches but I believe in the context of the pytorch tutorial they were simply trying to reduce cold start, not trying to keep inference optimized as well (they didn't benchamrk inference).

Copy link
Member Author

@sayakpaul sayakpaul May 15, 2025

Choose a reason for hiding this comment

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

So

  1. inference latency of compiling full model >= inference latency of regionally compiling repeated blocks + compiling additional blocks in a model
  2. cold start time of compiling full model >> cold start time of regionally compiling repeated blocks + compiling additional blocks in a model

Is my understanding right or is it still fragmented?

Do you think providing an option to NOT compile the rest of the blocks could still make sense?

Copy link
Member

@IlyasMoutawwakil IlyasMoutawwakil May 15, 2025

Choose a reason for hiding this comment

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

yes that is how it works !

Do you think providing an option to NOT compile the rest of the blocks could still make sense?

doesn't make sense for me personally, since you will miss on the tuning of the task-specific head. Do you have any specific cases where we don't want to compile the rest of the model ?

Copy link
Member

@SunMarc SunMarc left a comment

Choose a reason for hiding this comment

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

Thanks !

@sayakpaul sayakpaul merged commit 9836f0e into main May 15, 2025
5 checks passed
@sayakpaul sayakpaul deleted the regional-compilation-docs branch May 15, 2025 13:41
@DN6 DN6 added the roadmap Add to current release roadmap label Jun 5, 2025
@DN6 DN6 moved this from In Progress to Done in Diffusers Roadmap 0.34 Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
roadmap Add to current release roadmap
Projects
Development

Successfully merging this pull request may close these issues.

5 participants