Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@ repos:
rev: v6.0.0
hooks:
- id: trailing-whitespace
exclude: '\.patch$'
- id: check-yaml
- id: end-of-file-fixer
exclude: '\.patch$'
- id: requirements-txt-fixer
- id: double-quote-string-fixer
exclude: '\.patch$'
- id: check-merge-conflict
exclude: '\.patch$'
- id: mixed-line-ending
args: ["--fix=lf"]
exclude: '\.patch$'
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Recommended Runtime Environment:
| torch | >=2.0 | 2.8.0/2.11.0 | |
| transformer-engine | >=2.3 | 2.14.1 | |
| apex | | 0.1 | Optional |
| megatron-core | >=0.16,<0.20 | 0.17.1 | |
| megatron-core | >=0.16,<0.21 | 0.17.1 | |
| flash-attn | | 2.8.3/3.0.0b1 | Optional |
| transformers | >=4.33 | 4.57.6/5.8.1 | |
| modelscope | >=1.23 | | |
Expand Down
2 changes: 1 addition & 1 deletion README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ uv pip install -e . --torch-backend=auto
| torch | >=2.0 | 2.8.0/2.11.0 | |
| transformer-engine | >=2.3 | 2.14.1 | |
| apex | | 0.1 | 可选 |
| megatron-core | >=0.16,<0.20 | 0.17.1 | |
| megatron-core | >=0.16,<0.21 | 0.17.1 | |
| flash-attn | | 2.8.3/3.0.0b1 | 可选 |
| transformers | >=4.33 | 4.57.6/5.8.1 | |
| modelscope | >=1.23 | | |
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
megatron-core>=0.16,<0.20
megatron-core>=0.16,<0.21
modelscope
peft>=0.11,<0.21
safetensors
Expand Down
4 changes: 4 additions & 0 deletions src/mcore_bridge/config/model_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ class ModelConfig(TransformerConfig):
csa_compress_rotary_base: float = 40000.0
o_groups: int = 8
o_lora_rank: int = 1024
# Canonical names consumed by TransformerConfig.__post_init__ since the main->dev sync (0.20+);
# `o_groups` / `o_lora_rank` remain the dev-era aliases and are reconciled against these.
output_projection_groups: int = 8
output_projection_lora_rank: int = 1024
enable_hyper_connections: bool = False
num_residual_streams: int = 4
mhc_sinkhorn_iterations: int = 20
Expand Down
30 changes: 21 additions & 9 deletions src/mcore_bridge/model/mm_gpts/glm5_next.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) ModelScope Contributors. All rights reserved.
import copy
import inspect
import torch
import torch.nn as nn
from copy import deepcopy
Expand Down Expand Up @@ -34,6 +35,15 @@

logger = get_logger()

# Megatron 0.20 added a required `config` argument to select_pipeline_segment (the hybrid stack now
# returns per-layer TransformerConfig objects instead of layer symbols); 0.18/0.19 take
# `(main_pattern, pp_group, vp_stage, ...)`. GLM-5.3 itself is a dev-only feature -- a release without
# the packaged patch is rejected earlier by require_glm5_hybrid() -- so only the 0.20 signature runs
# today. Probe it anyway so a backport (or a release that grows the hybrid stack) cannot silently
# turn this call site into a TypeError.
_SELECT_PIPELINE_SEGMENT_TAKES_CONFIG = (
select_pipeline_segment is not None and 'config' in inspect.signature(select_pipeline_segment).parameters)

# Probes for require_glm5_hybrid(): the hybrid-stack APIs this model is built on, and the
# TransformerConfig fields that only the packaged patch provides.
_HYBRID_API_PROBES = (('megatron.core.models.hybrid.hybrid_model', 'HybridModel'),
Expand Down Expand Up @@ -227,15 +237,17 @@ def __init__(self, config, transformer_layer_spec, pre_process=True, post_proces
from megatron.core.process_groups_config import ProcessGroupCollection
pg = ProcessGroupCollection.use_mpu_process_groups()
pattern = self._resolve_hybrid_layer_pattern(config)
segment, offset = select_pipeline_segment(
parse_hybrid_pattern(pattern).main_pattern,
pg.pp,
vp_stage,
first_stage_layers=config.num_layers_in_first_pipeline_stage,
last_stage_layers=config.num_layers_in_last_pipeline_stage,
tp_group=pg.tp,
dp_cp_group=pg.dp_cp,
)
segment_kwargs = {
'first_stage_layers': config.num_layers_in_first_pipeline_stage,
'last_stage_layers': config.num_layers_in_last_pipeline_stage,
'tp_group': pg.tp,
'dp_cp_group': pg.dp_cp,
}
main_pattern = parse_hybrid_pattern(pattern).main_pattern
if _SELECT_PIPELINE_SEGMENT_TAKES_CONFIG:
segment, offset = select_pipeline_segment(main_pattern, config, pg.pp, vp_stage, **segment_kwargs)
else:
segment, offset = select_pipeline_segment(main_pattern, pg.pp, vp_stage, **segment_kwargs)
if offset % 2 or len(segment) % 2:
raise ValueError(
f'Pipeline stage boundaries of the current model must fall on complete attention+FFN blocks, '
Expand Down
Loading
Loading