安装¶
pip / uv¶
从 PyPI 安装最新发布版:
或
CUDA 支持¶
btorch 依赖 PyTorch。PyPI 默认提供 CPU 版本的 torch。如需 CUDA,请先安装对应计算平台版本的 PyTorch,再安装 btorch:
或使用 uv:
详见 PyTorch Get Started 页面了解其他 CUDA / ROCm 版本。
conda / mamba¶
environment.yml 通过 conda-forge 和 PyG 通道捆绑了含 CUDA 的 PyTorch、pytorch_sparse 及所有依赖:
conda env create -n btorch -f https://github.com/Criticality-Cognitive-Computation-Lab/btorch/raw/refs/heads/main/environment.yml
conda activate btorch
或使用 mamba:
mamba env create -n btorch -f https://github.com/Criticality-Cognitive-Computation-Lab/btorch/raw/refs/heads/main/environment.yml
mamba activate btorch
从版本控制安装¶
Btorch 迭代快速。如需最新的未发布改动,直接从仓库安装:
Gitee 镜像:
可编辑安装(开发)¶
克隆仓库并以可编辑模式安装:
git clone https://github.com/Criticality-Cognitive-Computation-Lab/btorch.git
cd btorch
pip install -e . --config-settings editable_mode=strict
若使用 uv,克隆并同步 lockfile:
git clone https://github.com/Criticality-Cognitive-Computation-Lab/btorch.git
cd btorch
uv sync --group dev
source .venv/bin/activate
pip install -e . --config-settings editable_mode=strict
CUDA + uv,先安装对应后端版本的 torch:
uv venv .venv-cuda
uv pip install torch --torch-backend auto --python .venv-cuda/bin/python
uv pip install -e . --python .venv-cuda/bin/python
可选:torch_sparse 后端¶
稀疏线性层默认使用 PyTorch 原生 torch.sparse 后端。安装 torch_sparse 可在大型稀疏网络上获得更好性能。
使用与 PyTorch 和 CUDA 版本匹配的 PyG 仓库 预编译 wheel:
# 以 PyTorch 2.7 + CUDA 12.6 为例
pip install torch_scatter torch_sparse -f https://data.pyg.org/whl/torch-2.7.0+cu126.html
若未安装 torch_sparse,层将静默回退到原生后端。