-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into bug/onnx_params
- Loading branch information
Showing
20 changed files
with
367 additions
and
54 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# labels: name::llama2_13b author::transformers task::Generative_AI license::apache-2.0 | ||
from turnkeyml.parser import parse | ||
from transformers import LlamaConfig, LlamaForCausalLM | ||
import torch | ||
|
||
torch.manual_seed(0) | ||
|
||
# Parsing command-line arguments | ||
pretrained, batch_size, max_seq_length, model_path = parse( | ||
["pretrained", "batch_size", "max_seq_length", "model_path"] | ||
) | ||
|
||
# Model and input configurations | ||
if pretrained: | ||
if not model_path: | ||
raise ValueError( | ||
"TurnkeyML does not include pretrained weights for LLaMA2 " | ||
"because it has special licensing terms. See for details: " | ||
"https://huggingface.co/docs/transformers/model_doc/llama2" | ||
) | ||
|
||
model = LlamaForCausalLM.from_pretrained(model_path) | ||
else: | ||
config = LlamaConfig( | ||
architectures=["LlamaForCausalLM"], | ||
hidden_size=5120, | ||
intermediate_size=13824, | ||
max_position_embeddings=4096, | ||
num_attention_heads=40, | ||
num_hidden_layers=40, | ||
num_key_value_heads=40, | ||
pad_token_id=0, | ||
vocab_size=32000, | ||
use_cache=True, | ||
) | ||
model = LlamaForCausalLM(config) | ||
|
||
inputs = { | ||
"input_ids": torch.ones(batch_size, max_seq_length, dtype=torch.long), | ||
"attention_mask": torch.ones(batch_size, max_seq_length, dtype=torch.float), | ||
} | ||
|
||
# Call model | ||
# Generate two tokens so that we can instrument both the prefill | ||
# and token generation stages. | ||
# The token generation stage is the invocation that has "past_key_values" | ||
# in the input shape. | ||
model.generate(**inputs, max_length=max_seq_length + 2) |
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,48 @@ | ||
# labels: name::llama2_34b author::transformers task::Generative_AI license::apache-2.0 | ||
from turnkeyml.parser import parse | ||
from transformers import LlamaConfig, LlamaForCausalLM | ||
import torch | ||
|
||
torch.manual_seed(0) | ||
|
||
# Parsing command-line arguments | ||
pretrained, batch_size, max_seq_length, model_path = parse( | ||
["pretrained", "batch_size", "max_seq_length", "model_path"] | ||
) | ||
|
||
# Model and input configurations | ||
if pretrained: | ||
if not model_path: | ||
raise ValueError( | ||
"TurnkeyML does not include pretrained weights for LLaMA2 " | ||
"because it has special licensing terms. See for details: " | ||
"https://huggingface.co/docs/transformers/model_doc/llama2" | ||
) | ||
|
||
model = LlamaForCausalLM.from_pretrained(model_path) | ||
else: | ||
config = LlamaConfig( | ||
architectures=["LlamaForCausalLM"], | ||
hidden_size=8192, | ||
intermediate_size=22016, | ||
max_position_embeddings=4096, | ||
num_attention_heads=64, | ||
num_hidden_layers=48, | ||
num_key_value_heads=8, | ||
pad_token_id=0, | ||
vocab_size=32000, | ||
use_cache=True, | ||
) | ||
model = LlamaForCausalLM(config) | ||
|
||
inputs = { | ||
"input_ids": torch.ones(batch_size, max_seq_length, dtype=torch.long), | ||
"attention_mask": torch.ones(batch_size, max_seq_length, dtype=torch.float), | ||
} | ||
|
||
# Call model | ||
# Generate two tokens so that we can instrument both the prefill | ||
# and token generation stages. | ||
# The token generation stage is the invocation that has "past_key_values" | ||
# in the input shape. | ||
model.generate(**inputs, max_length=max_seq_length + 2) |
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,48 @@ | ||
# labels: name::llama2_70b author::transformers task::Generative_AI license::apache-2.0 | ||
from turnkeyml.parser import parse | ||
from transformers import LlamaConfig, LlamaForCausalLM | ||
import torch | ||
|
||
torch.manual_seed(0) | ||
|
||
# Parsing command-line arguments | ||
pretrained, batch_size, max_seq_length, model_path = parse( | ||
["pretrained", "batch_size", "max_seq_length", "model_path"] | ||
) | ||
|
||
# Model and input configurations | ||
if pretrained: | ||
if not model_path: | ||
raise ValueError( | ||
"TurnkeyML does not include pretrained weights for LLaMA2 " | ||
"because it has special licensing terms. See for details: " | ||
"https://huggingface.co/docs/transformers/model_doc/llama2" | ||
) | ||
|
||
model = LlamaForCausalLM.from_pretrained(model_path) | ||
else: | ||
config = LlamaConfig( | ||
architectures=["LlamaForCausalLM"], | ||
hidden_size=8192, | ||
intermediate_size=28672, | ||
max_position_embeddings=4096, | ||
num_attention_heads=64, | ||
num_hidden_layers=80, | ||
num_key_value_heads=8, | ||
pad_token_id=0, | ||
vocab_size=32000, | ||
use_cache=True, | ||
) | ||
model = LlamaForCausalLM(config) | ||
|
||
inputs = { | ||
"input_ids": torch.ones(batch_size, max_seq_length, dtype=torch.long), | ||
"attention_mask": torch.ones(batch_size, max_seq_length, dtype=torch.float), | ||
} | ||
|
||
# Call model | ||
# Generate two tokens so that we can instrument both the prefill | ||
# and token generation stages. | ||
# The token generation stage is the invocation that has "past_key_values" | ||
# in the input shape. | ||
model.generate(**inputs, max_length=max_seq_length + 2) |
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,48 @@ | ||
# labels: name::llama2_7b author::transformers task::Generative_AI license::apache-2.0 | ||
from turnkeyml.parser import parse | ||
from transformers import LlamaConfig, LlamaForCausalLM | ||
import torch | ||
|
||
torch.manual_seed(0) | ||
|
||
# Parsing command-line arguments | ||
pretrained, batch_size, max_seq_length, model_path = parse( | ||
["pretrained", "batch_size", "max_seq_length", "model_path"] | ||
) | ||
|
||
# Model and input configurations | ||
if pretrained: | ||
if not model_path: | ||
raise ValueError( | ||
"TurnkeyML does not include pretrained weights for LLaMA2 " | ||
"because it has special licensing terms. See for details: " | ||
"https://huggingface.co/docs/transformers/model_doc/llama2" | ||
) | ||
|
||
model = LlamaForCausalLM.from_pretrained(model_path) | ||
else: | ||
config = LlamaConfig( | ||
architectures=["LlamaForCausalLM"], | ||
hidden_size=4096, | ||
intermediate_size=11008, | ||
max_position_embeddings=4096, | ||
num_attention_heads=32, | ||
num_hidden_layers=32, | ||
num_key_value_heads=32, | ||
pad_token_id=0, | ||
vocab_size=32000, | ||
use_cache=True, | ||
) | ||
model = LlamaForCausalLM(config) | ||
|
||
inputs = { | ||
"input_ids": torch.ones(batch_size, max_seq_length, dtype=torch.long), | ||
"attention_mask": torch.ones(batch_size, max_seq_length, dtype=torch.float), | ||
} | ||
|
||
# Call model | ||
# Generate two tokens so that we can instrument both the prefill | ||
# and token generation stages. | ||
# The token generation stage is the invocation that has "past_key_values" | ||
# in the input shape. | ||
model.generate(**inputs, max_length=max_seq_length + 2) |
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,35 @@ | ||
# labels: name::phi2 author::transformers task::Generative_AI license::mit | ||
from turnkeyml.parser import parse | ||
from transformers import AutoModelForCausalLM | ||
import torch | ||
|
||
torch.manual_seed(0) | ||
|
||
# Parsing command-line arguments | ||
pretrained, batch_size, max_seq_length = parse( | ||
["pretrained", "batch_size", "max_seq_length"] | ||
) | ||
|
||
# Model and input configurations | ||
if pretrained: | ||
model = AutoModelForCausalLM.from_pretrained("microsoft/phi-2") | ||
else: | ||
raise ValueError( | ||
"This model is only supported with pretrained weights, try again with --pretrained" | ||
) | ||
|
||
# Make sure the user's sequence length fits within the model's maximum | ||
assert max_seq_length <= model.config.max_position_embeddings | ||
|
||
|
||
inputs = { | ||
"input_ids": torch.ones(batch_size, max_seq_length, dtype=torch.long), | ||
"attention_mask": torch.ones(batch_size, max_seq_length, dtype=torch.float), | ||
} | ||
|
||
# Call model | ||
# Generate two tokens so that we can instrument both the prefill | ||
# and token generation stages. | ||
# The token generation stage is the invocation that has "past_key_values" | ||
# in the input shape. | ||
model.generate(**inputs, max_length=max_seq_length + 2) |
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.