-
Notifications
You must be signed in to change notification settings - Fork 8
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
Accelerate Inference in TransformerLens #26
Merged
dest1n1s
merged 13 commits into
main
from
11-proposal-accelerate-inference-in-transformerlens
Jul 3, 2024
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0d1220b
flash-attn update
StarConnor a916e86
use flash-attn source func instead to accomodate llama3 gqa
StarConnor 38af520
update conftest.py (cmd option updated)
StarConnor e6cec69
update pytest file of testing flash attention and attention_mask supp…
StarConnor 20a432d
Merge branch '11-proposal-accelerate-inference-in-transformerlens' of…
StarConnor b85c98e
delete real path
StarConnor a12cc22
Merge branch 'main' of https://github.com/OpenMOSS/Language-Model-SAE…
StarConnor 5447661
changed to install flash-attn by users
StarConnor 90a3361
Merge branch 'main' of https://github.com/OpenMOSS/Language-Model-SAE…
StarConnor 310193e
add flash-attn configuration in examples run files
StarConnor c8c86bd
fix and clean the code after first review
StarConnor 24ac042
Merge branch '11-proposal-accelerate-inference-in-transformerlens' of…
StarConnor b78b52f
Update test_flash_attn.py; move it to `TransformerLens/tests/integrat…
StarConnor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
TransformerLens/tests/unit/components/test_abstract_attention_flash_attn.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from transformer_lens import HookedTransformer | ||
from transformers import AutoModelForCausalLM, AutoTokenizer | ||
import torch | ||
|
||
MODEL_NAMES = { | ||
'gpt2':'gpt2', | ||
'llama3-base':'meta-llama/Meta-Llama-3-8B', | ||
'llama3-instruct':'meta-llama/Meta-Llama-3-8B-Instruct', | ||
} | ||
MODEL_PATHS = { | ||
'gpt2':'path/to/gpt2', | ||
'llama3':'path/to/llama3-base', | ||
'llama3-instruct':'path/to/llama3-instruct', | ||
} | ||
|
||
|
||
def test_hooked_transformer(): | ||
model_name = 'gpt2' | ||
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu") | ||
dtype = torch.bfloat16 | ||
hf_model = AutoModelForCausalLM.from_pretrained( | ||
MODEL_PATHS[model_name], | ||
trust_remote_code=True, | ||
local_files_only=True, | ||
torch_dtype=dtype, | ||
) | ||
|
||
hf_tokenizer:AutoTokenizer = AutoTokenizer.from_pretrained( | ||
MODEL_PATHS[model_name], | ||
trust_remote_code=True, | ||
use_fast=True, | ||
add_bos_token=True, | ||
) | ||
model = HookedTransformer.from_pretrained( | ||
MODEL_NAMES[model_name], | ||
use_flash_attn=False, | ||
device=device, | ||
hf_model=hf_model, | ||
tokenizer=hf_tokenizer, | ||
dtype=dtype, | ||
) | ||
|
||
assert not hasattr(model.blocks[0].attn, 'flash_attn_func'), "AbstractAttention should not have 'flash_attn_func' if set `use_flash_attn=False`" |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ use_ghost_grads = true | |
|
||
[lm] | ||
model_name = "gpt2" | ||
use_flash_attn = false | ||
d_model = 768 | ||
|
||
[dataset] | ||
|
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same issues to
test_flash_attn.py
: do not use real-world model for testing.