Weights & Biases Inference
Weights & Biases Inference
W&B Inference 서비스의 모든 모델을 LiteLLM에서 사용하는 방법을 알아봐요.
출처: 문서
본문
팁: LiteLLM은 W&B Inference 서비스의 모든 모델을 지원해요. 모델을 사용하려면 litellm 요청에
model=wandb/을 접두사로 붙이면 돼요. 지원 모델 전체 목록은 https://docs.wandb.ai/guides/inference/models/ 에서 볼 수 있어요.
API 키
W&B Inference용 API 키는 https://wandb.ai/authorize 에서 받을 수 있어요.
import os
# env variable
os.environ['WANDB_API_KEY']
사용 예시: 텍스트 생성
from litellm import completion
import os
os.environ['WANDB_API_KEY'] = "insert-your-wandb-api-key"
response = completion(
model="wandb/Qwen/Qwen3-235B-A22B-Instruct-2507",
messages=[
{
"role": "user",
"content": "What character was Wall-e in love with?",
}
],
max_tokens=10,
response_format={ "type": "json_object" },
seed=123,
temperature=0.6, # either set temperature or `top_p`
top_p=0.01, # to get as deterministic results as possible
)
print(response)
사용 예시 - 스트리밍
from litellm import completion
import os
os.environ['WANDB_API_KEY'] = ""
response = completion(
model="wandb/Qwen/Qwen3-235B-A22B-Instruct-2507",
messages=[
{
"role": "user",
"content": "What character was Wall-e in love with?",
}
],
stream=True,
max_tokens=10,
response_format={ "type": "json_object" },
seed=123,
temperature=0.6, # either set temperature or `top_p`
top_p=0.01, # to get as deterministic results as possible
)
for chunk in response:
print(chunk)
팁: 모델이 오프라인 전환되면 위 예시가 동작하지 않을 수 있어요. 사용 가능한 모델 전체 목록은 https://docs.wandb.ai/guides/inference/models/ 에서 확인할 수 있어요.
LiteLLM Proxy 서버 사용법
config.yaml 수정:
model_list:
- model_name: my-model
litellm_params:
model: wandb/ # add wandb/ prefix to use W&B Inference as provider
api_key: api-key # api key to send your model
Proxy 시작:
$ litellm --config /path/to/config.yaml
OpenAI Python SDK로 요청:
import openai
client = openai.OpenAI(
api_key="litellm-proxy-key", # pass litellm proxy key, if you're using virtual keys
base_url="http://0.0.0.0:4000" # litellm-proxy-base url
)
response = client.chat.completions.create(
model="my-model",
messages = [
{
"role": "user",
"content": "What character was Wall-e in love with?"
}
],
)
print(response)
curl --location 'http://0.0.0.0:4000/chat/completions' \
--header "Authorization: ***" \
--header 'Content-Type: application/json' \
--data '{
"model": "my-model",
"messages": [
{
"role": "user",
"content": "What character was Wall-e in love with?"
}
],
}'
지원 파라미터
W&B Inference 제공사는 다음 파라미터를 지원해요:
채팅 완성 파라미터
| 파라미터 | 타입 | 설명 |
|---|---|---|
| frequency_penalty | number | 텍스트에서의 빈도에 따라 새 토큰에 패널티 |
| function_call | string/object | 모델이 함수를 호출하는 방식을 제어 |
| functions | array | 모델이 JSON 입력을 생성할 함수 목록 |
| logit_bias | map | 지정된 토큰의 가능성 수정 |
| max_tokens | integer | 생성할 최대 토큰 수 |
| n | integer | 생성할 완성 수 |
| presence_penalty | number | 지금까지 텍스트에 나타났는지에 따라 토큰에 패널티 |
| response_format | object | 응답 형식, 예: {"type": "json"} |
| seed | integer | 결정적 결과를 위한 샘플링 시드 |
| stop | string/array | API가 토큰 생성을 중단할 시퀀스 |
| stream | boolean | 응답 스트리밍 여부 |
| temperature | number | 무작위성 제어 (0-2) |
| top_p | number | nucleus sampling 제어 |
오류 처리
이 통합은 표준 LiteLLM 오류 처리를 사용해요. W&B Inference API에서 자주 발생하는 오류는 다음과 같아요:
| 오류 코드 | 메시지 | 원인 | 해결책 |
|---|---|---|---|
| 401 | Authentication failed | 인증 자격 증명이 잘못됐거나 W&B 프로젝트 entity/name이 잘못됨 | 올바른 API 키를 사용하고 W&B 프로젝트 이름과 entity가 올바른지 확인 |
| 403 | Country, region, or territory not supported | 지원되지 않는 위치에서 API 접근 | Geographic restrictions 참고 |
| 429 | Concurrency limit reached for requests | 너무 많은 동시 요청 | 동시 요청 수를 줄이거나 한도를 늘리기 |
| 429 | You exceeded your current quota | 크레딧 부족 또는 월간 지출 상한 도달 | 크레딧 충전 또는 한도 증가 |
| 429 | W&B Inference isn't available for personal accounts | 개인 계정 | 비-개인 계정으로 전환 |
| 500 | The server had an error | 내부 서버 오류 | 잠시 후 재시도, 지속되면 지원 문의 |
| 503 | The engine is currently overloaded | 서버 트래픽 과다 | 짧은 지연 후 요청 재시도 |
오류 429: 개인 entity 미지원
사용자가 개인 계정이면 W&B Inference에 접근할 수 없어요. 사용 가능한 비-개인 계정이 없다면 Team을 만들어 비-개인 계정을 만들어야 해요. 완료 후 아래와 같이 요청에 openai-project 헤더를 추가해요:
response = completion(
model="...",
extra_headers={"openai-project": "team_name/project_name"},
# ...
)
자세한 내용은 "Personal entities unsupported" 문서를 참고해요. LiteLLM에서 커스텀 헤더를 사용하는 더 많은 방법은 https://docs.litellm.ai/docs/proxy/request_headers 에서 볼 수 있어요.
더 알아보기 (Learn more)
- W&B Inference 문서
- W&B 지원 모델 목록