Skip to content
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

Create zero_delay_qkv_benchmark.py #35329

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

itsmenick212
Copy link

@itsmenick212 itsmenick212 commented Dec 18, 2024

Implemented Zero-Delay QKV Compression with benchmarking for HuggingFace Transformers to optimize inference runtime.

  • Added CombinedQKVProjection class to replace separate query, key, and value projections with a single linear layer.
  • Modified BERT's attention mechanism by replacing query, key, and value layers with the combined QKV projection.
  • Introduced a replace_attn_qkv_with_combined function to automate the replacement process across all layers.
  • Added a benchmarking utility to compare inference runtime performance before and after QKV compression.
  • Provided a complete example script for testing and benchmarking with dummy data.

This change aims to demonstrate runtime optimizations for inference-heavy use cases in Transformer models.

What does this PR do?

Implemented Zero-Delay QKV Compression with benchmarking for HuggingFace Transformers to optimize inference runtime.

  • Added CombinedQKVProjection class to replace separate query, key, and value projections with a single linear layer.
  • Modified BERT's attention mechanism by replacing query, key, and value layers with the combined QKV projection.
  • Introduced a replace_attn_qkv_with_combined function to automate the replacement process across all layers.
  • Added a benchmarking utility to compare inference runtime performance before and after QKV compression.
  • Provided a complete example script for testing and benchmarking with dummy data.

This change aims to demonstrate runtime optimizations for inference-heavy use cases in Transformer models.

Fixes # (issue)

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

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.

Implemented Zero-Delay QKV Compression with benchmarking for HuggingFace Transformers to optimize inference runtime. 

- Added `CombinedQKVProjection` class to replace separate query, key, and value projections with a single linear layer.
- Modified BERT's attention mechanism by replacing `query`, `key`, and `value` layers with the combined QKV projection.
- Introduced a `replace_attn_qkv_with_combined` function to automate the replacement process across all layers.
- Added a benchmarking utility to compare inference runtime performance before and after QKV compression.
- Provided a complete example script for testing and benchmarking with dummy data.

This change aims to demonstrate runtime optimizations for inference-heavy use cases in Transformer models.
@itsmenick212
Copy link
Author

Implemented Zero-Delay QKV Compression with benchmarking for HuggingFace Transformers to optimize inference runtime.

  • Added CombinedQKVProjection class to replace separate query, key, and value projections with a single linear layer.
  • Modified BERT's attention mechanism by replacing query, key, and value layers with the combined QKV projection.
  • Introduced a replace_attn_qkv_with_combined function to automate the replacement process across all layers.
  • Added a benchmarking utility to compare inference runtime performance before and after QKV compression.
  • Provided a complete example script for testing and benchmarking with dummy data.

This change aims to demonstrate runtime optimizations for inference-heavy use cases in Transformer models.

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.

1 participant