8000 compilation error on SequenceParallel'ed Dropout · Issue #147757 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content
compilation error on SequenceParallel'ed Dropout #147757
@bonpyt

Description

@bonpyt

🐛 Describe the bug

Trying to compile a model with Dropout parallelised with SequenceParallel fails:

import torch
from torch.distributed.device_mesh import init_device_mesh
from torch.distributed.tensor import Shard, DTensor
from torch import nn
from torch.distributed import get_rank
from torch.distributed._tensor import Replicate, Shard
from torch.distributed.device_mesh import DeviceMesh
from torch.distributed.tensor import DTensor
from torch.distributed.tensor.parallel import (
    ColwiseParallel,
    PrepareModuleInput,
    PrepareModuleOutput,
    RowwiseParallel,
    SequenceParallel,
    parallelize_module,
)


class Model(nn.Module):
    def __init__(self, n):
        super().__init__()
        self.dropout = nn.Dropout()

    def forward(self, x):
        x = self.dropout(x)
        return x


def main():
    mesh = init_device_mesh("cuda", (2,))
    device = torch.device(f"cuda:{get_rank()}")
    torch.set_default_device(device)
    dim = 4
    model = Model(dim)

    if True:
        parallelize_module(
            model,
            mesh,
            {
                "dropout": SequenceParallel(),
            },
        )

    if True:
        model = torch.compile(model)
    dt = torch.randn(2, dim, dim)

    l = model(dt)
    print(l)


if __name__ == "__main__":
    main()

Fails with this error:

[rank1]:   File "python3.12/site-packages/torch/distributed/tensor/_random.py", line 186, in _distribute_region
[rank1]:     old_offset = self.get_offset("parallel-rng")
[rank1]:                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank1]:   File "python3.12/site-packages/torch/distributed/tensor/_random.py", line 204, in get_offset
[rank1]:     offset_tensor = (self.rng_states[name])[8:].view(dtype=torch.int64)
[rank1]:                     ~~~~~~~~~~~~~~~~~~~~~~~^^^^
[rank1]:   File "python3.12/site-packages/torch/utils/_stats.py", line 21, in wrapper
[rank1]:     return fn(*args, **kwargs)
[rank1]:            ^^^^^^^^^^^^^^^^^^^
[rank1]:   File "python3.12/site-packages/torch/_subclasses/fake_tensor.py", line 1276, in __torch_dispatch__
[rank1]:     return self.dispatch(func, types, args, kwargs)
[rank1]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank1]:   File "python3.12/site-packages/torch/_subclasses/fake_tensor.py", line 1816, in dispatch
[rank1]:     return self._cached_dispatch_impl(func, types, args, kwargs)
[rank1]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank1]:   File "python3.12/site-packages/torch/_subclasses/fake_tensor.py", line 1386, in _cached_dispatch_impl
[rank1]:     output = self._dispatch_impl(func, types, args, kwargs)
[rank1]:              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank1]:   File "python3.12/site-packages/torch/_subclasses/fake_tensor.py", line 2067, in _dispatch_impl
[rank1]:     (flat_args, flat_arg_fake_tensors) = self.validate_and_convert_non_fake_tensors(
[rank1]:                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank1]:   File "python3.12/site-packages/torch/_subclasses/fake_tensor.py", line 2465, in validate_and_convert_non_fake_tensors
[rank1]:     validated_args = [validate(a) for a in flat_args]
[rank1]:                       ^^^^^^^^^^^
[rank1]:   File "python3.12/site-packages/torch/_subclasses/fake_tensor.py", line 2453, in validate
[rank1]:     raise AssertionError(
[rank1]: torch._dynamo.exc.TorchRuntimeError: Failed running call_function <function dropout at 0x7f686830ab60>(*(DTensor(local_tensor=FakeTensor(..., device='cuda:1', size=(32, 4, 16)), device_mesh=DeviceMesh('cuda', [0, 1]), placements=(Shard(dim=1),)), 0.5, True, False), **{}):
[rank1]: Please convert all Tensors to FakeTensors first or instantiate FakeTensorMode with 'allow_non_fake_inputs'. Found in aten.slice.Tensor(tensor([...], size=(16,), dtype=torch.uint8), 0, 8, 9223372036854775807)

Disabling either compilation or parallelisation works.

Incidentally, the SequenceParallel documentation mentions that SequenceParallel supports Dropout:

SequenceParallel replicates a compatible nn.Module parameters and runs the sharded computation with input sharded on the sequence dimension. This currently supports nn.LayerNorm, nn.Dropout, and the RMSNorm python implementation

However the docstring and comments only mention LayerNorm and RMSNorm:

SequenceParallel style assumes ones initialization if there are weights in the nn.Module (i.e. nn.LayerNorm or RMSNorm, and they by default have ones initialization).

So the level of support for Dropout is not quite clear.

Versions

Collecting environment information...
PyTorch version: 2.6.0+cu124
Is debug build: False
CUDA used to build PyTorch: 12.4
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.6 LTS (x86_64)
GCC version: (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
Clang version: 10.0.0-4ubuntu1
CMake version: version 3.16.3
Libc version: glibc-2.31

Python version: 3.12.8 (main, Dec 4 2024, 08:54:13) [GCC 9.4.0] (64-bit runtime)
Python platform: Linux-5.15.0-116-generic-x86_64-with-glibc2.31
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration:
GPU 0: NVIDIA H200
GPU 1: NVIDIA H200
GPU 2: NVIDIA H200
GPU 3: NVIDIA H200
GPU 4: NVIDIA H200
GPU 5: NVIDIA H200
GPU 6: NVIDIA H200
GPU 7: NVIDIA H200

Nvidia driver version: 535.216.03
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
Address sizes: 46 bits physical, 57 bits virtual
CPU(s): 96
On-line CPU(s) list: 0-95
Thread(s) per core: 1
Core(s) per socket: 48
Socket(s): 2
NUMA node(s): 2
Vendor ID: GenuineIntel
CPU family: 6
Model: 207
Model name: INTEL(R) XEON(R) PLATINUM 8568Y+
Stepping: 2
CPU MHz: 2300.000
BogoMIPS: 4600.00
L1d cache: 4.5 MiB
L1i cache: 3 MiB
L2 cache: 192 MiB
L3 cache: 600 MiB
NUMA node0 CPU(s): 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94
NUMA node1 CPU(s): 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,69,71,73,75,77,79,81,83,85,87,89,91,93,95
Vulnerability Gather data sampling: Not affected
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Mmio stale data: Not affected
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed: Not affected
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass: Vulnerable
Vulnerability Spectre v1: Vulnerable: __user pointer sanitization and usercopy barriers only; no swapgs barriers
Vulnerability Spectre v2: Vulnerable; IBPB: disabled; STIBP: disabled; PBRSB-eIBRS: Vulnerable; BHI: Vulnerable
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Not affected
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cat_l2 cdp_l3 invpcid_single cdp_l2 ssbd mba ibrs ibpb stibp ibrs_enhanced fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local split_lock_detect avx_vnni avx512_bf16 wbnoinvd dtherm ida arat pln pts avx512vbmi umip pku ospke waitpkg avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq la57 rdpid bus_lock_detect cldemote movdiri movdir64b enqcmd fsrm md_clear serialize tsxldtrk pconfig arch_lbr amx_bf16 avx512_fp16 amx_tile amx_int8 flush_l1d arch_capabilities

Versions of relevant libraries:
[pip3] mypy==1.13.0
[pip3] mypy-extensions==1.0.0
[pip3] mypy-protobuf==3.6.0
[pip3] numpy==2.0.1
[pip3] nvidia-cublas-cu12==12.4.5.8
[pip3] nvidia-cuda-cupti-cu12==12.4.127
[pip3] nvidia-cuda-nvrtc-cu12==12.4.127
[pip3] nvidia-cuda-runtime-cu12==12.4.127
[pip3] nvidia-cudnn-cu12==9.1.0.70
[pip3] nvidia-cufft-cu12==11.2.1.3
[pip3] nvidia-curand-cu12==10.3.5.147
[pip3] nvidia-cusolver-cu12==11.6.1.9
[pip3] nvidia-cusparse-cu12==12.3.1.170
[pip3] nvidia-cusparselt-cu12==0.6.2
[pip3] nvidia-nccl-cu12==2.21.5
[pip3] nvidia-nvjitlink-cu12==12.4.127
[pip3] nvidia-nvtx-cu12==12.4.127
[pip3] pytorch-lightning==2.4.0
[pip3] torch==2.6.0
[pip3] torch-tb-profiler==0.4.3
[pip3] torchmetrics==1.6.0
[pip3] triton==3.2.0
[pip3] tritonclient==2.54.0
[conda] Could not collect

cc @H-Huang @awgu @kwen2501 @wanchaol @fegin @fduwjj @wz337 @wconstab @d4l3k @c-p-i-o @ezyang @albanD @chauhang @penguinwu @tianyu-l @XilunWu

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: dtensordistributed tensor tagoncall: distributedAdd this issue/PR to distributed oncall triage queueoncall: pt2tensor subclassRelated to tensor subclassestriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0