JaphetHernandez commited on
Commit
fea6542
·
verified ·
1 Parent(s): a476167

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -0
app.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+ model_name = "nvidia/Llama-3.1-Nemotron-70B-Instruct-HF"
4
+ model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16, device_map="auto")
5
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
6
+
7
+ prompt = "How many r in strawberry?"
8
+ messages = [{"role": "user", "content": prompt}]
9
+
10
+ tokenized_message = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt", return_dict=True)
11
+ response_token_ids = model.generate(tokenized_message['input_ids'].cuda(),attention_mask=tokenized_message['attention_mask'].cuda(), max_new_tokens=4096, pad_token_id = tokenizer.eos_token_id)
12
+ generated_tokens =response_token_ids[:, len(tokenized_message['input_ids'][0]):]
13
+ generated_text = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)[0]
14
+ print(generated_text)
15
+
16
+ # See response at top of model card