Skip to content
9 changes: 9 additions & 0 deletions megatron/core/tensor_parallel/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,15 @@ def _recompute(self, _):

# Store the inputs for backward pass
inputs = self.ctx.saved_tensors

def detach(t):
if isinstance(t, torch.Tensor):
requires_grad = t.requires_grad
t = t.detach()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain why we need detach here?

t.requires_grad_(requires_grad)
return t

inputs = tuple(detach(t) for t in inputs)
with torch.enable_grad(), fp8_ctx, recompute_ctx:
outputs = self.run_function(*inputs)

Expand Down
3 changes: 3 additions & 0 deletions megatron/core/transformer/multi_token_prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
from megatron.core.fp8_utils import get_fp8_context
from megatron.core.models.backends import BackendSpecProvider, LocalSpecProvider
from megatron.core.packed_seq_params import PackedSeqParams
from megatron.core.pipeline_parallel.fine_grained_activation_offload import (
fine_grained_offloading_set_last_layer,
)
from megatron.core.process_groups_config import ProcessGroupCollection
from megatron.core.tensor_parallel import (
gather_from_tensor_model_parallel_region,
Expand Down
2 changes: 1 addition & 1 deletion megatron/training/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -2346,7 +2346,7 @@ def _add_training_args(parser):
group.add_argument('--fine-grained-activation-offloading', action='store_true',
help='Enable fine-grained activation offloading.')
group.add_argument('--offload-modules', nargs='*', type=str, default=[],
help='The submodules to offload its input. Choices: "attn_norm", "core_attn", "attn_proj", "mlp_norm", "expert_fc1", "moe_act".')
help='The submodules to offload its input. Choices: "attn_norm", "qkv_linear", "core_attn", "attn_proj", "mlp_norm", "expert_fc1", "moe_act".')
group.add_argument('--min-offloaded-tensor-size', type=int, default=1024*1024,
help='The minimum size of the tensor to be offloaded.')
return parser
Expand Down
Loading
Loading