Repository: pytorch
Issue: [Runtime Error in ddp_pipeline.py] RuntimeError: unsupported operation: some elements of the input tensor and the written-to tensor refer to a single memory location. Please clone() the tensor before performing the operation.
Labels: high priority,triage review,oncall: distributed,module: docs,triaged,module: ddp

## 🐛 Bug

When following the [PyTorch tutorial (Training Transformer models using Distributed Data Parallel and Pipeline Parallelism)](https://github.com/pytorch/tutorials/blob/master/advanced_source/ddp_pipeline.py), there is a Runtime Error.
```
RuntimeError: unsupported operation: some elements of the input tensor and the written-to tensor refer to a single memory location. Please clone() the tensor before performing the operation.
```
The full error message is as follows.
```
(base) root@xxx:/xxx# python ddp_pipeline.py
[RANK 1]: Total parameters in model: 1,041,444,974
[RANK 0]: Total parameters in model: 1,041,444,974
Traceback (most recent call last):
  File "ddp_pipeline.py", line 452, in <module>
    mp.spawn(run_worker, args=(world_size, ), nprocs=world_size, join=True)
  File "/opt/conda/lib/python3.7/site-packages/torch/multiprocessing/spawn.py", line 230, in spawn
    return start_processes(fn, args, nprocs, join, daemon, start_method='spawn')
  File "/opt/conda/lib/python3.7/site-packages/torch/multiprocessing/spawn.py", line 188, in start_processes
    while not context.join():
  File "/opt/conda/lib/python3.7/site-packages/torch/multiprocessing/spawn.py", line 150, in join
    raise ProcessRaisedException(msg, error_index, failed_process.pid)
torch.multiprocessing.spawn.ProcessRaisedException:

-- Process 0 terminated with the following error:
Traceback (most recent call last):
  File "/opt/conda/lib/python3.7/site-packages/torch/multiprocessing/spawn.py", line 59, in _wrap
    fn(i, *args)
  File "/xxx/xxx/ddp_pipeline.py", line 419, in run_worker
    train()
  File "/xxx/xxx/ddp_pipeline.py", line 370, in train
    output = model(data).local_value()
  File "/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "/opt/conda/lib/python3.7/site-packages/torch/nn/parallel/distributed.py", line 878, in forward
    self._sync_params()
  File "/opt/conda/lib/python3.7/site-packages/torch/nn/parallel/distributed.py", line 1382, in _sync_params
    authoritative_rank,
  File "/opt/conda/lib/python3.7/site-packages/torch/nn/parallel/distributed.py", line 1335, in _distributed_broadcast_coalesced
    self.process_group, tensors, buffer_size, authoritative_rank
RuntimeError: unsupported operation: some elements of the input tensor and the written-to tensor refer to a single memory location. Please clone() the tensor before performing the operation.
```

## To Reproduce

Steps to reproduce the behavior:

1. Execute [ddp_pipeline.py](https://github.com/pytorch/tutorials/blob/master/advanced_source/ddp_pipeline.py)


<!-- If you have a code sample, error messages, stack traces, please provide it here as well -->

## Expected behavior

The code runs and doesn't crash.

<!-- A clear and concise description of what you expected to happen. -->

## Environment

 - PyTorch Version (e.g., 1.0): 1.10.0+cu102
 - OS (e.g., Linux): Ubuntu 18.04.6 LTS (x86_64)
 - How you installed PyTorch: `pip`
 - Build command you used (if compiling from source): `python ddp_pipeline.py`
 - Python version: 3.7.4
 - CUDA/cuDNN version: 10.1.243
 - GPU models and configuration: Tesla V100-PCIE-32GB (*8)




cc @ezyang @gchanan @zou3519 @bdhirsh @pietern @mrshenli @pritamdamania87 @zhaojuanmao @satgera @rohan-varma @gqchen @aazzolini @osalpekar @jiayisuse @SciPioneer @H-Huang @brianjo @mruberry