mindspore-ai / mindspore-ai/hyper-parallel
model parallize metadata
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 53
- Forks
- 63
- Avg merge
- 23h 45m
- Merged PRs (30d)
- 63
Description
1. 背景
from_pretrained原子操作:
- init model skeleton
- parallize & 其他处理
- 切分、mapping权重并加载
3依赖2的切分等处理,因此需要2输出 切分等(不需要输出sharding信息,这部分由param自己的placements, device_mesh属性来记录) 操作的信息,并规范其格式
2. 格式
from transformers.core_model_loading import (
WeightConverter,
WeightRenaming,
convert_and_load_state_dict_in_model,
revert_weight_conversion,
)
WeightMapping: list[WeightConverter | WeightRenaming] | None = None
3. 流程
Stage 1: init_model()
→ canonical、未并行化 model skeleton
→ 已执行 model.tie_weights()
Stage 1.5: init_build_ir()
→ checkpoint_mapping: checkpoint schema → canonical skeleton
→ model_mapping: canonical skeleton → current model(初始 identity)
→ tied alias groups
Stage 2: model transform + parallelize
→ 累积 model WeightMappingDelta
→ 累积 ParamLayoutDelta: 挂载到param上的,由fsdp2manager管理,外界无需关注
→ 更新最终 Parameter binding/local chunk
Stage 3: compile + load
→ compose(checkpoint_mapping, model_mapping)
→ combine with final Param Layout(param._placements, param._device_mesh)
→ 生成 rank-local LoadTargets
→ 读取 checkpoint 并写入 final model
3.1. 伪代码
def from_pretrained(...):
# 1. init model skeleton
with device_meta_init_ctx:
model = _init_model(...)
# 1.5. init ModelConversionMetadata
# - WeightMapping: from transformers
# - NO DTensor Metadata: as param attr managed by FSDP2Manager
weights_mapping = init_weights_mapping(model, ...)
# 2. parallize & ...
# 2.1. perf module
perf_model, weights_mapping = apply_perf_model(model, weights_mapping)
# 2.1. sharding plan
sharded_model = apply_sharding_plan(model, ...)
# 2.2. fsdp
final_model = fsdp2_manager.parallelize(sharded_model, ...)
# 3. load checkpoint
# Params of final_model have attr:
# - placements
# - device_mesh
# for checkpoint sharding & loading
load_checkpoint(final_model, ckpt_file, weights_mapping)
schema_version: 1
source: gitcode
gitcode_repo: mindspore/hyper-parallel
gitcode_issue: 327
source_url: https://gitcode.com/mindspore/hyper-parallel/issues/327
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No implementation files or tests are named. Start by tracing from_pretrained through init_model, init_weights_mapping, apply_perf_model, apply_sharding_plan, fsdp2_manager.parallelize, and load_checkpoint. Define the metadata and mapping composition needed between these stages, then verify that the final model can produce rank-local load targets from the accumulated mappings and parameter layout.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- distributed-systems, machine-learning
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100