본문 바로가기

Data Engineering/Cloud

[AWS] TroubleShooting Bedrock InvokeModel Error

Antropic Sonnet / Haiqu의 Model issue

ModelErrorException: An error occurred (ModelErrorException) when calling the InvokeModel operation: The system encountered an unexpected error during processing. Try your request again.

Trouble shooting

Antropic의 Sonnet과 haiqu를 사용할 때 간헐적으로 모델 이슈 에러가 발생하였다.

당시 구글링을 시도할때 Invoke-endpoint의 에러들에 대한 해결방법만 존재했고 ModelErrorException에 관한 내용은 없었다.

따라서 저 에러가 난 경우, Try your request again의 말에 따라 다시 시도해서 진행할때 다시 작업이 진행되는 듯 했으나,

얼마 안가 다시 에러가 발생하였다.

 

1) Encoding

스택 오버플로우를 참고해보니, Encoding에서 에러가 날 경우가 있다고 했다.

body = json.dumps({
        "anthropic_version": "bedrock-2023-05-31",
        "max_tokens": 4096,
        "messages": [
            {
                "role": "user",
                "content": [
                    {
                        "type": "text",
                        "text": prompt_template
                    }
                ]
            }
        ]
    })
    print(prompt_template)
    response = bedrock_client.invoke_model(
        body=body,
        contentType='application/json',
        accept='application/json',
        modelId=model_id
    )

 

body_bytes = json.dumps(payload["body"]).encode("utf-8")

response body=body_bytes를 주어 encoding하는 구문을 추가하여 진행했으나 얼마안가 또 에러가 발생하였다.

 

2) AWS re-post

해당 나온 모델이 출시된지 얼마 되지 않았으며 aws에서 boto3로 가져오기 때문에 bedrock api 문제인건지,

antropic model 문제인지 가늠할 수 없었다. 따라서 화자는 aws re-post에 이에 대한 모델 이슈 support를 요청드렸다

from botocore.exceptions import ClientError

 

결과적으로 해당 답변을 확인해보니, 일시적인 오류로 인해 문제가 발생한것이라고, 재시도를 걸어놓고 여러번 코드에 재시도 하는 방법이 있다고 했다. 위와 같은 코드를 import하여 재시도 max를 3번 넣고 작업을 진행했으나 3번 시도 후에도 오류가 나는것을 확인했다 ^^

(Sonnet이 아닌 haiqu도 에러가 동일하게 발생하였다.)

작업을 멈추고, 약 2시간 정도(?) 지난 후, 다시 모델을 돌려보니, 오류가 언제 났냐는듯, 또 잘 진행되는것이 아니던가,,,

 

느낌 상 LLM 모델의 가용성 또는 상태와 관련이 있을 것 같다는것이 최종 결론이다.

이에 대한 에러가 발생할 시에는 안전하게 재시도 정책을 3번 넣은 후 에러가 날 경우에는 약 30분여간 이후 로직을 시도하는 것이 제일 좋은 방법이라고 생각한다.

 

 

아래의 링크는 질문을 남긴 웹 페이지며 모델 에러가 날 시, 참고하시길 바란다.

https://repost.aws/ko/questions/QU-05GF7SkSWi2UyepdXIWrg/modelerrorexception-an-error-occurred-modelerrorexception-when-calling-the-invokemodel-operation-the-system-encountered-an-unexpected-error-during-processing-try-your-request-again

 

ModelErrorException: An error occurred (ModelErrorException) when calling the InvokeModel operation: The system encountered an u

**Hello, this is an error that occurred while using the model sonnet. I changed the model to haiqu and there was no model error. I don't know why. I tried again and it seems that the error is inte...

repost.aws

 

반응형