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

Add Llama2 Onnx Model E2E test #19417

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import argparse

from optimum.onnxruntime import ORTModelForCausalLM
from transformers import AutoTokenizer, pipeline


def get_args():
parser = argparse.ArgumentParser()
parser.add_argument(
"--model_dir",
required=True,
help="model direcotory, including config.json and tokenizer.model",
)
parser.add_argument(
"--prompt",
required=True,
help="prompt string for the model to generate text from. e.g. 'question: What is the lightest element?'",
)
args = parser.parse_args()
return args


def main():
args = get_args()
model_dir = args.model_dir

model = ORTModelForCausalLM.from_pretrained(model_dir)
tokenizer = AutoTokenizer.from_pretrained(model_dir)
ort_llama2_generator = pipeline("text-generation", model=model, tokenizer=tokenizer, device="cuda:0")

sequences = ort_llama2_generator(
args.prompt,
do_sample=False,
num_return_sequences=1,
eos_token_id=tokenizer.eos_token_id,
pad_token_id=tokenizer.pad_token_id,
max_new_tokens=256,
return_full_text=False,
repetition_penalty=1.1,
)
print(sequences[0]["generated_text"])


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"_name_or_path": "/home/azureuser/git/onnxruntime/onnxruntime/python/tools/transformers/Llama-2-7b-hf/config.json",
"architectures": [
"LlamaForCausalLM"
],
"attention_bias": false,
"attention_dropout": 0.0,
"bos_token_id": 1,
"eos_token_id": 2,
"hidden_act": "silu",
"hidden_size": 4096,
"initializer_range": 0.02,
"intermediate_size": 11008,
"max_position_embeddings": 4096,
"model_type": "llama",
"num_attention_heads": 32,
"num_hidden_layers": 32,
"num_key_value_heads": 32,
"pretraining_tp": 1,
"rms_norm_eps": 1e-05,
"rope_scaling": null,
"rope_theta": 10000.0,
"tie_word_embeddings": true,
"torch_dtype": "float16",
"transformers_version": "4.37.2",
"use_cache": true,
"vocab_size": 32000
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

The answer to this question is that hydrogen is the lightest element. Hydrogen has an atomic number of 1 and a mass number of 1, which means it only contains one proton in its nucleus. This makes it much lighter than other elements with higher atomic numbers or mass numbers.
Hydrogen also has a very low density compared to other elements due to its small size and low atomic weight (one-twelfth that of carbon). As such, it can be found in many different forms including gas, liquid, solid crystals and even plasma formations within stars like our sun!
What Is The Lightest Element In The Periodic Table?
The lightest element in the periodic table is helium. Helium is a noble gas and has two electrons in its outer shell, making it unreactive with most substances. It’s also extremely rare on Earth because it’s so lightweight – just one atom weighs less than four hydrogen atoms combined!
Helium was first discovered by Sir William Ramsay and Lord Rayleigh in 1895 when they isolated samples from air using liquefaction techniques at low temperatures (-269°C).
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"bos_token": {
"content": "<s>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false
},
"eos_token": {
"content": "</s>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false
},
"unk_token": {
"content": "<unk>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false
}
}
Loading
Loading