this is the follow up of this.
this is not urgent as it seems it is still in dev and not documented.
pytorch 1.9.0
hi,
log in ddp:

when using torch.distributed.run instead of torch.distributed.launch my code freezes since i got this warning The module torch.distributed.launch is deprecated and going to be removed in future.Migrate to torch.distributed.run. also, in the doc they talked about torchrun which we are supposed to use. probably it is not ready yet. because they didnt tell how to call torchrun. probably i need to change other options. i only used --nnodes=1      --node_rank=0      --nproc_per_node=2 .
in order to log 1 into files, they mentioned --log_dir, -r, and -t.  i tried: python -m torch.distributed.launch.py --log_dir logs -r 3 and also + -t 3. so the logger creates folders in logs with std and error for each process as mentioned in the doc but something else is still logging in terminal without logging in the files. the doc says that the log in files is for WORKERS. i think it is the launcher that is still logging into the terminal which is not considered as a worker i guess. warning which are important things are still go to terminal and not file. this is from the terminal which is not stored in file:

xxx/lib/python3.7/site-packages/torch/distributed/launch.py:164: 
DeprecationWarning: The 'warn' method is deprecated, use 'warning' instead
  "The module torch.distributed.launch is deprecated "

The module torch.distributed.launch is deprecated and going 
to be removed in future.Migrate to torch.distributed.run
*****************************************
Setting OMP_NUM_THREADS environment variable for 
each process to be 1 in default, to avoid your system 
 being overloaded, please further tune the variable for 
optimal performance in your application as needed. 
*****************************************
WARNING:torch.distributed.run:--use_env is 
deprecated and will be removed in future releases.
 Please read local_rank from `os.environ('LOCAL_RANK')` instead.

INFO:torch.distributed.launcher.api:Starting elastic_operator
 with launch configs:
  entrypoint       : multi_g.py
  min_nodes        : 1
  max_nodes        : 1
  nproc_per_node   : 2
  run_id           : none
  rdzv_backend     : static
  rdzv_endpoint    : 127.0.0.1:x
  rdzv_configs     : {'rank': 0, 'timeout': 900}
  max_restarts     : 3
  monitor_interval : 5
  log_dir          : logs
  metrics_cfg      : {}

INFO:torch.distributed.elastic.agent.server.local_elastic_agent:log 
directory set to: logs/none_5s_gkwa5
INFO:torch.distributed.elastic.agent.server.api:[default]
 starting workers for entrypoint: python
INFO:torch.distributed.elastic.agent.server.api:[default] 
Rendezvous'ing worker group
xxx/lib/python3.7/site-packages/torch/distributed/elastic/utils/store.py:53: 
FutureWarning: This is an experimental API and will be changed in future.

  "This is an experimental API and will be changed in future.", 
FutureWarning
INFO:torch.distributed.elastic.agent.server.api:[default] 
Rendezvous complete for workers. Result:
  restart_count=0
  master_addr=127.0.0.1
  master_port=x
  group_rank=0
  group_world_size=1
  local_ranks=[0, 1]
  role_ranks=[0, 1]
  global_ranks=[0, 1]
  role_world_sizes=[2, 2]
  global_world_sizes=[2, 2]

INFO:torch.distributed.elastic.agent.server.api:[default]
 Starting worker group
INFO:torch.distributed.elastic.multiprocessing:
Setting worker0 reply file to: 
logs/none_5s_gkwa5/attempt_0/0/error.json
INFO:torch.distributed.elastic.multiprocessing:
Setting worker1 reply file to: 
logs/none_5s_gkwa5/attempt_0/1/error.json
INFO:torch.distributed.elastic.agent.server.api:[default]
 worker group successfully finished. 
Waiting 300 seconds for other agents to finish.
INFO:torch.distributed.elastic.agent.server.api:
Local worker group finished (SUCCEEDED). 
Waiting 300 seconds for other agents to finish
xxx/lib/python3.7/site-packages/torch/distributed/elastic/
utils/store.py:71: FutureWarning: 
This is an experimental API and will be changed in future.
  "This is an experimental API and will be changed in future.", 
FutureWarning
INFO:torch.distributed.elastic.agent.server.api:
Done waiting for other agents. Elapsed: 
0.000919342041015625 seconds
{"name": "torchelastic.worker.status.SUCCEEDED", 
"source": "WORKER", "timestamp": 0, "metadata":
 {"run_id": "none", "global_rank": 0, "group_rank": 
0, "worker_id": "888", "role": "default",
 "hostname": "xxx", "state": "SUCCEEDED", 
"total_run_time": 10, "rdzv_backend": "static",
 "raw_error": null, "metadata": 
"{\"group_world_size\": 1, \"entry_point\":
 \"python\", \"local_rank\": [0], \"role_rank\": 
[0], \"role_world_size\": [2]}", "agent_restarts": 0}}
{"name": "torchelastic.worker.status.SUCCEEDED",
 "source": "WORKER", "timestamp": 0, "metadata": 
{"run_id": "none", "global_rank": 1, "group_rank": 0,
 "worker_id": "889", "role": "default", "hostname": 
"xxx", "state": "SUCCEEDED", "total_run_time": 10, 
"rdzv_backend": "static", "raw_error": null, "metadata": 
"{\"group_world_size\": 1, \"entry_point\": \"python\", 
\"local_rank\": [1], \"role_rank\": [1], \"role_world_size\": [2]}",
 "agent_restarts": 0}}
{"name": "torchelastic.worker.status.SUCCEEDED", "source": 
"AGENT", "timestamp": 0, "metadata": {"run_id": "none", 
"global_rank": null, "group_rank": 0, "worker_id": null, "role": 
"default", "hostname": "xxx", "state": "SUCCEEDED", 
"total_run_time": 10, "rdzv_backend": "static", "raw_error":
null, "metadata": "{\"group_world_size\": 1, \"entry_point\":
 \"python\"}", "agent_restarts": 0}}


files logs/none_5s_gkwa5/attempt_0/0/error.json are not created!!!
again, this is still under dev i guess. not ready yet but it is in master.
minimal code multigp.py from this:
import argparse

import torch
import torch.distributed as dist
import torch.nn as nn
import torch.optim as optim

from torch.nn.parallel import DistributedDataParallel as DDP
import numpy as np


class ToyModel(nn.Module):
    def __init__(self):
        super(ToyModel, self).__init__()
        self.net1 = nn.Linear(10, 10)
        self.relu = nn.ReLU()
        self.net2 = nn.Linear(10, 5)

    def forward(self, x):
        return self.net2(self.relu(self.net1(x)))


def spmd_main(local_world_size, local_rank):
    # These are the parameters used to initialize the process group
    np.random.seed(0)

    dist.init_process_group(backend="nccl")
    demo_basic(local_world_size, local_rank)

    # Tear down the process group
    dist.destroy_process_group()


def demo_basic(local_world_size, local_rank):

    # setup devices for this process. For local_world_size = 2, num_gpus = 8,
    # rank 0 uses GPUs [0, 1, 2, 3] and
    # rank 1 uses GPUs [4, 5, 6, 7].
    n = torch.cuda.device_count() // local_world_size
    device_ids = list(range(local_rank * n, (local_rank + 1) * n))

    model = ToyModel().cuda(device_ids[0])
    ddp_model = DDP(model, device_ids)

    loss_fn = nn.MSELoss()
    optimizer = optim.SGD(ddp_model.parameters(), lr=0.001)

    optimizer.zero_grad()
    outputs = ddp_model(torch.randn(20, 10))
    labels = torch.randn(20, 5).to(device_ids[0])
    loss_fn(outputs, labels).backward()
    optimizer.step()


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--local_rank", type=int, default=0)
    parser.add_argument("--local_world_size", type=int, default=1)
    args = parser.parse_args()
    spmd_main(args.local_world_size, args.local_rank)


bash to run it with 2 gpus:
python -m torch.distributed.launch \
       --log_dir logs \
       -r 3 \
       --nnodes=1 \
       --node_rank=0 \
       --nproc_per_node=2 \
       multigp.py \
       --local_world_size=2

thanks