赞
踩
git clone https://github.com/yangjianxin1/GPT2-chitchat.git
把项目拉下来
下载模型文件: 从[模型分享]中下载模型文件,例如 model_epoch40_50w
。
将模型文件放到正确的位置: 将下载的模型文件夹 model_epoch40_50w
放到项目的 model
目录下。
安装依赖: 进入项目目录,确保你的环境满足 requirements.txt
中指定的依赖。你可以运行以下命令:
pip install -r requirements.txt
运行交互式对话: 执行 interact.py
文件,指定模型路径。如果你想使用 GPU 进行生成,可以添加 --device gpu_id
参数,其中 gpu_id
是你要使用的 GPU 的编号。
python interact.py --model_path model/model_epoch40_50w --device 0
如果你想在 CPU 上运行,可以添加 --no_cuda
参数:
python interact.py --model_path model/model_epoch40_50w --no_cuda
与模型进行对话: 运行上述命令后,你可以与训练好的模型进行对话。在对话中输入 Ctrl+Z 可以结束对话,并聊天记录将保存到 sample/sample.txt
文件中。
确保你的环境中已经安装了 Python 3.6、transformers==4.2.0
和 pytorch==1.7.0
。
安装实例
# 安装 transformers 4.2.0
pip install transformers==4.2.0
# 安装 PyTorch 1.7.0(CPU版本)
pip install torch==1.7.0+cpu torchvision==0.8.1+cpu torchaudio==0.7.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
如果使用 GPU,可以使用以下命令:
# 安装 PyTorch 1.7.0(GPU版本,适用于 CUDA 11.0)
pip install torch==1.7.0+cu110 torchvision==0.8.1+cu110 torchaudio==0.7.0+cu110 -f https://download.pytorch.org/whl/torch_stable.html
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。