MCPcopy Create free account
hub / github.com/AIS-SNU/Smart-Infinity / forward

Method forward

DeepSpeedExample/megatron/mpu/random.py:253–276  ·  view source on GitHub ↗
(ctx, run_function, *args)

Source from the content-addressed store, hash-verified

251 """
252 @staticmethod
253 def forward(ctx, run_function, *args):
254 ctx.run_function = run_function
255
256 # Copy the rng states.
257 ctx.fwd_cpu_rng_state = torch.get_rng_state()
258 ctx.fwd_cuda_rng_state = torch.cuda.get_rng_state()
259 ctx.fwd_cuda_rng_state_tracker = get_cuda_rng_tracker().get_states()
260
261 with torch.no_grad():
262 outputs = run_function(*args)
263
264 # Divide hidden states across model parallel group and only keep
265 # the chunk corresponding to the current rank.
266 if _CHECKPOINTED_ACTIVATIONS_MEMORY_BUFFER is not None:
267 ctx.input_0_shape = args[0].data.shape
268 args[0].data = split_tensor_into_1d_equal_chunks(args[0].data)
269 args[0].data = _CHECKPOINTED_ACTIVATIONS_MEMORY_BUFFER.add(
270 args[0].data)
271
272 # Store everything.
273 ctx.save_for_backward(*args)
274
275
276 return outputs
277
278 @staticmethod
279 def backward(ctx, *args):

Callers

nothing calls this directly

Calls 5

get_cuda_rng_trackerFunction · 0.70
get_rng_stateMethod · 0.45
get_statesMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected