在用vscode jupyter训模型
遇到了内核崩溃
The Kernel crashed while executing code in the the current cell or a previous cell. Please review the code in the cell(s) to identify a possible cause of the failure. Click here for more info. View Jupyter log for further details
所以我打算重新配一个conda环境 以后遇到问题直接找自己的帖子
1. 环境设计目标
- 稳定性:避免之前的 encodings 模块缺失问题,确保标准库完整。
- 性能:充分利用 A100 GPU 的计算能力,支持混合精度训练和大规模模型。
- 兼容性:支持 PyTorch、NumPy、SciPy、Matplotlib 等核心库,以及 Jupyter 笔记本。
- 可扩展性:便于未来添加新模型(如 Transformer 变体)或数据处理工具。
- 版本一致性:使用与当前项目兼容的库版本,避免冲突。
2. 环境配置详情
2.1 基本信息
- 环境名称:dem_reconstruction_env(建议名称,方便识别项目用途)。
- Python 版本:3.8(与你当前环境一致,兼容现有代码)。
- 操作系统:假设 Linux(基于 /home/liukunkai 路径,适合 A100 GPU)。
- Conda 版本:最新稳定版(确保包管理器正常工作)。
2.2 依赖库
以下是推荐的库及其版本,涵盖项目核心需求和开发支持:
- Python:python=3.8
- 提供标准库(包括 encodings)和兼容性。
- PyTorch:pytorch=2.3.0 torchvision=0.18.0 cudatoolkit=12.1
- 最新稳定版,支持 A100 GPU(CUDA 12.1),启用混合精度训练。
- 从 PyTorch 官方 Conda 通道安装,确保 CUDA 兼容性。
- NumPy:numpy=1.24.3
- 数据处理和数组操作,兼容 SciPy 和 PyTorch。
- SciPy:scipy=1.10.1
- 支持样条插值和数值计算。
- Matplotlib:matplotlib=3.7.1
- 可视化 DEM 数据(等高线图)。
- Scikit-Image:scikit-image=0.20.0
- 计算 MSE 和 SSIM 指标。
- Jupyter:jupyter=1.0.0 notebook=7.1.2
- 支持交互式开发和内核管理。
- IPython:ipython=8.12.0
- 增强 Jupyter 体验。
- Tqdm:tqdm=4.65.0
- 训练进度条,方便监控。
- Pandas:pandas=2.0.1
- 数据分析和结果记录(可选,但推荐)。
- Pillow:pillow=9.5.0
- 图像处理支持(用于保存可视化图)。
2.3 硬件优化
- GPU 支持:
- A100 使用 CUDA 12.1,确保 PyTorch 与 NVIDIA 驱动兼容。
- 安装 nvidia-cuda-toolkit(通过 Conda 自动配置)。
- 混合精度:
- PyTorch 2.3.0 内置 torch.cuda.amp 支持,利用 A100 的 FP16 能力。
- 批量大小:
- 环境支持批量大小 128(与 Swin-Unet 设计匹配),A100 80GB 显存足够。
2.4 开发工具
- Conda:用于环境管理和包安装。
- Jupyter Kernel:自定义内核,便于在 Jupyter 中选择该环境。
- Git(可选):git=2.39.2
- 版本控制,方便代码管理。
-
3. 创建环境步骤
-
3.1 安装最新 Conda
确保 Conda 是最新版本:
bash
Copy
conda update -n base conda3.2 创建新环境
运行以下命令创建 dem_reconstruction_env:
bash
Copy
conda create -n dem_reconstruction_env python=3.8 conda activate dem_reconstruction_env3.3 安装核心依赖
安装 PyTorch 和其他库:
bash
Copy
conda install pytorch=2.3.0 torchvision=0.18.0 cudatoolkit=12.1 -c pytorch conda install numpy=1.24.3 scipy=1.10.1 matplotlib=3.7.1 scikit-image=0.20.0 jupyter=1.0.0 notebook=7.1.2 ipython=8.12.0 tqdm=4.65.0 pandas=2.0.1 pillow=9.5.0 -c conda-forge - 使用 -c pytorch 和 -c conda-forge 确保从官方通道获取包。
- 如果遇到冲突,尝试 conda config --set channel_priority strict 并重新安装。
-
3.4 验证安装
检查安装是否成功:
bash
Copy
python -c "import torch; print(torch.__version__); print(torch.cuda.is_available())" python -c "import numpy, scipy, matplotlib, skimage, jupyter, IPython, tqdm, pandas, PIL; print('All modules imported successfully!')" - 预期输出:
- 2.3.0
- True(如果 GPU 可用)
- All modules imported successfully!
-
3.5 配置 Jupyter Kernel
注册新环境作为 Jupyter 内核:
bash
Copy
python -m ipykernel install --user --name=dem_reconstruction_env --display-name="Python 3.8 (dem_reconstruction_env)" - 启动 Jupyter:
bash
Copy
jupyter notebook - 在 Jupyter 中选择 Python 3.8 (dem_reconstruction_env) 内核。
-
常见问题
- 你安装了 PyTorch 版本要求系统具备
GLIBC_2.27或更高版本,但你的系统(如 CentOS 7)默认只提供 GLIBC 2.17。这在老服务器、HPC 或学院集群上很常见。 - 降低版本 一定一定要降低版本 之前vscode版本太高还不能ssh远程连接
-
使用 PyTorch 的兼容旧 glibc 的版本(手动降级)
你可以尝试使用 较旧的 PyTorch + CUDA 版本组合,例如:
conda create -n torch-cuda112 python=3.8 -y conda activate torch-cuda112 conda install pytorch=1.12.1 torchvision=0.13.1 torchaudio=0.12.1 cudatoolkit=11.3 -c pytorch这组版本对老系统兼容性更好,不要求 GLIBC 2.27。
2148

被折叠的 条评论
为什么被折叠?



