当前位置: 首页> 房产> 建筑 > 北京专业网站翻译影音字幕翻译速记速记速记速而高效_橙子建站官网价格_最近的头条新闻_百度快速排名工具

北京专业网站翻译影音字幕翻译速记速记速记速而高效_橙子建站官网价格_最近的头条新闻_百度快速排名工具

时间:2025/7/12 22:02:42来源:https://blog.csdn.net/wn030416/article/details/146959875 浏览次数:1次
北京专业网站翻译影音字幕翻译速记速记速记速而高效_橙子建站官网价格_最近的头条新闻_百度快速排名工具

以Llama-3.2-1B为例

Llama-3.2-1B · 模型库

安装库

pip install modelscope

运行程序

#模型下载
from modelscope import snapshot_download
model_dir = snapshot_download('LLM-Research/Llama-3.2-1B')

下载好的模型在 C:\Users\Administrator\.cache\modelscope\hub\models\LLM-Research\Llama-3___2-1B

import torch
from transformers import AutoTokenizer, AutoModelForCausalLM# 模型所在目录
model_path = r"C:\Users\Administrator\.cache\modelscope\hub\models\LLM-Research\Llama-3___2-1B"# 加载分词器和模型
try:tokenizer = AutoTokenizer.from_pretrained(model_path)model = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype=torch.float16, use_safetensors=True)
except Exception as e:print(f"加载模型时出现错误: {e}")import syssys.exit(1)# 将模型移到 GPU 上(如果可用)
device = "cuda" if torch.cuda.is_available() else "cpu"
model.to(device)
while True:# 输入文本input_text = input("请输入一些内容: ")# 对输入文本进行分词input_ids = tokenizer.encode(input_text, return_tensors='pt').to(device)# 生成输出try:output = model.generate(input_ids, max_length=150, num_beams=5, no_repeat_ngram_size=2, early_stopping=True)except Exception as e:print(f"生成输出时出现错误: {e}")import syssys.exit(1)# 将输出的 ID 转换为文本output_text = tokenizer.decode(output[0], skip_special_tokens=True)# 打印输入和输出print("输入内容:", input_text)print("输出内容:", output_text)

运行结果(因为模型参数量只有2B,效果不好),成功本地部署人工智障

关键字:北京专业网站翻译影音字幕翻译速记速记速记速而高效_橙子建站官网价格_最近的头条新闻_百度快速排名工具

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: