728x90 반응형 RuntimeError7 RuntimeError: view size is not compatible with input tensor's size and stride ~ - 전체 에러 문구 RuntimeError: view size is not compatible with input tensor's size and stride (at least one dimension spans across two contiguous subspaces). Use .reshape(...) instead. expand(), view(), transpose() 등의 함수를 이용해 텐서의 모양을 바꿀 때 새로운 텐서를 생성하는 것이 아니라, 저장된 메모리의 주소는 그대로 둔체 텐서의 모양만 바꾸게 됩니다. 이런 경우 메모리 주소가 연속적이지 않게 변하게되므로 발생하는 에러입니다. - 해결 방법 연속적이지 않은 메모리 주소를 연속적이게 만들어주면 됩니다. 1) contiguous() .. 2023. 1. 30. RuntimeError: grad can be implicitly created only for scalar outputs - 전체 에러 문구 RuntimeError: grad can be implicitly created only for scalar outputs 파이토치에서 모델 학습 중 backporpagation을 시도하는 도중에 발생하는 에러입니다. loss.backward()는 기본적으로 1개의 스칼라 데이터에 대해 backporpagation를 수행하도록 되어있습니다. 그러나, loss 변수 내에는 배치에 포함된 모든 데이터 각각에 대한 loss 가 저장되어 있습니다. 이 값들을 sum이나 mean을 통해 하나로 합쳐주어야 합니다. - 해결 방법 배치 안에 포함된 모든 데이터들에 대한 loss를 모아서 역전파를 수행해야하기 때문에, sum이나 mean을 통해서 값을 하나로 만들어 주면 됩니다. lo.. 2023. 1. 30. RuntimeError: result type Float can't be cast to the desired output type Long - 전체 에러 문구 RuntimeError: result type Float can't be cast to the desired output type Long => output 텐서와 target 텐서의 데이터 타입이 같지 않을 때 발생하는 에러입니다. - 해결 방법 저의 경우에는 output 텐서는 float32 타입, target 텐서는 int64 타입이었습니다. 두 텐서의 데이터 타입을 동일하게 맞춰주었습니다. 따라서, target텐서를 float 타입으로 변경해주었습니다. labels => labels.float() self.loss(logits, labels.view([-1,1]).float(), alpha=0.75, reduction='mean') 2023. 1. 30. [Pytorch] RuntimeError: CUDA error: device-side assert triggered - 전체 에러 문구 RuntimeError: CUDA error: device-side assert triggered /pytorch/aten/src/ATen/native/cuda/Indexing.cu:699: indexSelectLargeIndex: block: [129,0,0], thread: [127,0,0] Assertion `srcIndex < srcSelectDimSize` failed. Pytorch의 nn.embedding() 레이어에 유효하지 않은 값(-1 이나 nan)이 입력으로 들어갔을 때 발생하는 에러입니다. 저의 경우에는 -1이 입력으로 들어가 발생하였습니다. - 해결 방법 유효한 입력값이 들어갈 수 있도록 수정해주었습니다. 이외에도 아래의 경우에 에러가 발생할.. 2023. 1. 29. 이전 1 2 다음 728x90 반응형