# Model grad buffer ranges.
self.model_gbuf_ranges =[]for model_index, model inenumerate(self.models):
self.model_gbuf_ranges.append(self.build_model_gbuf_range_map(model))
@classmethoddefbuild_model_gbuf_range_map(cls, model):"""
Create param-to-grad-buffer mappings, for grad buffer data types
within a specific virtual model.
"""return{
dtype : cls.build_model_gbuf_range(model, dtype)for dtype in model._grad_buffers
}classRange:"""
A range represents a start and end points for indexing a shard
from a full tensor.
"""def__init__(self, start, end):
self.start = start
self.end = end
self.size = end - start
defnormalize(self, start =0):return Range(start, start + self.size)def__str__(self):return"%d,%d [%d]"%(self.start, self.end, self.size)def__len__(self):return self.end - self.start
build_model_gbuf_range初始化range的流程如下:
获取DP的rank,计算单个Grad buffer切片的大小
保存当前rank的world range和local range, 分别对应world index和local index
计算param的range范围,对应param index
返回当前rank的相关range范围
@classmethoddefbuild_model_gbuf_range(cls, model, dtype):# 获取DP的rank
data_parallel_rank = mpu.get_data_parallel_rank()
data_parallel_world_size = mpu.get_data_parallel_world_size()# 计算单个Grad buffer切片的大小
grad_buffer = model._grad_buffers[dtype]
gbuf_size = grad_buffer.numel
max_gbuf_range_size =int(math.ceil(gbuf_size / data_parallel_world_size))# 跟据DDP的rank总数,分别计算每个rank对应的全局range
gbuf_world_all_ranges =[]for r inrange(data_parallel_world_size):
gbuf_world_start = r * max_gbuf_range_size
gbuf_world_end =min(gbuf_size, gbuf_world_start+max_gbuf_range_size)
gbuf_world_range = Range(gbuf_world_start, gbuf_world_end)
gbuf_world_all_ranges.append(gbuf_world_range)# 保存当前rank的world range和local range# Local DP's ranges.
gbuf_world_range = gbuf_world_all_ranges[data_parallel_rank]
gbuf_local_range = gbuf_world_range.normalize()# 计算param的range范围
param_range_map = cls.build_model_gbuf_param_range_map(model,
dtype,
gbuf_world_range)# Group into dict.
data ={"local": gbuf_local_range,"world": gbuf_world_range,"world_all": gbuf_world_all_ranges,"param_map": param_range_map,"max_range_size": max_gbuf_range_size,}return data
classDistributedOptimizer(MixedPrecisionOptimizer):def__init__(...):...
self.model_param_gbuf_map = \
self.build_model_param_gbuf_map(self.model_gbuf_ranges)...defbuild_model_param_gbuf_map(cls, model_gbuf_ranges):"""
Create a reverse of the model_gbuf_ranges, for referencing in
opposite direction.
"""
param_gbuf_map ={}for model_index, model_gbuf_range_map inenumerate(model_gbuf_ranges):for dtype, gbuf_range_map in model_gbuf_range_map.items():for param, param_range_map in gbuf_range_map["param_map"].items():
param_gbuf_map[param]=(model_index, dtype)return param_gbuf_map
在self.build_model_param_gbuf_map之后是初始化Optimizer对应的local group range,Optimizer原本有param_groups包括多个参数组,这里build_optimizer_group_ranges为了创建param参数到group_index的map映射,也就是<model_parameter:group_index>;self.build_model_param_gbuf_map最后对每个group_range中增加新的orig_group和orig_group_idx两个key,原来group_range初始化的时候只有params一个key
名称: An Adaptive Metadata Management Scheme Based on Deep Reinforcement Learning for Large-Scale Distributed File Systems
I. 引言
如今,大型集群文件系统的规模已达到PB甚至EB级别,由此产生的数据呈指数级增长。系统架构师不断设…