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

apiVersion: batch/v1
kind: Job
metadata:
  name: dynamo-benchmark
spec:
  template:
    spec:
      imagePullSecrets:
      - name: docker-imagepullsecret
      securityContext:
        runAsNonRoot: true
        runAsUser: 1000
        fsGroup: 1000
      containers:
      - name: benchmark-runner
        # TODO: update to latest public image in next release
        image: nvcr.io/nvidia/ai-dynamo/vllm-runtime:my-tag
        securityContext:
          allowPrivilegeEscalation: false
          capabilities:
            drop:
            - ALL
          runAsNonRoot: true
        resources:
          requests:
            cpu: "4"
            memory: "8Gi"
          limits:
            cpu: "8"
            memory: "16Gi"
        env:
          - name: HUGGING_FACE_HUB_TOKEN
            valueFrom:
              secretKeyRef:
                name: hf-token-secret
                key: HF_TOKEN
        command: ["/bin/bash", "-c"]
        args:
          - |
            set -euo pipefail
            MODEL="Qwen/Qwen3-0.6B"
            URL="http://vllm-agg-frontend:8000"
            OUTPUT_DIR="/data/results/qwen3-0p6b-vllm-agg"

            for c in 1 2 5 10 50 100; do
                echo "=== Concurrency $c ==="
                aiperf profile \
                    --model "$MODEL" \
                    --url "$URL" \
                    --endpoint-type chat \
                    --streaming \
                    --concurrency $c \
                    --request-count $(( c * 3 > 10 ? c * 3 : 10 )) \
                    --synthetic-input-tokens-mean 2000 \
                    --output-tokens-mean 256 \
                    --artifact-dir "$OUTPUT_DIR/c$c" \
                    --ui none
            done
            echo "=== Benchmark complete ==="
        volumeMounts:
          - name: data-volume
            mountPath: /data
      restartPolicy: Never
      volumes:
        - name: data-volume
          persistentVolumeClaim:
            claimName: dynamo-pvc
  backoffLimit: 0
  ttlSecondsAfterFinished: 3600  # Clean up job after 1 hour
