feat: Add torch.compile support for ~2x faster inference#16
Merged
Conversation
- Add HEARTMULA_COMPILE and HEARTMULA_COMPILE_MODE environment variables - Add apply_torch_compile() function that compiles backbone and decoder - Auto-detect Triton availability (inductor vs eager backend) - Support compile modes: default, reduce-overhead, max-autotune - Update create_quantized_pipeline() with compile_model/compile_mode params - Apply torch.compile to both quantized and non-quantized pipelines - Update .env.example with new configuration options - Update README.md with torch.compile documentation Note: First generation will be slower due to compilation, but subsequent generations benefit from the compiled kernels (~2x speedup on RTX 4090, A100). Requirements: - PyTorch 2.0+ - Linux/WSL2: pip install triton - Windows: pip install -U 'triton-windows>=3.2,<3.3'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds support for PyTorch 2.0+
torch.compileto significantly improve inference speed (~2x on supported GPUs like RTX 4090, A100).Changes
New Environment Variables
HEARTMULA_COMPILE: Enable torch.compile (true/false, default:false)HEARTMULA_COMPILE_MODE: Compile optimization mode (default/reduce-overhead/max-autotune)Code Changes
apply_torch_compile()function that compiles the model backbone and decodercreate_quantized_pipeline()with compile parametersDocumentation
.env.examplewith new configuration optionsUsage
Requirements
pip install tritonpip install -U 'triton-windows>=3.2,<3.3'Notes
Related
This implements a feature similar to heartlib PR #64.