9999
100100</div>
101101
102- # ## Inactivity duration
103-
104- Set [`inactivity_duration`](../reference/dstack.yml/dev-environment.md#inactivity_duration)
105- to automatically stop the dev environment after a configured period of inactivity.
106-
107- <div editor-title=".dstack.yml">
108-
109- ` ` ` yaml
110- type: dev-environment
111- name: vscode
112- ide: vscode
113-
114- # Stop if inactive for 2 hours
115- inactivity_duration: 2h
116- ` ` `
117-
118- </div>
119-
120- The dev environment becomes inactive when you close the remote VS Code window,
121- close any `ssh <run name>` shells, and stop the `dstack apply` or `dstack attach` command.
122- If you go offline without stopping anything manually, the dev environment will also become inactive
123- within about 3 minutes.
124-
125- If `inactivity_duration` is configured for your dev environment, you can see how long
126- it has been inactive in `dstack ps --verbose`.
127-
128- <div class="termy">
129-
130- ` ` ` shell
131- $ dstack ps --verbose
132- NAME BACKEND RESOURCES PRICE STATUS SUBMITTED
133- vscode cudo 2xCPU, 8GB, $0.0286 running 8 mins ago
134- 100.0GB (disk) (inactive for 2m 34s)
135- ` ` `
136-
137- </div>
138-
139- If you reattach to the dev environment using [`dstack attach`](../reference/cli/dstack/attach.md),
140- the inactivity timer will be reset within a few seconds.
141-
142- ??? info "In-place update"
143- As long as the configuration defines the `name` property, the value of `inactivity_duration`
144- can be changed for a running dev environment without a restart.
145- Just change the value in the configuration and run `dstack apply` again.
146-
147- <div class="termy">
148-
149- ` ` ` shell
150- $ dstack apply -f .dstack.yml
151-
152- Detected configuration changes that can be updated in-place: ['inactivity_duration']
153- Update the run? [y/n]:
154- ` ` `
155-
156- </div>
157-
158- > `inactivity_duration` is not to be confused with [`idle_duration`](#idle-duration).
159- > The latter determines how soon the underlying cloud instance will be terminated
160- > _after_ the dev environment is stopped.
161-
162102# ## Resources
163103
164104When you specify a resource value like `cpu` or `memory`,
@@ -307,19 +247,6 @@ If you don't assign a value to an environment variable (see `HF_TOKEN` above),
307247 | `DSTACK_REPO_ID` | The ID of the repo |
308248 | `DSTACK_GPUS_NUM` | The total number of GPUs in the run |
309249
310- # ## Spot policy
311-
312- By default, `dstack` uses on-demand instances. However, you can change that
313- via the [`spot_policy`](../reference/dstack.yml/dev-environment.md#spot_policy) property. It accepts `spot`, `on-demand`, and `auto`.
314-
315- !!! info "Reference"
316- Dev environments support many more configuration options,
317- incl. [`backends`](../reference/dstack.yml/dev-environment.md#backends),
318- [`regions`](../reference/dstack.yml/dev-environment.md#regions),
319- [`max_price`](../reference/dstack.yml/dev-environment.md#max_price), and
320- [`max_duration`](../reference/dstack.yml/dev-environment.md#max_duration),
321- among [others](../reference/dstack.yml/dev-environment.md).
322-
323250# ## Retry policy
324251
325252By default, if `dstack` can't find capacity or the instance is interrupted, the run will fail.
@@ -345,8 +272,108 @@ retry:
345272
346273</div>
347274
275+ # ## Inactivity duration
276+
277+ Set [`inactivity_duration`](../reference/dstack.yml/dev-environment.md#inactivity_duration)
278+ to automatically stop the dev environment after a configured period of inactivity.
279+
280+ <div editor-title=".dstack.yml">
281+
282+ ` ` ` yaml
283+ type: dev-environment
284+ name: vscode
285+ ide: vscode
286+
287+ # Stop if inactive for 2 hours
288+ inactivity_duration: 2h
289+ ` ` `
290+
291+ </div>
292+
293+ The dev environment becomes inactive when you close the remote VS Code window,
294+ close any `ssh <run name>` shells, and stop the `dstack apply` or `dstack attach` command.
295+ If you go offline without stopping anything manually, the dev environment will also become inactive
296+ within about 3 minutes.
297+
298+ If `inactivity_duration` is configured for your dev environment, you can see how long
299+ it has been inactive in `dstack ps --verbose`.
300+
301+ <div class="termy">
302+
303+ ` ` ` shell
304+ $ dstack ps --verbose
305+ NAME BACKEND RESOURCES PRICE STATUS SUBMITTED
306+ vscode cudo 2xCPU, 8GB, $0.0286 running 8 mins ago
307+ 100.0GB (disk) (inactive for 2m 34s)
308+ ` ` `
309+
310+ </div>
311+
312+ If you reattach to the dev environment using [`dstack attach`](../reference/cli/dstack/attach.md),
313+ the inactivity timer will be reset within a few seconds.
314+
315+ ??? info "In-place update"
316+ As long as the configuration defines the `name` property, the value of `inactivity_duration`
317+ can be changed for a running dev environment without a restart.
318+ Just change the value in the configuration and run `dstack apply` again.
319+
320+ <div class="termy">
321+
322+ ` ` ` shell
323+ $ dstack apply -f .dstack.yml
324+
325+ Detected configuration changes that can be updated in-place: ['inactivity_duration']
326+ Update the run? [y/n]:
327+ ` ` `
328+
329+ </div>
330+
331+ > `inactivity_duration` is not to be confused with [`idle_duration`](#idle-duration).
332+ > The latter determines how soon the underlying cloud instance will be terminated
333+ > _after_ the dev environment is stopped.
334+
335+ # ## Utilization policy
336+
337+ Sometimes it’s useful to track whether a dev environment is fully utilizing all GPUs. While you can check this with
338+ [`dstack metrics`](../reference/cli/dstack/metrics.md), `dstack` also lets you set a policy to auto-terminate the run if any GPU is underutilized.
339+
340+ Below is an example of a dev environment that auto-terminate if any GPU stays below 10% utilization for 1 hour.
341+
342+ <div editor-title=".dstack.yml">
343+
344+ ` ` ` yaml
345+ type: dev-environment
346+ name: my-dev
347+
348+ python: 3.12
349+ ide: cursor
350+
351+ resources:
352+ gpu: H100:8
353+
354+ utilization_policy:
355+ min_gpu_utilization: 10
356+ time_window: 1h
357+ ` ` `
358+
359+ </div>
360+
361+ # ## Spot policy
362+
363+ By default, `dstack` uses on-demand instances. However, you can change that
364+ via the [`spot_policy`](../reference/dstack.yml/dev-environment.md#spot_policy) property. It accepts `spot`, `on-demand`, and `auto`.
365+
348366--8<-- "docs/concepts/snippets/manage-fleets.ext"
349367
368+ !!! info "Reference"
369+ Dev environments support many more configuration options,
370+ incl. [`backends`](../reference/dstack.yml/dev-environment.md#backends),
371+ [`regions`](../reference/dstack.yml/dev-environment.md#regions),
372+ [`max_price`](../reference/dstack.yml/dev-environment.md#max_price), and
373+ [`max_duration`](../reference/dstack.yml/dev-environment.md#max_duration),
374+ among [others](../reference/dstack.yml/dev-environment.md).
375+
376+
350377--8<-- "docs/concepts/snippets/manage-runs.ext"
351378
352379!!! info "What's next?"
0 commit comments