Megatron 应用镜像构建在 flagos-runtime 之上,打包可用的 megatron-core 库,用于 megatron-lm 训练栈。

已发布的镜像按后端拆分——镜像引用与启动方式见 应用镜像 目录或各个后端的独立页面。

构建参数

参数默认值说明
RUNTIME_IMAGE(必填)运行时镜像引用,如 harbor.baai.ac.cn/flagos-runtime/flagos-runtime-hygon-dtk26.04:2.1.2
MEGATRON_VERSION0.17.1要安装的 megatron-core 版本。该版本的 wheel 必须已上传到 FLAGOS_PYPI。
FLAGOS_PYPI""厂商 PyPI 索引 — 存放 megatron-core wheel,优先搜索。
EXTRA_PYPIhttps://mirrors.aliyun.com/pypi/simple阿里云镜像 — 其他所有依赖的回退源。
APP_DEPS""厂商条件包(configs.yaml deps_app.{app}),空格分隔。在 wheel 之前从厂商 PyPI 安装——index 隔离,防止厂商包被 mirror 重新解析。无厂商包的 app 为空。
APP_ENV""每后端 app 环境变量(configs.yaml env.app.{app}),写入 /etc/profile.d/app_env.sh。

megatron-core wheel

megatron-core 的直接依赖面极小(torch>=2.6.0、numpy、packaging>=24.2), wheel 原样保留这些声明——不做 repack、不动 METADATA。所有受支持后端的 runtime vendor torch 均 ≥ 2.7.1,满足 torch>=2.6.0 的 Requires-Dist, pip 无需解析、不会覆盖任何包。

pip install 时优先搜索厂商 PyPI — 找到该 wheel 并使用。其余(安全)依赖 全部从 EXTRA_PYPI 解析。torch 已存在于 runtime venv 中且满足所有传递约束, pip 不会去动它。安装是单步 pip install(无 --no-deps)。

wheel 由 packaging/megatron/builder/ 从 Megatron-LM-FL fork 构建——就在该 后端的 runtime 镜像内构建,构建环境 == 交付环境,单步安装的安全性在构建时 即被验证(cp310/cp311/cp312 三个 ABI 专属 wheel;fork 的 requires-python >=3.12 在构建时 on-the-fly 放宽到 >=3.10)。详见 packaging/megatron/builder/README.md。

构建示例

  docker build \
  --build-arg RUNTIME_IMAGE=harbor.baai.ac.cn/flagos-runtime/flagos-runtime-hygon-dtk26.04:2.1.2 \
  --build-arg FLAGOS_PYPI=https://resource.flagos.net/repository/flagos-pypi-hygon/simple \
  -t harbor.baai.ac.cn/flagos-app/megatron_training0.17.1-hygon-dtk26.04:2.1.2-0.2.1 \
  -f app/megatron/Containerfile.megatron-training .
# RL app: -f app/megatron/Containerfile.rl, tag megatron_rl0.17.1-{vendor}-{backend}:2.1.2-0.2.1
  

Last updated 23 Aug 2026, 12:04 +0800. history