RuntimeError: Error(s) in loading state_dict : Unexpected key(s) in state_dict: "bert.embeddings.position_ids" GPU에서 train한 모델을 CPU에서 test하려고 하니 위와 같은 에러 메시지가 발생했다. 에러가 난 코드는 이 부분이었다. model.load_state_dict(torch.load(state_save_path, map_location='cpu')) state_dict를 불러오는 과정에서 서버 환경이 달라져서 key 값이 매칭이 되지 않아 발생한 에러다. 해결 방법은 load_state_dict()에 strict=False를 추가해주면 된다. 이를 추가해주면 state_dict를 불러올때 모든 key를..
서버 internet connection에 문제가 있을 경우 다음과 같은 에러 메시지들이 출력된다. 에러 메시지 1 'ValueError: Connection error, and we cannot find the requested files in the cached path ...' Huggingface에서 사전학습된 모델을 내려받으려 했는데, 원래는 잘 작동했지만 요즘 서버가 불안정해서 그런지 위와 같은 에러 메시지가 출력되었다. 에러 메시지 2 'fatal: unable to access 'https://github.com/~.git/': Could not resolve host: github.com' git clone 시에도 위와 같은 에러 메시지가 출력되면서 동작하지 않는다. 에러 메시지 3 'F..
Collecting package metadata (current_repodata.json): failed CondaHTTPError: HTTP 000 CONNECTION FAILED for url Elapsed: - An HTTP error occurred when trying to retrieve this URL. HTTP errors are often intermittent, and a simple retry will get you on your way. If your current network has https://www.anaconda.com blocked, please file a support request with your network engineering team. Connection..
'RuntimeError: CUDA error: device-side assert triggered' 이 에러는 가질 수 있는 값의 범위를 벗어나는 값이 들어왔을 때 발생한다. embed_tokens = nn.Embedding(vocab_size, hidden_size) ... embeds = embed_tokens(input_ids) # 에러 발생 나의 경우, 위 부분에서 에러가 발생했다. 내가 사용한 사전학습 모델에서의 tokenizer의 vocab_size는 30000이었는데, 여기에 special token을 10개 추가하고 아래와 같이 resize를 해주어서 vocab_size를 30010으로 설정했다. model.resize_token_embeddings(len(tokenizer)) (resi..
with open('file.txt', 'r', encoding='utf8') as f: lines = f.readlines() python에서 텍스트 파일을 읽어들일 때 일반적으로 위와 같이 코드를 작성하는데, 이 때 인코딩 에러가 자주 발생하곤 한다. 'UnicodeDecodeError: 'cp949' codec can't decode byte 0xeb in position 15: illegal multibyte sequence' 이를 확실하게 해결하는 방법은 텍스트 파일을 '메모장'으로 열기 - 다른 이름으로 저장 - 인코딩(E)를 ANSI로 저장하는 것이다.
이 에러는 float 타입의 텐서에 너무 큰 값을 저장할 때 발생한다. 다시 말하자면, int 타입으로 저장해야 할 텐서를 데이터 타입을 지정해주지 않아서 기본 타입인 float 타입으로 만든 경우에 흔히 발생한다. 예시 코드> tokens_list # [14054, 10788, 9241, 18831, 10396, 10910, 14304, 3, 3, 3, # 3, 3, 3, 3, 3, 3, 3, 3, 3, 3] tokens_tensor = torch.Tensor(tokens_list) # tensor([1.4054e+04, 1.0788e+04, 9.2410e+03, 1.8831e+04, 1.0396e+04, 1.0910e+04, # 1.4304e+04, 3.0000e+00, 3.0000e+00, 3.00..
"NameError: name '_C' is not defined" Jupyter Notebook를 사용 중에, Anaconda prompt를 통해 새로운 라이브러리를 설치한 후 설치한 라이브러리를 사용하려 import하려 하니 위 에러가 발생했다. 보통의 경우 jupyter notebook에서 kernel restart를 하면 해결된다. (새로운 라이브러리를 설치하면 항상 restart해주는게 옳다) 하지만 내 경우 kernel을 재시작했는데도 위 에러가 발생해서 시스템적인 에러인가 싶었는데, 간단한 에러였다. Anaconda prompt에서 라이브러리를 설치한 후, 기존에 켜져있던 jupyter notebook은 닫고 Anaconda prompt에서 jupyter-notebook 을 입력해 주피터를 ..

GPU 서버에서는 GitHub에 나온 대로 $ pip install --user annoy 를 수행하면 잘 설치되었는데, CPU에서는 아래와 같은 에러 메시지가 발생하면서 설치가 안 되었다. 'error: subprocess-exited-with-error', 'error: legacy-install-failure' 구글링해보니 이는 annoy의 문제가 아니라 gcc 버전의 문제 때문이라고 하는데, 나는 그냥 conda를 이용함으로써 해결했다. conda 가상환경을 만들어 활성화한 후, 아래 명령어를 수행한다. conda install -c conda-forge python-annoy import 시에는 원래의 annoy 라이브러리와 동일하게 import annoy로 사용 가능하다.