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 맥을 살까 고민하다 부트캠프 때문에 인텔맥을 선택한 아쉬움....

델파이 12.1이냐 11.3이냐?

 델파이가 12.1이 나왔습니다. 혹시 11.3버전의 커뮤니티버전이 필요하시는분이 있을 수 있을 것 같아 https://altd.embarcadero.com/.../RADStudio_11_3_esd_28... 와 이것 찾느랴 엄청고생함.