2024년 6월 7일 금요일

Intel Mac torch(인텔 맥에서 파이토치)사용시 에러중


을 따라하다가

TypeError:
Cannot convert a MPS Tensor to float64 dtype as the MPS framework 
    doesn't support float64. Please use float32 instead.

def evaluate(length):
input = torch.tensor(data_train[-24*7*2:]).reshape(1,-1,1).\
        to(device).float().to(device)
output = torch.tensor(data_train[-1].reshape(1,-1,1)).float().\
        to(device)
model.eval()
for i in range(length):
src_mask = model.generate_square_subsequent_mask(input.shape[1]).to(device)
tgt_mask = model.generate_square_subsequent_mask(output.shape[1]).to(device)

predictions = model(input, output, src_mask, tgt_mask).transpose(0,1)
predictions = predictions[:, -1:, :]
output = torch.cat([output, predictions.to(device)], axis=1)
return torch.squeeze(output, axis=0).detach().cpu().numpy()[1:]


result = evaluate(24*7)
result = min_max_scaler.inverse_transform(result)

--------------------------------------------------------------------------- TypeError Traceback (most recent call last) Cell In[29], line 1 ----> 1 result = evaluate(24*7) 2 result = min_max_scaler.inverse_transform(result) 3 real = rawdata["평균속도"].to_numpy() Cell In[28], line 2 1 def evaluate(length): ----> 2 input = torch.tensor(data_train[-24*7*2:]).reshape(1,-1,1).to(device).float().to(device) 3 output = torch.tensor(data_train[-1].reshape(1,-1,1)).float().to(device) 4 model.eval() TypeError: Cannot convert a MPS Tensor to float64 dtype as the MPS framework
     doesn't support float64. Please use float32 instead.


에러가 발생하여


def evaluate(length):
input = torch.tensor(data_train[-24*7*2:]).reshape(1,-1,1).\
        to(torch.float32).to(device)
output = torch.tensor(data_train[-1].reshape(1,-1,1)).float().\
        to(device)
model.eval()
for i in range(length):
src_mask = model.generate_square_subsequent_mask(input.shape[1]).\
            to(device)
tgt_mask = model.generate_square_subsequent_mask(output.shape[1]).\
            to(device)

predictions = model(input, output, src_mask, tgt_mask).transpose(0,1)
predictions = predictions[:, -1:, :]
output = torch.cat([output, predictions.to(device)], axis=1)
return torch.squeeze(output, axis=0).detach().cpu().numpy()[1:]

이렇게 수정하니 정상으로 실행이 되었습니다.(2024.6.7)

즉 .to(device).float().to(device) => .to(torch.float32).to(device)

아! 인텔맥을 살까 M1 맥을 살까 고민하다 부트캠프 때문에 인텔맥을 선택한 아쉬움....

댓글 없음:

[Antigravity 입문 7강] 슬래시 명령어·멘션·스킬·MCP로 실전 업무 자동화 파이프라인 만들기

지금까지 1강부터 6강까지 Antigravity 설치, 슬래시 명령어, @ 멘션, 규칙(Rules)과 스킬(Skills), 그리고 MCP 서버 연결까지 하나씩 배웠습니다. 기능을 하나씩 따로 써도 편하지만, 이 도구들을 순서대로 묶어 두면 귀찮은 반...