[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

just import of peft leads to cuda context initialization #1877

Closed
PhyscalX opened this issue Jun 21, 2024 · 1 comment · Fixed by #1879
Closed

just import of peft leads to cuda context initialization #1877

PhyscalX opened this issue Jun 21, 2024 · 1 comment · Fixed by #1879

Comments

@PhyscalX
Copy link
Contributor
PhyscalX commented Jun 21, 2024

System Info

PyTorch version: 2.2.1
peft version: 0.11.1

Reproduction

The following snippet can trigger this bug:

import multiprocessing
import peft
from torch import nn

def func():
    m = nn.Linear(2, 3).cuda(0)

if __name__ == "__main__":
    proc = multiprocessing.Process(target=func)
    proc.start(), proc.join()

Raise:
RuntimeError: Cannot re-initialize CUDA in forked subprocess. To use CUDA with multiprocessing, you must use the 'spawn' start method

Issue: early import torch.utils.cpp_extension in peft/tuners/boft/layer.py

How to fix: import cpp_extension module in the get_fbd_cuda function.

Expected behavior

No RuntimeError. CUDA context is not initialized in the main process.

@BenjaminBossan
Copy link
Member

Thanks for investigating. The proposed solution sounds reasonable. Are you interested in creating the PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants