【GPT模型训练】第一课:安装PyTorch环境
这里写自定义目录标题
- 概述
- 1.安装环境
- 1.1 conda环境
- 1.2 查看自己电脑的CUDA型号
- 1.3 查看pytorch官网版本建议
- 1.4 安装本地的torch
- 测试
概述
为了深入深入理解大模型底层原理,未来更好微调,成为大模型架构师,开始从零到一开发一个大模型实践,实践过程笔记,进行记录,同时,帮志同道合的同学,打平这条学习的道路。
《从零构建大模型》书籍,运行环境配置
PyTorch版本 2.5.1
1.安装环境
1.1 conda环境
conda create --name scrach python=3.10
1.2 查看自己电脑的CUDA型号
命令:mvidia-smi
1.3 查看pytorch官网版本建议
https://pytorch.org/get-started/previous-versions/
- torch2.4.1版本
pip install torch==2.4.1 torchvision==0.19.1 torchaudio==2.4.1 --index-url https://download.pytorch.org/whl/cu118
- torch2.4.0版本 CUDA 11.8
# CUDA 11.8
pip install torch==2.4.0 torchvision==0.19.0 torchaudio==2.4.0 --index-url https://download.pytorch.org/whl/cu118
- torch2.5.1版本
# CUDA 11.8
pip install torch==2.5.1 torchvision==0.20.1 torchaudio==2.5.1 --index-url https://download.pytorch.org/whl/cu118
发现安装过程,主要卡住在下载torch包,该包2.5G,用浏览器或迅雷下载,
安装文件2.5G,可以下载回本地后,安装
1.4 安装本地的torch
pip install “torch-2.5.1+cu118-cp310-cp310-win_amd64.whl”
2.5.1版本,安装剩余模块
pip install torchvision0.20.1 torchaudio2.5.1 --index-url https://download.pytorch.org/whl/cu118
pip install tiktoken==0.7.0
pip install ipykernel
测试
File c:\ProgramData\anaconda3\envs\scratch\lib\site-packages\torch\utils\data\dataloader.py:701, in _BaseDataLoaderIter.__next__(self)698 if self._sampler_iter is None:699 # TODO(https://github.com/pytorch/pytorch/issues/76750)700 self._reset() # type: ignore[call-arg]
--> 701 data = self._next_data()702 self._num_yielded += 1703 if (704 self._dataset_kind == _DatasetKind.Iterable705 and self._IterableDataset_len_called is not None706 and self._num_yielded > self._IterableDataset_len_called707 ):File c:\ProgramData\anaconda3\envs\scratch\lib\site-packages\torch\utils\data\dataloader.py:756, in _SingleProcessDataLoaderIter._next_data(self)755 def _next_data(self):
--> 756 index = self._next_index() # may raise StopIteration
...
File c:\ProgramData\anaconda3\envs\scratch\lib\site-packages\torch\utils\data\sampler.py:125, in SequentialSampler.__iter__(self)124 def __iter__(self) -> Iterator[int]:
--> 125 return iter(range(len(self.data_source)))TypeError: object of type 'GPTDatasetV1' has no len()
检查版本:
把tiktoken改为与书本的环境一致就OK
pip install tiktoken==0.7.0