가져온 모델 간접 호출 - Amazon Bedrock

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

가져온 모델 간접 호출

CreateModelImportJob 요청을 전송한 후 모델 가져오기 작업으로 모델을 가져오는 데 몇 분 정도 걸릴 수 있습니다. 콘솔에서 가져오기 작업의 상태를 확인하거나 GetModelImportJob 작업을 직접 호출하여 응답의 Status 필드를 확인할 수 있습니다. 모델이 완료 상태이면 가져오기 작업이 완료된 것입니다.

가져온 모델을 Amazon Bedrock에서 사용할 수 있게 되면 InvokeModel 또는 InvokeModelWithResponseStream 요청을 전송하여 모델에 추론 직접 호출을 수행해 온디맨드 처리량으로 모델을 사용할 수 있습니다. 자세한 내용은 InvokeModel을 사용하여 단일 프롬프트 제출 단원을 참조하십시오.

메시지 형식을 사용하여 가져온 모델과 인터페이스하려면 Converse 또는 ConverseStream 작업을 직접적으로 호출할 수 있습니다. 자세한 내용은 Converse API 사용 단원을 참조하십시오.

참고

Qwen2.5, Qwen2-VL, Qwen2.5-VL 및 GPT-OSS 모델에서는 Converse API가 지원되지 않습니다.

향상된 API 지원: 여러 API 형식

2025년 11월 17일부터 Amazon Bedrock Custom Model Import는 포괄적인 OpenAI 호환 API 형식을 지원하여 사용자 지정 모델을 통합하고 배포하는 방법에 유연성을 제공합니다. 2025년 11월 11일 이후에 가져온 모든 모델은 추가 구성 없이 이러한 향상된 기능을 자동으로 활용할 수 있습니다.

사용자 지정 모델 가져오기는 이제 세 가지 API 형식을 지원합니다.

  • BedrockCompletion(텍스트) - 현재 Bedrock 워크플로와 호환

  • OpenAICompletion(텍스트) - OpenAI Completions 스키마 호환성

  • OpenAIChatCompletion(텍스트 및 이미지) - 완전한 대화형 스키마 호환성

이러한 향상된 기능에는 JSON 스키마 및 패턴을 적용하기 위한 구조화된 출력, 다중 이미지 처리를 통한 향상된 비전 지원, 모델 신뢰도 인사이트에 대한 로그 확률, GPT-OSS 모델의 도구 호출 기능이 포함됩니다.

자세한 API 참조 설명서는 공식 OpenAI 설명서를 참조하세요.

API 형식 예제

다음 예제에서는 지원되는 4가지 API 형식을 각각 가져온 모델과 함께 사용하는 방법을 보여줍니다.

BedrockCompletion

BedrockCompletion 형식은 현재 Bedrock 워크플로와 호환되며 텍스트 기반 추론 요청을 지원합니다.

요청 예제:

import json import boto3 client = boto3.client('bedrock-runtime', region_name='us-east-1') payload = { "prompt": "How is the rainbow formed?", "max_gen_len": 100, "temperature": 0.5 } response = client.invoke_model( modelId='your-model-arn', body=json.dumps(payload), accept='application/json', contentType='application/json' ) response_body = json.loads(response['body'].read())

응답 예제:

{ "generation": " – A scientific explanation\nA rainbow is a beautiful natural phenomenon that occurs when sunlight passes through water droplets in the air. It is formed through a process called refraction, which is the bending of light as it passes from one medium to another.\nHere's a step-by-step explanation of how a rainbow is formed:\n1. Sunlight enters the Earth's atmosphere: The first step in forming a rainbow is for sunlight to enter the Earth's atmosphere. This sunlight is made up of a spectrum of", "prompt_token_count": 7, "generation_token_count": 100, "stop_reason": "length", "logprobs": null }

BedrockCompletion은 json_objectjson_schema 유형과 함께 response_format 파라미터를 사용하여 구조화된 출력을 지원합니다.

OpenAICompletion

OpenAICompletion 형식은 OpenAI Completions 스키마 호환성을 제공합니다. 이 형식을 사용하려면 대신 max_tokens 파라미터를 포함합니다max_gen_len.

요청 예제:

import json import boto3 client = boto3.client('bedrock-runtime', region_name='us-east-1') payload = { "prompt": "How is the rainbow formed?", "max_tokens": 100, "temperature": 0.5 } response = client.invoke_model( modelId='your-model-arn', body=json.dumps(payload), accept='application/json', contentType='application/json' ) response_body = json.loads(response['body'].read())

응답 예제:

{ "id": "cmpl-b09d5810bd64428f8a853be71c31f912", "object": "text_completion", "created": 1763166682, "choices": [ { "index": 0, "text": " The formation of a rainbow is a complex process that involves the interaction of sunlight with water droplets in the air. Here's a simplified explanation: 1. Sunlight enters the Earth's atmosphere and is refracted, or bent, as it passes through the air. 2. When sunlight encounters a water droplet, such as a cloud, mist, or fog, it is refracted again and split into its individual colors, a process known as dispersion. 3. The refracted and", "finish_reason": "length" } ], "usage": { "prompt_tokens": 7, "total_tokens": 107, "completion_tokens": 100 } }

OpenAICompletion은 structured_outputs 파라미터를 사용하여 json, regexchoice, 및 제약 grammar 조건을 포함한 전체 구조화된 출력 기능을 지원합니다.

OpenAIChatCompletion

OpenAIChatCompletion 형식은 완전한 대화형 스키마 호환성을 제공하고 텍스트 및 이미지 입력을 모두 지원합니다.

요청 예제:

import json import boto3 client = boto3.client('bedrock-runtime', region_name='us-east-1') payload = { "messages": [ { "role": "user", "content": "How is the rainbow formed?" } ], "max_tokens": 100, "temperature": 0.5 } response = client.invoke_model( modelId='your-model-arn', body=json.dumps(payload), accept='application/json', contentType='application/json' ) response_body = json.loads(response['body'].read())

응답 예제:

{ "id": "chatcmpl-1d84ce1d3d61418e8c6d1973f87173db", "object": "chat.completion", "created": 1763166683, "choices": [ { "index": 0, "message": { "role": "assistant", "content": "A rainbow is a beautiful natural phenomenon that occurs when sunlight passes through water droplets in the air. The process of forming a rainbow involves several steps:\n\n1. **Sunlight**: The first requirement for a rainbow is sunlight. The sun should be shining brightly, but not directly overhead.\n2. **Water droplets**: The second requirement is water droplets in the air..." }, "finish_reason": "length" } ], "usage": { "prompt_tokens": 41, "completion_tokens": 100, "total_tokens": 141 } }

OpenAIChatCompletion은 response_formatstructured_outputs 파라미터를 모두 사용하여 구조화된 출력을 지원합니다. 비전 기능의 경우 base64로 인코딩된 이미지 데이터와 함께 콘텐츠 배열에 이미지를 포함합니다.

참고

ChatCompletion 형식을 사용하려면 채팅 템플릿이의 일부여야 합니다tokenizer_config.json. 사용자 지정 모델 가져오기는 요청에 기본 채팅 템플릿을 적용하지 않습니다.

새로 가져온 모델에 추론 직접 호출을 수행하려면 모델 ARN이 필요합니다. 가져오기 작업이 성공적으로 완료되고 가져온 모델이 활성화된 후, 콘솔에서 또는 ListImportedModels 요청을 전송하여 가져온 모델의 모델 ARN을 가져올 수 있습니다.

InvokeModel 또는 InvokeModelWithStream를 사용하여 가져온 모델을 간접적으로 호출하면 요청이 5분 이내에 처리되거나 ModelNotReadyException를 받을 수 있습니다. ModelNotReadyException을 이해하려면 이 다음 섹션의 ModelNotreadyException 처리 단계를 따르세요.

FAQ

Q: 어떤 API 형식을 사용해야 하나요?

A: 다양한 SDKs와의 호환성을 극대화하려면 OpenAICompletion 또는 OpenAIChatCompletion 형식을 사용하는 것이 좋습니다. 다양한 도구 및 라이브러리에서 널리 지원되는 OpenAI 호환 스키마를 제공하기 때문입니다.

Q: Amazon Bedrock Custom Model ImportGPT-OSS에서 Converse API를 지원하나요?

A: 아니요. GPT-OSS 기반 사용자 지정 모델 가져오기 모델은 Converse API 또는 ConverseStream API를 지원하지 않습니다. GPT-OSS 기반 사용자 지정 모델로 작업할 때는 OpenAI 호환 스키마와 함께 InvokeModel API를 사용해야 합니다.

Q: 도구 호출을 지원하는 모델은 무엇입니까?

A: GPT-OSS 기반 사용자 지정 모델은 도구 호출 기능을 지원합니다. 도구 호출은 복잡한 워크플로에 대한 함수 호출을 활성화합니다.

Q: 2025년 11월 11일 이전에 가져온 모델은 어떻게 됩니까?

A: 2025년 11월 11일 이전에 가져온 모델은 기존 API 형식 및 기능에서 그대로 작동합니다.

Q: OpenAI 기반 모델의 generation_config.json 경우 어떨까요?

A:와 같은 OpenAI 기반 모델을 가져올 때 올바른 generation_config.json 파일을 포함하는 것이 중요합니다GPT-OSS. https://huggingface.co/openai/gpt-oss-20b/blob/main/generation_config.json 제공되는 업데이트된 구성 파일(2024년 8월 13일 업데이트됨)을 사용해야 합니다. 업데이트된 구성에는 세 개의 end-of-sequence 토큰 IDs([200002, 199999, 200012])가 포함된 반면, 이전 버전에는 두 개의 토큰()만 포함되었습니다[200002, 199999]. 오래된 generation_config.json 파일을 사용하면 모델 호출 중에 런타임 오류가 발생합니다. 이 파일은 적절한 모델 동작에 필수적이며 OpenAI 기반 모델 가져오기에 포함되어야 합니다.

ModelNotReadyException 처리

Amazon Bedrock Custom Model Import는 활성화되지 않은 모델을 제거하여 하드웨어 사용률을 최적화합니다. 제거된 모델을 간접적으로 호출하려고 하면 ModelNotReadyException가 표시됩니다. 모델이 제거되고 모델을 처음 간접적으로 호출하면 사용자 지정 모델 가져오기가 모델을 복원하기 시작합니다. 복원 시간은 온디맨드 플릿 크기와 모델 크기에 따라 달라집니다.

InvokeModel 또는 InvokeModelWithStream 요청이 ModelNotReadyException를 반환하는 경우 단계에 따라 예외를 처리합니다.

  1. 재시도를 구성합니다

    기본적으로 요청은 지수 백오프를 통해 자동으로 재시도됩니다. 최대 재시도 횟수를 구성할 수 있습니다.

    다음 예제에서는 재시도를 구성하는 방법을 보여줍니다. ${region-name}, ${model-arn}, 10을 해당하는 리전, 모델 ARN, 최대 시도 횟수로 바꿉니다.

    import json import boto3 from botocore.config import Config REGION_NAME = ${region-name} MODEL_ID= '${model-arn}' config = Config( retries={ 'total_max_attempts': 10, //customizable 'mode': 'standard' } ) message = "Hello" session = boto3.session.Session() br_runtime = session.client(service_name = 'bedrock-runtime', region_name=REGION_NAME, config=config) try: invoke_response = br_runtime.invoke_model(modelId=MODEL_ID, body=json.dumps({'prompt': message}), accept="application/json", contentType="application/json") invoke_response["body"] = json.loads(invoke_response["body"].read().decode("utf-8")) print(json.dumps(invoke_response, indent=4)) except Exception as e: print(e) print(e.__repr__())
  2. 재시도 중 응답 코드 모니터링

    각 재시도는 모델 복원 프로세스를 시작합니다. 복원 시간은 온디맨드 플릿의 가용성과 모델 크기에 따라 달라집니다. 복원 프로세스가 진행되는 동안 응답 코드를 모니터링합니다.

    재시도가 지속적으로 실패하는 경우 다음 단계를 계속 진행합니다.

  3. 모델을 성공적으로 가져왔는지 확인

    콘솔에서 가져오기 작업의 상태를 확인하거나 GetModelImportJob 작업을 직접 호출하여 모델 가져오기를 완료했는지 확인할 수 있습니다. 응답의 Status 필드를 참조하세요. 모델이 완료 상태이면 가져오기 작업이 완료된 것입니다.

  4. 추가 조사를 지원위해에 문의

    로 티켓을 엽니다. 지원자세한 내용은 지원 사례 생성을 참조하세요.

    모델 ID 및 타임스탬프와 같은 관련 세부 정보를 지원 티켓에 포함합니다.