강의

멘토링

커뮤니티

Cộng đồng Hỏi & Đáp của Inflearn

Hình ảnh hồ sơ của mjoon03095007
mjoon03095007

câu hỏi đã được viết

[Pytorch] Xây dựng mô hình Deep Learning bằng Pytorch

Thực hành - Cơ bản về Pytorch - phần 1

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

Viết

·

694

0

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

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

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

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

딥러닝딥러닝인공신경망anacondapytorchcnn

Câu trả lời 1

0

YoungJea Oh님의 프로필 이미지
YoungJea Oh
Người chia sẻ kiến thức

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 문서를 참조하세요. 좋은 질문 감사 드립니다.

mjoon03095007님의 프로필 이미지
mjoon03095007
Người đặt câu hỏi

감사합니다.

Hình ảnh hồ sơ của mjoon03095007
mjoon03095007

câu hỏi đã được viết

Đặt câu hỏi