使用光源容器安装python库

本文最后更新于 2026年1月22日 下午

使用光源容器安装 AutoGluon(基于海光 DTK)

本文档记录在“光源”基础镜像容器内安装 AutoGluon 的推荐流程,目标是:在满足 DTK/驱动约束的前提下,尽量复用镜像自带的 PyTorch 生态版本,减少依赖冲突。

0. 前置条件

  • 已完成海光 DTK 开发环境安装与 Docker 环境部署
  • 参考:https://blog.csdn.net/JulyLi2019/article/details/153266775

1. 版本兼容性确认

安装前先确认 AutoGluon 支持的 PyTorch 版本范围(避免选错镜像导致依赖不兼容):

  • https://auto.gluon.ai/stable/whats_new/index.html

2. 拉取基础镜像

从光源镜像仓库选择与目标 DTK/Python 版本匹配的容器,例如:

1
docker pull harbor.sourcefind.cn:5443/dcu/admin/base/pytorch:2.7.1-ubuntu22.04-dtk25.04.2-py3.10-alpha

建议:后续 docker run 使用同一个镜像标签(tag),避免“pull 的镜像”和“run 的镜像”不一致。

3. 启动容器(最小化配置示例)

按需调整挂载目录、镜像地址与 tag。以下为最小化启动命令示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
docker run -it \
--network=host \
--ipc=host \
--shm-size=16G \
--device=/dev/kfd \
--device=/dev/mkfd \
--device=/dev/dri \
-v /opt/hyhal:/opt/hyhal \
--group-add video \
--cap-add=SYS_PTRACE \
--security-opt seccomp=unconfined \
harbor.sourcefind.cn:5443/dcu/admin/base/pytorch:2.7.1-ubuntu22.04-dtk25.04.2-py3.10-alpha \
/bin/bash

4. 容器内:生成依赖约束(constraints)

4.1 查看容器当前库版本

1
pip list

4.2 导出约束文件

1
pip freeze > constraints.txt

说明:

  • constraints.txt 仅包含“包名==版本号”,不包含依赖关系解析信息
  • 部分镜像内置/自定义包可能无法通过公网 PyPI 直接安装;如安装时报错,需以 pip list 的版本为准手动修正

示例(以镜像内版本为准):

1
2
3
4
5
6
fastpt==2.2.0+das.dtk25042
lightop==0.6.0+das.dtk25042
torch==2.7.1+das.opt1.dtk25042
torchvision==0.22.0+das.opt1.dtk25042
transformer_engine==2.7.0+das.opt1.dtk25042
triton==3.1+das.opt1.dtk25042

5. 容器内:安装 AutoGluon

5.1 配置 pip 镜像源(可选)

1
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

5.2 按约束安装(两种方式任选其一)

方式 A:使用 requirements.txt(推荐用于项目化复现)

1
pip install -r requirements.txt -c constraints.txt

方式 B:模块化最小化安装(推荐用于快速验证)

1
pip install autogluon.tabular -c constraints.txt

6.(可选)安装 Jupyter

1
pip install jupyter -c constraints.txt

7. 快速验证(PyTorch / DCU)

在容器内执行以下代码,快速确认 PyTorch 版本以及设备是否可用:

1
2
3
4
5
6
python - <<'PY'
import torch
print('pytorch version:', torch.__version__)
print('DCU is', torch.cuda.is_available())
print(torch.cuda.device_count())
PY

参考资料

  • AutoGluon 官方文档:https://auto.gluon.ai/stable/index.html
  • DCU快速上手步骤:https://developer.sourcefind.cn/gitbook//dcu_tutorial/index.html
  • 光源容器镜像仓库:https://developer.sourcefind.cn/servicelist

使用光源容器安装python库
https://bintodo.top/links/install-python-libraries-in-guangyuan-container.html
作者
bin
发布于
2026年1月21日
许可协议