Skip to content

🧹 Remove deprecated RotaryEmbedding parts in the Attention layers #34858

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 11 commits into from
Dec 11, 2024

Conversation

Cyrilvallez
Copy link
Member

@Cyrilvallez Cyrilvallez commented Nov 21, 2024

What does this PR do?

This cleans-up the (expired) deprecated cycle for the rotary embeddings and fully move them to the Model instead of the Attention. Also removes deprecated EmbeddingClasses, and fix the tests accordingly.

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

@Cyrilvallez Cyrilvallez changed the title Remove deprecated RotaryEmbedding in the Attention layers 🧹 Remove deprecated RotaryEmbedding in the Attention layers Nov 21, 2024
@Cyrilvallez Cyrilvallez changed the title 🧹 Remove deprecated RotaryEmbedding in the Attention layers 🧹 Remove deprecated RotaryEmbedding parts in the Attention layers Nov 21, 2024
@Cyrilvallez Cyrilvallez marked this pull request as ready for review November 21, 2024 16:06
Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

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

Let's make sure we only remove where it is needed, make mandatory and should be good to go!

Comment on lines -317 to -319
kv_seq_len = key_states.shape[-2]
if past_key_value is not None:
kv_seq_len += cache_position[0]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unwanted change I think

Copy link
Member Author

Choose a reason for hiding this comment

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

Nop, this is actually doing nothing (never used, no purpose here) so I cleaned it up!

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed not linked to the rotary though, but as I'm cleaning stuff, let's remove it as the same time

@Cyrilvallez
Copy link
Member Author

@ArthurZucker should be good to go!

@Cyrilvallez Cyrilvallez mentioned this pull request Dec 4, 2024
5 tasks
Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

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

Nice, btw one thing we can include: default rope initialization should be in the function itself!

@Cyrilvallez Cyrilvallez merged commit d363e71 into main Dec 11, 2024
20 checks passed
@Cyrilvallez Cyrilvallez deleted the rotary branch December 11, 2024 10:16
@ydshieh
Copy link
Collaborator

ydshieh commented Dec 11, 2024

Looks like there is a regression?

https://app.circleci.com/pipelines/github/huggingface/transformers/113239/workflows/d8800ea1-6599-4640-95cb-e9c558496c41/jobs/1512452

@Cyrilvallez Cyrilvallez mentioned this pull request Dec 11, 2024
@Cyrilvallez
Copy link
Member Author

True! Aria relies on Llama and was merged in the meantime - #35208 correctly reapplies new Llama change to Aria

BenjaminBossan added a commit to BenjaminBossan/peft that referenced this pull request Dec 12, 2024
This PR resolves the failing adoption prompt tests in the CI using
transformers installed from source.

In this transformers PR:

huggingface/transformers#34858

the module.rotary_emb attribute has been removed, which adoption prompt
so far assumed was present. Instead, the position_embeddings are now
already computed and can be taken directly from the kwargs.
BenjaminBossan added a commit to BenjaminBossan/peft that referenced this pull request Dec 12, 2024
This PR resolves the failing adoption prompt tests in the CI using
transformers installed from source.

In this transformers PR:

huggingface/transformers#34858

the module.rotary_emb attribute has been removed, which adoption prompt
so far assumed was present. Instead, the position_embeddings are now
already computed and can be taken directly from the kwargs.
BenjaminBossan added a commit to huggingface/peft that referenced this pull request Dec 13, 2024
This PR resolves the failing adoption prompt tests in the CI using
transformers installed from source.

In this transformers PR:

huggingface/transformers#34858

the module.rotary_emb attribute has been removed, which adoption prompt
so far assumed was present. Instead, the position_embeddings are now
already computed and can be taken directly from the kwargs.
dsikka added a commit to vllm-project/llm-compressor that referenced this pull request Feb 11, 2025
## Purpose ##
* SparseGPT
* Fix behavior where `targets` specifies which modules to sparsity, not
which layers to target
  * Fix broken behavior with `_infer_owl_layer_sparsity` and add test
  * Fix owl argument validation
  * Add type hints and abstract methods for clarity
* Pipelines
* Fix bug revealed by decorators added to the llama model definition in
the latest transformers release
    * huggingface/transformers#35757
* For the sequential pipeline, this revealed a bug in
torch.fx._symbolic_trace where wrapped functions were not being handled
properly
    * Future work could involve upstreaming a bug fix
  * Fix issue caused by changes to llama model definition
    * huggingface/transformers#34858
* For the layer sequential pipeline, this challenges the assumption that
each layer input is the previous layer's output (which was known to be a
fragile assumption)
  * Fix issue related to basic pipeline slowdowns and inaccuracy

## Changes ##
* SparseGPT
  * Fully separate `targets` and `sequential_targets`
    * Modify hooks adding logic to reflect this change
  * Fix behavior of `_infer_owl_layer_sparsity` and add test
  * Code clarity
    * Add additional type hints
* Designate `calibrate_module` as an abstract method on the sgpt mixin
* Pipelines
* Sequential pipeline: unwrap model forward function to avoid issues
with pytorch function patching
* Layer Sequential Pipeline: Add `maybe_inject_pos_embeddings` to
sequential pipeline to hackily support models with `position_embeddings`
* Basic Pipeline: Fix `on_sequential_batch_end` to call on the end of
epoch, rather than every batch
    * Calling every batch was likely causing slowdowns

## Followups ##
* Remove deprecated `sequential_update` option from examples and tests

## Testing ##
* Added `tests/llmcompressor/transformers/obcq/test_obcq_owl.py`
* Tested OBCQ+llama with sequential, layer sequential, and basic
pipelines independently

## Regression Evaluations ##
Models were compressed using
`examples/sparse_2of4_quantization_fp8/llama3_8b_2of4.py` without fp8
option

<details><summary>sparsegpt</summary>

Main
```
vllm (pretrained=/home/kyle/llm-compressor/Meta-Llama-3-8B-InstructSparseGPTModifierMAIN,dtype=bfloat16,add_bos_token=True), gen_kwargs: (None), limit: None, num_fewshot: 5, batch_size: 1
|  Tasks   |Version|Filter|n-shot|Metric|   |Value |   |Stderr|
|----------|------:|------|-----:|------|---|-----:|---|-----:|
|winogrande|      1|none  |     5|acc   |↑  |0.6243|±  |0.0136|
```

This branch

```
vllm (pretrained=/home/kyle/llm-compressor/Meta-Llama-3-8B-InstructSparseGPTModifierFEATURE,dtype=bfloat16,add_bos_token=True), gen_kwargs: (None), limit: None, num_fewshot: 5, batch_size: 1
|  Tasks   |Version|Filter|n-shot|Metric|   |Value |   |Stderr|
|----------|------:|------|-----:|------|---|-----:|---|-----:|
|winogrande|      1|none  |     5|acc   |↑  |0.6306|±  |0.0136|
```
</details>

To test wanda, the `SparseGPTModifier` was replaced with the
`WandaPruningModifier`

<details><summary>wanda</summary>

Main
```
vllm (pretrained=/home/kyle/llm-compressor/Meta-Llama-3-8B-InstructWandaPruningModifierMAIN,dtype=bfloat16,add_bos_token=True), gen_kwargs: (None), limit: None, num_fewshot: 5, batch_size: 1
|  Tasks   |Version|Filter|n-shot|Metric|   |Value |   |Stderr|
|----------|------:|------|-----:|------|---|-----:|---|-----:|
|winogrande|      1|none  |     5|acc   |↑  |0.5912|±  |0.0138|
```

This branch
```
vllm (pretrained=/home/kyle/llm-compressor/Meta-Llama-3-8B-InstructWandaPruningModifierFEATURE,dtype=bfloat16,add_bos_token=True), gen_kwargs: (None), limit: None, num_fewshot: 5, batch_size: 1
|  Tasks   |Version|Filter|n-shot|Metric|   |Value |   |Stderr|
|----------|------:|------|-----:|------|---|-----:|---|-----:|
|winogrande|      1|none  |     5|acc   |↑  |0.5817|±  |0.0139|
```
</details>

---------

Signed-off-by: Kyle Sayers <[email protected]>
Co-authored-by: Dipika Sikka <[email protected]>
Guy-Bilitski pushed a commit to Guy-Bilitski/peft that referenced this pull request May 13, 2025
This PR resolves the failing adoption prompt tests in the CI using
transformers installed from source.

In this transformers PR:

huggingface/transformers#34858

the module.rotary_emb attribute has been removed, which adoption prompt
so far assumed was present. Instead, the position_embeddings are now
already computed and can be taken directly from the kwargs.
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.

4 participants