一键导入
sequence-parallel
Add, review, update, and validate recipe-local sequence-parallel plans that reuse the tensor-parallel mesh in mvp-engine models.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Add, review, update, and validate recipe-local sequence-parallel plans that reuse the tensor-parallel mesh in mvp-engine models.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Use and extend the MVP-Engine MLLM data kit with explicit specs, handlers, and sample objects. Use for recipe data wiring, MLLMDataSpec construction, source resample/resolve_refs policy, schema/media/tokenization handlers, packing, guards, collation, dataloader setup, Qwen VL data support, and multimodal data extensions.
Add, review, update, and validate recipe-local tensor-parallel plans, TP metadata postprocessors, and compatible mesh config for mvp-engine models.
Add, review, update, and validate VLM/MLLM data pipelines using the current spec/handler-based MLLMDataKit design. Use for raw schema normalization, MLLMDataSpec wiring, source resample/resolve_refs policy, media extensions, processor setup, packing, guards, collation, step estimation, and recipe integration.
Add, review, update, and validate VLM/MLLM packing behavior around the current MLLMDataKit design, including MLLMPackingSpec, MLLMPackingAssembler, MLLMPack metadata, block-causal masks, model-specific packed input preparation, token accounting, and step estimation.
Use LigerKernelKit for reusable Liger Kernel integration before model construction, covering official model-family dispatch, custom-model symbol patching via LigerPatch, module selection validation, and loss-kernel guards.
Decide where and how to wire Liger Kernel into an MVP-Engine recipe using LigerKernelKit, including official family dispatch, authoring a custom or composite model's LigerPatch map, module selection, and loss-kernel safety.
| name | sequence-parallel |
| description | Add, review, update, and validate recipe-local sequence-parallel plans that reuse the tensor-parallel mesh in mvp-engine models. |
Add Megatron-style sequence parallelism for models that already use tensor parallelism:
parallel.backend_kwargs.sequence_parallel;parallel.mesh.tensor as the SP size;The repo runtime contract is fixed:
mvp_engine/distributed/tp.py reads model.__class__.TP_MODULE_CONFIG, and when
sequence parallel is enabled it also merges optional
model.__class__.SEQUENCE_PARALLEL_MODULE_CONFIG.
Identify these before editing:
TP_MODULE_CONFIG and TP_MODULE_POSTPROCESSORS;RuntimeContext,
DataLoadMesh, sampler, or rank/world-size logic;parallel.mesh values and intended TP/SP size;tests/test_structure.py and tests/test_smoke.py.Ask the user only if TP/SP size, sequence dimension, available devices, or target module ownership cannot be derived from the task.
Search the recipe first:
rg -n "TP_MODULE_CONFIG|SEQUENCE_PARALLEL|parallelize_model|parallel.mesh|sequence_parallel" recipes/<recipe>
rg -n "RuntimeContext|DataLoadMesh|device_mesh|dp_dims|DistributedSampler|rank|world_size" recipes/<recipe>
rg -n "LayerNorm|RMSNorm|Dropout|dropout|norm" recipes/<recipe>
Find:
[batch, seq, hidden]
or [seq, batch, hidden];Sequence parallel reuses tensor parallelism:
parallel:
mesh:
shard: <fsdp2 shard size>
tensor: <tp_sp_size>
backend_kwargs:
sequence_parallel: true
Rules:
parallel.mesh.tensor > 1 is required;parallel.mesh.shard > 1 is required because this repo rejects pure TP/SP
without FSDP2;sp_size == tp_size;tensor is model-parallel, not data-parallel, and must not multiply global
batch size or dataset slots;replicate and
FSDP2 shard;tensor and any other non-data-parallel dimensions such as context
from dataloader sharding;mvp_dataset, pass a device_mesh plus dp_dims that excludes
tensor, or provide an equivalent sampler/loader guarantee;seq_len % parallel.mesh.tensor == 0; otherwise pad/mask explicitly
and verify every SP gather/scatter/reduce path handles uneven sequence shards;parallel.mesh.sequence.Keep normal TP linears in TP_MODULE_CONFIG. Add sequence-sharded modules to
SEQUENCE_PARALLEL_MODULE_CONFIG:
MODEL_SEQUENCE_PARALLEL_MODULE_CONFIG: dict[str, object] = {
"<RuntimeBlockClass>": {
"input_layernorm": "sequence",
"post_attention_layernorm": "sequence",
"dropout": "sequence",
},
}
Bind on the same top-level model class:
class <TopModelClass>(...):
TP_MODULE_CONFIG = MODEL_TP_MODULE_CONFIG
SEQUENCE_PARALLEL_MODULE_CONFIG = MODEL_SEQUENCE_PARALLEL_MODULE_CONFIG
SEQUENCE_PARALLEL_SEQUENCE_DIM = 1
Use SEQUENCE_PARALLEL_SEQUENCE_DIM = 1 for [batch, seq, hidden]. Use 0 for
[seq, batch, hidden].
Read references/sp_rules.md before finalizing the plan. Check:
"tensor" mesh dim,
which need post-accumulate sync of the newly added .grad delta;Use existing TP_MODULE_POSTPROCESSORS only for metadata changed by TP sharding,
such as head counts or hidden dimensions. Sequence parallel usually should not
mutate model config or cached global sequence length.
Review the modified recipe without running tests:
sequence_parallel is configured under parallel.backend_kwargs;parallel.mesh.tensor > 1 and parallel.mesh.shard > 1 for SP-active smoke;parallel.mesh.sequence field was introduced;tensor
mesh dimension;tensor and includes only data-parallel
dimensions such as replicate and shard;TP_MODULE_CONFIG remains bound on the real top-level model class;SEQUENCE_PARALLEL_MODULE_CONFIG, if present, is bound on the same class;SEQUENCE_PARALLEL_SEQUENCE_DIM matches the model hidden-state layout;"sequence" and TP plan values use "col" or
"row";zero_grad, so post-accumulate hooks do not re-reduce old gradients.Copy and adapt references/asserts.py into:
recipes/<recipe>/tests/skills/sequence-parallel/asserts.py
Ensure the recipe has tests/test_structure.py and tests/test_smoke.py; use
tests/templates/ if missing.
Run in fresh subagents, in order, stopping on first failure:
pytest recipes/<recipe>/tests/test_structure.py -q
pytest recipes/<recipe>/tests/test_smoke.py -q \
--config-override parallel.mesh.tensor=2 \
--config-override parallel.mesh.shard=2 \
--config-override parallel.backend_kwargs.sequence_parallel=true
Also pass --world-size 4 or another compatible value when the recipe smoke test
requires the world size to match replicate * shard * tensor.
Add optional sequence-layout impact validation when the task requires proof that norm/dropout modules receive sequence-local tensors. Use a recipe-local file such as:
recipes/<recipe>/tests/skills/sequence-parallel/test_sequence_layout_impact.py
The impact test should run with parallel.backend_kwargs.sequence_parallel=true
and inspect a stable hook point before/after SP-planned modules. Assert local
hidden-state sequence length is divided across the tensor mesh, while batch and
hidden dimensions remain compatible with the recipe's model layout. If the
recipe uses [seq, batch, hidden], assert that SEQUENCE_PARALLEL_SEQUENCE_DIM
is 0; otherwise assert against the default [batch, seq, hidden] layout.
Add optional numerical impact validation when the task requires proof that SP preserves model semantics. Use a recipe-local file such as:
recipes/<recipe>/tests/skills/sequence-parallel/test_loss_parity_impact.py
The impact test should run the same deterministic batch through TP/SP-off and TP/SP-on models and compare loss or logits within recipe-appropriate tolerances. Use eval mode, fixed seeds, no optimizer step, identical weights, identical packing/collation, and the same mixed precision policy where feasible. Gather or reduce global token counts before loss/metric normalization when the loss path consumes sequence-local tensors.
Add optional replicated-gradient impact validation when replicated parameters consume sequence-sharded activations, especially norms or dropout-adjacent modules. Use a recipe-local file such as:
recipes/<recipe>/tests/skills/sequence-parallel/test_replicated_grad_impact.py
The impact test should compare TP/SP-off and TP/SP-on gradients for replicated
parameters, and should cover at least two backward calls before zero_grad when
post-accumulate hooks are used.
Add a dataloader identity impact test when changing recipe data loading. Within one TP/SP group, assert sample ids or a stable batch fingerprint are identical across tensor ranks, while data-parallel ranks receive distinct slots. Use a recipe-local file such as:
recipes/<recipe>/tests/skills/sequence-parallel/test_dataloader_identity_impact.py
SEQUENCE_PARALLEL_MODULE_CONFIG by runtime module class.SEQUENCE_PARALLEL_SEQUENCE_DIM was added and why.references/sp_rules.md: sequence-parallel layout and boundary rules.references/asserts.py: recipe-local hard-validation assertion template.