Cannot import name '_resolve_process_group' from 'torch.distributed.distributed_c10d'

I got the following error when calling the HuggingFaceLLM class:

Failed to import transformers.generation.utils because of the following error (look up to see its traceback): cannot import name '_resolve_process_group' from 'torch.distributed.distributed_c10d'

I looked into the source code and sure enough that function is not in there. Is this a versioning problem?

Update: I downgraded transformers to version 4.27.4 and that seemed to solve that issue but now I have a keyerror for “mistral”. Is there anyway I can solve this issue without downgrading transformers?

1 Like

This error seems to occur when PyTorch is far older than Transformers. It should be OK with PyTorch 2.4 or later.

import torch, torch.distributed as dist
print(torch.__version__, 'dist?', dist.is_available())
# Expect: 2.4+  dist? True

Thanks this worked

1 Like