VinAIResearch / PhoGPT

PhoGPT: Generative Pre-training for Vietnamese (2023)
Apache License 2.0
744 stars 65 forks source link

Temporarily set the `instruct` version private #4

Closed datquocnguyen closed 11 months ago

datquocnguyen commented 11 months ago

We temporarily set the instruct version private to reinvestigate its safety level. We will make it public within this week.

datquocnguyen commented 11 months ago

Available, works with all transformers version.

hacbachvotu commented 11 months ago

z4876691733259_7426ad5b582f9fc096dcd0181a9a32fa Why do I get this error, author?

datquocnguyen commented 11 months ago

code?

hacbachvotu commented 11 months ago

code?

z4876767591002_1b2f96f80a718b30c9094f1c0ba59dd0 z4876766864816_c738b76f6dc21941b2efede54fc17c12 Here it is, thanks for your support!

datquocnguyen commented 11 months ago

does the following code work in your side?

from transformers import AutoConfig, AutoModelForCausalLM, AutoTokenizer  

model_path = "vinai/PhoGPT-7B5-Instruct"  

config = AutoConfig.from_pretrained(model_path, trust_remote_code=True)  
config.init_device = "cuda"
# config.attn_config['attn_impl'] = 'triton' # Enable if "triton" installed!

model = AutoModelForCausalLM.from_pretrained(  
    model_path, config=config, torch_dtype=torch.bfloat16, trust_remote_code=True  
)
# If your GPU does not support bfloat16:
# model = AutoModelForCausalLM.from_pretrained(model_path, config=config, torch_dtype=torch.float16, trust_remote_code=True)
model.eval()  

tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)  

PROMPT = "### Câu hỏi:\n{instruction}\n\n### Trả lời:"  

input_prompt = PROMPT.format_map(  
    {"instruction": "xin chào"}  
)  

input_ids = tokenizer(input_prompt, return_tensors="pt")  

outputs = model.generate(  
    inputs=input_ids["input_ids"].to("cuda"),  
    attention_mask=input_ids["attention_mask"].to("cuda"),  
    do_sample=True,  
    temperature=1.0,  
    top_k=50,  
    top_p=0.9,  
    max_new_tokens=1024,  
    eos_token_id=tokenizer.eos_token_id,  
    pad_token_id=tokenizer.pad_token_id  
)  

response = tokenizer.batch_decode(outputs, skip_special_tokens=True)[0]  
response = response.split("### Trả lời:")[1]
hacbachvotu commented 11 months ago

does the following code work in your side?

from transformers import AutoConfig, AutoModelForCausalLM, AutoTokenizer  

model_path = "vinai/PhoGPT-7B5-Instruct"  

config = AutoConfig.from_pretrained(model_path, trust_remote_code=True)  
config.init_device = "cuda"
# config.attn_config['attn_impl'] = 'triton' # Enable if "triton" installed!

model = AutoModelForCausalLM.from_pretrained(  
    model_path, config=config, torch_dtype=torch.bfloat16, trust_remote_code=True  
)
# If your GPU does not support bfloat16:
# model = AutoModelForCausalLM.from_pretrained(model_path, config=config, torch_dtype=torch.float16, trust_remote_code=True)
model.eval()  

tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)  

PROMPT = "### Câu hỏi:\n{instruction}\n\n### Trả lời:"  

input_prompt = PROMPT.format_map(  
    {"instruction": "xin chào"}  
)  

input_ids = tokenizer(input_prompt, return_tensors="pt")  

outputs = model.generate(  
    inputs=input_ids["input_ids"].to("cuda"),  
    attention_mask=input_ids["attention_mask"].to("cuda"),  
    do_sample=True,  
    temperature=1.0,  
    top_k=50,  
    top_p=0.9,  
    max_new_tokens=1024,  
    eos_token_id=tokenizer.eos_token_id,  
    pad_token_id=tokenizer.pad_token_id  
)  

response = tokenizer.batch_decode(outputs, skip_special_tokens=True)[0]  
response = response.split("### Trả lời:")[1]

z4876946639218_adda9a67200c95d05dac20fe8aecb598

I created a python file and used the code you sent, edited the path to the model in the internal drive and got this error. EDIT: I just imported "import torch" into the python file.