• 카테고리

    질문 & 답변
  • 세부 분야

    딥러닝 · 머신러닝

  • 해결 여부

    미해결

파이토치 device (gpu / cpu) 관련 질문드립니다.

23.02.26 18:24 작성 조회수 375

0

파이토치를 처음 배우는 학생입니다.

처음 텐서를 만들 때 cpu와 gpu 중 원하는 곳에 텐서를 저장할 수 있다고 배웠습니다.

이때 기본적으로 torch.tensor로 텐서를 만들면 cpu로 가는지, 아니면 cpu / gpu 그 어느것도 아닌 기본형으로 만들어지는지 궁금합니다.

또 이와 관련하여 텐서를 출력했을 때 <device = 'cuda:0'>이런 게 안 뜨면 cpu에 저장되어 있다고 보면 되는건가요?

답변 1

답변을 작성해보세요.

0

device를 지정해 주지 않고 만들면 CPU tensor가 되고 device를 "cuda:0"로 지정해 주고 만들면 GPU tensor가 됩니다.

x = torch.tensor([[1, 2, 3], [4, 5, 6]], dtype=torch.int32)
x --> cpu tensor
x = torch.tensor([[1, 2, 3], [4, 5, 6]], dtype=torch.int32, device="cuda:0")
x --> gpu tensor

document에 다음과 같이 설명이 되어 있습니다.

torch.tensor(data, *, dtype=None, device=None, requires_grad=False, pin_memory=False)

  • device (torch.device, optional) – the device of the constructed tensor. If None and data is a tensor then the device of data is used. If None and data is not a tensor then the result tensor is constructed on the CPU.

더 자세한 사항은 https://pytorch.org/docs/stable/generated/torch.tensor.html 문서를 참조하세요. 좋은 질문 감사 드립니다.

백민준님의 프로필

백민준

질문자

2023.02.28

감사합니다.