服务生成式 AI 模型面临两大问题:GPU 稀缺成本高昂

  • GPU 短缺:AI 部署通常在单一区域(或数据中心)中遇到容量不足的问题。然而,现有的服务解决方案(例如 Kubernetes)通常只关注单一区域甚至单一可用区,这意味着生成式 AI 工作负载常常因容量短缺而无法自动扩展。
  • 成本高昂:GPU 实例通常比 CPU 实例贵得多,尤其当你受限于单一云提供商时。对于 A100-80GB 实例,在三大主流云提供商之间的成本差异可能高达 30%。

为了缓解这些问题,我们推出了 SkyServe,一个简单、经济高效、跨区域、跨云的生成式 AI 模型服务库,它可以带来约 50% 的成本节省,并提供最佳的 GPU 可用性。

SkyServe:一个跨区域、跨云的服务库

SkyServe

SkyServe 是一个开源库,它可以将现有的服务框架部署到一个或多个区域或云上。SkyServe 专注于扩展生成式 AI 模型,但也支持任何具有 HTTP 端点的服务,并智能支持预留实例、按需实例和 Spot 实例。其目标是通过一个简单的接口,使模型部署更轻松、更经济。SkyServe 正在被 LMSys ChatBot Arena 在生产环境中积极使用,该平台已处理了超过 800,000 个请求,并在全球范围内提供了约 10 个开放的大型语言模型。

我们的关键观察是,GPU 的成本和可用性在不同的云和区域之间分布不均匀。智能优化选择合适的资源可以以降低的成本可靠地服务生成式 AI。此外,基于位置的优化是可行的,因为生成式 AI 工作负载主要受计算时间或排队延迟的影响,而不是跨区域通信的网络延迟(网络延迟最多 300 毫秒,而计算需要几秒钟)。即便如此,SkyServe 完全支持在单一可用区/区域/云中部署服务。

为何选择 SkyServe

  • 带上任何推理引擎(vLLM、TGI 等),并使用开箱即用的负载均衡和自动扩展进行服务。
  • 通过利用不同区域/云和加速器,提高可用性1
  • 通过自动资源选择和 Spot 实例,降低成本约 50%2
  • 通过统一的服务接口和自动故障恢复,简化部署
Multiple Locations
SkyServe 通过使用更多位置来提高可用性和降低成本。数据收集了 2 个月。

工作原理

给定一个暴露 HTTP 端点的现有模型推理引擎(vLLM、TGI 等),SkyServe 会将其部署到一个或多个区域或云上。SkyServe 将会

  • 自动找出使用最便宜资源和加速器的位置(可用区/区域/云),
  • 在多个“副本”上部署和复制服务,以及
  • 暴露一个将请求负载均衡到服务副本的单一端点。

当发生任何错误或 Spot 实例被抢占时,SkyServe 将通过使用当前价格和可用性重新优化部署来恢复该副本。

快速上手

首先,安装 SkyPilot 并检查云凭证是否已设置(参阅此处的文档)

pip install "skypilot-nightly[all]"
sky check

安装完成后,我们可以启动由 vLLM 引擎驱动的 Mixtral 8x7b 的双副本部署。要指定服务,需要定义一个服务 YAML 文件

# mixtral.yaml
service:
  readiness_probe: /v1/models
  replicas: 2

# Fields below describe each replica.
resources:
  ports: 8080
  accelerators: {L4:8, A10g:8, A100:4, A100:8, A100-80GB:2, A100-80GB:4, A100-80GB:8}

setup: |
  conda create -n vllm python=3.10 -y
  conda activate vllm
  pip install vllm==0.3.0 transformers==4.37.2  

run: |
  conda activate vllm
  export PATH=$PATH:/sbin
  python -m vllm.entrypoints.openai.api_server \
    --tensor-parallel-size $SKYPILOT_NUM_GPUS_PER_NODE \
    --host 0.0.0.0 --port 8080 \
    --model mistralai/Mixtral-8x7B-Instruct-v0.1  

服务 YAML 文件所需的字段是 service 部分和 resources.ports 字段。在前者中,我们配置服务

  • readiness_probe:检查副本上服务状态的路径。SkyServe 会探测此路径并检查返回码是否为 200 OK。请求可以是服务暴露的健康检查 API,例如 /health,也可以是实际请求。如果无法获得响应,SkyServe 会将此副本标记为未就绪,并停止向该副本路由流量3

  • replicas:此部署中的目标副本数量。这是固定副本部署的快捷方式。自动扩展选项将在下一节中展示。

此外,resources 下的 accelerators 部分指定了一组要使用的资源。启动副本时,SkyServe 会选择最便宜且可用的加速器。实际上,指定一组资源可以提高 GPU 的可用性。

最后,resources.ports 指定了所有副本为运行在其上的服务所暴露的端口。

让我们用 1 条命令启动此服务

sky serve up mixtral.yaml -n mixtral

这就够了!这将显示包含下表的输出

Service from YAML spec: mixtral.yaml
Service Spec:
Readiness probe method:           GET /v1/models
Readiness initial delay seconds:  1200
Replica autoscaling policy:       Fixed 2 replicas        
Each replica will use the following resources (estimated):
== Optimizer ==
Estimated cost: $7.3 / hour

Considered resources (1 node):
----------------------------------------------------------------------------------------------------------
 CLOUD   INSTANCE                    vCPUs   Mem(GB)   ACCELERATORS   REGION/ZONE     COST ($)   CHOSEN   
----------------------------------------------------------------------------------------------------------
 Azure   Standard_NC48ads_A100_v4    48      440       A100-80GB:2    eastus          7.35          ✔     
 GCP     g2-standard-96              96      384       L4:8           us-east4-a      7.98                
 GCP     a2-ultragpu-2g              24      340       A100-80GB:2    us-central1-a   10.06               
 GCP     a2-highgpu-4g               48      340       A100:4         us-central1-a   14.69               
 Azure   Standard_NC96ads_A100_v4    96      880       A100-80GB:4    eastus          14.69               
 AWS     g5.48xlarge                 192     768       A10G:8         us-east-1       16.29               
 GCP     a2-ultragpu-4g              48      680       A100-80GB:4    us-central1-a   20.11               
 Azure   Standard_ND96asr_v4         96      900       A100:8         eastus          27.20               
 GCP     a2-highgpu-8g               96      680       A100:8         us-central1-a   29.39               
 Azure   Standard_ND96amsr_A100_v4   96      1924      A100-80GB:8    eastus          32.77               
 AWS     p4d.24xlarge                96      1152      A100:8         us-east-1       32.77               
 GCP     a2-ultragpu-8g              96      1360      A100-80GB:8    us-central1-a   40.22               
 AWS     p4de.24xlarge               96      1152      A100-80GB:8    us-east-1       40.97               
----------------------------------------------------------------------------------------------------------

Launching a new service 'mixtral'. Proceed? [Y/n]:

这里显示了 AWS、GCP 和 Azure 上所有可能的资源,以及 YAML 中列出的所有可能的加速器。确认后,SkyServe 会通过一个 SkyServe 控制器 VM 处理副本管理、负载均衡和可选的自动扩展。

您可以使用 sky serve status 命令检查服务状态。服务状态变为 READY 后,即可开始处理流量

SkyServe Status

请注意,这两个副本是在不同区域启动的,以实现最低成本和最高 GPU 可用性。通常情况下,如果单一云提供商没有足够的 GPU 容量,副本也可以托管在不同的云提供商上。(参阅此处 SkyPilot 支持的所有云提供商。)

SkyServe 为所有副本生成一个单一服务端点。该端点由 SkyServe 控制器在所有副本之间进行负载均衡,针对此端点的简单 curl -L 命令将自动路由到其中一个副本(需要 -L,因为底层使用了 HTTP 重定向)

$ curl -L 3.84.15.251:30001/v1/chat/completions \
    -X POST \
    -d '{"model": "mistralai/Mixtral-8x7B-Instruct-v0.1", "messages": [{"role": "user", "content": "Who are you?"}]}' \
    -H 'Content-Type: application/json'

# Example output:
{"id":"cmpl-80b2bfd6f60c4024884c337a7e0d859a","object":"chat.completion","created":1005,"model":"mistralai/Mixtral-8x7B-Instruct-v0.1","choices":[{"index":0,"message":{"role":"assistant","content":" I am a helpful AI assistant designed to provide information, answer questions, and engage in conversation with users. I do not have personal experiences or emotions, but I am programmed to understand and process human language, and to provide helpful and accurate responses."},"finish_reason":"stop"}],"usage":{"prompt_tokens":13,"total_tokens":64,"completion_tokens":51}}

恭喜您!您已成功部署 Mixtral 模型,包含 2 个节点。接下来,让我们看看 SkyServe 中的一些高级配置,以进一步改进服务。

高级配置

就绪探测

在前面的示例中,我们使用了 /v1/models 端点兼作健康检查端点。SkyServe 会定期发送 GET 请求并期望返回 200 OK,系统将此解释为“副本已就绪”。

在先前的配置中,readiness_probe: <path> 是以下规范的简写,即对该路径执行 HTTP GET 请求

service:
  readiness_probe:
    path: <path>

SkyServe 还支持发送 POST 请求作为就绪探测。这在多种情况下非常有用,例如确保 GPU 能够实际处理请求。要使用真实的计算流量作为探测,我们可以指定一个 POST 请求

service:
  readiness_probe:
    path: /v1/chat/completions
    post_data:
      model: mistralai/Mixtral-8x7B-Instruct-v0.1
      messages:
        - role: user
          content: Hello! What is your name?
      max_tokens: 1
  replicas: 2

这样,每次就绪探测都是发送到服务副本的聊天完成 POST 请求。尽管处理探测可能需要更长时间,但这更准确地反映了系统的状态,因为即使 /v1/chat/completions 出现故障,原始的 /v1/models 也可能成功。

由于大型语言模型(LLM)的冷启动时间较长,例如安装依赖、下载模型以及将模型加载到 GPU 内存,SkyServe 默认会忽略最初 1200 秒(或 20 分钟)内的任何就绪探测失败。这可以通过以下方式配置

service:
  readiness_probe:
    initial_delay_seconds: 1800

要使用新配置更新服务,可以运行

sky serve update mixtral mixtral.yaml
更新了就绪探测的新 mixtral.yaml 文件
# mixtral.yaml
service:
  readiness_probe:
    path: /v1/chat/completions
    post_data:
      model: mistralai/Mixtral-8x7B-Instruct-v0.1
      messages:
        - role: user
          content: Hello! What is your name?
      max_tokens: 1
    initial_delay_seconds: 1800
  replicas: 2

# Fields below describe each replica.
resources:
  ports: 8080
  accelerators: {L4:8, A10g:8, A100:4, A100:8, A100-80GB:2, A100-80GB:4, A100-80GB:8}

setup: |
  conda create -n vllm python=3.10 -y
  conda activate vllm
  pip install vllm==0.3.0 transformers==4.37.2  

run: |
  conda activate vllm
  export PATH=$PATH:/sbin
  python -m vllm.entrypoints.openai.api_server \
    --tensor-parallel-size $SKYPILOT_NUM_GPUS_PER_NODE \
    --host 0.0.0.0 --port 8080 \
    --model mistralai/Mixtral-8x7B-Instruct-v0.1  

自动扩展

前面的示例使用了固定数量副本的简单部署。如果流量波动较大(例如白天与夜间流量),这可能不是理想的选择。

SkyServe 支持开箱即用的自动扩展,基于端点的动态负载(每秒查询数,即 QPS)。

要启用自动扩展,您可以通过将 replicas 字段替换为 replica_policy 配置来指定一些附加配置

service:
  readiness_probe: ...
  replica_policy:
    min_replicas: 0
    max_replicas: 10
    target_qps_per_replica: 2.5
  • min_replicasmax_replicas 决定了副本数量的下限和上限。

  • target_qps_per_replica 是 SkyServe 用于自动扩展的阈值——每个服务副本预期应处理的 QPS(每秒查询数)。SkyServe 将扩展服务,以确保每个副本大约接收 target_qps_per_replica 个每秒查询。

请注意,我们将 min_replicas 设置为 0,这样当一段时间没有收到请求时,SkyServe 可以缩减到零以节省成本。

有关自动扩展的更多详细信息,请参阅我们的文档

要将之前的服务更新为支持自动扩展,运行

sky serve update mixtral mixtral.yaml
具有高级就绪探测和自动扩展功能的 mixtral.yaml 文件
# mixtral.yaml
service:
  readiness_probe:
    path: /v1/chat/completions
    post_data:
      model: mistralai/Mixtral-8x7B-Instruct-v0.1
      messages:
        - role: user
          content: Hello! What is your name?
      max_tokens: 1
    initial_delay_seconds: 1800
  replica_policy:
    min_replicas: 0
    max_replicas: 10
    target_qps_per_replica: 2.5

# Fields below describe each replica.
resources:
  ports: 8080
  accelerators: {L4:8, A10g:8, A100:4, A100:8, A100-80GB:2, A100-80GB:4, A100-80GB:8}

setup: |
  conda create -n vllm python=3.10 -y
  conda activate vllm
  pip install vllm==0.3.0 transformers==4.37.2  

run: |
  conda activate vllm
  export PATH=$PATH:/sbin
  python -m vllm.entrypoints.openai.api_server \
    --tensor-parallel-size $SKYPILOT_NUM_GPUS_PER_NODE \
    --host 0.0.0.0 --port 8080 \
    --model mistralai/Mixtral-8x7B-Instruct-v0.1  

托管 Spot 实例:约 50% 的成本节省

前面的示例使用按需实例作为服务副本。由于昂贵的高端 GPU 实例的特性,按需实例可能相当昂贵。

然而,Spot 实例可以提供超过 3 倍的成本节省,尽管由于抢占的原因可靠性较低,并且在不同区域/云之间更为稀缺。模型服务的无状态特性使其适合在 Spot 实例上运行。借助 SkyServe,服务可以轻松地部署在 Spot 实例上,并具有自动抢占恢复功能,同时享受跨多个区域/云的容量

通过在 resources 部分指定 use_spot: true,SkyServe 将为您的服务启动 Spot 实例并自动管理它们

resources:
  use_spot: true
  accelerators: {L4:8, A10g:8, A100:4, A100:8, A100-80GB:2, A100-80GB:4, A100-80GB:8}

通过启用更多区域、云和加速器类型,SkyServe 可以在多个资源池中搜索 Spot 实例,这显著提高了 Spot 实例的可用性。此外,我们建议增加副本数量或减少 target_qps_per_replica,以超额配置一些 Spot 实例,从而更好地处理抢占。例如,用 3 个 Spot 副本替换 2 个按需副本可以提供

  • 更好的服务水平保证;
  • 50% 的成本节省。

请继续关注 SkyServe 正在添加的一项高级策略,该策略将进一步降低成本并使恢复更加智能。

SkyServe 与 Chatbot Arena

Chatbot Arena

过去四个月,LMSys Chatbot Arena 一直使用 SkyServe 来提供约 10 个开放模型(包括 Mixtral、Llama2 等),并在全球范围内处理了超过 800,000 个请求。我们很高兴看到 SkyServe 为 LLM 服务提供了真正的价值增益:简单的部署和升级、显著的成本节省以及自动故障恢复。

可运行示例

SkyServe Runnable Examples

SkyServe 集成了许多流行的开源 AI 框架。下面是您可以直接复制粘贴并在自己的云账户中启动的可运行示例。

  • HuggingFace TGI:TGI 框架支持的任何 LLM 都可以轻松启动。只需通过环境变量(模型 ID)切换模型即可!
  • Meta 的 CodeLlama-70B:使用 SkyServe 启动您的私有 CodeLlama-70B,并通过 VSCode、API 和 Chat 端点与您的团队共享!(感谢 Tabby 提供了简单的 IDE 集成。)
  • vLLM:在 SkyServe 上使用 PagedAttention 进行轻松、快速、经济实惠的 LLM 服务。
  • SGLang:在 SkyServe 上尝试 LMSys 的下一代 LLM 推理接口和运行时 SGLang!
  • Tabby:一个轻量级代码助手,可以使用 SkyServe 轻松托管,并通过 VSCode 访问它!
  • LoRAX:轻松使用 Predibase LoRAX 服务器来服务数百个 LoRA 模型。

HuggingFace TGI 上任何兼容 OpenAI API 的 LLM

sky serve up -n tgi-mistral huggingface-tgi.yaml --env MODEL_ID=mistralai/Mistral-7B-Instruct-v0.1
sky serve up -n tgi-vicuna huggingface-tgi.yaml --env MODEL_ID=lmsys/vicuna-13b-v1.5
点击查看 huggingface-tgi.yaml 文件和 curl 命令

了解更多请点击这里

# SkyServe YAML to run HuggingFace TGI
#
# Usage:
#   sky serve up -n tgi huggingface-tgi.yaml
# Then visit the endpoint printed in the console. You could also
# check the endpoint by running:
#   sky serve status --endpoint tgi

envs:
  MODEL_ID: lmsys/vicuna-13b-v1.5

service:
  readiness_probe: /health
  replicas: 2

resources:
  ports: 8082
  accelerators: A100:1

run: |
  docker run --gpus all --shm-size 1g -p 8082:80 \
    -v ~/data:/data ghcr.io/huggingface/text-generation-inference \
    --model-id $MODEL_ID  
curl -L $(sky serve status tgi --endpoint)/generate \
    -X POST \
    -H 'Content-Type: application/json' \
    -d '{
      "inputs": "What is Deep Learning?",
      "parameters": {
        "max_new_tokens": 20
      }
    }'

# Example Output:
{"generated_text":"\n\nDeep learning is a subset of machine learning that uses artificial neural networks to model and solve"}

托管 Meta 的 Code Llama 70B 模型

sky serve up -n codellama codellama.yaml
点击查看 codellama.yaml 文件和 curl 命令

了解更多请点击这里

# An example yaml for serving Code Llama model from Meta with an OpenAI API.
# Usage:
#  1. Launch on a single instance: `sky launch -c code-llama codellama.yaml`
#  2. Scale up to multiple replicas with a single endpoint:
#     `sky serve up -n code-llama codellama.yaml`
service:
  readiness_probe:
    path: /v1/completions
    post_data:
      model: codellama/CodeLlama-70b-Instruct-hf
      prompt: "def hello_world():"
      max_tokens: 1
    initial_delay_seconds: 1800
  replicas: 2

resources:
  accelerators: {L4:8, A10g:8, A10:8, A100:4, A100:8, A100-80GB:2, A100-80GB:4, A100-80GB:8}
  disk_size: 1024
  disk_tier: best
  memory: 32+
  ports: 8000

setup: |
  conda activate codellama
  if [ $? -ne 0 ]; then
    conda create -n codellama python=3.10 -y
    conda activate codellama
  fi

  pip list | grep vllm || pip install "git+https://github.com/vllm-project/vllm.git"
  pip install git+https://github.com/huggingface/transformers  

run: |
  conda activate codellama
  export PATH=$PATH:/sbin
  # Reduce --max-num-seqs to avoid OOM during loading model on L4:8
  python -u -m vllm.entrypoints.openai.api_server \
    --host 0.0.0.0 \
    --model codellama/CodeLlama-70b-Instruct-hf \
    --tensor-parallel-size $SKYPILOT_NUM_GPUS_PER_NODE \
    --max-num-seqs 64 | tee ~/openai_api_server.log  
curl -L $(sky serve status codellama --endpoint)/v1/completions \
    -H "Content-Type: application/json" \
    -d '{
      "model": "codellama/CodeLlama-70b-Instruct-hf",
      "prompt": "def quick_sort(a: List[int]):",
      "max_tokens": 512
  }'

# Example Output:
{"id":"cmpl-f0ceac768bf847269f64c2e5bc08126f","object":"text_completion","created":1770,"model":"codellama/CodeLlama-70b-Instruct-hf","choices":[{"index":0,"text":"\n    if len(a) < 2:\n        return a\n    else:\n        pivot = a[0]\n        lesser = quick_sort([x for x in a[1:] if x < pivot])\n        greater = quick_sort([x for x in a[1:] if x >= pivot])\n        return lesser + pivot + greaterq\n        \n","logprobs":null,"finish_reason":"stop"}],"usage":{"prompt_tokens":13,"total_tokens":97,"completion_tokens":84}}

vLLM:使用最先进的 LLM 推理引擎服务 Llama-2

sky serve up -n vllm vllm.yaml --env HF_TOKEN=<your-huggingface-token>
点击查看 vllm.yaml 文件和 curl 命令

了解更多请点击这里

# SkyServe YAML for vLLM inference engine
#
# Usage:
#   set your HF_TOKEN in the envs section or pass it in CLI
#   sky serve up -n vllm vllm.yaml
# Then visit the endpoint printed in the console. You could also
# check the endpoint by running:
#   sky serve status --endpoint vllm
service:
  # Specifying the path to the endpoint to check the readiness of the service.
  readiness_probe: /v1/models
  # How many replicas to manage.
  replicas: 2

envs:
  MODEL_NAME: meta-llama/Llama-2-7b-chat-hf
  HF_TOKEN: <your-huggingface-token> # Change to your own huggingface token

resources:
  accelerators: {L4:1, A10G:1, A10:1, A100:1, A100-80GB:1}
  ports:
    - 8000

setup: |
  conda activate vllm
  if [ $? -ne 0 ]; then
    conda create -n vllm python=3.10 -y
    conda activate vllm
  fi

  pip list | grep vllm || pip install vllm==0.3.0
  pip list | grep transformers || pip install transformers==4.37.2

  python -c "import huggingface_hub; huggingface_hub.login('${HF_TOKEN}')"  


run: |
  conda activate vllm
  echo 'Starting vllm openai api server...'
  python -m vllm.entrypoints.openai.api_server \
    --model $MODEL_NAME --tokenizer hf-internal-testing/llama-tokenizer \
    --host 0.0.0.0  
curl -L $(sky serve status vllm --endpoint)/v1/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "meta-llama/Llama-2-7b-chat-hf",
    "prompt": "San Francisco is a",
    "max_tokens": 7,
    "temperature": 0
  }'

# Example Output:
{"id":"cmpl-6e3b960a5e7b47dbadb8846e76aef87d","object":"text_completion","created":1479,"model":"meta-llama/Llama-2-7b-chat-hf","choices":[{"index":0,"text":" city in Northern California that is known","logprobs":null,"finish_reason":"length"}],"usage":{"prompt_tokens":5,"total_tokens":12,"completion_tokens":7}}

使用 SGLang 服务多模态模型 LLaVA

sky serve up -n sglang sglang.yaml
点击查看 sglang.yaml 文件和 curl 命令

了解更多请点击这里

# SkyServe YAML for SGLang
#
# Usage:
#   set your HF_TOKEN in the envs section or pass it in CLI
#   sky serve up -n sglang sglang.yaml --env HF_TOKEN=<your-huggingface-token>
# Then visit the endpoint printed in the console. You could also
# check the endpoint by running:
#   sky serve status --endpoint sglang
service:
  # Specifying the path to the endpoint to check the readiness of the service.
  readiness_probe: /health
  # How many replicas to manage.
  replicas: 2

envs:
  MODEL_NAME: liuhaotian/llava-v1.6-vicuna-7b
  TOKENIZER_NAME: llava-hf/llava-1.5-7b-hf

resources:
  accelerators: {L4:1, A10G:1, A10:1, A100:1, A100-80GB:1}
  ports:
    - 8000

setup: |
  conda activate sglang
  if [ $? -ne 0 ]; then
    conda create -n sglang python=3.10 -y
    conda activate sglang
  fi

  pip list | grep sglang || pip install "sglang[all]"
  pip list | grep transformers || pip install transformers==4.37.2  

run: |
  conda activate sglang
  echo 'Starting sglang openai api server...'
  export PATH=$PATH:/sbin/
  python -m sglang.launch_server --model-path $MODEL_NAME \
    --tokenizer-path $TOKENIZER_NAME \
    --chat-template vicuna_v1.1 \
    --host 0.0.0.0 --port 8000  
curl -L $(sky serve status sglang --endpoint)/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "liuhaotian/llava-v1.6-vicuna-7b",
    "messages": [
      {
        "role": "user",
        "content": [
            {"type": "text", "text": "Describe this image"},
            {
              "type": "image_url",
              "image_url": {
                "url": "https://raw.githubusercontent.com/sgl-project/sglang/main/examples/quick_start/images/cat.jpeg"
              }
            }
        ]
      }
    ]
  }'

# Example Output:
{"id":"eea519a1e8a6496fa449d3b96a3c99c1","object":"chat.completion","created":1707709646,"model":"liuhaotian/llava-v1.6-vicuna-7b","choices":[{"index":0,"message":{"role":"assistant","content":" This is an image of an anthropomorphic cat character wearing sunglass"},"finish_reason":null}],"usage":{"prompt_tokens":46,"total_tokens":2205,"completion_tokens":2159}}

使用 Tabby 在 VSCode 中自托管轻量级代码助手

sky serve up -n tabby tabby.yaml
点击查看 tabby.yaml 文件和 curl 命令

了解更多请点击这里

# SkyServe YAML for code assistant in VSCode with Tabby
#
# Usage:
#   sky serve up -n tabby tabby.yaml
# Then visit the endpoint printed in the console. You could also
# check the endpoint by running:
#   sky serve status --endpoint tabby

service:
  readiness_probe: /v1/health
  replicas: 2

resources:
  ports: 8080
  accelerators: {T4:1, L4:1, A100:1, A10G:1}

run: |
  docker run --gpus all -p 8080:8080 -v ~/.tabby:/data \
    tabbyml/tabby \
    serve --model TabbyML/StarCoder-1B --device cuda  
curl -L $(sky serve status tabby --endpoint)/v1/completions \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{
    "language": "python",
    "segments": {
      "prefix": "def fib(n):\n    ",
      "suffix": "\n        return fib(n - 1) + fib(n - 2)"
    }
  }'

# Example Output:
{"id":"cmpl-7305a984-429a-4342-bf95-3d47f668c8cd","choices":[{"index":0,"text":"    if n == 0:\n            return 0\n        if n == 1:\n            return 1"}]}

使用 LoRAX 扩展 Multi-LoRA 推理服务器

sky serve up -n lorax lorax.yaml [--env MODEL_ID=mistralai/Mistral-7B-Instruct-v0.1]
点击查看 lorax.yaml 文件和 curl 命令

了解更多请点击这里

# SkyServe YAML for multi-LoRA inference server using LoRAX
#
# Usage:
#   sky serve up -n lorax lorax.yaml
# Then visit the endpoint printed in the console. You could also
# check the endpoint by running:
#   sky serve status --endpoint lorax

envs:
  MODEL_ID: mistralai/Mistral-7B-Instruct-v0.1

service:
  readiness_probe:
    path: /generate
    post_data:
      inputs: "[INST] Natalia sold clips to 48 of her friends in April, and then she sold half as many clips in May. How many clips did Natalia sell altogether in April and May? [/INST]"
      parameters:
        max_new_tokens: 64
        adapter_id: vineetsharma/qlora-adapter-Mistral-7B-Instruct-v0.1-gsm8k
  replicas: 2

resources:
  accelerators: {L4:1, A100:1, A10G:1}
  memory: 32+
  ports: 
    - 8080

run: |
  docker run --gpus all --shm-size 1g -p 8080:80 -v ~/data:/data \
    ghcr.io/predibase/lorax:latest \
    --model-id $MODEL_ID  
curl -L $(sky serve status lorax --endpoint)/generate \
    -X POST \
    -H 'Content-Type: application/json' \
    -d '{
      "inputs": "[INST] Natalia sold clips to 48 of her friends in April, and then she sold half as many clips in May. How many clips did Natalia sell altogether in April and May? [/INST]",
      "parameters": {
        "max_new_tokens": 64,
        "adapter_id": "vineetsharma/qlora-adapter-Mistral-7B-Instruct-v0.1-gsm8k"
      }
    }'

# Example Output:
{"generated_text":"Natalia sold 48/2 = <<48/2=24>>24 clips in May.\nIn total, Natalia sold 48 + 24 = <<48+24=72>>72 clips in April and May.\n#### 72"}

SkyServe 路线图

SkyServe 的路线图上有很多令人兴奋的改进

  • 可定制的负载均衡和自动扩展
  • 支持 AI 云(Lambda, RunPod),可节省 3-4 倍成本
  • 更高级的 Spot 策略 - 一种使用 Spot 实例可节省 > 50% 成本,同时保证/提高服务质量的策略
  • 更高级的多加速器支持 - 将流量路由到不同的加速器以提高成本效率

请继续关注这些更新,并通过加入我们的 Slack 或在我们的 GitHub 仓库上提交问题来提供反馈。欢迎加入我们的 SkyPilot 开源社区,让在任何云上处理 AI 工作负载变得更加轻松!

了解更多

加入我们的 Slack 与 SkyPilot 社区交流!


  1. 图表显示,从单一可用区扩展到多个区域,可用性(在 AWS 上启动 Spot V100 实例的时间百分比)从 59% 提高到 100%。 ↩︎

  2. 根据 Spot 实例可用性,假设在 Spot 实例不可用时必须使用按需实例,成本节省约为 2.4 倍。 ↩︎

  3. 由于探测可能因网络拥堵或计算过载而失败,SkyServe 不会立即重启副本。如果探测在指定时间内持续失败,SkyServe 将终止该副本并为您启动一个新的。 ↩︎