[Unit]
Description={{ service.name }}
After=network.target
StartLimitBurst=5
StartLimitIntervalSec=60

[Service]
Type=simple
Environment="CUDA_VISIBLE_DEVICES={{ settings.cuda_devices | default('0') }}"
Environment="HF_HOME={{ settings.hf_home | default('%h/.cache/huggingface') }}"
{% for key, value in extra_env.items() %}
Environment="{{ key }}={{ value }}"
{% endfor %}

ExecStart={{ settings.vllm_bin | default('vllm') }} serve \
    {{ service.model_id }} \
    --port {{ service.port }} \
    --host 0.0.0.0 \
    --gpu-memory-utilization {{ unit_vars.gpu_mem_util | default(0.9) }} \
    --max-model-len {{ unit_vars.max_model_len | default(4096) }}{% if unit_vars.max_num_seqs is defined %} \
    --max-num-seqs {{ unit_vars.max_num_seqs }}{% endif %}{% if unit_vars.dtype is defined %} \
    --dtype {{ unit_vars.dtype }}{% endif %}{% if unit_vars.enforce_eager | default(false) %} \
    --enforce-eager{% endif %}{% if unit_vars.runner is defined %} \
    --task {{ 'embed' if unit_vars.runner == 'pooling' else unit_vars.runner }}{% endif %}{% if unit_vars.hf_overrides is defined %} \
    --hf-overrides '{{ unit_vars.hf_overrides }}'{% endif %}{% if unit_vars.enable_sleep_mode | default(false) %} \
    --enable-sleep-mode{% endif %}{% if unit_vars.sleep_level is defined %} \
    --sleep-level {{ unit_vars.sleep_level }}{% endif %}{% if unit_vars.trust_remote_code | default(false) %} \
    --trust-remote-code{% endif %}{% if unit_vars.extra_args is defined %} \
    {{ unit_vars.extra_args }}{% endif %}

Restart=on-failure
RestartSec=30
KillMode=control-group
TimeoutStopSec=30

[Install]
WantedBy=default.target
