目录

计划

TorchRec Planner 负责确定性能最高、最平衡的 用于分布式训练和推理的分片计划。

生成分片计划的主要 API 是EmbeddingShardingPlanner.plan

torchrec.distributed.types 中。ShardingPlanplan Dict[str ModuleShardingPlan])

分片计划的表示。这将使用较大包装模型(即使用 DistributedModelParallel 包装的模型)的 FQN 当需要 TorchRec 可组合性时,应使用 EmbeddingModuleShardingPlan。

计划

dict 以模块路径 以参数名称为键的参数分片规范的 dict。

类型

Dict[str, EmbeddingModuleShardingPlan]

get_plan_for_modulemodule_path: str 可选[ModuleShardingPlan]
参数

module_pathstr) –

结果

以参数名称为键的参数分片规范的 dict。如果给定module_path不存在分片规范,则为 None。

返回类型

可选[ModuleShardingPlan]

torchrec.distributed.planner.planners。EmbeddingShardingPlannertopology Optional[topology] = Nonebatch_size: Optional[int] = 枚举器可选[枚举器] = storage_reservation:可选[StorageReservation] = None提议者 Optional[Union[提议者 List[提议者]]] = 分区程序可选[分区程序] = performance_model: 可选[PerfModel] = Nonestats 可选[Union[Stats List[Stats]]] = 约束 可选[Dict[str ParameterConstraints]] = debug bool = True回调 可选[List[Callable[[List[ShardingOption]]], List[ShardingOption]]]] = )

为给定模块提供具有可分片参数的优化分片计划 根据提供的分片、拓扑和约束。

参数
  • topologyOptional[Topology]) – 当前进程组的拓扑。

  • batch_sizeOptional[int]) – 模型的批量大小。

  • enumeratorOptional[Enumerator]) – 要使用的枚举器

  • storage_reservationOptional[StorageReservation]) – 要使用的存储预留

  • proposerOptional[Union[ProposerList[Proposer]]]) – 要使用的提议者

  • partitionerOptional[Partitioner]) – 要使用的分区器

  • performance_modelOptional[PerfModel]) – 要使用的性能模型

  • statsOptional[Union[StatsList[Stats]]]) – 要使用的统计数据

  • constraintsOptional[Dict[strParameterConstraints]]) – 每个表的约束 进行分片。

  • debugbool) – 是否打印调试信息。

例:

ebc = EmbeddingBagCollection(tables=eb_configs, device=torch.device("meta"))
planner = EmbeddingShardingPlanner()
plan = planner.plan(
    module=ebc,
    sharders=[EmbeddingBagCollectionSharder()],
)
collective_planmodule Modulesharders Optional[List[ModuleSharder[Module]]] = Nonepg 可选[ProcessGroup] = None ShardingPlan

在排名 0 上调用 self.plan(...) 并广播

参数
  • 模块nn.Module) – 要分片的模块。

  • 分片器Optional[List[ModuleSharder[nn.Module]]]) – 用于分片的分片

  • pg可选[dist.ProcessGroup]) – 用于集合操作的流程组

结果

模块的分片计划。

返回类型

分片计划

planmodule Module分片器: List[ModuleSharder[Module]]) ShardingPlan

为给定模块提供具有可分片参数的优化分片计划 根据提供的分片、拓扑和约束。

参数
  • 模块nn.Module) – 要分片的模块。

  • 分片List[ModuleSharder[nn.Module]]) – 用于分片的分片程序。

结果

模块的分片计划。

返回类型

分片计划

torchrec.distributed.planner.enumerators。EmbeddingEnumeratortopology Topologybatch_size intconstraints Optional[Dict[str ParameterConstraints]] = Noneestimator 可选[Union[ShardEstimator List[ShardEstimator]]] = use_exact_enumerate_order:可选[bool] = False)

为给定的 nn 生成嵌入分片选项。模块,考虑用户提供 约束。

参数
  • topologyTopology) – 设备拓扑。

  • batch_sizeint) – 批量大小。

  • constraintsOptional[Dict[strParameterConstraints]]) – 参数名称的字典 添加到提供的 ParameterConstraints 中。

  • estimatorOptional[Union[ShardEstimatorList[ShardEstimator]]]) – 分片性能估算器。

  • use_exact_enumerate_orderbool) – 是否按确切的 name_children 枚举顺序枚举可分片参数

enumeratemodule Modulesharders List[ModuleSharder[Module]]) List[ShardingOption]

在给定的 module 和 sharders 中生成相关的分片选项。

参数
  • 模块nn.Module) – 要分片的模块。

  • 分片List[ModuleSharder[nn.Module]]) – 为 module 提供分片。

结果

填充了值的有效分片选项。

返回类型

列表[ShardingOption]

populate_estimatessharding_options List[ShardingOption]

请参阅类描述。

torchrec.distributed.planner.partitioners 中。GreedyPerfPartitionersort_by: SortBy = SortBy.STORAGEbalance_modules: bool = False)

贪婪分区程序。

参数
  • sort_bySortBy) – 按存储或性能对分片选项进行排序 降序(即,大表将放在最前面)。

  • balance_modulesbool) – 是否先按模块排序,其中 较小的模块将首先排序。实际上,这将 表。

partition提案 List[ShardingOption]storage_constraint 拓扑 List[ShardingOption]

根据每个分片选项的 partition_by 属性将分片选项放置在拓扑上。 topology、storage 和 perfs 将在放置结束时更新。

参数
  • proposalList[ShardingOption]) – 填充的分片选项列表。

  • storage_constraintTopology) – 设备拓扑。

结果

所选计划的分片选项列表。

返回类型

列表[ShardingOption]

例:

sharding_options = [
        ShardingOption(partition_by="uniform",
                shards=[
                    Shards(storage=1, perf=1),
                    Shards(storage=1, perf=1),
                ]),
        ShardingOption(partition_by="uniform",
                shards=[
                    Shards(storage=2, perf=2),
                    Shards(storage=2, perf=2),
                ]),
        ShardingOption(partition_by="device",
                shards=[
                    Shards(storage=3, perf=3),
                    Shards(storage=3, perf=3),
                ])
        ShardingOption(partition_by="device",
                shards=[
                    Shards(storage=4, perf=4),
                    Shards(storage=4, perf=4),
                ]),
    ]
topology = Topology(world_size=2)

# First [sharding_options[0] and sharding_options[1]] will be placed on the
# topology with the uniform strategy, resulting in

topology.devices[0].perf.total = (1,2)
topology.devices[1].perf.total = (1,2)

# Finally sharding_options[2] and sharding_options[3]] will be placed on the
# topology with the device strategy (see docstring of `partition_by_device` for
# more details).

topology.devices[0].perf.total = (1,2) + (3,4)
topology.devices[1].perf.total = (1,2) + (3,4)

# The topology updates are done after the end of all the placements (the other
# in the example is just for clarity).
torchrec.distributed.planner.storage_reservations 类HeuristicalStorageReservation百分比 floatparameter_multiplier: float = 6.0dense_tensor_estimate 可选 [int] = )

为要使用启发式计算分片的模型保留存储。存储 reservation 由密集张量存储、KJT 存储和额外的 总存储的百分比。

参数
  • percentagefloat) – 要预留的额外存储百分比,用作边距 超出 storage 的启发式计算的误差。

  • parameter_multiplierfloat) – 总参数存储的启发式乘数。

  • dense_tensor_estimateOptional[int]) – 密集张量的存储估计值,使用 default heuristic estimate (如果未提供)。

torchrec.distributed.planner.proposers 中。GreedyProposeruse_depth: bool = Truethreshold Optional[int] = None)

以贪婪的方式提出分片计划。

按 perf 对每个可分片参数的分片选项进行排序。 在每次迭代中,查找当前存储使用率最高的参数,并尝试其 next sharding 选项。

参数
  • use_depthbool) – 启用后,fqn 的sharding_options将根据 max(shard.perf.total) 进行排序,否则sharding_options按 sum(shard.perf.total) 排序。

  • thresholdOptional[int]) – 提前停止的阈值。指定后, 当提案连续出现更差perf_rating时,提议者停止提议 比 best_perf_rating。

feedbackpartitionable boolplan Optional[List[ShardingOption]] = Noneperf_rating可选[浮点数] = storage_constraint可选[拓扑] =

向提议者提供反馈。

参数
  • partitionablebool) – 计划是否可分区。

  • planOptional[List[ShardingOption]]) – 提供反馈的计划。

  • perf_ratingOptional[float]) – 计划的性能评级。

  • storage_constraintOptional[Topology]) – 计划的存储约束。

loadsearch_space: List[ShardingOption]enumerator 可选[Enumerator] = None

将搜索空间加载到 proposer 中。

参数
  • search_spaceList[ShardingOption]) – 要加载的搜索空间。

  • enumeratorEnumerator) - 用于生成搜索空间的枚举器。

propose 可选[List[ShardingOption]]

提出分片计划。

结果

拟议计划。

返回类型

可选[List[ShardingOption]]

torchrec.distributed.planner.shard_estimators 类EmbeddingPerfEstimatortopology 拓扑constraints Optional[Dict[str ParameterConstraints]] = is_inference:bool = False)

Embedding Wall Time Perf Estimator (嵌入 Wall Time Perf Estimator)。此估算器估计实际时间 的 sharding 选项。

参数
  • topologyTopology) – 设备拓扑。

  • constraintsOptional[Dict[strParameterConstraints]]) – 参数约束。

  • is_inferencebool) – 估计器是否用于推理。

estimatesharding_options List[ShardingOption]sharder_map: Optional[Dict[str ModuleSharder[模块]]] =

估计给定分片选项的固定时间。

参数
  • sharding_optionsList[ShardingOption]) – 分片选项列表。

  • sharder_map可选[Dict[strModuleSharder[nn.Module]]]) – 分片映射。

类方法 perf_func_emb_wall_timeshard_sizes: List[List[int]], compute_kernel: strcompute_device:strsharding_typestrbatch_sizesList[int]world_size:intlocal_world_sizeintinput_lengthsList[float]input_data_type_sizefloattable_data_type_大小浮点数,output_data_type_size:浮点数fwd_a2a_comm_data_type_size:浮点数,bwd_a2a_comm_data_type_size:浮点数、fwd_sr_comm_data_type_sizefloatbwd_sr_comm_data_type_sizefloatnum_poolings:List[float]hbm_mem_bw floatddr_mem_bw floathbm_to_ddr_mem_bw: floatintra_host_bw floatinter_host_bw floatbwd_compute_multiplier: floatweighted_feature_bwd_compute_multiplier: floatis_pooled boolis_weighted bool = Falsecaching_ratio 可选[float] = is_inferencebool = False,prefetch_pipeline:bool = False,expected_cache_fetches:float = 0,uneven_sharding_perf_multiplier:float = 1.0 列表[Perf]

尝试将 perfs 建模为相对实际时间的函数。

参数
  • shard_sizesList[List[int]]) – 每个列表的 (local_rows, local_cols) 碎片。

  • compute_kernelstr) – 计算内核。

  • compute_devicestr) – 计算设备。

  • sharding_typeSTR) – TW、RW、CW、TWRW、DP。

  • batch_sizesList[int]) – 每个输入特征的批量大小。

  • world_sizeint) – 所有主机的设备数量。

  • local_world_sizeint) – 每个主机的设备编号。

  • input_lengthsList[float]) – 每个的平均查找次数列表 input 查询功能。

  • input_data_type_sizefloat) – 分布式的数据类型大小 data_parallel input。

  • table_data_type_sizefloat) – 表的数据类型大小。

  • output_data_type_sizefloat) – 输出嵌入的数据类型大小。

  • fwd_comm_data_type_sizefloat) – 分布式的数据类型大小 data_parallel 正向通信期间的输入。

  • bwd_comm_data_type_sizefloat) – 分布式的数据类型大小 data_parallel 反向通信期间的输入。

  • num_poolingsList[float]) – 每个样本的池化数,通常为 1.0。

  • hbm_mem_bwfloat) – 设备 HBM 的带宽。

  • ddr_mem_bwfloat) – 系统 DDR 内存的带宽。

  • hbm_to_ddr_bwfloat) – 设备 HBM 和系统 DDR 之间的带宽。

  • intra_host_bwfloat) – 单个主机(如多个线程)内的带宽。

  • inter_host_bwfloat) – 两台主机(如多台计算机)之间的带宽。

  • is_pooledbool) - 如果嵌入输出是池化的(即.EmbeddingBag)、False 如果未池化/顺序(即。嵌入)。

  • is_weightedbool = False) – 如果模块是 EBC 并且是加权的,通常 表示 ID 分数列表特征。

  • is_inferencebool = False) – 如果计划推理。

  • caching_ratioOptional[float] = None) – 用于确定带宽的缓存比率 的设备。

  • prefetch_pipelinebool = False) – 是否启用预取管道。

  • expected_cache_fetchesfloat) – 跨全局批处理的预期缓存获取次数

  • uneven_sharding_perf_multiplierfloat = 1.0) – 考虑分片性能不均匀的乘数

结果

每个分片的性能列表。

返回类型

列表[float]

torchrec.distributed.planner.shard_estimators 类EmbeddingStorageEstimatortopology 拓扑constraints Optional[Dict[str ParameterConstraints]] = pipeline_typePipelineType = PipelineType.NONE,run_embedding_at_peak_memorybool = Falseis_inference: bool = False)

嵌入存储使用估算器

参数
  • topologyTopology) – 设备拓扑。

  • constraintsOptional[Dict[strParameterConstraints]]) – 参数约束。

  • pipeline_typePipelineType) – 管道的类型(如果有)。将决定 在内存估计期间输入 replication factor。

  • run_embedding_at_peak_memorybool) –

    如果在 HBM 使用量处于峰值。当设置为 TRUE 时,在 embedding forward/backward,只要 output_dist 之前的输出大小就会 计入 HBM 存储成本。否则他们不会,因为他们会 被真实内存峰值“隐藏”。

    仅当 pipeline_type 设置为向后兼容时生效(不影响 使用旧管道不可知公式的模型)

    默认为 false,因为对于 RecSys 来说,这通常为 false,因为内存 峰值发生在 DENSE Forwrad 的末尾/DENSE BACKWARD 的开头。

  • is_inferencebool) – 如果模型是推理模型。默认为 False。

estimatesharding_options List[ShardingOption]sharder_map: Optional[Dict[str ModuleSharder[模块]]] =

估算每个分片选项的存储成本。

参数
  • sharding_optionsList[ShardingOption]) – 分片选项列表。

  • sharder_map可选[Dict[strModuleSharder[nn.Module]]]) – 来自模块的映射 键入到 sharder。

文档

访问 PyTorch 的全面开发人员文档

查看文档

教程

获取面向初学者和高级开发人员的深入教程

查看教程

资源

查找开发资源并解答您的问题

查看资源