Skip to content

Commit f95ee76

Browse files
author
Andrey Cheptsov
committed
Add endpoint preset creation and reuse
1 parent 74b87ed commit f95ee76

32 files changed

Lines changed: 4091 additions & 12 deletions

mkdocs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ nav:
297297
- Services: docs/concepts/services.md
298298
- Volumes: docs/concepts/volumes.md
299299
- More:
300+
- Endpoints: docs/concepts/endpoints.md
300301
- Gateways: docs/concepts/gateways.md
301302
- Secrets: docs/concepts/secrets.md
302303
- Projects: docs/concepts/projects.md
@@ -344,6 +345,7 @@ nav:
344345
- dev-environment: docs/reference/dstack.yml/dev-environment.md
345346
- task: docs/reference/dstack.yml/task.md
346347
- service: docs/reference/dstack.yml/service.md
348+
- endpoint: docs/reference/dstack.yml/endpoint.md
347349
- fleet: docs/reference/dstack.yml/fleet.md
348350
- gateway: docs/reference/dstack.yml/gateway.md
349351
- volume: docs/reference/dstack.yml/volume.md
@@ -366,6 +368,7 @@ nav:
366368
- dstack volume: docs/reference/cli/dstack/volume.md
367369
- dstack gateway: docs/reference/cli/dstack/gateway.md
368370
- dstack secret: docs/reference/cli/dstack/secret.md
371+
- dstack endpoint: docs/reference/cli/dstack/endpoint.md
369372
- dstack export: docs/reference/cli/dstack/export.md
370373
- dstack import: docs/reference/cli/dstack/import.md
371374
- HTTP API:

mkdocs/docs/concepts/endpoints.md

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
---
2+
title: Endpoints
3+
description: Creating and reusing optimized model inference recipes
4+
---
5+
6+
# Endpoints
7+
8+
An endpoint configuration is a new `dstack` feature that lets you use an agent to create presets: validated and optimized model inference endpoint recipes. Once a preset is created, it can be reused to deploy model inference on validated hardware without an agent.
9+
10+
The value of presets comes from combining two fundamental features: agent-driven model inference optimization and the `dstack` [service](services.md) primitive, which can deploy model inference to any cloud, Kubernetes, or on-prem cluster.
11+
12+
> The endpoints feature is experimental and may change.
13+
14+
??? info "Prerequisites"
15+
Before using endpoint presets, make sure you’ve [installed](../installation.md) the server and CLI, and created a [fleet](fleets.md).
16+
17+
Creating an endpoint preset requires the `claude` CLI to be installed on the machine where you create a preset.
18+
19+
## Define an endpoint
20+
21+
Before you can create or reuse an endpoint preset, you first have to define an endpoint configuration. The filename must end with `.dstack.yml`.
22+
23+
<div editor-title="endpoint.dstack.yml">
24+
25+
```yaml
26+
type: endpoint
27+
name: qwen25-7b
28+
29+
model:
30+
base: Qwen/Qwen2.5-7B-Instruct
31+
32+
env:
33+
- HF_TOKEN
34+
```
35+
36+
</div>
37+
38+
Since `base` is specified, the preset can use any compatible variant of the base model, including a different precision, quantization, or trusted fork.
39+
40+
If you want to deploy an exact model, set `model` directly to the repo of that model:
41+
42+
<div editor-title="endpoint.dstack.yml">
43+
44+
```yaml
45+
type: endpoint
46+
name: qwen25-7b
47+
48+
model: Qwen/Qwen2.5-7B-Instruct
49+
50+
env:
51+
- HF_TOKEN
52+
```
53+
54+
</div>
55+
56+
Set `context_length` to require a minimum context length. Placement properties,
57+
including `fleets`, `backends`, `max_price`, and `spot_policy`, constrain both
58+
creation and reuse. Environment variables such as `HF_TOKEN` can be passed
59+
through `env`.
60+
61+
See the [reference](../reference/dstack.yml/endpoint.md) for all supported configuration options.
62+
63+
## Create a preset
64+
65+
To create a preset, pass the configuration file to the `dstack endpoint preset create` command:
66+
67+
<div class="termy">
68+
69+
```shell
70+
$ dstack endpoint preset create -f endpoint.dstack.yml
71+
```
72+
73+
</div>
74+
75+
This command executes entirely locally and uses the locally installed `claude` CLI along with `dstack`'s bundled skills. The agent uses a `dstack` task to find the best serving recipe matching the available fleet offers. Once the recipe is found, it submits a `dstack` service for a final benchmark. The validated recipe is saved locally under `~/.dstack/presets`.
76+
77+
??? info "Claude authorization"
78+
Preset creation supports two Claude authorization methods. To use an Anthropic API key, set:
79+
80+
```shell
81+
export DSTACK_AGENT_ANTHROPIC_API_KEY=...
82+
```
83+
84+
If you are already logged in with `claude`, use the existing authorization instead:
85+
86+
```shell
87+
export DSTACK_AGENT_CLAUDE_USE_EXISTING_AUTH=1
88+
```
89+
90+
These options are mutually exclusive.
91+
92+
## List presets
93+
94+
Use `dstack endpoint preset` to list existing presets:
95+
96+
<div class="termy">
97+
98+
```shell
99+
$ dstack endpoint preset list
100+
MODEL GPU
101+
Qwen/Qwen2.5-7B-Instruct
102+
recipe=8f3a12c4 L4:24GB:1..
103+
```
104+
105+
</div>
106+
107+
Each base model corresponds to one preset. A preset may contain multiple recipes built for specific hardware. Each recipe includes benchmark data.
108+
109+
Pass `-v` to include the full service resources and verified context length.
110+
111+
## Apply a preset
112+
113+
To deploy a preset as a service, pass the endpoint configuration to the `dstack endpoint preset apply` command:
114+
115+
<div class="termy">
116+
117+
```shell
118+
$ dstack endpoint preset apply -f endpoint.dstack.yml
119+
```
120+
121+
</div>
122+
123+
If you don't pass `--recipe ID` (or specify it in the endpoint configuration), `dstack` automatically picks one of the recipes that matches the available fleet offers.
124+
125+
If a recipe matches, `dstack` deploys it as a service.
126+
127+
## Delete a preset
128+
129+
You can delete a specific recipe or the entire preset.
130+
131+
<div class="termy">
132+
133+
```shell
134+
dstack endpoint preset delete --recipe 8f3a12c4
135+
```
136+
137+
</div>
138+
139+
To delete the entire preset and all its recipes, pass the base model:
140+
141+
<div class="termy">
142+
143+
```shell
144+
dstack endpoint preset delete Qwen/Qwen2.5-7B-Instruct
145+
```
146+
147+
</div>
148+
149+
For command options and agent settings, see the
150+
[`dstack endpoint` CLI reference](../reference/cli/dstack/endpoint.md).
151+
152+
!!! info "What's next?"
153+
1. Learn how dstack [services](services.md) work
154+
2. Learn how to configure [fleets](fleets.md)
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# dstack endpoint
2+
3+
The `dstack endpoint` commands create, list, apply, and delete local endpoint
4+
[preset recipes](../../../concepts/endpoints.md).
5+
6+
## dstack endpoint preset list
7+
8+
The `dstack endpoint preset list` command lists locally stored recipes.
9+
10+
##### Usage
11+
12+
<div class="termy">
13+
14+
```shell
15+
$ dstack endpoint preset list --help
16+
#GENERATE#
17+
```
18+
19+
</div>
20+
21+
## dstack endpoint preset create
22+
23+
The `dstack endpoint preset create` command uses an agent to create and save a
24+
verified recipe from an endpoint configuration.
25+
26+
##### Usage
27+
28+
<div class="termy">
29+
30+
```shell
31+
$ dstack endpoint preset create --help
32+
#GENERATE#
33+
```
34+
35+
</div>
36+
37+
##### Agent settings
38+
39+
Set either `DSTACK_AGENT_ANTHROPIC_API_KEY` or
40+
`DSTACK_AGENT_CLAUDE_USE_EXISTING_AUTH` before creating a preset.
41+
42+
| Variable | Description |
43+
| --- | --- |
44+
| `DSTACK_AGENT_ANTHROPIC_API_KEY` | Anthropic API key used by the agent. |
45+
| `DSTACK_AGENT_CLAUDE_USE_EXISTING_AUTH` | Use the existing `claude` login. |
46+
| `DSTACK_AGENT_CLAUDE_PATH` | `claude` executable name or path. Defaults to `claude` from `PATH`. |
47+
| `DSTACK_AGENT_ANTHROPIC_MODEL` | Claude model used by the agent. |
48+
| `DSTACK_AGENT_CLAUDE_EFFORT` | Claude effort level: `low`, `medium`, `high`, `xhigh`, or `max`. |
49+
50+
## dstack endpoint preset apply
51+
52+
The `dstack endpoint preset apply` command selects a matching local recipe and
53+
submits its service.
54+
55+
##### Usage
56+
57+
<div class="termy">
58+
59+
```shell
60+
$ dstack endpoint preset apply --help
61+
#GENERATE#
62+
```
63+
64+
</div>
65+
66+
## dstack endpoint preset delete
67+
68+
The `dstack endpoint preset delete` command deletes one local recipe by ID or
69+
all recipes for a base model.
70+
71+
##### Usage
72+
73+
<div class="termy">
74+
75+
```shell
76+
$ dstack endpoint preset delete --help
77+
#GENERATE#
78+
```
79+
80+
</div>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# `endpoint`
2+
3+
The `endpoint` configuration type describes a model request and the constraints
4+
used to create or apply an [endpoint preset](../../concepts/endpoints.md).
5+
6+
## Root reference
7+
8+
#SCHEMA# dstack._internal.core.models.endpoints.EndpointConfiguration
9+
overrides:
10+
show_root_heading: false
11+
type:
12+
required: true
13+
14+
### `model`
15+
16+
=== "Base model"
17+
18+
Allows the creation agent to select a compatible model variant.
19+
20+
#SCHEMA# dstack._internal.core.models.endpoints.EndpointModelBase
21+
overrides:
22+
show_root_heading: false
23+
24+
=== "Exact model"
25+
26+
Requires an exact model repo or path and optionally sets another
27+
client-facing model name.
28+
29+
#SCHEMA# dstack._internal.core.models.endpoints.EndpointModelRepo
30+
overrides:
31+
show_root_heading: false
32+
33+
### `retry`
34+
35+
#SCHEMA# dstack._internal.core.models.profiles.ProfileRetry
36+
overrides:
37+
show_root_heading: false
38+
39+
### `utilization_policy`
40+
41+
#SCHEMA# dstack._internal.core.models.profiles.UtilizationPolicy
42+
overrides:
43+
show_root_heading: false
44+
type:
45+
required: true
46+
47+
### `schedule`
48+
49+
#SCHEMA# dstack._internal.core.models.profiles.Schedule
50+
overrides:
51+
show_root_heading: false
52+
type:
53+
required: true

pyproject.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,19 @@ artifacts = [
6262
"src/dstack/_internal/server/statics/**",
6363
]
6464

65+
[tool.hatch.build.targets.sdist.force-include]
66+
"skills/dstack/SKILL.md" = "skills/dstack/SKILL.md"
67+
"skills/dstack-prototyping/SKILL.md" = "skills/dstack-prototyping/SKILL.md"
68+
6569
[tool.hatch.build.targets.wheel]
6670
artifacts = [
6771
"src/dstack/_internal/server/statics/**",
6872
]
6973

74+
[tool.hatch.build.targets.wheel.force-include]
75+
"skills/dstack/SKILL.md" = "dstack/_internal/core/resources/endpoint_agent/skills/dstack/SKILL.md"
76+
"skills/dstack-prototyping/SKILL.md" = "dstack/_internal/core/resources/endpoint_agent/skills/dstack-prototyping/SKILL.md"
77+
7078
[tool.hatch.metadata.hooks.fancy-pypi-readme]
7179
content-type = "text/markdown"
7280

0 commit comments

Comments
 (0)