# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
apiVersion: nvidia.com/v1alpha1
kind: DynamoGraphDeployment
metadata:
  name: vllm-disagg
spec:
  pvcs:
  - create: false
    name: model-cache
  - create: false
    name: compilation-cache
  services:
    Frontend:
      componentType: frontend
      envs:
        - name: HF_HOME
          value: /home/dynamo/.cache/huggingface
      replicas: 1
      resources:
        requests:
          cpu: "8"
        limits:
          cpu: "8"
      volumeMounts:
      - name: model-cache
        mountPoint: /home/dynamo/.cache/huggingface
      extraPodSpec:
        affinity:
          podAffinity:
            requiredDuringSchedulingIgnoredDuringExecution:
              - topologyKey: "topology.kubernetes.io/zone"
                labelSelector:
                  matchLabels:
                    nvidia.com/dynamo-graph-deployment-name: "vllm-disagg"
                    nvidia.com/dynamo-component-type: "worker"
        mainContainer:
          image: nvcr.io/nvidia/ai-dynamo/dynamo-frontend:1.0.0
          workingDir: /workspace
          command:
          - /bin/bash
          - -c
          - |
            exec python3 -m dynamo.frontend --router-mode kv --router-reset-states
    VllmDecodeWorker:
      envFromSecret: hf-token-secret
      componentType: worker
      subComponentType: decode
      replicas: 2
      resources:
        requests:
          gpu: "2"
          custom:
            vpc.amazonaws.com/efa: "8"
        limits:
          gpu: "2"
          custom:
            vpc.amazonaws.com/efa: "8"
      volumeMounts:
      - name: model-cache
        mountPoint: /home/dynamo/.cache/huggingface
      - name: compilation-cache
        mountPoint: /home/dynamo/.cache/vllm
        useAsCompilationCache: true
      extraPodSpec:
        nodeSelector:
          node.kubernetes.io/instance-type: p5.48xlarge
          karpenter.sh/capacity-type: reserved
        tolerations:
        - key: "nvidia.com/gpu"
          operator: "Exists"
          effect: "NoSchedule"
        affinity:
          podAffinity:
            requiredDuringSchedulingIgnoredDuringExecution:
              - topologyKey: "topology.kubernetes.io/zone"
                labelSelector:
                  matchLabels:
                    nvidia.com/dynamo-graph-deployment-name: "vllm-disagg"
          podAntiAffinity:
            preferredDuringSchedulingIgnoredDuringExecution:
              - weight: 100
                podAffinityTerm:
                  labelSelector:
                    matchLabels:
                      nvidia.com/dynamo-component: "VllmPrefillWorker"
                  topologyKey: "kubernetes.io/hostname"
        mainContainer:
          env:
          - name: HF_HOME
            value: /home/dynamo/.cache/huggingface
          securityContext:
            capabilities:
              add:
                - IPC_LOCK
          image: nvcr.io/nvidia/ai-dynamo/vllm-runtime:1.0.0-efa-amd64
          workingDir: /workspace
          command:
          - /bin/bash
          - -c
          - |
            exec python3 -m dynamo.vllm \
             --model Qwen/Qwen3-32B \
             --tensor-parallel-size 2 \
             --disaggregation-mode decode \
             --kv-transfer-config '{"kv_connector":"NixlConnector","kv_role":"kv_both","kv_connector_extra_config": {"backends": ["LIBFABRIC"]}}'
    VllmPrefillWorker:
      envFromSecret: hf-token-secret
      componentType: worker
      subComponentType: prefill
      replicas: 6
      resources:
        requests:
          gpu: "2"
          custom:
            vpc.amazonaws.com/efa: "8"
        limits:
          gpu: "2"
          custom:
            vpc.amazonaws.com/efa: "8"
      volumeMounts:
      - name: model-cache
        mountPoint: /home/dynamo/.cache/huggingface
      - name: compilation-cache
        mountPoint: /home/dynamo/.cache/vllm
        useAsCompilationCache: true
      extraPodSpec:
        nodeSelector:
          node.kubernetes.io/instance-type: p5.48xlarge
          karpenter.sh/capacity-type: reserved
        tolerations:
        - key: "nvidia.com/gpu"
          operator: "Exists"
          effect: "NoSchedule"
        affinity:
          podAffinity:
            requiredDuringSchedulingIgnoredDuringExecution:
              - topologyKey: "topology.kubernetes.io/zone"
                labelSelector:
                  matchLabels:
                    nvidia.com/dynamo-graph-deployment-name: "vllm-disagg"
          podAntiAffinity:
            preferredDuringSchedulingIgnoredDuringExecution:
              - weight: 100
                podAffinityTerm:
                  labelSelector:
                    matchLabels:
                      nvidia.com/dynamo-component: "VllmPrefillWorker"
                  topologyKey: "kubernetes.io/hostname"
        mainContainer:
          env:
          - name: HF_HOME
            value: /home/dynamo/.cache/huggingface
          securityContext:
            capabilities:
              add:
                - IPC_LOCK
          image: nvcr.io/nvidia/ai-dynamo/vllm-runtime:1.0.0-efa-amd64
          workingDir: /workspace
          command:
          - /bin/bash
          - -c
          - |
            exec python3 -m dynamo.vllm \
             --model Qwen/Qwen3-32B \
             --tensor-parallel-size 2 \
             --disaggregation-mode prefill \
             --kv-transfer-config '{"kv_connector":"NixlConnector","kv_role":"kv_both","kv_connector_extra_config": {"backends": ["LIBFABRIC"]}}'