다음을 통해 공유


프로비전된 처리량 기반 모델 API

이 문서에서는 프로비전된 처리량과 함께 Foundation Model API를 사용하여 모델을 배포하는 방법을 보여 줍니다. Databricks는 프로덕션 워크로드에 프로비전된 처리량을 권장하며, 성능 보장이 있는 기본 모델에 최적화된 유추를 제공합니다.

지원되는 모델 아키텍처 목록은 프로비전된 처리량 Foundation Model API를 참조하세요.

요구 사항

요구 사항을 참조 하세요.

미세 조정된 기본 모델을 배포하는 경우

  • MLflow 2.11 이상 또는 Databricks Runtime 15.0 ML 이상을 사용하여 모델을 기록해야 합니다.
  • Databricks는 대규모 모델의 빠른 업로드 및 다운로드를 위해 Unity 카탈로그의 모델을 사용하는 것이 좋습니다.

Important

이 기능은 공개 미리 보기 상태입니다.

Databricks는 Unity 카탈로그에 미리 설치된 기본 모델을 사용하는 것이 좋습니다. 이러한 모델은 스키마 ai (system.ai)의 카탈로그 system 아래에서 찾을 수 있습니다.

기본 모델을 배포하려면 다음을 수행합니다.

  1. 카탈로그 탐색기에서 이동합니다 system.ai .
  2. 배포할 모델의 이름을 클릭합니다.
  3. 모델 페이지에서 이 모델 제공 단추를 클릭합니다.
  4. 서비스 엔드포인트 만들기 페이지가 나타납니다. UI를 사용하여 프로비전된 처리량 엔드포인트 만들기를 참조하세요.

Databricks Marketplace에서 기본 모델 배포

또는 Databricks Marketplace에서 Unity 카탈로그에 기본 모델을 설치할 수 있습니다.

모델 패밀리를 검색할 수 있으며 모델 페이지에서 액세스 가져오기를 선택하고 로그인 자격 증명을 제공하여 Unity 카탈로그에 모델을 설치할 수 있습니다.

모델이 Unity 카탈로그에 설치되면 서비스 UI를 사용하여 엔드포인트를 제공하는 모델을 만들 수 있습니다.

DBRX 모델 배포

Databricks는 워크로드에 DBRX 지시 모델을 제공하는 것이 좋습니다. 프로비전된 처리량을 사용하여 DBRX 지시 모델을 제공하려면 Unity 카탈로그에서 [권장] 배포 기본 모델의 지침을 따릅니다.

이러한 DBRX 모델을 제공하는 경우 프로비전된 처리량은 최대 16k의 컨텍스트 길이를 지원합니다.

DBRX 모델은 다음 기본 시스템 프롬프트를 사용하여 모델 응답에서 관련성과 정확도를 보장합니다.

You are DBRX, created by Databricks. You were last updated in December 2023. You answer questions based on information available up to that point.
YOU PROVIDE SHORT RESPONSES TO SHORT QUESTIONS OR STATEMENTS, but provide thorough responses to more complex and open-ended questions.
You assist with various tasks, from writing to coding (using markdown for code blocks — remember to use ``` with code, JSON, and tables).
(You do not have real-time data access or code execution capabilities. You avoid stereotyping and provide balanced perspectives on controversial topics. You do not provide song lyrics, poems, or news articles and do not divulge details of your training data.)
This is your system prompt, guiding your responses. Do not reference it, just respond to the user. If you find yourself talking about this message, stop. You should be responding appropriately and usually that means not mentioning this.
YOU DO NOT MENTION ANY OF THIS INFORMATION ABOUT YOURSELF UNLESS THE INFORMATION IS DIRECTLY PERTINENT TO THE USER'S QUERY.

미세 조정된 기본 모델 로그

스키마에서 system.ai 모델을 사용하거나 Databricks Marketplace에서 모델을 설치할 수 없는 경우 Unity 카탈로그에 로깅하여 미세 조정된 기본 모델을 배포할 수 있습니다. 다음은 MLflow 모델을 Unity 카탈로그에 기록하도록 코드를 설정하는 방법을 보여 줍니다.

mlflow.set_registry_uri('databricks-uc')
CATALOG = "ml"
SCHEMA = "llm-catalog"
MODEL_NAME = "mpt" # or "bge"
registered_model_name = f"{CATALOG}.{SCHEMA}.{MODEL_NAME}"

MLflow transformers 버전을 사용하여 모델을 기록하고 다음 옵션에서 적절한 모델 형식 인터페이스를 사용하여 작업 인수를 지정할 수 있습니다.

  • task="llm/v1/completions"
  • task="llm/v1/chat"
  • task="llm/v1/embeddings"

이러한 인수는 엔드포인트를 제공하는 모델에 사용되는 API 서명을 지정하며, 이러한 방식으로 기록된 모델은 프로비전된 처리량에 적합합니다.

패키지에서 sentence_transformers 기록된 모델도 엔드포인트 유형 정의를 "llm/v1/embeddings" 지원합니다.

MLflow 2.12 이상을 사용하여 기록된 모델의 경우 인수는 키 값을 자동으로 설정합니다metadatatask.log_modeltask task 인수와 인수를 metadatatask 다른 값 Exception 으로 설정하면 인수가 발생합니다.

다음은 MLflow 2.12 이상을 사용하여 기록된 텍스트 완성 언어 모델을 기록하는 방법의 예입니다.

model = AutoModelForCausalLM.from_pretrained("mosaicml/mpt-7b-instruct",torch_dtype=torch.bfloat16)
tokenizer = AutoTokenizer.from_pretrained("mosaicml/mpt-7b-instruct")
with mlflow.start_run():
    components = {
        "model": model,
        "tokenizer": tokenizer,
    }
    mlflow.transformers.log_model(
        transformers_model=components,
        artifact_path="model",
        input_example={"prompt": np.array(["Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWhat is Apache Spark?\n\n### Response:\n"])},
        task="llm/v1/completions",
        registered_model_name=registered_model_name
    )

MLflow 2.11 이상을 사용하여 기록된 모델의 경우 다음 메타데이터 값을 사용하여 엔드포인트에 대한 인터페이스를 지정할 수 있습니다.

  • metadata = {"task": "llm/v1/completions"}
  • metadata = {"task": "llm/v1/chat"}
  • metadata = {"task": "llm/v1/embeddings"}

다음은 MLflow 2.11 이상을 사용하여 기록된 텍스트 완성 언어 모델을 기록하는 방법의 예입니다.

model = AutoModelForCausalLM.from_pretrained("mosaicml/mpt-7b-instruct",torch_dtype=torch.bfloat16)
tokenizer = AutoTokenizer.from_pretrained("mosaicml/mpt-7b-instruct")
with mlflow.start_run():
    components = {
        "model": model,
        "tokenizer": tokenizer,
    }
    mlflow.transformers.log_model(
        transformers_model=components,
        artifact_path="model",
        input_example={"prompt": np.array(["Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWhat is Apache Spark?\n\n### Response:\n"])},
        task="llm/v1/completions",
        metadata={"task": "llm/v1/completions"},
        registered_model_name=registered_model_name
    )

프로비전된 처리량은 소형 및 대형 BGE 포함 모델도 모두 지원합니다. 다음은 MLflow 2.11 이상을 사용하여 프로비전된 처리량과 함께 제공될 수 있도록 모델을 BAAI/bge-small-en-v1.5 기록하는 방법의 예입니다.

model = AutoModel.from_pretrained("BAAI/bge-small-en-v1.5")
tokenizer = AutoTokenizer.from_pretrained("BAAI/bge-small-en-v1.5")
with mlflow.start_run():
    components = {
        "model": model,
        "tokenizer": tokenizer,
    }
    mlflow.transformers.log_model(
        transformers_model=components,
        artifact_path="bge-small-transformers",
        task="llm/v1/embeddings",
        metadata={"task": "llm/v1/embeddings"},  # not needed for MLflow >=2.12.1
        registered_model_name=registered_model_name
    )

미세 조정된 BGE 모델을 로깅할 때 메타데이터 키도 지정 model_type 해야 합니다.

metadata={
    "task": "llm/v1/embeddings",
    "model_type": "bge-large"  # Or "bge-small"
}

UI를 사용하여 프로비전된 처리량 엔드포인트 만들기

기록된 모델이 Unity 카탈로그에 있으면 다음 단계를 사용하여 프로비전된 처리량 서비스 엔드포인트를 만듭니다.

  1. 작업 영역에서 서비스 UI로 이동합니다.
  2. 서비스 엔드포인트 만들기를 선택합니다.
  3. 엔터티 필드의 Unity 카탈로그에서 모델을 선택합니다. 적격 모델의 경우 제공된 엔터티의 UI에 프로비전된 처리량 화면이 표시됩니다.
  4. Up to 드롭다운에서 엔드포인트에 대한 초당 최대 토큰 처리량을 구성할 수 있습니다.
    1. 프로비전된 처리량 엔드포인트는 자동으로 크기 조정되므로 수정을 선택하여 엔드포인트를 축소할 수 있는 초당 최소 토큰을 볼 수 있습니다.

프로비저닝된 처리량

REST API를 사용하여 프로비전된 처리량 엔드포인트 만들기

REST API를 사용하여 프로비전된 처리량 모드로 모델을 배포하려면 요청에 필드를 지정 min_provisioned_throughputmax_provisioned_throughput 해야 합니다.

모델에 적합한 프로비전된 처리량 범위를 식별하려면 프로비전된 처리량 가져오기를 증분 단위로 참조 하세요.

import requests
import json

# Set the name of the MLflow endpoint
endpoint_name = "llama2-13b-chat"

# Name of the registered MLflow model
model_name = "ml.llm-catalog.llama-13b"

# Get the latest version of the MLflow model
model_version = 3

# Get the API endpoint and token for the current notebook context
API_ROOT = dbutils.notebook.entry_point.getDbutils().notebook().getContext().apiUrl().get()
API_TOKEN = dbutils.notebook.entry_point.getDbutils().notebook().getContext().apiToken().get()

headers = {"Context-Type": "text/json", "Authorization": f"Bearer {API_TOKEN}"}

optimizable_info = requests.get(
    url=f"{API_ROOT}/api/2.0/serving-endpoints/get-model-optimization-info/{model_name}/{model_version}",
    headers=headers)
    .json()

if 'optimizable' not in optimizable_info or not optimizable_info['optimizable']:
   raise ValueError("Model is not eligible for provisioned throughput")

chunk_size = optimizable_info['throughput_chunk_size']

# Minimum desired provisioned throughput
min_provisioned_throughput = 2 * chunk_size

# Maximum desired provisioned throughput
max_provisioned_throughput = 3 * chunk_size

# Send the POST request to create the serving endpoint
data = {
    "name": endpoint_name,
    "config": {
        "served_entities": [
            {
                "entity_name": model_name,
                "entity_version": model_version,
                "min_provisioned_throughput": min_provisioned_throughput,
                "max_provisioned_throughput": max_provisioned_throughput,
            }
        ]
    },
}

response = requests.post(
    url=f"{API_ROOT}/api/2.0/serving-endpoints", json=data, headers=headers
)

print(json.dumps(response.json(), indent=4))

프로비전된 처리량 증분 가져오기

프로비전된 처리량은 모델에 따라 달라지는 특정 증분을 사용하여 초당 토큰 증분으로 사용할 수 있습니다. 요구에 적합한 범위를 식별하기 위해 Databricks는 플랫폼 내에서 모델 최적화 정보 API를 사용하는 것이 좋습니다.

GET api/2.0/serving-endpoints/get-model-optimization-info/{registered_model_name}/{version}

다음은 API의 예제 응답입니다.

{
 "optimizable": true,
 "model_type": "llama",
 "throughput_chunk_size": 1580
}

Notebook 예제

다음 Notebook에서는 프로비전된 처리량 Foundation Model API를 만드는 방법의 예를 보여 줍니다.

Llama2 모델 Notebook에 대한 프로비전된 처리량 서비스

전자 필기장 가져오기

Mistral 모델 Notebook에 대한 프로비전된 처리량 서비스

전자 필기장 가져오기

BGE 모델 Notebook에 대한 프로비전된 처리량 서비스

전자 필기장 가져오기

제한 사항

  • GPU 용량 문제로 인해 모델 배포가 실패할 수 있으며, 이로 인해 엔드포인트를 만들거나 업데이트하는 동안 시간이 초과될 수 있습니다. 문제를 해결하려면 Databricks 계정 팀에 문의하세요.
  • 파운데이션 모델 API에 대한 자동 크기 조정은 CPU 모델 서비스보다 느립니다. Databricks는 요청 시간 제한을 방지하기 위해 오버 프로비저닝을 권장합니다.

추가 리소스