【llm 使用llama 小案例】

huggingfacehttps://huggingface.co/meta-llama

python 复制代码
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.
相关推荐
Warson_L6 小时前
Python的TypedDict
python·langchain·llm
一航jason7 小时前
Android平台推理框架及试用场景模型对比
android·人工智能·ai·架构·ai编程·llama
一航jason7 小时前
Android 端侧大模型推理框架对比
android·人工智能·ai·ai编程·llama·ai-native
XLYcmy8 小时前
面向安全领域决策的大型语言模型漏洞价值评估对齐机制与智能化评级系统研发 研究方向与核心内容
网络安全·llm·sft·cve·cot·对齐·漏洞检测
程序猿编码9 小时前
LLM+Agent 全栈推理底座:Triton 算子优化・语义级缓存・分布式调度
大模型·llm·agent·推理
小白跃升坊9 小时前
大模型推理入门:从原理到实践
ai·大模型·llm·推理优化
武子康10 小时前
把 SGLang 接进 Agent,查一次订单要走几步
人工智能·llm·agent
demo007x11 小时前
让大模型活在你的鼠标旁:我用 Tauri 2 + Rust 打造了一款“反直觉”的 AI 全局划词效率神器
macos·程序员·llm
孙启超11 小时前
【AI开发之Rust】第 3 课:字符串与复合类型 —— 数据怎么放
开发语言·人工智能·后端·rust·llm·transformer
不好听61311 小时前
从朴素到智能:RAG 为什么需要 Agent 化——Agentic RAG 系列之一
llm