DEV Community

GyeongSeon
GyeongSeon

Posted on

config init container for Nsigth Command

apiVersion: apps/v1
kind: Deployment
metadata:
  name: vllm-nsys-inject
spec:
  replicas: 1
  selector:
    matchLabels:
      app: vllm-nsys
  template:
    metadata:
      labels:
        app: vllm-nsys
    spec:
      hostPID: true
      volumes:
        - name: nsys-bin
          emptyDir: {}
        - name: profile-output
          emptyDir: {}
        - name: dshm
          emptyDir:
            medium: Memory
            sizeLimit: 16Gi
      # 1. nsys가 포함된 공식 이미지에서 바이너리만 볼륨으로 복사
      initContainers:
        - name: copy-nsys
          # Nsight Systems가 내장된 NVIDIA 공식 devel 이미지 사용
          image: nvidia/cuda:12.4.1-devel-ubuntu22.04
          command: ["/bin/sh", "-c"]
          args:
            - |
              cp -r /opt/nvidia/nsight-systems/* /nsys-target/
          volumeMounts:
            - name: nsys-bin
              mountPath: /nsys-target
      # 2. 원본 vLLM 이미지는 수정 없이 그대로 실행
      containers:
        - name: vllm
          image: vllm/vllm-openai:latest
          securityContext:
            capabilities:
              add: ["SYS_ADMIN", "SYS_PTRACE"]
          env:
            - name: VLLM_WORKER_MULTIPROC_METHOD
              value: "spawn"
          command: ["/bin/sh", "-c"]
          args:
            - |
              # 복사된 경로에서 nsys 실행 파일 찾아서 실행
              NSYS_PATH=$(find /nsys -name nsys -type f | head -n 1)
              $NSYS_PATH profile \
                --trace=cuda,nvtx,osrt \
                --trace-fork-before-exec=true \
                --cuda-graph-trace=node \
                --capture-range=cudaProfilerApi \
                --capture-range-end=repeat \
                -o /profiles/vllm_trace_%p \
                vllm serve meta-llama/Llama-3.1-8B-Instruct \
                  --profiler-config '{"profiler": "cuda"}'
          resources:
            limits:
              nvidia.com/gpu: 1
          volumeMounts:
            - name: nsys-bin
              mountPath: /nsys
            - name: profile-output
              mountPath: /profiles
            - name: dshm
              mountPath: /dev/shm
Enter fullscreen mode Exit fullscreen mode

Top comments (0)