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

Question/Answer with xgen #16

Open
tonyphoang opened this issue Jul 18, 2023 · 0 comments
Open

Question/Answer with xgen #16

tonyphoang opened this issue Jul 18, 2023 · 0 comments

Comments

@tonyphoang
Copy link

Hi all,

I've been able to get xgen7b to work with sentence completion using GPU but cannot get it to work with question/answer.

The code I'm using is below:

import torch
torch.cuda.empty_cache()
from transformers import AutoTokenizer, AutoModelForCausalLM
device_map = {"cuda:0" if torch.cuda.is_available() else "cpu"}
model_name='Salesforce/xgen-7b-8k-base'

tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
model =AutoModelForCausalLM.from_pretrained(model_name, 
                                            torch_dtype=torch.bfloat16, 
                                            device_map="auto")

header = (
    "You are an artificial intelligence assistant. "
    "The assistant gives helpful, detailed, and polite answers to the human's questions.\n\n"
)
prompt = f"who is the president of the usa?"

inputs = tokenizer(header + prompt, return_tensors="pt").to('cuda')
sample = model.generate(**inputs, max_length=128, do_sample=True, top_k=100, eos_token_id=50256)
print(tokenizer.decode(sample[0]))


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

No branches or pull requests

1 participant