📎 上级文档: HyperParallel / PyTorch / TorchTitan 用户接口对标 #1 📎 姊妹专项(差距与路线图): 张量并行 TP 对标 PyTorch #6
📎 上级文档: HyperParallel / PyTorch / TorchTitan 用户接口对标 #1
📎 姊妹专项(差距与路线图): 张量并行 TP 对标 PyTorch #6
本 Issue 定位: 在 #1 模块划分下,汇总 §3 张量并行(TP) 子模块的全量对外接口对标总表(表头:接口名 · 参数 · 功能 · hyper · pytorch · titan),作为 #6 差距梳理的接口索引附录。
分析依据(源码,2026-07):
hyper_parallel/__init__.py
hyper_parallel/core/tensor_parallel/
platform/*/loss_parallel_ops.py
torch/distributed/tensor/parallel/
api.py
style.py
loss.py
input_reshard.py
fsdp.py
ddp.py
torchtitan/distributed/tensor_parallel.py
models/common/decoder_sharding.py
models/*/parallelize.py
components/loss.py
图例: ✅ 有对标 · ⚠️ 部分对标 · ❌ 无 · 🔶 Hyper 扩展
列说明:
torch.distributed.tensor.parallel
架构备注: Hyper 策略类使用公开 apply()(PyTorch 为 _apply());I/O 边界 redistribute 当前全同步(PyTorch 默认 async_op=True → ACT),见 #270。
apply()
_apply()
redistribute
async_op=True
parallelize_module
module
device_mesh
parallelize_plan
*, src_data_rank=0
hyper_parallel.parallelize_module
torch.distributed.tensor.parallel.parallelize_module
Module.parallelize()
DeviceMesh | None
None
ndim>1
parallel_dims.get_mesh("tp")
ParallelStyle | dict[str, ParallelStyle] | None
ShardingConfig
layers.*
src_data_rank
int | None
0
distribute_tensor
plan=None
plan=""
ValueError
_tensor_parallel_mesh_context
api._tensor_parallel_mesh_context
ParallelStyle
hyper_parallel.ParallelStyle
tensor.parallel.ParallelStyle
NoParallel
ParallelStyle.apply
apply
_apply
ParallelStyle.src_data_rank
ColwiseParallel
*, input_layouts
output_layouts
use_local_output
hyper_parallel.ColwiseParallel
colwise_config()
Shard(0)
Shard(1)
Replicate()
Shard(-1)
True
to_local()
Dense
Embedding
Linear
RowwiseParallel
use_local_output=True
rowwise_config()
Partial("sum")
SequenceParallel
*, sequence_dim=1
use_local_output=False
dense_sequence_parallel_placement()
PrepareModuleInput
input_layouts
desired_input_layouts
input_kwarg_layouts
desired_input_kwarg_layouts
with_kwargs=True
PrepareModuleOutput
desired_output_layouts
PrepareModuleInputOutput
use_local_input
*, input_layout
output_layout
desired_input_layout
hyper_parallel.NoParallel
loss_parallel
*, mesh=None, strict=True
core.tensor_parallel.loss_parallel
__all__
tensor.parallel.loss_parallel
_LossParallelCrossEntropy
is_loss_parallel_active
get_loss_parallel_count
loss_parallel.py
cross_entropy
CrossEntropyLoss
_OP_DISPATCHER
DTensor.__torch_dispatch__
label_smoothing
input_reshard
tp_device_mesh
input_reshard_dim=None
tensor.parallel.input_reshard
DTensorExtensions
tensor.parallel.fsdp.DTensorExtensions
_pre_dp_module_transform
tensor.parallel.ddp
_data_parallel_utils
sync_grad_hook
maybe_enable_async_tp
parallelism
compile_config
tp_mesh
distributed/tensor_parallel.py
parallelize_llama
model.parallelize
parallel_dims
examples/torch/llama3/parallelize.py
models/llama3/parallelize.py
parallelize_qwen3_5
model
mesh
cfg
NotImplementedError
decoder_sharding
colwise_config
rowwise_config
set_gqa_attention_sharding
SpmdLayout
Module.parallelize(parallel_dims)
spmd_backend=full_dtensor
loss_parallel()
ChunkedLossWrapper
input_layout
shard_module
sharding_plan
hyper_parallel.shard_module
ShardingPlan
core/shard/sharding_plan.py
protocols/sharding.py
DFunction
hyper_parallel.DFunction
parallelize_value_and_grad
hyper_parallel.parallelize_value_and_grad
gather_tensor_parallel_logits
logits
config
hyper_parallel.infer
ParallelDims
dp_replicate
dp_shard
cp
tp
pp
ep
hyper_parallel.trainer.parallel_dims
torchtitan.distributed.ParallelDims
ParallelDims.get_mesh
"tp"
ParallelDims.seq_len_divisor
tp * (cp*2)
本节从 总表 中筛出 hyper 列为 ❌ 或 ⚠️ 的项,按来源拆为四块。详细 P0/P1 补齐路线见 #6;loss_parallel 子专项见 #269;TP 异步 ACT 见 #270。
tensor.parallel.fsdp
fully_shard
parallelize_plan=""
parallel.api
tensor.parallel
ParallelStyle._apply
Titan 底层 TP 原语多数直接调用 PyTorch parallelize_module / ParallelStyle。下表为 Titan 训练编排层 特有、Hyper 无对等公开 API 的项。
torch.compile
protocols/
full_dtensor
parallelize_llama3
strict
""
__torch_dispatch__
__torch_function__
loss_parallel(mesh=..., strict=...)
is_loss_parallel_active()
infer/
Cell
apply_tp
hyper_parallel.__all__
"parallelize_module", "ColwiseParallel", "RowwiseParallel", "SequenceParallel", "PrepareModuleInput", "PrepareModuleInputOutput", "PrepareModuleOutput", "NoParallel", "ParallelStyle",
子包 hyper_parallel.core.tensor_parallel 额外导出:
hyper_parallel.core.tensor_parallel
"loss_parallel", "is_loss_parallel_active"
未导出但常用:
from hyper_parallel.core.tensor_parallel import ...
PyTorch 对标导出(torch.distributed.tensor.parallel):
"parallelize_module", "loss_parallel", "ColwiseParallel", "RowwiseParallel", "SequenceParallel", "PrepareModuleInput", "PrepareModuleInputOutput", "PrepareModuleOutput", "ParallelStyle" # 注意:无 NoParallel;input_reshard 在子模块单独导入
父文档:#1 · 姊妹专项:#6 TP 差距与路线图 · 关联:#7 DTensor 总表 · #8 FSDP 总表 · #269 loss_parallel · #270 TP 异步 ACT
一、文档说明
本 Issue 定位: 在 #1 模块划分下,汇总 §3 张量并行(TP) 子模块的全量对外接口对标总表(表头:接口名 · 参数 · 功能 · hyper · pytorch · titan),作为 #6 差距梳理的接口索引附录。
分析依据(源码,2026-07):
hyper_parallel/__init__.py、hyper_parallel/core/tensor_parallel/、platform/*/loss_parallel_ops.pytorch/distributed/tensor/parallel/(api.py、style.py、loss.py、input_reshard.py、fsdp.py、ddp.py)torchtitan/distributed/tensor_parallel.py、models/common/decoder_sharding.py、models/*/parallelize.py、components/loss.py图例: ✅ 有对标 · ⚠️ 部分对标 · ❌ 无 · 🔶 Hyper 扩展
列说明:
torch.distributed.tensor.parallel对标 API架构备注: Hyper 策略类使用公开
apply()(PyTorch 为_apply());I/O 边界redistribute当前全同步(PyTorch 默认async_op=True→ ACT),见 #270。二、全量接口对标总表
parallelize_modulemodule,device_mesh,parallelize_plan,*, src_data_rank=0hyper_parallel.parallelize_moduletorch.distributed.tensor.parallel.parallelize_moduleModule.parallelize()parallelize_module·device_meshDeviceMesh | NoneNone取当前 mesh 上下文ndim>1显式抛错parallel_dims.get_mesh("tp")parallelize_module·parallelize_planParallelStyle | dict[str, ParallelStyle] | NoneShardingConfig映射为等价 layoutparallelize_module· fnmatch globlayers.*等parallelize_module·src_data_rankint | None,默认0distribute_tensorparallelize_module·plan=Noneparallelize_module·plan=""空路径ValueError_tensor_parallel_mesh_contextdevice_meshapi._tensor_parallel_mesh_context(未导出)ParallelStylehyper_parallel.ParallelStyletensor.parallel.ParallelStyleNoParallel)ParallelStyle.applymodule,device_meshapply_apply(私有)_applyParallelStyle.src_data_rankparallelize_module写入ColwiseParallel*, input_layouts,output_layouts,use_local_outputhyper_parallel.ColwiseParallelcolwise_config()/ 等价Shard(0)Shard(1)Replicate()→Shard(-1)use_local_outputTrueto_local()Dense/EmbeddingLinear、Embeddingredistributeasync_op=TrueRowwiseParallel*, input_layouts,output_layouts,use_local_output=Truerowwise_config()Shard(1)/Replicate()Shard(0)Partial("sum")再 redistributeReplicate()(非Shard(-1))SequenceParallel*, sequence_dim=1,use_local_output=Falsedense_sequence_parallel_placement()PrepareModuleInputinput_layouts,desired_input_layouts,input_kwarg_layouts,desired_input_kwarg_layouts,use_local_output=Falsewith_kwargs=Truepre-hookNonelayout 槽PrepareModuleOutputoutput_layouts,desired_output_layouts,use_local_output=TruePrepareModuleInputOutputuse_local_inputNoParallel*, input_layout,output_layout,desired_input_layout,use_local_output=Truehyper_parallel.NoParalleltorchtitan/distributed/tensor_parallel.pyloss_parallel*, mesh=None, strict=True(Hyper)core.tensor_parallel.loss_parallel(未进顶层__all__)tensor.parallel.loss_parallel_LossParallelCrossEntropyis_loss_parallel_activeget_loss_parallel_countloss_parallel.py(未导出)cross_entropy/CrossEntropyLoss_OP_DISPATCHER+ CE registryDTensor.__torch_dispatch__handler_LossParallelCrossEntropylabel_smoothinginput_reshardmodule,tp_device_mesh,input_reshard_dim=Nonetensor.parallel.input_reshardDTensorExtensionstensor.parallel.fsdp.DTensorExtensions_pre_dp_module_transformmoduletensor.parallel.ddp(内部)_data_parallel_utilssync_grad_hook等maybe_enable_async_tpparallelism,compile_config,tp_meshdistributed/tensor_parallel.pyparallelize_llama/model.parallelizeparallel_dims, …examples/torch/llama3/parallelize.pymodels/llama3/parallelize.pyparallelize_qwen3_5model,mesh,cfgNotImplementedErrordecoder_shardingcolwise_config,rowwise_config,set_gqa_attention_sharding, …ShardingConfig/SpmdLayoutmodels/common/decoder_sharding.pyModule.parallelize(parallel_dims)spmd_backend=full_dtensorShardingConfig/SpmdLayout_LossParallelCrossEntropyloss_parallel()components/loss.pyChunkedLossWrapperCrossEntropyLoss(Titan 组件)NoParallelinput_layout,output_layout,use_local_outputdesired_input_layoutshard_modulemodule,device_mesh,sharding_planhyper_parallel.shard_module🔶ShardingPlancore/shard/sharding_plan.pyprotocols/sharding.pyDFunctionhyper_parallel.DFunction🔶parallelize_value_and_gradhyper_parallel.parallelize_value_and_grad🔶gather_tensor_parallel_logitslogits,confighyper_parallel.infer🔶ParallelDimsdp_replicate,dp_shard,cp,tp,pp,ep, …hyper_parallel.trainer.parallel_dims🔶torchtitan.distributed.ParallelDimsParallelDims.get_mesh"tp"等ParallelDims.seq_len_divisortp * (cp*2)三、差距速查(与 #6 联动)
3.1 仅 PyTorch 有 · Hyper 无
input_reshardtensor.parallel.input_reshardDTensorExtensionstensor.parallel.fsdpfully_shard互操作_pre_dp_module_transformtensor.parallel.ddpparallelize_plan=""空路径 shortcutparallel.apiloss_parallel顶层导出tensor.parallelParallelStyle._apply命名_applyapply3.2 仅 TorchTitan 有 · Hyper 无
maybe_enable_async_tpdistributed/tensor_parallel.pytorch.compile+ micro-pipeline TPModule.parallelize(parallel_dims)ShardingConfig一站式 TPdecoder_sharding全套models/common/decoder_sharding.pyShardingConfig/SpmdLayoutprotocols/parallelize_module的 SPMD 协议full_dtensor后端_LossParallelCrossEntropy+ChunkedLossWrappercomponents/loss.pyparallelize_llama全流水线models/llama3/parallelize.pyparallelize_llama3parallelize_qwen3_5TPNotImplementedErrorNoParallel(distributed/tensor_parallel.py)3.3 PyTorch 有 · Hyper 有但语义偏弱(⚠️)
redistributeasync_op=True→ ACTsrc_data_rank+distribute_tensorloss_parallel()mesh/strict扩展;未顶层导出label_smoothingfully_shardDTensorExtensions桥接parallelize_moduledict 空 tokenValueError""行为不一致__torch_dispatch__custom handler__torch_function__+_OP_DISPATCHER3.4 Hyper 有 · PyTorch 用户 API 无直接对标
NoParallel(官方 TP 包)loss_parallel(mesh=..., strict=...)is_loss_parallel_active()ParallelStyle.apply(公开)_applyshard_module+ShardingPlanDFunction_OP_DISPATCHERparallelize_value_and_gradgather_tensor_parallel_logitsinfer/)ParallelDims(trainer)ParallelStyle适配Cell/Dense;pre-hook 须返回 tupleexamples/torch/llama3/parallelize.pyapply_tp的参考编排四、顶层导出清单(
hyper_parallel.__all__,本模块相关)"parallelize_module", "ColwiseParallel", "RowwiseParallel", "SequenceParallel", "PrepareModuleInput", "PrepareModuleInputOutput", "PrepareModuleOutput", "NoParallel", "ParallelStyle",子包
hyper_parallel.core.tensor_parallel额外导出:"loss_parallel", "is_loss_parallel_active"未导出但常用:
loss_parallel/is_loss_parallel_active(需from hyper_parallel.core.tensor_parallel import ...)_tensor_parallel_mesh_context(测试内部)shard_module、DFunction、parallelize_value_and_grad(低层扩展,在顶层__all__)gather_tensor_parallel_logits(hyper_parallel.infer)ParallelDims(hyper_parallel.trainer.parallel_dims)PyTorch 对标导出(
torch.distributed.tensor.parallel):"parallelize_module", "loss_parallel", "ColwiseParallel", "RowwiseParallel", "SequenceParallel", "PrepareModuleInput", "PrepareModuleInputOutput", "PrepareModuleOutput", "ParallelStyle" # 注意:无 NoParallel;input_reshard 在子模块单独导入五、维护说明
distribute_tensor通信(影响 TP 参数初始化)归属 #2 / #7,本表仅标注依赖关系。fully_shard衔接见 #8。父文档:#1 · 姊妹专项:#6 TP 差距与路线图 · 关联:#7 DTensor 总表 · #8 FSDP 总表 · #269 loss_parallel · #270 TP 异步 ACT