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

[KV Cache] Support for CodeGen #1590

Merged
merged 12 commits into from
Jun 27, 2023
Merged

Conversation

dbogunowicz
Copy link
Contributor

@dbogunowicz dbogunowicz commented May 29, 2023

The implementation of the KV Cache injection for the CodeGen model.
The model that was used for the injection is exported using transformers==4.30.2 (anticipating the incoming internal transformers upgrade)

Feature Preview

see: neuralmagic/deepsparse#1078

Notes:

  • Decided to add a KVCacheConfig class for a clearer interface for setting up KV Cache injection parameter. I like how it makes things more structured, but I see potential disadvantages of its presence. Something I'd definitely like to talk about.
  • Made CacheKeysAndValues transformation more robust and extendable.
  • With this PR in place, the integration of the BLOOM model should not take more than a few hours, all the building blocks are there.
  • The transformations for injecting positions input are lightweight, they share components such as add_position_input methods or a helper function for deleting orphaned nodes.

Graph Changes Post Transformers Upgrade

Codegen:

Positions

Range gets replaced with the positions input

Without KV Cache Injection
image
With KV Cache Injection
image

Attention Block

Without KV Cache Injection
image
With KV Cache Injection
image

OPT:

Attention Block

With KV Cache Injection
image
Without KV Cache Injection
image

Positions

With KV Cache Injection

("Add" node is required, see: https://github.com/huggingface/transformers/blob/main/src/transformers/models/opt/modeling_opt.py#LL105C32-L105C32)
image

Without KV Cache Injection
image

Testing Plan

  • Test that the generated model gives the correct output in the pipeline (CodeGen)
  • Test that the generated model gives correct output in the pipeline (OPT)
  • Test the pathway, where the user provides kwargs instead of model_path to the KVCacheInjector transformation.

@dbogunowicz dbogunowicz changed the base branch from main to feature/damian/4d_kv_cache May 29, 2023 14:59
Base automatically changed from feature/damian/4d_kv_cache to feature/damian/fb_kv_cache June 12, 2023 16:05
Base automatically changed from feature/damian/fb_kv_cache to main June 16, 2023 12:32
@dbogunowicz dbogunowicz marked this pull request as draft June 16, 2023 13:51
@dbogunowicz dbogunowicz force-pushed the feature/damian/kv_cache_codegen branch from 74df8c7 to 87b40fb Compare June 19, 2023 11:32
@neuralmagic neuralmagic deleted a comment from bfineran Jun 19, 2023
@dbogunowicz dbogunowicz marked this pull request as ready for review June 19, 2023 13:17
@dbogunowicz dbogunowicz requested review from bfineran, markurtz and KSGulin and removed request for markurtz June 19, 2023 13:17
KSGulin
KSGulin previously approved these changes Jun 20, 2023
Copy link
Contributor

@KSGulin KSGulin left a comment

Choose a reason for hiding this comment

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

Looks great. Left a couple questions, but they're non-blocking

src/sparseml/exporters/kv_cache_injector.py Outdated Show resolved Hide resolved
src/sparseml/exporters/kv_cache_injector.py Outdated Show resolved Hide resolved
src/sparseml/onnx/utils/graph_editor.py Show resolved Hide resolved
bfineran
bfineran previously approved these changes Jun 21, 2023
Copy link
Member

@bfineran bfineran left a comment

Choose a reason for hiding this comment

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

looks great pending comments

@dbogunowicz dbogunowicz dismissed stale reviews from KSGulin and bfineran via bba3924 June 23, 2023 11:39
@dbogunowicz dbogunowicz merged commit 4a4b324 into main Jun 27, 2023
10 checks passed
@dbogunowicz dbogunowicz deleted the feature/damian/kv_cache_codegen branch June 27, 2023 08:51
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.

None yet

3 participants