能力标签
🛠
AI工具

MCore-Bridge

基于 Python · 开源免费,本地部署,数据完全自主可控
英文名:mcore-bridge
⭐ 66 Stars 🍴 13 Forks 💻 Python 📄 Apache-2.0 🏷 AI 7.5分
7.5AI 综合评分
installabledeepseek-r1gemma4glm-5gpt-ossllama4python
✦ AI Skill Hub 推荐

经 AI Skill Hub 精选评估,MCore-Bridge 获评「推荐使用」。这款AI工具在功能完整性、社区活跃度和易用性方面表现出色,AI 评分 7.5 分,适合有一定技术背景的用户使用。

📚 深度解析
MCore-Bridge 是一款基于 Python 的开源工具,在 GitHub 上收获 0k+ Star,是installable、deepseek-r1、gemma4、glm-5领域中的优质开源项目。开源工具的最大优势在于代码完全透明,你可以审计每一行代码的安全性,也可以根据自身需求进行二次开发和定制。

**为什么要使用开源工具而非商业 SaaS?**
对于个人开发者和有隐私需求的用户,本地部署的开源工具意味着数据不离本机,不受第三方服务商的数据政策约束。同时,开源工具通常没有使用次数限制和月度费用,一次安装即可长期使用,对于高频使用场景的总拥有成本(TCO)远低于订阅制商业工具。

**安装与环境准备**
MCore-Bridge 依赖 Python 运行环境。建议通过 pyenv(Python)或 nvm(Node.js)管理 Python 版本,避免全局环境污染。对于新手用户,推荐先创建虚拟环境(python -m venv venv && source venv/bin/activate),再安装依赖,这样即使出现问题也可以随时删除虚拟环境重新开始,不影响系统稳定性。

**社区与维护**
GitHub Issue 和 Discussion 是获取帮助的最快渠道。在提问前建议先检查 Closed Issues(已关闭的问题),大多数常见问题都已有解答。遇到 Bug 时,提供 pip list 的输出、完整错误堆栈和最小可复现示例,能显著提高开发者响应速度。AI Skill Hub 将持续追踪 MCore-Bridge 的版本更新,及时通知重要功能变化。
📋 工具概览

MCore-Bridge是开源AI工具,提供Megatron-Core模型定义,实现了state-of-the-art语言模型的应用。它支持多种模型,包括GPT-OSS和LLAM4等,帮助开发者快速构建高质量的语言模型应用。

MCore-Bridge 是一款基于 Python 开发的开源工具,专注于 installable、deepseek-r1、gemma4 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。

GitHub Stars
⭐ 66
开发语言
Python
支持平台
Windows / macOS / Linux
维护状态
轻量级项目,按需更新
开源协议
Apache-2.0
AI 综合评分
7.5 分
工具类型
AI工具
Forks
13
📖 中文文档
以下内容由 AI Skill Hub 根据项目信息自动整理,如需查看完整原始文档请访问底部「原始来源」。

MCore-Bridge是开源AI工具,提供Megatron-Core模型定义,实现了state-of-the-art语言模型的应用。它支持多种模型,包括GPT-OSS和LLAM4等,帮助开发者快速构建高质量的语言模型应用。

MCore-Bridge 是一款基于 Python 开发的开源工具,专注于 installable、deepseek-r1、gemma4 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。

📌 核心特色
  • 开源免费,支持本地部署,数据完全自主可控
  • 活跃的 GitHub 开源社区,持续迭代更新
  • 提供详细文档和使用示例,新手友好
  • 支持自定义配置,灵活适配不同使用环境
  • 可作为基础组件集成进现有技术栈或进行二次开发
🎯 主要使用场景
  • 本地部署运行,保护数据隐私,满足合规要求
  • 自定义集成到现有系统,扩展技术栈能力
  • 作为开源基础组件进行商业化二次开发
以下安装命令基于项目开发语言和类型自动生成,实际以官方 README 为准。
安装命令
# 方式一:pip 安装(推荐)
pip install mcore-bridge

# 方式二:虚拟环境安装(推荐生产环境)
python -m venv .venv
source .venv/bin/activate  # Windows: .venv\Scripts\activate
pip install mcore-bridge

# 方式三:从源码安装(获取最新功能)
git clone https://github.com/modelscope/mcore-bridge
cd mcore-bridge
pip install -e .

# 验证安装
python -c "import mcore_bridge; print('安装成功')"
📋 安装步骤说明
  1. 访问 GitHub 仓库页面
  2. 按照 README 文档完成依赖安装
  3. 根据系统环境完成初始化配置
  4. 参考官方示例或文档开始使用
  5. 遇到问题可在 GitHub Issues 中查找解答
以下用法示例由 AI Skill Hub 整理,涵盖最常见的使用场景。
常用命令 / 代码示例
# 命令行使用
mcore-bridge --help

# 基本用法
mcore-bridge input_file -o output_file

# Python 代码中调用
import mcore_bridge

# 示例
result = mcore_bridge.process("input")
print(result)
以下配置示例基于典型使用场景生成,具体参数请参照官方文档调整。
配置示例
# mcore-bridge 配置文件示例(config.yml)
app:
  name: "mcore-bridge"
  debug: false
  log_level: "INFO"

# 运行时指定配置文件
mcore-bridge --config config.yml

# 或通过环境变量配置
export MCORE_BRIDGE_API_KEY="your-key"
export MCORE_BRIDGE_OUTPUT_DIR="./output"
📑 README 深度解析 真实文档 完整度 52/100 查看 GitHub 原文 →
以下内容由系统直接从 GitHub README 解析整理,保留代码块、表格与列表结构。

MCore-Bridge: Making Megatron training as simple as Transformers

<p align="center"> <b>Providing Megatron-Core model definitions for state-of-the-art large models</b> </p>

<p align="center"> <a href="https://modelscope.cn">ModelScope</a> <br> <a href="README_zh.md">中文</a> &nbsp | &nbsp English &nbsp </p>

<p align="center"> <img src="https://img.shields.io/badge/python-3.12-5be.svg"> <img src="https://img.shields.io/badge/pytorch-%E2%89%A52.0-orange.svg"> <a href="https://github.com/NVIDIA/Megatron-LM/"><img src="https://img.shields.io/badge/megatron--core-%E2%89%A50.15-76B900.svg"></a>

<a href="https://pypi.org/project/mcore-bridge/"><img src="https://badge.fury.io/py/mcore-bridge.svg"></a> <a href="https://github.com/modelscope/mcore-bridge/blob/main/LICENSE"><img src="https://img.shields.io/github/license/modelscope/mcore-bridge"></a> <a href="https://pepy.tech/project/mcore-bridge"><img src="https://pepy.tech/badge/mcore-bridge"></a> <a href="https://github.com/modelscope/mcore-bridge/pulls"><img src="https://img.shields.io/badge/PR-welcome-55EB99.svg"></a> </p>

📝 Introduction

mcore-bridge is a large language model and multimodal large model definition library built on the Megatron-Core ecosystem, developed by the ModelScope community. It currently supports 300+ text-only models and 200+ multimodal models, including large language models such as Qwen3-Next, GLM5.1, DeepSeek-V3.2, Minimax2.7, Kimi K2.5, and GPT-OSS, as well as multimodal large models such as Qwen3.5, Qwen3-Omni, Gemma4, GLM4.6-V, InternVL3.5, and Ovis2.5.

------

Why Choose mcore-bridge?

  • Model Coverage: Supports 300+ text-only large language models and 200+ multimodal large models, with Day 0 support for popular models.
  • Hardware Support: Compatible with a wide range of hardware platforms, including A10/A100/H100/B200, RTX series, and domestic hardware such as Ascend NPU.
  • Training Methods: Supports both full-parameter training and LoRA training, with compatibility with the PEFT ecosystem.
  • Parallelism Techniques: Supports multiple parallelism strategies provided by Megatron-Core, including tensor parallelism, pipeline parallelism, sequence parallelism, context parallelism, expert parallelism, and virtual pipeline parallelism.
  • Multimodal Capabilities: Supports multimodal FP8 training, MTP, sequence padding-free, and packing features.
  • Task Types: Supports a variety of task types, including Causal LM, sequence classification, Embedding, and Reranker.
  • Ecosystem Compatibility: Supports direct loading and saving of LoRA/full-parameter safetensors weights, with compatibility with mainstream inference frameworks such as Transformers, vLLM, and SGLang.

------

Related Documentation:

🛠️ Installation

To install using pip: ```shell pip install mcore-bridge -U

pip install git+https://github.com/modelscope/mcore-bridge.git

git clone https://github.com/modelscope/mcore-bridge.git cd mcore-bridge pip install -e .

🚀 Quick Start

How to use MCore-Bridge for training can be referred to the ms-swift project. Here we introduce how to use MCore-Bridge programmatically.

You need to create the following file (test.py), then run CUDA_VISIBLE_DEVICES=0,1,2,3 torchrun --nproc_per_node=4 test.py. Below is sample code demonstrating how to use Mcore-Bridge for model creation, weight loading, export, and saving.

The saved model can be used for inference by referring to the example code in the model card.

```python import os import torch import torch.distributed as dist from megatron.core import mpu from modelscope import snapshot_download from transformers import AutoConfig, AutoProcessor from mcore_bridge import ModelConfig, get_mcore_model, hf_to_mcore_config

is_rank0 = int(os.getenv('RANK')) == 0 torch.cuda.set_device(f"cuda:{os.getenv('LOCAL_RANK')}") dist.init_process_group(backend='nccl') TP, PP, EP, ETP = 2, 2, 2, 1 mpu.initialize_model_parallel( tensor_model_parallel_size=TP, pipeline_model_parallel_size=PP, expert_model_parallel_size=EP, expert_tensor_parallel_size=ETP, )

model_dir = snapshot_download('Qwen/Qwen3.5-35B-A3B') hf_config = AutoConfig.from_pretrained(model_dir, trust_remote_code=True) processor = AutoProcessor.from_pretrained(model_dir, trust_remote_code=True) config_kwargs = hf_to_mcore_config(hf_config) config = ModelConfig( params_dtype=torch.bfloat16, tensor_model_parallel_size=TP, pipeline_model_parallel_size=PP, expert_model_parallel_size=EP, expert_tensor_parallel_size=ETP, sequence_parallel=True, mtp_num_layers=1, **config_kwargs)

Minimal forward example

Mcore-Bridge integrates seamlessly with the ms-swift template for model training. You can also replace the ms-swift template module with a custom data processing pipeline to suit your own workflow.

The following provides a minimal example demonstrating how to perform a forward pass and compute the loss using a model created with Mcore-Bridge, helping users quickly integrate Mcore-Bridge into other projects.

Create the following file (test.py) and run it with: CUDA_VISIBLE_DEVICES=0,1 torchrun --nproc_per_node=2 test.py.

import os
import torch
import torch.distributed as dist
from megatron.core import mpu
from modelscope import snapshot_download
from swift import get_processor, get_template
from swift.megatron.utils import get_packed_seq_params, get_padding_to
from swift.utils import to_device

from mcore_bridge import ModelConfig, get_mcore_model, hf_to_mcore_config, set_random_seed

data = {
    'messages': [{
        'role': 'user',
        'content': '<image>describe the image.'
    }, {
        'role':
        'assistant',
        'content':
        'The image depicts a close-up of a kitten with striking features. '
        'The kitten has a white and gray coat with distinct black stripes, '
        'particularly noticeable on its face and ears. Its eyes are large '
        'and expressive, with a captivating blue hue that stands out against '
        "the darker fur around them. The kitten's nose is small and pink, "
        'and it has long, delicate whiskers extending from either side of its mouth. '
        "The background is blurred, drawing attention to the kitten's face and "
        'making it the focal point of the image. The overall impression is '
        'one of cuteness and charm.'
    }],
    'images': ['http://modelscope-open.oss-cn-hangzhou.aliyuncs.com/images/cat.png']
}


def forward_mg_model(mg_model, template):
    template.use_megatron = True
    template.set_mode('train')
    inputs = template.encode(data, return_length=True)
    mg_inputs = to_device(template.data_collator([inputs], padding_to=get_padding_to(mg_model.config)), 'cuda')
    text_position_ids = mg_inputs.pop('text_position_ids', None)
    if text_position_ids is None:
        text_position_ids = mg_inputs.get('position_ids')
    for key in ['num_samples', 'attention_mask_2d', 'loss_scale']:
        mg_inputs.pop(key, None)
    if template.padding_free:
        mg_inputs['packed_seq_params'] = get_packed_seq_params(text_position_ids)
    mg_inputs['labels'] = torch.roll(mg_inputs['labels'], -1, dims=-1)
    loss = mg_model(**mg_inputs)
    loss_mask = mg_inputs['labels'] != -100
    loss = loss * loss_mask
    return loss.sum() / loss_mask.sum()


torch.cuda.set_device(f"cuda:{os.getenv('LOCAL_RANK')}")
dist.init_process_group(backend='nccl')
TP, PP, EP, ETP = 2, 1, 2, 1
mpu.initialize_model_parallel(
    tensor_model_parallel_size=TP,
    pipeline_model_parallel_size=PP,
    expert_model_parallel_size=EP,
    expert_tensor_parallel_size=ETP,
)
set_random_seed(42)

model_dir = snapshot_download('Qwen/Qwen3.5-35B-A3B')
template = get_template(get_processor(model_dir), padding_free=True)
config_kwargs = hf_to_mcore_config(template.config)
config = ModelConfig(
    params_dtype=torch.bfloat16,
    tensor_model_parallel_size=TP,
    pipeline_model_parallel_size=PP,
    expert_model_parallel_size=EP,
    expert_tensor_parallel_size=ETP,
    sequence_parallel=True,
    mtp_num_layers=1,
    **config_kwargs)

mg_model = get_mcore_model(config)[0]
mg_model.cuda()
config.bridge.load_weights([mg_model], model_dir)
loss = forward_mg_model(mg_model, template)
print(f'loss: {loss}')  # loss: 0.8161308169364929

Optional

✨ Model List

The following is the list of models supported by MCore-Bridge:

text-only large models:

Seriesmodel_type
Qwenqwen2, qwen2_moe<br />qwen3, qwen3_moe, qwen3_next
DeepSeekdeepseek_v3, deepseek_v32
GLMglm4, glm4_moe, glm4_moe_lite<br />glm_moe_dsa
MiniMaxminimax_m2
Kimikimi_k2, kimi_k25
Bailingbailing_moe
InternLMinternlm3
Llamallama
GPT-OSSgpt_oss
Hunyuanhy_v3
ERNIEernie4_5, ernie4_5_moe
MiMomimo
Dotsdots1
OLMoEolmoe

multimodal large models: <div class="rdm-tbl-wrap"><table class="rdm-tbl"><thead><tr><th>Series</th><th>model_type</th></tr></thead><tbody><tr><td>Qwen</td><td>qwen2_vl, qwen2_5_vl, qwen2_5_omni&lt;br /&gt;qwen3_vl, qwen3_vl_moe, qwen3_omni_moe, qwen3_asr&lt;br /&gt;qwen3_5, qwen3_5_moe</td></tr><tr><td>Gemma</td><td>gemma4</td></tr><tr><td>GLM</td><td>glm4v, glm4v_moe</td></tr><tr><td>Kimi</td><td>kimi_vl</td></tr><tr><td>InternVL</td><td>internvl_chat, internvl</td></tr><tr><td>Ovis</td><td>ovis2_5</td></tr><tr><td>Llama</td><td>llama4</td></tr><tr><td>Llava</td><td>llava-onevision</td></tr></tbody></table></div>

When saving as safetensors, you need to store the corresponding HF target_modules

hf_target_modules = r'^model.language_model.*\.(in_proj_qkv|in_proj_z|in_proj_b|in_proj_a|out_proj|gate_proj|up_proj|down_proj|q_proj|k_proj|v_proj|o_proj)$' lora_config = LoraConfig(task_type='CAUSAL_LM', r=8, lora_alpha=32, lora_dropout=0.05, target_modules=target_modules) peft_models = [get_peft_model(model, lora_config) for model in mg_models]

🎯 aiskill88 AI 点评 A 级 2026-05-23

MCore-Bridge是一个有潜力的开源AI工具,提供了多种模型和应用场景,帮助开发者快速构建高质量的语言模型应用。然而,工具的文档和示例应用需要进一步完善。

⚡ 核心功能
👥 适合人群
AI 技术爱好者研究人员和学生开发者和工程师技术创业者
🎯 使用场景
  • 本地部署运行,保护数据隐私,满足合规要求
  • 自定义集成到现有系统,扩展技术栈能力
  • 作为开源基础组件进行商业化二次开发
⚖️ 优点与不足
✅ 优点
  • +Apache-2.0 协议,可免费商用
  • +完全开源免费,无授权费用
  • +本地部署,数据完全自主可控
  • +开发者社区支持,遇问题可查可问
⚠️ 不足
  • 安装和初始配置可能需要一定技术基础
  • 功能完整性通常不如成熟商业产品
  • 技术支持主要依赖开源社区,响应速度不稳定
⚠️ 使用须知

AI Skill Hub 为第三方内容聚合平台,本页面信息基于公开数据整理,不对工具功能和质量作任何法律背书。

建议在沙箱或测试环境中充分验证后,再部署至生产环境,并做好必要的安全评估。

📄 License 说明

✅ Apache 2.0 — 宽松开源协议,可商用,需保留版权声明和 NOTICE 文件,含专利授权条款。

🔗 相关工具推荐
🧩 你可能还需要
基于当前 Skill 的能力图谱,自动补全的工具组合
❓ 常见问题 FAQ
解答:请参阅README文件或联系作者获取帮助
💡 AI Skill Hub 点评

AI Skill Hub 点评:MCore-Bridge 的核心功能完整,质量良好。对于AI 技术爱好者来说,这是一个值得纳入个人工具库的选择。建议先在非生产环境试用,再逐步推广。

📚 深入学习 MCore-Bridge
查看分步骤安装教程和完整使用指南,快速上手这款工具
🌐 原始信息
原始名称 mcore-bridge
原始描述 开源AI工具:MCore-Bridge: Providing Megatron-Core model definitions for state-of-the-art lar。⭐66 · Python
Topics installabledeepseek-r1gemma4glm-5gpt-ossllama4python
GitHub https://github.com/modelscope/mcore-bridge
License Apache-2.0
语言 Python
🔗 原始来源
🐙 GitHub 仓库  https://github.com/modelscope/mcore-bridge 🌐 官方网站  https://swift.readthedocs.io/en/latest/Megatron-SWIFT/Mcore-Bridge.html

收录时间:2026-05-21 · 更新时间:2026-05-22 · License:Apache-2.0 · AI Skill Hub 不对第三方内容的准确性作法律背书。