Skip to content

Commit

Permalink
Restore compatibility with Python 3.8 (#1189)
Browse files Browse the repository at this point in the history
* Restore compatibility with Python 3.8

Signed-off-by: Przemyslaw Tredak <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Signed-off-by: Przemyslaw Tredak <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
ptrendx and pre-commit-ci[bot] authored Sep 20, 2024
1 parent 195d703 commit 0c74535
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions transformer_engine/pytorch/distributed.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,12 +354,8 @@ def backward(

# Compute the forward pass.
detached_inputs = detach_variable(inputs)
with (
torch.enable_grad(),
ctx.recompute_ctx,
ctx.torch_gpu_amp_ctx,
ctx.torch_cpu_amp_ctx,
activation_recompute_forward(activation_recompute=True, recompute_phase=True),
with torch.enable_grad(), ctx.recompute_ctx, ctx.torch_gpu_amp_ctx, ctx.torch_cpu_amp_ctx, activation_recompute_forward(
activation_recompute=True, recompute_phase=True
):
outputs = ctx.run_function(*detached_inputs, **ctx.kwargs)

Expand Down Expand Up @@ -680,13 +676,9 @@ def checkpoint(
torch_gpu_amp_forward_ctx, torch_cpu_amp_forward_ctx = _get_active_autocast_contexts()

def recompute_fn(*args, **kwargs):
with (
torch.autograd.enable_grad(),
te_recompute_ctx,
user_recompute_ctx,
torch_gpu_amp_forward_ctx,
torch_cpu_amp_forward_ctx,
):
with torch.autograd.enable_grad(), (
te_recompute_ctx
), user_recompute_ctx, torch_gpu_amp_forward_ctx, torch_cpu_amp_forward_ctx:
function(*args, **kwargs)

# Initialize a new checkpoint frame for each new forward pass.
Expand Down

0 comments on commit 0c74535

Please sign in to comment.