Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
b03e864
Add GLM-5.2 chat tokenization
jayhenry Jul 3, 2026
8c99cba
Add GLM-5.2 native MoE config
jayhenry Jul 3, 2026
2d4088f
Align GLM-5.2 token labels with golden
jayhenry Jul 3, 2026
5dfac65
Add DSA for GLM-5.2
jayhenry Jul 3, 2026
92ccc2a
test: add glm52 hf numeric oracle
jayhenry Jul 3, 2026
88ccf07
test: add glm52 moe distributed coverage
jayhenry Jul 3, 2026
67a51c8
test: add glm52 sft smoke
jayhenry Jul 3, 2026
90a40bc
test: add glm52 moe engine coverage
jayhenry Jul 3, 2026
35eae5c
test: add glm52 30b crop utility
jayhenry Jul 4, 2026
06d81fe
test: preserve glm52 mtp config
jayhenry Jul 4, 2026
aa05200
test: map glm52 mtp hf layer keys
jayhenry Jul 4, 2026
af4d640
test: add tilelang sparse mla backend
jayhenry Jul 4, 2026
7a1575b
test: reuse dsa indexer for glm52 mtp layers
jayhenry Jul 4, 2026
786b43e
test: preserve glm52 mtp indexer crop metadata
jayhenry Jul 4, 2026
ca7f308
test: validate generated glm52 30b checkpoints
jayhenry Jul 4, 2026
d46ab38
test: add tilelang dsa indexer backend
jayhenry Jul 4, 2026
7ce7570
fix: update glm52 mtp router bias
jayhenry Jul 4, 2026
60bd2fa
test: add glm52 30b long train smoke
jayhenry Jul 4, 2026
a9684de
refactor: move sparse mla tilelang ops
jayhenry Jul 6, 2026
619acf4
refactor: move sparse mla dispatch into ops
jayhenry Jul 6, 2026
c21d30a
Add GLM5.2 SFT config and launcher
jayhenry Jul 6, 2026
b292bb0
feat: add GLM memory stage profiling
jayhenry Jul 7, 2026
cfde1e3
docs: add GBS16 GLM memory profile notebook
jayhenry Jul 7, 2026
14cd639
fix: handle tilewise fp8 fsdp single-rank gather
jayhenry Jul 8, 2026
266df3b
feat: support GLM FP8 SFT training
jayhenry Jul 8, 2026
b848c30
fix: honor grouped gemm fp8 config
jayhenry Jul 8, 2026
2ca2cd1
fix: make DSA topk indexer compile friendly
jayhenry Jul 8, 2026
c92db0b
fix: make PyTorch SparseMLA fullgraph friendly
jayhenry Jul 8, 2026
fed801e
test: cover GLM compile granularity
jayhenry Jul 8, 2026
b025d0a
Support compile for TileLang sparse MLA ops
jayhenry Jul 9, 2026
f1f1265
Support GLM compile graph-break strategy
jayhenry Jul 9, 2026
4e55bc9
test: cover GLM activation offload train step
jayhenry Jul 9, 2026
affc460
Add DSA topk checkpoint cache release
jayhenry Jul 9, 2026
8c74d96
Offload DSA topk cache during checkpoint replay
jayhenry Jul 9, 2026
32a92f8
Include MTP in DSA topk release plan
jayhenry Jul 9, 2026
d0b9f37
Make DSA topk offload compile safe
jayhenry Jul 9, 2026
11282d6
Move DSA top-k lifecycle outside compiled decoder
jayhenry Jul 10, 2026
c1cbc39
Clarify DSA top-k decoder hook seam
jayhenry Jul 10, 2026
90b8021
Group DSA top-k cache state on SequenceContext
jayhenry Jul 10, 2026
15077a5
Encapsulate DSA top-k decoder lifecycle setup
jayhenry Jul 10, 2026
7685de9
Exercise DSA top-k offload through decoder hooks
jayhenry Jul 10, 2026
d44cfce
init glm topk cache design
jayhenry Jul 11, 2026
81896e1
Document DSA top-k release plan scopes
jayhenry Jul 11, 2026
031a3b6
Move GLM DSA lifecycle setup to Glm52MoE
jayhenry Jul 11, 2026
08afc1d
Refresh DSA top-k cache design docs
jayhenry Jul 11, 2026
702da0b
Use DSA top-k cache state in tests
jayhenry Jul 11, 2026
4cf6666
Prefetch offloaded DSA top-k before decoder forward
jayhenry Jul 11, 2026
87ef251
Cover GLM DSA top-k offload through model forward
jayhenry Jul 11, 2026
f63ee94
Document DSA top-k int32 dtype constraints
jayhenry Jul 11, 2026
0010df6
Close remaining DSA top-k cache design tasks
jayhenry Jul 11, 2026
a1cdeb5
Add cuDNN DSA sparse MLA backend
jayhenry Jul 11, 2026
fdf4543
Keep cuDNN DSA sparse MLA eager under compile
jayhenry Jul 12, 2026
fb6763f
Fix cuDNN DSA compile LSE handling
jayhenry Jul 12, 2026
e8b8cef
Fix DSA top-k offload with microbatch split
jayhenry Jul 12, 2026
73f9207
Fix GLM MTP aux stats in micro-batch forward
jayhenry Jul 12, 2026
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
143 changes: 143 additions & 0 deletions examples/v1/config/sft_glm5p2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import os
from pathlib import Path

from xtuner.v1.config import AdamWConfig, FSDPConfig, LRConfig
from xtuner.v1.datasets import OpenaiTokenizeFunctionConfig
from xtuner.v1.datasets.config import DataloaderConfig, DatasetConfig
from xtuner.v1.float8.config import Float8Config, ScalingGranularity
from xtuner.v1.loss import CELossConfig
from xtuner.v1.model import get_model_config_from_hf
from xtuner.v1.train import TrainerConfig
from xtuner.v1.train.trainer import LoadCheckpointConfig


def _get_bool_env(name: str, default: bool = False) -> bool:
return os.environ.get(name, "1" if default else "0").lower() in ("1", "true", "yes", "on")


def _get_dispatcher():
dispatcher = os.environ.get("DISPATCHER", "all2all").lower()
if dispatcher in ("", "none", "null"):
return None
return dispatcher


def _get_float8_config() -> Float8Config | None:
if not _get_bool_env("FP8", False):
return None
return Float8Config(
scaling_granularity_gemm=ScalingGranularity.TILEWISE,
scaling_granularity_grouped_gemm=ScalingGranularity.TILEWISE,
)


def _dataset_entry(name: str, anno_path: str | Path, sample_ratio: float, cache_dir: str, cache_tag: str):
return {
"dataset": DatasetConfig(
name=name,
anno_path=anno_path,
sample_ratio=sample_ratio,
cache_dir=cache_dir,
cache_tag=cache_tag,
),
"tokenize_fn": OpenaiTokenizeFunctionConfig(
chat_template="glm5.2",
max_length=sample_max_length,
),
}


GLM5_2_MODEL_PATH = os.environ["GLM5_2_MODEL_PATH"]
ALPACA_PATH = os.environ["ALPACA_PATH"]
ALPACA_LONG_PATH = os.environ["ALPACA_LONG_PATH"]

work_dir = os.environ.get("WORK_DIR", "work_dirs/glm52_sft")
# On single-node 8-GPU SFT, EP=8 leaves FSDP size at 1 and replicates non-expert params.
ep_size = int(os.environ.get("EP_SIZE", "1"))
intra_layer_micro_batch = int(os.environ.get("INTRA_LAYER_MICRO_BATCH", "1"))
global_batch_size = int(os.environ.get("GLOBAL_BATCH_SIZE", os.environ.get("WORLD_SIZE", "8")))
sample_max_length = int(os.environ.get("SAMPLE_MAX_LENGTH", "4096"))
pack_max_length = int(os.environ.get("PACK_MAX_LENGTH", "16384"))
total_step = int(os.environ.get("TOTAL_STEP", "10"))

loss_cfg = CELossConfig(
mode=os.environ.get("LOSS_MODE", "chunk"),
chunk_size=int(os.environ.get("LOSS_CHUNK_SIZE", "1024")),
)

model_cfg = get_model_config_from_hf(GLM5_2_MODEL_PATH)
model_cfg.dispatcher = _get_dispatcher()
model_cfg.ep_size = ep_size
model_cfg.compile_cfg = _get_bool_env("MODEL_COMPILE", False)
model_cfg.float8_cfg = _get_float8_config()
model_cfg.lm_loss_cfg = loss_cfg
if hasattr(model_cfg.attention, "sparse_mla_backend"):
model_cfg.attention.sparse_mla_backend = os.environ.get("SPARSE_MLA_BACKEND", "tilelang")

cache_dir = os.path.join(work_dir, "jsonl_cache")
cache_tag = os.environ.get("CACHE_TAG", f"glm52_{sample_max_length}")
dataset_type = os.environ.get("DATASET_TYPE", "alpaca").lower()
dataset_paths = {
"alpaca": ALPACA_PATH,
"alpaca_long": ALPACA_LONG_PATH,
}
if dataset_type not in dataset_paths:
raise ValueError(f"Unsupported DATASET_TYPE={dataset_type!r}. Use alpaca or alpaca_long.")
dataset_config = [
_dataset_entry(
dataset_type,
dataset_paths[dataset_type],
float(os.environ.get("DATASET_SAMPLE_RATIO", "1.0")),
cache_dir,
f"{cache_tag}_{dataset_type}",
)
]

dataloader_config = DataloaderConfig(
dataset_config_list=dataset_config,
pack_level=os.environ.get("PACK_LEVEL", "soft"),
pack_max_length=pack_max_length,
pack_chunk_size=int(os.environ.get("PACK_CHUNK_SIZE", "10000")),
pack_workers=int(os.environ.get("PACK_WORKERS", "4")),
global_pack=_get_bool_env("GLOBAL_PACK", True),
group_by_length=_get_bool_env("GROUP_BY_LENGTH", True),
num_workers=int(os.environ.get("DATALOADER_NUM_WORKERS", "4")),
)

optim_cfg = AdamWConfig(
lr=float(os.environ.get("LR", "1e-6")),
foreach=_get_bool_env("ADAMW_FOREACH", False),
swap_optimizer=_get_bool_env("SWAP_OPTIMIZER", False),
)
lr_cfg = LRConfig(lr_type=os.environ.get("LR_TYPE", "cosine"), warmup_ratio=float(os.environ.get("WARMUP_RATIO", "0")))
fsdp_cfg = FSDPConfig(
cpu_offload=_get_bool_env("CPU_OFFLOAD", False),
ep_size=ep_size,
torch_compile=_get_bool_env("TORCH_COMPILE", False),
)

trainer = TrainerConfig(
model_cfg=model_cfg,
load_from=GLM5_2_MODEL_PATH,
tokenizer_path=GLM5_2_MODEL_PATH,
strict_load=_get_bool_env("STRICT_LOAD", True),
optim_cfg=optim_cfg,
dataloader_cfg=dataloader_config,
lr_cfg=lr_cfg,
loss_cfg=loss_cfg,
fsdp_cfg=fsdp_cfg,
global_batch_size=global_batch_size,
total_step=total_step,
intra_layer_micro_batch=intra_layer_micro_batch,
sp_size=int(os.environ.get("SP_SIZE", "1")),
load_checkpoint_cfg=LoadCheckpointConfig(checkpoint_path=os.environ.get("LOAD_CHECKPOINT_PATH")),
checkpoint_interval=int(os.environ.get("CHECKPOINT_INTERVAL", "200")),
checkpoint_maxkeep=int(os.environ.get("CHECKPOINT_MAX_KEEP", "3")),
hf_interval=int(os.environ.get("HF_INTERVAL", "200")),
hf_max_keep=int(os.environ.get("HF_MAX_KEEP", "3")),
work_dir=work_dir,
profile_memory=_get_bool_env("PROFILE_MEMORY", False),
profile_time=_get_bool_env("PROFILE_TIME", False),
profile_step=[int(x) for x in os.environ.get("PROFILE_STEP", "2,3").split(",") if x],
debug_skip_save=_get_bool_env("DEBUG_SKIP_SAVE", False),
)
Loading