우리는 직접 수집,생성한 데이터로 파인튜닝한 모델을 sentence transformer와 pytorch를 통해 돌려보기로 했다.
def predict_grade(request: GetGradeRequest):
# 파인 튜닝 모델 불러오기
use_cuda = torch.cuda.is_available()
print(use_cuda)
device = 'cuda' if torch.cuda.is_available() else 'cpu'
model = torch.load('./model/model.pt', map_location=torch.device(device))
# 두 문장을 모델로 임베딩
embeddings = model.encode([request.correct_answer, request.answer], convert_to_tensor=True)
# 코사인 유사도 계산
cosine_score = util.pytorch_cos_sim(embeddings[0], embeddings[1])
#print(cosine_score[0][0].item())
return cosine_score[0][0].item()
노트북에 gpu를 사용할 수 없는 상황이라 cuda 사용이 안돼서, cpu로 돌리려고 pytorch도 cpuonly로 깔고, device도 cpu로 다 설정을 해줬는데..ㅠㅠ 계속 AssertionError: Torch not compiled with CUDA enabled 에러가 떴다.

이게같은에러진짜 죽이고싶엇음
오류코드 계속 타고 타고 들어가보니까
# 두 문장을 모델로 임베딩
embeddings = model.encode([request.correct_answer, request.answer], convert_to_tensor=True)
여기가 문제길래 자꾸 노려봤다... 대체 device cpu로 설정했는데 왜 자꾸 쿠다를쓰려는거니.....
그래서 encode 함수 파라미터에 device가 있길래 그냥 파라미터도 지정해줬다.
# 두 문장을 모델로 임베딩
embeddings = model.encode([request.correct_answer, request.answer], convert_to_tensor=True,device='cpu')
그랬더니ㅠㅠ

해방됐다..
굿