Skip to content

Distributed training with synchronized SGD using 'grpc+verbs' sometimes hangs indefinitely #11416

Closed

Description

@on-the-run

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): Yes.
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 16.04.2 LTS
  • TensorFlow installed from (source or binary): Source
  • TensorFlow version (use command below): v1.2.0-1755-gee4259a 1.2.1
  • Python version: Python 3.5.2
  • Bazel version (if compiling from source): 0.5.1
  • CUDA/cuDNN version: 8.0/5.1
  • GPU model and memory: GeForce GTX 1080 Ti
  • Exact command to reproduce: Sorry, the command is not available since this is custom code
  • RDMA driver version: libibverbs-dev (1.2.1mlnx1-OFED.4.0.1.5.3.40200)

Describe the problem

I am training a seq2seq model with synchronized SGD (using tf.train.SyncReplicasOptimizer and tf.train.Supervisor), over RDMA (using grpc+verbs protocol), on 2 workers and 1 parameter server. Each worker has 8 GPUs, and the model on each GPU is the same.

I can train this model fine with the default grpc protocol using the same setting. When I switched to grpc+verbs, the behavior becomes unpredictable. Most of the times both workers hang (for at least 12 hours, so not because I didn't wait long enough). Sometimes the chief worker (worker 0) starts training, but worker 1 hangs. (This should not happen since I am programming with synchronized SGD. Worker 0 should be blocked if worker 1 is not ready.) In rare case it can go through and start training. I believe the RDMA driver is correctly installed.

When worker hangs, the CPU utilization stays low but not zero, and the GPU utilization is 0.

Source code / logs

I attached below the log from worker 1 worker1.txt. In this case, worker 1 hangs, and worker 0 starts training. (There are some custom logs printed.) In the log you can find that worker 1 sent a RDMA_MESSAGE_TENSOR_REQUEST to the parameter server, but never got an ACK, and I have checked the log from the parameter server, which showed that it never received a RDMA_MESSAGE_TENSOR_REQUEST from worker 1.

I also attached the full trace gdb_worker1.txt collected on worker 1 in gdb with thread apply all bt, during worker 1 hanging.

Thanks.

Activity

  1. on-the-run commented on Jul 10, 2017

    @on-the-run
    Author

    @junshi15 Could you shed some light on this? Thanks!

  2. byronyi commented on Jul 10, 2017

    @byronyi
    Contributor

    Have you tried your code in loopback mode? It helps to make sure that the problem doesn't lie in your network fabrics configuration.

  3. on-the-run commented on Jul 10, 2017

    @on-the-run
    Author

    @byronyi Thanks for the quick reply. I have tried my code over Ethernet, and it worked fine. I think that should indicate the network fabrics is fine. Also, one experiment I tried over RDMA did go through as I described in the issue. So RDMA fabric seems fine. The loopback mode won't traverse the network stack, right?

  4. byronyi commented on Jul 10, 2017

    @byronyi
    Contributor

    Note that RoCE requires a lossless fabric, while gRPC does not. If you could reproduce the error in loopback mode, it would be easier for us to identify the possible issue.

  5. shamoya commented on Jul 10, 2017

    @shamoya
    Contributor

    @on-the-run, can u verify the RoCE configuration with ib_write_bw between the 2 nodes ?
    As @byronyi said, you may need to configure lossless (PFC) or ECN to prevent the packet loss.
    ib_write_bw is a good stress test to see if RoCE is configured good.
    Can u attach the full logs of the PS and worker ? I'm missing a lot of events here in the logs.

  6. on-the-run commented on Jul 10, 2017

    @on-the-run
    Author

    @shamoya, the RDMA I am using is Infiniband, instead of RoCE. ib_write_bw runs fine. The workers and the parameter sever can talk to each other via RDMA. Posting the output from running ib_write_bw between one worker and one parameter server below.

    ---------------------------------------------------------------------------------------
                        RDMA_Write BW Test
     Dual-port       : OFF          Device         : mlx4_0
     Number of qps   : 1            Transport type : IB
     Connection type : RC           Using SRQ      : OFF
     CQ Moderation   : 100
     Mtu             : 2048[B]
     Link type       : IB
     Max inline data : 0[B]
     rdma_cm QPs     : OFF
     Data ex. method : Ethernet
    ---------------------------------------------------------------------------------------
     local address: LID 0x15 QPN 0x32da PSN 0xebb028 RKey 0xa0010194 VAddr 0x007f11bbfc2000
     remote address: LID 0x12 QPN 0x0337 PSN 0x198251 RKey 0xd001018f VAddr 0x007f728f89f000
    ---------------------------------------------------------------------------------------
     #bytes     #iterations    BW peak[MB/sec]    BW average[MB/sec]   MsgRate[Mpps]
     65536      5000             6071.23            6071.03            0.097136
    ---------------------------------------------------------------------------------------
    
  7. on-the-run commented on Jul 10, 2017

    @on-the-run
    Author

    @shamoya, about the logs of PS and worker, I didn't turn on VLOG for the log file I posted earlier. Will a log with VLOG(2) enabled be useful?

  8. shamoya commented on Jul 10, 2017

    @shamoya
    Contributor

    If it's IB then we shouldn't have any packet loss.
    VLOG(2) is maybe too much verbose, maybe just change all VLOG in rdma.cc to 0, so we can just see the Rendezvous protocol messages.
    How many model parameters are there ?

  9. junshi15 commented on Jul 10, 2017

    @junshi15
    Contributor

    @on-the-run Did you even run an example successfully, say InceptionV3 training on ImageNet dataset?

  10. on-the-run commented on Jul 10, 2017

    @on-the-run
    Author

    @junshi15, Yes. The same code did go through once on RDMA, and it worked well at that time. I didn't try InceptionV3, though.

  11. junshi15 commented on Jul 10, 2017

    @junshi15
    Contributor

    that's strange. I have not seen issues like that, Your problem probably depends on the ordering of events, which is random. I am wondering if there is memory corruption somewhere.

  12. on-the-run commented on Jul 10, 2017

    @on-the-run
    Author

    @junshi15, one thing that I observed to happen repeatedly was that after the RDMA channels have been built, worker 1 sent a RDMA_MESSAGE_TENSOR_REQUEST to PS, and never got an ACK. Then worker 1 was blocked there. And, PS never received that RDMA_MESSAGE_TENSOR_REQUEST . Does this ring a bell?

  13. on-the-run commented on Jul 10, 2017

    @on-the-run
    Author

    @shamoya, there are about 70 million parameters. Here are full logs:
    ps.txt,
    worker0.txt,
    worker1.txt
    In this case, worker 1 hanged, but worker 0 didn't. Not sure if the log of worker 1 gives enough information. Let me know if you need me to turn on other logs. Thanks.

  14. added
    stat:awaiting response
    on Jul 10, 2017
  15. suiyuan2009 commented on Jul 11, 2017

    @suiyuan2009
    Contributor

    does distributed tensorflow using 'grpc+verbs' have unit tests? I didn't find any. I meet 2017-07-11 09:46:46.591411: F tensorflow/contrib/verbs/rdma.cc:95] Check failed: cq_ Failed to create completion queue when using 'grpc+verbs' in an ib network.

  16. 42 remaining items

  17. junshi15 commented on Jul 18, 2017

    @junshi15
    Contributor

    All the buffers are allocated in system memory, so CUDA8 should not play a role here. My impression is that ibv_reg_mr does pin the memory, although I am not familiar with the source code. @shamoya may be able to explain it.

  18. bobzhuyb commented on Jul 18, 2017

    @bobzhuyb

    @junshi15 I understand that you only allocate main memory. Nevertheless, CUDA starts after your code, and with Pascal GPUs, it maps GPU memory to the same virtual memory address space as the process (see Unified Memory in https://devblogs.nvidia.com/parallelforall/cuda-8-features-revealed/). We do not know what it does with the existing virtual addr and physical addr mapping.

    Otherwise, I don't know how to explain why it works with one GPU, while starts to break with more GPUs..

  19. byronyi commented on Jul 18, 2017

    @byronyi
    Contributor

    Maybe I didn't make it clear, I mean the verbs library is not doing nor supposed to do memory pinning in user space: that job is solely done by the in kernel part of your IB driver. Thus you should search it in the kernel source tree and kernel memory pinning API, something like get_user_pages, not the syscall nor user space API like mlock.

  20. byronyi commented on Jul 19, 2017

    @byronyi
    Contributor

    @bobzhuyb And I think I have checked with TF people before, and they have made it pretty clear that TF is not designed to utilize UVM nor support this feature. See relevant discussion in here. I also tend to believe neither IB driver or CUDA driver should alter memory mappings managed by the other one, as we are not doing peer memory access for NIC and GPU.

    On the other hand I have worked with TF memory allocation subsystem and they are doing a pretty good job on keeping track of CUDA host/device memory allocation. See relevant details for host and device memory. And if you adjust those parameters (like the initial memory allocation or allow_growth=False), you could force it to allocate all CUDA memory at very early stage (before the whole distributed runtime is even initialized). After that, the virtual memory mappings of these memory regions should not be altered. If you do that, the step 2 of your speculation is rather unlikely to happen.

    Being said that, the is a possibility that something is wrong in either CUDA or IB driver, but our chances are small. cc @zheng-xq @poxvoculi any comments on this?

  21. shamoya commented on Jul 19, 2017

    @shamoya
    Contributor

    @on-the-run @bobzhuyb, the assumption doesn't make sense to me.
    The memory is being pinned in https://github.com/torvalds/linux/blob/master/drivers/infiniband/core/umem.c#L83 , which is executed in the ibv_reg_mr flow, so mlcok shouldn't have any effect.
    Also as @byronyi (this is what I know as well) said, TF doesn't support UVM.
    Are u sure this is the only thing u changed that fixed the bug ?

    I'm having a similar issue with 8 P100 per node (4 nodes), happens with only certain conditions (tf_cnn_script benchmark with "real" data) and the pinning issue is not the case.
    I think maybe found the issue (checking now and will report soon).

  22. bobzhuyb commented on Jul 19, 2017

    @bobzhuyb

    @byronyi @shamoya Thanks for the clarification. Yes, mlock() was the thing that made it stable in our environment. Good to know that you can reproduce the issue. Please keep us posted.

  23. shamoya commented on Jul 24, 2017

    @shamoya
    Contributor

    Hi @bobzhuyb,
    The mlock solution still doesn't make sense to me.
    it shouldn't have any effect, unless you a severe driver issues.
    Can u involve RDMA community in this issue in https://github.com/linux-rdma/rdma-core ?

    Anyway my issue still not solved, I opened an issue in #11725.

    Any help is appreciated, if u can take a look.
    @junshi15 @byronyi if u have time I would be delighted as well.

  24. shamoya commented on Aug 7, 2017

    @shamoya
    Contributor

    Hi @on-the-run,
    Is there any way to know if the CUDA remaps the memory mapping of the process ?
    As said, I feel we see a similar issue, but the mlock workaround doesn't help in our case.
    We also feel it's something to do with Pascal memory management (can't say exactly what).
    Any clues to what we can check ?
    Thanks !

  25. junshi15 commented on Aug 7, 2017

    @junshi15
    Contributor

    I was using K80 and CUDA-7.5, and was able to reproduce the other issue (#11725). So at least that issue is not only limited to Pascal.

  26. bobzhuyb commented on Aug 7, 2017

    @bobzhuyb

    We don't have a concrete evidence. However, we did a basic test -- when we malloc the receiver buffer, we init the buffer with a special value as a signature (say every byte initialized as 0xab). After the successful receive event triggered by WRITE_WITH_IMM, we immediate check the receiver buffer contents. It remains unchanged in TF process.

    If you use ibdump at the receiver side, you should see the special signature in the packets. So the data must have arrived. Would you do the same as above to confirm that we are seeing the same (or similar) problem?

    There are only two potential explanations,

    1. Receiver NIC didn't DMA the data into the receiver buffer -- we don't see why this may happen
    2. NIC did write the data to physical memory, but the vaddr mapping has changed

    To get a concrete evidence, we will need to get the vaddr to physical addr mapping at different stages. Not sure whether the info in /proc/$PID/maps can help us.

  27. on-the-run commented on Aug 7, 2017

    @on-the-run
    Author

    @shamoya, unfortunately I am not an expert on CUDA. Also, my colleague @bobzhuyb has taken this issue over. @bobzhuyb, could you give some input when you have time? Thanks!

  28. byronyi commented on Aug 8, 2017

    @byronyi
    Contributor

    Hi @bobzhuyb, I made a separate RDMA patch #11392 that supports checksum with VLOG=2. It computes the checksum before sending and after receiving, and the checksum is transmitted out-of-band via gRPC. Maybe you could give it a try and see wether the problem persists.

  29. tensorflowbutler commented on Dec 20, 2017

    @tensorflowbutler
    Member

    It has been 14 days with no activity and this issue has an assignee.Please update the label and/or status accordingly.

  30. on-the-run commented on Dec 20, 2017

    @on-the-run
    Author

    Closed due to inactivity. Please reopen the issue if you have updates or resolved the issue. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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