MCPcopy Create free account
hub / github.com/zai-org/CodeGeeX / model_parallel_cuda_manual_seed

Function model_parallel_cuda_manual_seed

codegeex/megatron/mpu/random.py:220–262  ·  view source on GitHub ↗

Initialize model parallel cuda seed. This function should be called after the model parallel is initialized. Also, no torch.cuda.manual_seed should be called after this function. Basically, this is replacement for that function. Two set of RNG states are tracked: default

(seed)

Source from the content-addressed store, hash-verified

218
219
220def model_parallel_cuda_manual_seed(seed):
221 """Initialize model parallel cuda seed.
222
223 This function should be called after the model parallel is
224 initialized. Also, no torch.cuda.manual_seed should be called
225 after this function. Basically, this is replacement for that
226 function.
227 Two set of RNG states are tracked:
228 default state: This is for data parallelism and is the same among a
229 set of model parallel GPUs but different across
230 different model paralle groups. This is used for
231 example for dropout in the non-tensor-model-parallel regions.
232 tensor-model-parallel state: This state is different among a set of model
233 parallel GPUs, but the same across data parallel
234 groups. This is used for example for dropout in
235 model parallel regions.
236 """
237 # 2718 is just for fun and any POSITIVE value will work.
238 offset = seed + 2718
239 tensor_model_parallel_seed = offset + get_tensor_model_parallel_rank()
240 # Data parallel gets the original seed.
241 data_parallel_seed = seed
242
243 if torch.distributed.get_rank() == 0:
244 print(
245 "> initializing model parallel cuda seeds on global rank {}, "
246 "model parallel rank {}, and data parallel rank {} with "
247 "model parallel seed: {} and data parallel seed: {}".format(
248 torch.distributed.get_rank(),
249 get_tensor_model_parallel_rank(),
250 get_data_parallel_rank(),
251 tensor_model_parallel_seed,
252 data_parallel_seed,
253 ),
254 flush=True,
255 )
256 _CUDA_RNG_STATE_TRACKER.reset()
257 # Set the default state.
258 torch.cuda.manual_seed(data_parallel_seed)
259 # and model parallel state.
260 _CUDA_RNG_STATE_TRACKER.add(
261 _MODEL_PARALLEL_RNG_TRACKER_NAME, tensor_model_parallel_seed
262 )
263
264
265class CheckpointFunction(torch.autograd.Function):

Callers

nothing calls this directly

Calls 4

get_data_parallel_rankFunction · 0.85
resetMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected