Skip to content

ybalbert001/sglang-aws-kit

Repository files navigation

SGLang AWS Kit

SGLang 在 AWS 上的配套工具集,包含 SageMaker Endpoint 部署方案、Prometheus + Grafana 监控栈、LiteLLM 代理定制 Hook,以及 Anthropic API 兼容性修复补丁。

项目结构

sglang-aws-kit/
├── sagemaker_endpoint_deploy/   # SGLang 部署到 SageMaker Endpoint
├── monitoring/                  # Prometheus + Grafana 监控服务
├── customerize_litellm/         # LiteLLM 代理配置与 Anthropic Schema 修复 Hook
├── faq/                         # 常见问题解答
└── sglang_thinking_usage_fix.patch  # Anthropic API 兼容性修复补丁

组件说明

1. SageMaker Endpoint 部署 (sagemaker_endpoint_deploy/)

利用 SGLang v0.2.13+ 原生的 SageMaker API 支持(/ping/invocations 端点),将 LLM 模型部署为 SageMaker 实时推理端点。

特性:

  • 直接使用 SGLang 内置的 SageMaker 接口,无需代理层
  • 支持 Chat Completions API(流式 / 非流式)
  • 通过 s5cmd 从 S3 高速下载模型

快速开始:

  1. 在 SageMaker Notebook 中打开 deploy_and_test.ipynb
  2. 配置模型参数(模型 ID、实例类型、SGLang 版本)
  3. 构建 Docker 镜像并推送到 ECR
  4. 下载模型上传至 S3,部署 SageMaker 端点

详见 sagemaker_endpoint_deploy/README.md

2. 监控服务 (monitoring/)

详见 monitoring/README.md

3. LiteLLM 代理定制 (customerize_litellm/)

通过自定义 LiteLLM Hook,可以对litellm的request 和 response进行定制性的处理。

解决的问题:

  1. SageMaker Endpoint 的响应格式与标准 Anthropic API 不完全兼容,导致 LiteLLM 无法正确解析流式响应。stream_anthropic_schema_fixer.py 作为 LiteLLM 的 callback hook,在响应返回前进行格式修正。
  2. 有些任务可以分发到不同的模型来处理,以节约成本。dynamic_tagging_handler.py 构建了一个hook,用于通过message的动态分发任务。代码中的例子是用于区分Claude Code的主线任务和支线任务。

包含文件:

  • stream_anthropic_schema_fixer.py:Anthropic Schema 修复 Hook,注册为 LiteLLM callback
  • dynamic_tagging_handler.py: 区分ClaudeCode的主线任务和支线任务,把支线任务分发给开源模型。
  • config.yaml:LiteLLM 代理配置,启用 hook 并配置 SageMaker 模型
  • docker-compose.yml:一键启动 LiteLLM 代理(含 PostgreSQL + Prometheus)

快速开始:

cd customerize_litellm
# 配置 config.yaml 中的模型名称和 AWS Region
# 配置 .env 文件中的 AWS 凭证
docker compose up

3. Hyperpod PD分离部署 (hyperpod_pd_digg_deploy/)

提供了PD分离多机部署的EKS yaml配置文件。 具体步骤:

  1. 在AMP(Amazon Managed Prometheus) 创建workspace
  2. 执行build-image.sh 构建Pod中运行sglang所需的Image
  3. 执行kubectl apply -f download-model-daemonset.yaml 把模型下载到nvme磁盘
  4. 修改sgl059-pd-kimi-k2.5-slgcu13dev-with-monitoring-v4.yaml,配置上AMP endpoint
  5. 执行kubectl apply -f sgl059-pd-kimi-k2.5-slgcu13dev-with-monitoring-v4.yaml 启动pd分离的sglang部署
  6. 打开AMG(Amazon Managed Grafana)配置上AMP的数据源,导入./monitoring/grafana/dashboards/json/中的dashbroad

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors