You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Browse filesBrowse the repository at this point in the historyBrowse files
authored
[Presets] Patching framework and --previous support (#4118)
* Record each preset trial and service attempt in its own directory
A trial was one appended line in a shared `trials.jsonl`, mirrored into the
session directory by byte offset. An agent rewriting the file moved every
offset, and the mirror then committed a torn fragment forever: one verified
preset still carries an unparseable trial record. Service attempts had the
same shape in `verifications.jsonl`.
Every record is now written exactly once and reading is listing a directory:
- `trials/<n>/` holds the trial's compiled `task.dstack.yml` and its
`trial.json`; the presence of `trial.json` is what marks the trial
completed, so in-flight and torn states are visible instead of corrupting.
- `service/<k>/` holds each verification attempt's submitted YAML and a
`verification.json` written when the attempt ends; an attempt directory
without a result is one still in progress.
- The byte-offset record mirrors are replaced by a stateless directory
mirror that re-lists the source and copies changed files whole, scrubbed,
and atomically. A torn read can never be committed; the next pass
converges. Trial and attempt directories sort numerically, pinned past 9.
The trial contract in the agent prompt is rewritten around the layout, with
every per-trial file referenced by its full path and the write order stated
where the files are defined.
The listing shows the trial being worked on rather than the completed count
while trialing, so `trialing (2/3)` cannot read as two finished;
`verifying (3/3)` keeps the completed count.
Validated end to end: a session on one RTX PRO 4500 produced three
contract-exact trial records, a recorded verification attempt, and a saved
preset that `dstack preset apply` deploys.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* Mirror preset record files byte-exactly
The directory mirror decoded each file to text and re-encoded it, which
rewrote newlines (CRLF became LF on Unix, LF would become CRLF on
Windows) and replaced non-UTF-8 bytes. Harmless for the CLI's own JSON
and YAML records, but the mirror now also carries patch files, where the
recorded copy must be exactly the bytes that ran. Copy bytes verbatim
and redact at the byte level.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* Support patching and failed-trial verification in preset creation
The preset agent may now patch the serving framework source code,
generate custom kernels, and patch drivers during trials. Patches are
recorded as unified diffs under `trials/<n>/patches`, referenced from the
trial's `task.dstack.yml` via `files`, and applied with `patch` from its
commands, so the recorded configuration reproduces the trial exactly.
The verified service records its patches the same way under
`service/<k>/patches`, and the saved preset re-roots `files` onto the
mirrored session copies, so `dstack preset apply` reproduces the patched
configuration after the agent workspace is deleted.
When no trial meets the constraints, the best failed trial that has a
benchmark is still verified and saved instead of failing the whole
creation: the hardware's best is worth keeping even when it falls short
of what was asked. To keep that honest, the final report now records the
verified trial, presets store the requested `min_context_length` and
`max_ttft` alongside the verified values, and `dstack preset apply`
warns, instead of refusing, when the preset's verified context is below
the requested one.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* Mark constraint-breaching presets and scale the trial spark from zero
A preset saved from a failed trial shows `*` next to its benchmark, the
same mark a running session uses when it has only failed trials to show,
computed from the requested constraints the preset now stores. In the
trial spark, bars scale from zero so their heights compare as the numbers
do, failed trials are red rather than gold, and gold marks the best
result only while no trial meets the constraints. While trialing, the
`(N/M)` progress counts the trial being worked on rather than the
completed ones.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* Add if/else/end conditionals to the preset agent prompt
The system prompt rendered conditional blocks with a non-nesting
`<!--?NAME:CONTENT-->` directive. Replace it with `<!--?if NAME-->` /
`<!--?else-->` / `<!--?end-->`: blocks nest, markers may be inline or alone
on a possibly indented line, and a branch body is dedented by the one
indentation shared by all its lines. Both branches are always parsed, so an
unknown variable cannot hide behind a flag combination, and unbalanced or
malformed directives fail loudly.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* Support --previous in preset creation
`dstack preset create --previous <ID>` (repeatable, or a `previous` list in
the configuration) gives the agent the records of earlier creation sessions:
their trials, configurations, patches, and reports are copied into the
workspace under `previous/`, and the prompt tells the agent to analyze them
and improve on them. With `baseline: true`, the first trial reproduces the
best comparable previous result before optimizing further.
The IDs are pinned in the session manifest, so a resumed session keeps the
same context. A still-running previous session is rejected; a chained
session whose parents were not included warns. `constraints.json` is now
written as a session record for every creation, not only under `--debug`,
so a preset's constraints survive after its workspace is deleted.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* Wrap the preset listing gracefully on narrow terminals
CONSTRAINTS and BENCHMARK now wrap together to keep their full content,
STATUS and SUBMITTED wrap at their spaces, and BASE and GPU truncate (capped
in the compact view) so a long model name cannot starve the data columns.
Previously only BENCHMARK folded while its neighbours clipped, so a narrow
terminal rendered one tall column beside single-line ones.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* Document preset patching and limitations
Note in the concepts intro that the agent optimizes across the serving
stack and may patch the framework's source, generate kernels, and patch
drivers. Replace the roadmap admonition with a limitations one that also
records the random-dataset and runtime-only-patch limits.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* Clean up preset comments and docstrings
Cut comments that restate the code or explain what it doesn't do, rewrite
jargon-heavy ones concretely, and add docstrings only where a method's
intent is genuinely non-obvious.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* Remove archive-on-delete from the preset store
`dstack preset delete` now removes the preset permanently after its
confirmation. Git covers committed presets, and a user who wants a copy
can move `~/.dstack/presets/<id>/` manually.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* Default preset baseline to true
Every session gets an anchor by default: the first trial serves the
framework's recommended configuration, or reproduces the previous best
when the session builds on `--previous`. Set `baseline: false` to spend
every trial on optimization.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* Save preset patch files with relative paths
A preset directory is now portable: `preset.yaml` references its patch
files relative to its own location, resolved at load, so the directory
works after being copied to another path or machine. Re-saving a loaded
preset (e.g. on name reuse) keeps the paths relative. Presets saved with
absolute paths continue to load as before.
Verified end to end by applying a patched preset from a relocated copy:
all patches uploaded and applied, and the service answered.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Andrey Cheptsov <andrey.cheptsov@github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: mkdocs/docs/concepts/presets.md
+25-8Lines changed: 25 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,8 @@ A preset configuration lets you use an agent to create a preset: a verified and
9
9
10
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
11
12
+
To get the best performance for the given model, hardware, and other constraints, the agent selects the serving framework, quantization, and serving parameters, and can patch the framework's source code, generate custom kernels, and patch drivers.
13
+
12
14
> The presets feature is experimental and may change.
13
15
14
16
??? info "Prerequisites"
@@ -167,7 +169,24 @@ prompt: |
167
169
168
170
### Baseline
169
171
170
-
Set `baseline: true` to make the first trial a baseline: the agent serves the model the way the chosen serving framework recommends, without tuning it for performance. Later trials are optimization attempts.
172
+
By default, the first trial is a baseline: the agent serves the model the way the chosen serving framework recommends, without tuning it for performance. Later trials are optimization attempts. Set `baseline: false` to make every trial an optimization attempt.
173
+
174
+
### Previous sessions
175
+
176
+
Set `previous` to a list of preset IDs to give the agent the results of earlier creation sessions. It analyzes what they tried and how it worked, and aims to improve on them instead of rediscovering it.
177
+
178
+
<div editor-title="preset.dstack.yml">
179
+
180
+
```yaml
181
+
previous:
182
+
- c83375b4
183
+
```
184
+
185
+
</div>
186
+
187
+
Alternatively, pass `--previous` (repeatable) to `dstack preset create`.
188
+
189
+
In this case, the baseline trial reproduces the best comparable previous result to confirm it still holds before optimizing further.
171
190
172
191
!!! info "Reference"
173
192
The `preset` configuration supports many more options. See the [`.dstack.yml` reference](../reference/dstack.yml/preset.md).
For command options and agent settings, see the [`dstack preset` CLI reference](../reference/cli/dstack/preset.md).
253
272
254
-
!!! info "Roadmap and feedback"
255
-
Here's what is coming soon:
256
-
257
-
* Allow the agent to change the source code, compile binaries, etc.
258
-
* Support for PD disaggregation
259
-
* Allow passing multiple `--previous <preset ID>` to `dstack preset create` to reuse the insights from previous sessions
260
-
* Allow passing ranges to `concurrency`
273
+
!!! info "Limitations"
274
+
* Currently, the agent doesn't upload compiled binaries anywhere; patches compile at runtime
275
+
* Doesn't support PD disaggregation (coming soon)
276
+
* Doesn't allow a custom dataset; always uses `random`
277
+
* Doesn't support ranges for `concurrency`
261
278
262
279
Report bugs and request features on [GitHub](https://github.com/dstackai/dstack/issues), and ask questions on [Discord](https://discord.gg/u8SmfwPpMd).
0 commit comments