self-hosted-llm-batch-inference

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Self-Hosted LLM Batch Inference

自托管 LLM 批量推理

Build a repeatable offline inference path for a startup that needs GPU economics without operating an ML platform. Use one AWS Batch job for one corpus run, backed by Amazon ECS Managed Instances Spot. Stage model weights in Amazon S3, divide the corpus into deterministic shards, and process those shards sequentially with vLLM on one GPU.
Keep the infrastructure stack separate from each run. Provision reusable Batch, ECR, IAM, logging, and optional networking resources with infrastructure as code. Submit each run separately with immutable image, model, prompt, input manifest, and output identifiers.
Set
scaleInAfter
to
0
for this architecture. No follow-up task is expected on the instance after the Batch job ends, so retaining idle GPU capacity adds cost without improving the run.
为需要在不运营 ML 平台的情况下获得良好 GPU 成本效益的初创公司构建可重复的离线推理路径。每次语料库运行使用一个 AWS Batch job,并由 Amazon ECS Managed Instances Spot 提供算力。将模型权重暂存在 Amazon S3 中,把语料库划分为确定性分片,并使用单 GPU 上的 vLLM 按顺序处理这些分片。
将基础设施栈与每次运行分离。通过 infrastructure as code 预置可复用的 Batch、ECR、IAM、日志记录和可选网络资源。每次运行单独提交,并携带不可变的镜像、模型、prompt、输入 manifest 和输出标识符。
在此架构中,将
scaleInAfter
设置为
0
。Batch job 结束后,实例上预计不会执行任何后续任务,因此保留闲置 GPU 容量只会增加成本,对本次运行没有任何收益。

Scope

适用范围

Apply this skill only when all of these conditions hold:
  • The workload is recurring, latency-tolerant, generative offline inference.
  • The model is approximately 1B to 8B parameters and fits on one GPU after measurement.
  • The team accepts Spot interruption and requires automatic recovery.
  • One model is loaded once and reused across many input shards in a corpus run.
  • Persistent artifacts and completion records can live in Amazon S3.
Do not apply this skill to online endpoints, training or fine-tuning, embedding models, other inference engines, multi-GPU or distributed inference, or one-off experiments where an operator can rerun the command manually.
仅当以下所有条件均成立时,才应用此 skill:
  • 工作负载是周期性、可容忍延迟的生成式离线推理。
  • 模型约为 1B 至 8B 参数,并且经测量后可装入单个 GPU。
  • 团队接受 Spot 实例中断,并要求自动恢复。
  • 在一次语料库运行中,模型仅加载一次,并在许多输入分片之间重复使用。
  • 持久化制品和完成记录可以存放在 Amazon S3 中。
不要将此 skill 用于在线端点、训练或微调、embedding 模型、其他推理引擎、多 GPU 或分布式推理,也不要用于操作员可以手动重新运行命令的一次性实验。

Workflow

工作流

  1. Read
    references/prepare-model-and-input.md
    and define the immutable model artifact, prompt contract, deterministic shard manifest, output schema, quarantine schema, and measured sizing inputs.
  2. Read
    references/run-with-aws-batch.md
    and author the reusable infrastructure plus the separate
    SubmitJob
    invocation. Preserve one Batch job per corpus run.
  3. Read
    references/verify-and-optimize.md
    before the canary and again after the full run. Reconcile records, confirm retry behavior, measure cost inputs, and verify that GPU capacity has terminated.
  1. 阅读
    references/prepare-model-and-input.md
    ,定义不可变的模型制品、prompt 契约、确定性分片 manifest、输出 schema、隔离区 schema 和用于容量测算的实测输入。
  2. 阅读
    references/run-with-aws-batch.md
    ,编写可复用的基础设施以及独立的
    SubmitJob
    调用。保持每次语料库运行对应一个 Batch job。
  3. 在运行 canary 之前和完整运行之后阅读
    references/verify-and-optimize.md
    。核对记录、确认重试行为、测量成本输入,并验证 GPU 容量已经释放。

Required deliverables

必需交付物

  • A reusable infrastructure stack for the Batch compute environment, queue, job definition, ECR repository, IAM roles and instance profile, log group, and only the networking resources that the chosen path requires.
  • An immutable model artifact and manifest in Amazon S3.
  • Deterministic input shards and an input manifest in Amazon S3.
  • A separate
    SubmitJob
    invocation containing immutable image, model, prompt, input manifest, and output prefix identifiers.
  • Output, quarantine, and run metadata that survive infrastructure deletion.
  • A verification record proving completion, record reconciliation, and GPU capacity release.
  • 用于 Batch compute environment、queue、job definition、ECR repository、IAM roles、instance profile 和 log group 的可复用基础设施栈,并且仅包含所选路径需要的网络资源。
  • 存储在 Amazon S3 中的不可变模型制品和 manifest。
  • 存储在 Amazon S3 中的确定性输入分片和输入 manifest。
  • 独立的
    SubmitJob
    调用,其中包含不可变的镜像、模型、prompt、输入 manifest 和输出前缀标识符。
  • 在基础设施删除后仍可保留的输出、隔离区数据和运行元数据。
  • 证明运行完成、记录核对完成以及 GPU 容量已释放的验证记录。

Upstream skills

上游 skills

Invoke upstream skills only when authoring the artifacts they own. The
aws-core:
skills ship in the separate
aws-core
plugin. If it is not installed, tell the user, recommend installing it, and continue with the steps that do not depend on it. Do not reproduce its content from memory.
  • Skill("aws-core:aws-containers")
    : ECS Managed Instances, ECR, and container mechanics.
  • Skill("aws-core:aws-cloudformation")
    or
    Skill("aws-core:aws-cdk")
    : the selected infrastructure-as-code implementation.
  • Skill("aws-core:aws-iam")
    : role and policy implementation.
  • Skill("aws-core:aws-storage")
    : S3 storage and transfer implementation.
  • Skill("aws-core:aws-compute")
    : actual single-GPU instance candidates after measuring the workload.
  • Skill("aws-core:aws-billing-and-cost-management")
    : current rates and cost calculations using the measurements defined here.
  • Skill("aws-core:aws-messaging-and-streaming")
    : Batch state-change notifications when unattended completion needs a notification path.
  • Skill("aws-core:aws-secrets-manager")
    : gated model credentials during staging only.
仅在编写由上游 skill 负责的制品时调用上游 skills。
aws-core:
skills 随独立的
aws-core
plugin 提供。如果尚未安装,请告知用户,建议其进行安装,然后继续执行不依赖该 plugin 的步骤。不要凭记忆复述其内容。
  • Skill("aws-core:aws-containers")
    :ECS Managed Instances、ECR 和容器机制。
  • Skill("aws-core:aws-cloudformation")
    或
    Skill("aws-core:aws-cdk")
    :所选的 infrastructure as code 实现。
  • Skill("aws-core:aws-iam")
    :role 和 policy 实现。
  • Skill("aws-core:aws-storage")
    :S3 存储和传输实现。
  • Skill("aws-core:aws-compute")
    :测量工作负载后得出的实际单 GPU 实例候选项。
  • Skill("aws-core:aws-billing-and-cost-management")
    :使用此处定义的测量值计算当前费率和成本。
  • Skill("aws-core:aws-messaging-and-streaming")
    :无人值守完成需要通知路径时,用于 Batch 状态变更通知。
  • Skill("aws-core:aws-secrets-manager")
    :仅在模型暂存阶段受控启用模型凭据。

Reference files

参考文件

  • references/prepare-model-and-input.md
    : Read before choosing GPU capacity or writing infrastructure. Defines model staging, prompt and record contracts, deterministic shards, manifests, output and quarantine schemas, and measurement inputs.
  • references/run-with-aws-batch.md
    : Read before authoring the stack or submitting a run. Defines the AWS Batch architecture,
    scaleInAfter
    , networking decision, job lifecycle, retries, resumability, IAM boundaries, and stack-to-run contract.
  • references/verify-and-optimize.md
    : Read before the canary and after every full run. Defines acceptance checks, reconciliation, interruption testing, capacity-release verification, and the measurements passed to cost analysis.
  • references/prepare-model-and-input.md
    :在选择 GPU 容量或编写基础设施之前阅读。定义模型暂存、prompt 和记录契约、确定性分片、manifest、输出和隔离区 schema,以及测量输入。
  • references/run-with-aws-batch.md
    :在编写基础设施栈或提交运行之前阅读。定义 AWS Batch 架构、
    scaleInAfter
    、网络决策、job 生命周期、重试、可恢复性、IAM 边界,以及基础设施栈与运行之间的契约。
  • references/verify-and-optimize.md
    :在 canary 之前以及每次完整运行之后阅读。定义验收检查、核对、中断测试、容量释放验证,以及传递给成本分析的测量值。