网站建设购买什么境外主机,做行政关注什么类型的网站,欧米茄官方手表价格,目前做网站流行的语言1.安装anaconda#xff0c;安装python 安装torch等参考网上资料非常多 不细描述
2.参考微软官网【在windows上通过DirectML启用Pytorch文档#xff0c;检查系统版本 检查gpu版本
3.参考微软官网【在windows上通过DirectML启用Pytorch】文档#xff0c;安装torch_directml模…1.安装anaconda安装python 安装torch等参考网上资料非常多 不细描述
2.参考微软官网【在windows上通过DirectML启用Pytorch文档检查系统版本 检查gpu版本
3.参考微软官网【在windows上通过DirectML启用Pytorch】文档安装torch_directml模块
4.参考微软官网【在windows上通过DirectML启用Pytorch】文档验证设备是否可用。
5.下载phi-3模型
6.运行模型
import torch
import torch_directml
from transformers import Phi3Model,Phi3Config
from transformers import AutoTokenizer,pipeline
dmltorch_directml,device(0) #0为GPU设备index
torch.set_default_device(dml)
model_dir./ #模型所在文件路径
configuration Phi3Config.from_pretrained(model_dir)
modelPhi3Model(configuration)tokenizer AutoTokenizer.from_pretrained(model_dir)messages[{role:system,content:who are you}]
pipe pipeline(text-generation,modelmodel,tokenizertokenizer)generation_args {
max_new_tokens:500,
return_full_text,False,
temperature:0.0,
do_sample:False,
}
output pipe(message,**generation_args)
print(output[0][generated_text])有两点要特别讲一下第一可用使用 torch_directml.device_name(0)来查看具体使用的是哪个显卡。
第二我有安装onnxruntime但是好像不安装也可以这点没有验证。
最后要说明一下我上面的代码并没有进行完全验证主要是在执行到加载模型处因显卡内存不足程序退出。