Problems when launching from other programs like `llama-swap`
The GGUF and Metal files are loaded relative to the current working directory, not relative to the ds4-server binary. So llama-swap and other external programs can't just easily execute the binary directly:
username@MacStudio ~ % /Users/username/git/ds4/ds4-server --port 5555 --ctx 262144 --kv-disk-dir /tmp/ds4-kv --kv-disk-space-mb 32768
ds4: cannot open model 'ds4flash.gguf': No such file or directory
Alright, let's give it the full path to the model:
username@MacStudio ~ % /Users/username/git/ds4/ds4-server -m /Users/username/git/ds4/gguf/DeepSeek-V4-Flash-Q4KExperts-F16HC-F16Compressor-F16Indexer-Q8Attn-Q8Shared-Q8Out-chat-v2.gguf --port 5555 --ctx 262144 --kv-disk-dir /tmp/ds4-kv --kv-disk-space-mb 32768
ds4: Metal source metal/flash_attn.metal not found (set DS4_METAL_FLASH_ATTN_SOURCE to override)
ds4: Metal backend unavailable; aborting startup
A simple workaround is to create a shell script and launch that instead:
#!/bin/sh
set -e
cd /Users/username/git/ds4
exec ./ds4-server --port 5555 --ctx 262144 --kv-disk-dir /tmp/ds4-kv --kv-disk-space-mb 32768
llama-swap also attempts to perform a health check (requesting /health by default). If that endpoint doesn't respond, requests are queued indefinitely waiting for a successful health check that will never arrive. So this could be a good candidate for a future endpoint if other software checks /health too.
But this is also easy to work around by simply giving it one of the other endpoints instead. Here's a working config for llama-swap:
models:
"deepseek-v4-flash":
cmd: /Users/username/git/ds4/start-ds4.sh
proxy: http://127.0.0.1:5555
checkEndpoint: /v1/models
This project is amazing. Thank you to all contributors.
Maybe we should inline the metal files at build time as string literals? So that the binary does not require anything external.
Maybe we should inline the metal files at build time as string literals? So that the binary does not require anything external.
I am working on this and a shared library, as I'm making Golang wrappers a la yzma and this does hamper deployment.
Are you opposed to using C23 and its #embed directive? gcc 15+ and modern clang support it.
Fixing with a very simple --chdir option in the end.
After using --chdir, the command runs without any problem when I execute it directly in the terminal. However, when the same command is invoked from another process (e.g., llama‑swap), it still fails. This is the command I use:
/Users/xxx/code/ds4/ds4-server --chdir /Users/xxx/code/ds4 -m /Users/xxx/code/ds4/gguf/DeepSeek-V4-Flash-IQ2XXS-w2Q2K-AProjQ8-SExpQ8-OutQ8-chat-v2-imatrix.gguf --ctx 1048576 --kv-disk-dir /tmp/ds4-kv --kv-disk-space-mb 8192 --host 0.0.0.0 --port 9001
The error output is: ds4: Metal device Apple M4 Max, 128.00 GiB RAM ds4: Metal source metal/flash_attn.metal not found (set DS4_METAL_FLASH_ATTN_SOURCE to override) ds4: metal backend unavailable; aborting startup
I have a fork exploring shared-libraries. This is what using #embed looks like, I had not used it in C before. I absolutely love it in Golang.
https://github.com/antirez/ds4/commit/77964084ae1d784ea54851eec49ea8f8bf032df5
After using --chdir, the command runs without any problem when I execute it directly in the terminal. However, when the same command is invoked from another process (e.g., llama‑swap), it still fails. This is the command I use:
/Users/xxx/code/ds4/ds4-server --chdir /Users/xxx/code/ds4 -m /Users/xxx/code/ds4/gguf/DeepSeek-V4-Flash-IQ2XXS-w2Q2K-AProjQ8-SExpQ8-OutQ8-chat-v2-imatrix.gguf --ctx 1048576 --kv-disk-dir /tmp/ds4-kv --kv-disk-space-mb 8192 --host 0.0.0.0 --port 9001
The error output is: ds4: Metal device Apple M4 Max, 128.00 GiB RAM ds4: Metal source metal/flash_attn.metal not found (set DS4_METAL_FLASH_ATTN_SOURCE to override) ds4: metal backend unavailable; aborting startup
Are you sure the caller is not using chroot / container of some kind? If this persists the solution will be to inline the Metal kernels, even if the build process is less ideal, but the difference is small, we probably can just use the clang support and new C features that make inlining much simpler. I'm reopening the issue.
Apologies, I've double-checked my configuration and retried it. It's now working properly—this might have been due to the configuration file not taking effect. Please close this Issue.
Still not seeing any stats reported to llama-swap. My setup:
"dsv4-flash-0731":
cmd: |
/Users/xxx/codebases/ds4/ds4-server -m /Users/xxx/models-gpt/DeepSeek-V4-Flash-Q4KExperts-F16HC-F16Compressor-F16Indexer-Q8Attn-Q8Shared-Q8Out-chat-v2-imatrix-0731.gguf
--chdir /Users/xxx/codebases/ds4
--ctx 256000
--kv-disk-dir /tmp/ds4-kv
--kv-disk-space-mb 16192
--mtp-model /Users/xxx/models-gpt/DeepSeek-V4-Flash-DSpark-support-0731.gguf
--dspark
--port ${PORT}
proxy: http://127.0.0.1:${PORT}
checkEndpoint: /v1/models
on commit 0aaea5a238fb41a35106a551e73c8409dfb751ac released today
Not sure if I am doing something wrong?