# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

# ──────────────────────────────────────────────────────────────────────────────
# Planner profiling data ConfigMap
#
# The planner requires pre-deployment profiling data (prefill & decode
# interpolation curves) for throughput-based scaling.  The values below are
# PLACEHOLDERS for Qwen/Qwen3-0.6B — replace them with real measurements
# before deploying to production.
#
# How to obtain real data:
#   • Run the Dynamo Profiler against your target GPU/model combination.
#     See docs/components/profiler/profiler-guide.md for instructions.
#   • Or run manual benchmarks and fill in the arrays below.
#
# Key format (JSON files mounted into the planner container):
#   prefill_raw_data.json — prefill_isl (input sequence lengths),
#       prefill_ttft (time-to-first-token in ms), prefill_thpt_per_gpu
#       (tokens/s per GPU) — all 1-D arrays of equal length.
#   decode_raw_data.json  — x_kv_usage (KV-cache utilisation fractions),
#       y_context_length (context lengths), z_itl (inter-token latency in ms),
#       z_thpt_per_gpu (tokens/s per GPU), max_kv_tokens (scalar).
#       x_kv_usage, y_context_length, z_itl, and z_thpt_per_gpu must all be
#       flat 1-D arrays of the same length (one entry per measurement point).
# ──────────────────────────────────────────────────────────────────────────────
apiVersion: v1
kind: ConfigMap
metadata:
  name: planner-profile-data
data:
  prefill_raw_data.json: |
    {
      "prefill_isl":          [128, 256, 512, 1024, 2048],
      "prefill_ttft":         [12,  18,  30,  55,   105],
      "prefill_thpt_per_gpu": [9800, 8500, 6200, 3800, 2000]
    }
  decode_raw_data.json: |
    {
      "x_kv_usage":       [0.1, 0.1, 0.1, 0.1, 0.3, 0.3, 0.3, 0.3, 0.5, 0.5, 0.5, 0.5, 0.7, 0.7, 0.7, 0.7, 0.9, 0.9, 0.9, 0.9],
      "y_context_length": [128, 512, 1024, 2048, 128, 512, 1024, 2048, 128, 512, 1024, 2048, 128, 512, 1024, 2048, 128, 512, 1024, 2048],
      "z_itl":            [5, 6, 7, 9, 6, 7, 8, 10, 7, 8, 10, 12, 8, 10, 12, 15, 10, 12, 15, 20],
      "z_thpt_per_gpu":   [4500, 4000, 3500, 2800, 4200, 3700, 3200, 2500, 3800, 3300, 2800, 2200, 3400, 2900, 2400, 1800, 2800, 2400, 1900, 1400],
      "max_kv_tokens": 32768
    }
---
apiVersion: nvidia.com/v1alpha1
kind: DynamoGraphDeployment
metadata:
  name: trtllm-disagg-planner
spec:
  services:
    Frontend:
      componentType: frontend
      replicas: 1
      extraPodSpec:
        mainContainer:
          image: my-registry/tensorrtllm-runtime:my-tag
          workingDir: /workspace/examples/backends/trtllm
          command:
            - python3
          args:
            - -m
            - dynamo.frontend
            - --http-port
            - "8000"
            - --kv-cache-block-size
            - "128"
            - --router-mode
            - kv
            - --kv-overlap-score-weight
            - "0.0"
            - --router-temperature
            - "0.0"
            - --no-kv-events
    Planner:
      envFromSecret: hf-token-secret
      componentType: planner
      replicas: 1
      extraPodSpec:
        mainContainer:
          # Planner image selection:
          #   Dynamo >= 1.1.0: use the dedicated planner image
          #     <registry>/dynamo-planner:<version>
          #     (backend runtime images no longer ship planner runtime deps
          #     such as kubernetes_asyncio, pmdarima, prophet, aiconfigurator).
          #   Dynamo <  1.1.0: use the backend runtime image
          #     <registry>/tensorrtllm-runtime:<version>.
          image: my-registry/dynamo-planner:my-tag
          ports:
            - name: metrics
              containerPort: 9085
          command:
            - python3
          args:
            - -m
            - dynamo.planner
            - --config
            - '{"environment": "kubernetes", "backend": "trtllm", "throughput_adjustment_interval": 60, "profile_results_dir": "/workspace/profiling_results"}'
          volumeMounts:
            - name: planner-profile-data
              mountPath: /workspace/profiling_results
              readOnly: true
        volumes:
          - name: planner-profile-data
            configMap:
              name: planner-profile-data
    TRTLLMDecodeWorker:
      envFromSecret: hf-token-secret
      componentType: worker
      subComponentType: decode
      replicas: 1
      livenessProbe:
        httpGet:
          path: /live
          port: 9090
        periodSeconds: 5
        timeoutSeconds: 30
        failureThreshold: 1
      readinessProbe:
        httpGet:
          path: /health
          port: 9090
        periodSeconds: 10
        timeoutSeconds: 30
        failureThreshold: 60
      resources:
        limits:
          gpu: "1"
      extraPodSpec:
        terminationGracePeriodSeconds: 600
        mainContainer:
          image: my-registry/tensorrtllm-runtime:my-tag
          workingDir: /workspace/
          command:
            - python3
          args:
            - -m
            - dynamo.trtllm
            - --model-path
            - Qwen/Qwen3-0.6B
            - --served-model-name
            - Qwen/Qwen3-0.6B
            - --extra-engine-args
            - ./examples/backends/trtllm/engine_configs/qwen3/decode.yaml
            - --disaggregation-mode
            - decode
    TRTLLMPrefillWorker:
      envFromSecret: hf-token-secret
      componentType: worker
      subComponentType: prefill
      replicas: 1
      resources:
        limits:
          gpu: "1"
      extraPodSpec:
        terminationGracePeriodSeconds: 600
        mainContainer:
          image: my-registry/tensorrtllm-runtime:my-tag
          workingDir: /workspace/
          command:
            - python3
          args:
            - -m
            - dynamo.trtllm
            - --model-path
            - Qwen/Qwen3-0.6B
            - --served-model-name
            - Qwen/Qwen3-0.6B
            - --extra-engine-args
            - ./examples/backends/trtllm/engine_configs/qwen3/prefill.yaml
            - --disaggregation-mode
            - prefill
