#!/bin/bash
# Serve DeepSeek-V4-Flash GALE 1-bit, fully resident across all visible GPUs.
# resolve to this script's own directory so a fresh clone runs without editing anything
D="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
read -r -d '' ONESHOT <<'SHOT'
User: hello
Assistant: Hello! How can I help?
User: What is 6 * 7?
Assistant: 42
User: Write a Python function that adds two numbers.
Assistant: ```python
def add(a, b):
return a + b
```
SHOT
read -r -d '' ONESHOT_TOOLS <<'SHOT2'
User: hello
Assistant: Hello! How can I help?
User: show me the code for hello world in python
Assistant: ```python
print("hello world")
```
User: Create note.txt containing the word hi, then show me what is in it.
Assistant: <|DSML|tool_calls>
<|DSML|invoke name="write_file">
<|DSML|parameter name="path" string="true">note.txt|DSML|parameter>
<|DSML|parameter name="content" string="true">hi|DSML|parameter>
|DSML|invoke>
|DSML|tool_calls>
User: Created /root/note.txt (1 lines, 3 bytes).
Assistant: <|DSML|tool_calls>
<|DSML|invoke name="bash">
<|DSML|parameter name="command" string="true">cat note.txt|DSML|parameter>
|DSML|invoke>
|DSML|tool_calls>
User: hi
Assistant: note.txt contains "hi".
SHOT2
export PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True # full residency fragments the default allocator
export DSV4_ROOT=$D
export DSV4_REF_DIR=$D/server/reference
export DSV4_TOKENIZER=$D/server/tokenizer.json
export DSV4_MANIFEST=$D/packed_v4/manifest_mixed_full.jsonl
export DSV4_PACKED_DIR=$D/packed_v4
export DSV4_MISC_DIR=$D/misc_v3
export DSV4_ROUTING_COUNTS=$D/routing_counts.json
export DSV4_MODEL_NAME=deepseek-v4-flash-gale-1bit
export DSV4_KV_SNAPSHOT_DIR=$D/kv_snapshots
export DSV4_TIER_BIAS= # nothing is on a slow tier when fully resident
export DSV4_HARD_CAP=${DSV4_HARD_CAP:-256}
export CUDA_DEVICE_ORDER=PCI_BUS_ID
export DSV4_ONESHOT="$ONESHOT"
# with tools offered: show answering directly, calling a tool, AND consuming a tool_result
export DSV4_ONESHOT_TOOLS="$ONESHOT_TOOLS"
exec python3 -u "$D/server/agent_bridge/agent_server.py" \
--runtime "$D" --weights "$D"