Skip to content

Help!RuntimeError: a leaf Variable that requires grad is being used in an in-place operation. #203

Open

Description

@doqizuo

creating data loader...
creating model and diffusion...
training...
Traceback (most recent call last):
File "scripts/segmentation_train.py", line 118, in
main()
File "scripts/segmentation_train.py", line 70, in main
TrainLoop(
File "D:\MedSegDiff-master.\guided_diffusion\train_util.py", line 83, in init
self._load_and_sync_parameters()
File "D:\MedSegDiff-master.\guided_diffusion\train_util.py", line 139, in _load_and_sync_parameters
dist_util.sync_params(self.model.parameters())
File "D:\MedSegDiff-master.\guided_diffusion\dist_util.py", line 111, in sync_params
dist.broadcast(p, 0)
File "D:\Anaconda\envs\sg\lib\site-packages\torch\distributed\distributed_c10d.py", line 1195, in broadcast
work.wait()
RuntimeError: a leaf Variable that requires grad is being used in an in-place operation.

Plz!Tell me where the problem lies? and why? Hope someone nice can help me~ Thanks!!!

Activity

  1. Mnk208 commented on Dec 4, 2024

    @Mnk208

    Try add p = p + 0 in the sync_params function within dist_util.py as follows:
    def sync_params(params):
    """
    Synchronize a sequence of tensors across ranks from rank 0.
    """
    for p in params:
    with th.no_grad():
    p = p + 0
    dist.broadcast(p, 0)

  2. Mnk208 commented on Dec 4, 2024

    @Mnk208
  3. Issues-translate-bot commented on Dec 4, 2024

    @Issues-translate-bot

    Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


    #84

  4. doqizuo commented on Dec 6, 2024

    @doqizuo
    Author

    Try add p = p + 0 in the sync_params function within dist_util.py as follows: def sync_params(params): """ Synchronize a sequence of tensors across ranks from rank 0. """ for p in params: with th.no_grad(): p = p + 0 dist.broadcast(p, 0)

    THANKSSSSSS!!

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

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