version: 1
kind: platform-infra-selfmedia-voice

metadata:
  id: selfmedia-voice
  owner: unidesk
  relatedIssues:
    - 2139
    - 2216
  mdtodo: R9.5.2

rollout:
  prerequisite: R9.1.1 CosyVoice3 GPU HTTP/WAV smoke
  approved: true

artifacts:
  root: deploy/selfmedia-voice
  containerfile: deploy/selfmedia-voice/Containerfile
  api: deploy/selfmedia-voice/api.py
  modelInit: deploy/selfmedia-voice/model-init.sh
  sourceInit: deploy/selfmedia-voice/source-init.sh
  d518Compose: deploy/selfmedia-voice/compose.d518.yaml
  nc01Compose: deploy/selfmedia-voice/compose.nc01.yaml
  frpcTemplate: deploy/selfmedia-voice/frpc.toml.tmpl
  frpsTemplate: deploy/selfmedia-voice/frps.toml.tmpl

image:
  name: unidesk-selfmedia-voice:cosyvoice3-0.5b-2512
  base:
    repository: docker.m.daocloud.io/pytorch/pytorch
    tag: 2.3.1-cuda12.1-cudnn8-runtime
    digest: sha256:fc47f8018254e6df30f48c48f2db1c758d44de21a8c553de1a1c451a65baa70a
    imageId: sha256:2d1dee23cc95bf01aad2a292c10f051b01ddc6e7fa7535620cc8a7457720794c
  source:
    repository: https://github.com/FunAudioLLM/CosyVoice.git
    ref: 074ca6dc9e80a2f424f1f74b48bdd7d3fea531cc
    submodules: recursive
    cache:
      retryAttempts: 3
      retryDelaySeconds: 5
  modelSource:
    provider: modelscope-git-lfs
    id: FunAudioLLM/Fun-CosyVoice3-0.5B-2512
    repository: https://www.modelscope.cn/FunAudioLLM/Fun-CosyVoice3-0.5B-2512.git
    branch: master
    ref: 9f9c56f2514700ef79d64fd0afb693e0d672373b
    requireBranchHeadMatch: true
  referenceVoice:
    id: official-zero-shot-prompt
    path: asset/zero_shot_prompt.wav
    sha256: c7b31d6dbe7cc6a716dded00550db5b50940bf209e424e4ad207b12e657c8ff6
    promptText: You are a helpful assistant.<|endofprompt|>希望你以后能够做的比我还好呦。

dependencies:
  pip:
    version: "24.0"
    indexUrl: https://mirrors.ustc.edu.cn/pypi/simple
  setuptools:
    installSpec: setuptools<81
  torch:
    versionIdentity: 2.3.1
    libraryPath: /opt/conda/lib/python3.10/site-packages/torch/lib
  torchaudio:
    package: torchaudio
    installSpec: torchaudio==2.3.1
    versionIdentity: 2.3.1
    abiPolicy: torch-major-minor-match
  openaiWhisper:
    installSpec: openai-whisper==20231117
    noBuildIsolation: true
  onnxRuntimeGpu:
    installSpec: onnxruntime-gpu==1.18.0
    indexUrl: https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/onnxruntime-cuda-12/pypi/simple/
    independentLayer: true

frp:
  images:
    frps: fatedier/frps:v0.68.1
    frpc: fatedier/frpc:v0.68.1
  secret:
    sourceRef: /root/.unidesk/.env/selfmedia-voice-frp.env
    sourceKey: FRP_TOKEN
  server:
    targetId: NC01
    address: 152.53.229.148
    controlPort: 22110
    workDir: /root/.unidesk/platform-infra/selfmedia-voice/frps
    composeProject: unidesk-selfmedia-voice-frps
  tunnel:
    targetId: D518
    proxyName: selfmedia-voice-d518
    remotePort: 24317
    localAddress: 127.0.0.1
    localPort: 18327

bridge:
  targetId: NC01
  mode: systemd-socket-proxyd
  listenAddress: 10.42.0.1
  listenPort: 24318
  upstreamAddress: 127.0.0.1
  upstreamPort: 24317
  baseUrl: http://10.42.0.1:24318
  socketProxydPath: /usr/lib/systemd/systemd-socket-proxyd
  socketUnitName: unidesk-selfmedia-voice-bridge.socket
  socketUnitPath: /etc/systemd/system/unidesk-selfmedia-voice-bridge.socket
  serviceUnitName: unidesk-selfmedia-voice-bridge.service
  serviceUnitPath: /etc/systemd/system/unidesk-selfmedia-voice-bridge.service
  probePath: /v1/models
  timeoutSeconds: 10

targets:
  - id: D518
    role: gpu-service
    route: D518
    workDir: /root/.unidesk/platform-infra/selfmedia-voice/runtime
    composeProject: unidesk-selfmedia-voice
    cacheDir: /root/.cache/unidesk/selfmedia-voice
    sourceDir: /root/.cache/unidesk/selfmedia-voice/source
    dataDir: /root/.unidesk/.state/selfmedia-voice
  - id: NC01
    role: frps
    route: NC01
    workDir: /root/.unidesk/platform-infra/selfmedia-voice/frps
    composeProject: unidesk-selfmedia-voice-frps

runtime:
  serviceName: voice
  frpcServiceName: frpc
  frpsServiceName: frps
  bindAddress: 127.0.0.1
  port: 18327
  publicBaseUrl: http://152.53.229.148:24317
  inference:
    device: cuda:0
    fp16: true
    loadTrt: false
    loadVllm: false
    replicas: 1
    workers: 1
    concurrency: serial
    referenceVoice: official-zero-shot-prompt
    speed:
      min: 0.5
      max: 2.0
    cudaAllocator: expandable_segments:True,max_split_size_mb:128
    cudaModuleLoading: LAZY
    speechTokenizerProvider: CPUExecutionProvider
  operations:
    applyTimeoutSeconds: 3600
  smoke:
    healthPath: /health
    speechPath: /v1/audio/speech
    text: 你好，这是 SelfMedia 语音平台的固定验收请求。
    voice: official-zero-shot-prompt
    timeoutSeconds: 600
