Skip to content

Is torch_remat intended to avoid per-op SAC dispatch overhead in host-bound workloads? #5

Description

@DavidFFFan

Hi, thanks for open-sourcing this project.

We encountered a performance issue when using PyTorch native Selective Activation Checkpointing (SAC) for a Transformer layer.

Our intended policy was:

  • recompute the Transformer layer as a whole;
  • save the All-to-All operation and exclude it from recomputation;
  • recompute the remaining operations.

Conceptually, the SAC policy looked like this:

def policy_fn(ctx, op, *args, **kwargs):
    if is_all_to_all(op):
        return CheckpointPolicy.MUST_SAVE
    return CheckpointPolicy.PREFER_RECOMPUTE

Unexpectedly, this selective configuration was slower than fully recomputing the entire Transformer layer, even though it avoided repeating the All-to-All operation.

Profiler analysis suggested that the workload became Host-bound. In particular, the per-operation TorchDispatchMode / policy callback path appeared to delay accelerator operator launches. The additional Host dispatch overhead outweighed the compute/communication saved by excluding All-to-All from recomputation.

Is this type of workload one of the main motivations for torch_remat?

Our understanding is that the equivalent configuration would be approximately:

def transformer_layer(x):
    # Other operations recompute by default.
    x = remat.region(
        all_to_all_region,
        "all_to_all",
        recompute=False,
    )(x)
    return remaining_layer(x)

output = remat.checkpoint(
    region_name="transformer_layer",
)(transformer_layer)(input)

Unlike native SAC, this makes the save/recompute decision at explicit callable-region boundaries rather than invoking a Python policy for every dispatched ATen operation.

We would like to confirm:

  1. Is avoiding per-ATen-op dispatch overhead a design goal of torch_remat?
  2. Is wrapping the whole Transformer layer with remat.checkpoint and marking only the All-to-All region with recompute=False the recommended configuration?
  3. Are there any benchmarks comparing the Host overhead of region-based rematerialization against native SAC?
  4. Are there recommended region granularities for Host-bound workloads?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions