huggingfacehttps://huggingface.co/meta-llama文章來源地址http://www.zghlxwxcb.cn/news/detail-811479.html
from transformers import AutoTokenizer, LlamaForCausalLM
PATH_TO_CONVERTED_WEIGHTS = ''
PATH_TO_CONVERTED_TOKENIZER = '' # 一般和模型地址一樣
model = LlamaForCausalLM.from_pretrained(PATH_TO_CONVERTED_WEIGHTS)
tokenizer = AutoTokenizer.from_pretrained(PATH_TO_CONVERTED_TOKENIZER)
prompt = "Hey, are you conscious? Can you talk to me?"
inputs = tokenizer(prompt, return_tensors="pt")
# Generate
generate_ids = model.generate(inputs.input_ids, max_length=30)
tokenizer.batch_decode(generate_ids, skip_special_tokens=True,
clean_up_tokenization_spaces=False)[0]
> Hey, are you conscious? Can you talk to me?\nI'm not conscious, but I can talk to you.
文章來源:http://www.zghlxwxcb.cn/news/detail-811479.html
到了這里,關(guān)于【llm 使用llama 小案例】的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!