gpushift 0.1.0__tar.gz → 0.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. {gpushift-0.1.0 → gpushift-0.1.2}/.gitignore +1 -0
  2. {gpushift-0.1.0 → gpushift-0.1.2}/CHANGELOG.md +13 -0
  3. gpushift-0.1.2/PKG-INFO +204 -0
  4. gpushift-0.1.2/README.md +173 -0
  5. {gpushift-0.1.0 → gpushift-0.1.2}/pyproject.toml +1 -1
  6. {gpushift-0.1.0 → gpushift-0.1.2}/src/gpushift/__init__.py +1 -1
  7. {gpushift-0.1.0 → gpushift-0.1.2}/src/gpushift/_proc.py +45 -1
  8. {gpushift-0.1.0 → gpushift-0.1.2}/src/gpushift/cli.py +52 -7
  9. {gpushift-0.1.0 → gpushift-0.1.2}/src/gpushift/config.py +0 -53
  10. {gpushift-0.1.0 → gpushift-0.1.2}/src/gpushift/control.py +4 -12
  11. {gpushift-0.1.0 → gpushift-0.1.2}/src/gpushift/daemon.py +34 -90
  12. {gpushift-0.1.0 → gpushift-0.1.2}/src/gpushift/gpumem.py +1 -2
  13. {gpushift-0.1.0 → gpushift-0.1.2}/src/gpushift/ui.html +9 -9
  14. {gpushift-0.1.0 → gpushift-0.1.2}/src/gpushift/ui.py +15 -7
  15. {gpushift-0.1.0 → gpushift-0.1.2}/tests/test_integration.py +16 -53
  16. gpushift-0.1.0/PKG-INFO +0 -354
  17. gpushift-0.1.0/README.md +0 -323
  18. {gpushift-0.1.0 → gpushift-0.1.2}/LICENSE +0 -0
  19. {gpushift-0.1.0 → gpushift-0.1.2}/examples/hf_trainer_resumable.py +0 -0
  20. {gpushift-0.1.0 → gpushift-0.1.2}/examples/lightning_resumable.py +0 -0
  21. {gpushift-0.1.0 → gpushift-0.1.2}/examples/pytorch_resumable.py +0 -0
  22. {gpushift-0.1.0 → gpushift-0.1.2}/src/gpushift/__main__.py +0 -0
  23. {gpushift-0.1.0 → gpushift-0.1.2}/src/gpushift/_entry.py +0 -0
  24. {gpushift-0.1.0 → gpushift-0.1.2}/src/gpushift/autostart.py +0 -0
  25. {gpushift-0.1.0 → gpushift-0.1.2}/src/gpushift/checkpoint.py +0 -0
  26. {gpushift-0.1.0 → gpushift-0.1.2}/src/gpushift/cpustat.py +0 -0
  27. {gpushift-0.1.0 → gpushift-0.1.2}/src/gpushift/db.py +0 -0
  28. {gpushift-0.1.0 → gpushift-0.1.2}/src/gpushift/gpus.py +0 -0
  29. {gpushift-0.1.0 → gpushift-0.1.2}/src/gpushift/hook.py +0 -0
  30. {gpushift-0.1.0 → gpushift-0.1.2}/src/gpushift/notify.py +0 -0
  31. {gpushift-0.1.0 → gpushift-0.1.2}/src/gpushift/paths.py +0 -0
  32. {gpushift-0.1.0 → gpushift-0.1.2}/src/gpushift/runner.py +0 -0
  33. {gpushift-0.1.0 → gpushift-0.1.2}/src/gpushift/scheduler.py +0 -0
  34. {gpushift-0.1.0 → gpushift-0.1.2}/tests/conftest.py +0 -0
  35. {gpushift-0.1.0 → gpushift-0.1.2}/tests/jobs/counter.py +0 -0
  36. {gpushift-0.1.0 → gpushift-0.1.2}/tests/test_hook.py +0 -0
  37. {gpushift-0.1.0 → gpushift-0.1.2}/tests/test_scheduler.py +0 -0
  38. {gpushift-0.1.0 → gpushift-0.1.2}/tests/test_units.py +0 -0
@@ -4,4 +4,5 @@ __pycache__/
4
4
  dist/
5
5
  build/
6
6
  .pytest_cache/
7
+ .ruff_cache/
7
8
  checkpoints/
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.2 (2026-11-12)
4
+
5
+ - Removed automatic free mode (freeing the GPUs while you run a game or other
6
+ heavy GPU program). Free and resume by hand with `gpushift free` / `resume`.
7
+ - The daemon uses about a quarter of the CPU it did on Windows.
8
+
9
+ ## 0.1.1 (2026-11-12)
10
+
11
+ - Agents are now woken when their jobs end, even if they were idle: `gpushift wait`
12
+ without a job id waits for the next of the session's own jobs, and the skill tells
13
+ agents to run it in the background after submitting.
14
+ - The dashboard is shown in the README, which is now much shorter.
15
+
3
16
  ## 0.1.0 (2026-11-12)
4
17
 
5
18
  First release.
@@ -0,0 +1,204 @@
1
+ Metadata-Version: 2.5
2
+ Name: gpushift
3
+ Version: 0.1.2
4
+ Summary: Share one GPU machine between AI coding agents and yourself: a GPU job queue that steps aside when you need the GPUs.
5
+ Project-URL: Homepage, https://github.com/EdwardGlockner/gpushift
6
+ Project-URL: Issues, https://github.com/EdwardGlockner/gpushift/issues
7
+ Project-URL: Changelog, https://github.com/EdwardGlockner/gpushift/blob/main/CHANGELOG.md
8
+ Author: Edward Glockner
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: agents,claude-code,cuda,gpu,machine-learning,queue,scheduler
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: Operating System :: MacOS
17
+ Classifier: Operating System :: Microsoft :: Windows
18
+ Classifier: Operating System :: POSIX :: Linux
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3 :: Only
21
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
22
+ Requires-Python: >=3.10
23
+ Requires-Dist: psutil>=5.9
24
+ Requires-Dist: tomli>=2.0; python_version < '3.11'
25
+ Provides-Extra: demo
26
+ Requires-Dist: pillow>=10; extra == 'demo'
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest>=7; extra == 'dev'
29
+ Requires-Dist: ruff>=0.6; extra == 'dev'
30
+ Description-Content-Type: text/markdown
31
+
32
+ # gpushift
33
+
34
+ [![ci](https://github.com/EdwardGlockner/gpushift/actions/workflows/ci.yml/badge.svg)](https://github.com/EdwardGlockner/gpushift/actions/workflows/ci.yml)
35
+ [![pypi](https://img.shields.io/pypi/v/gpushift)](https://pypi.org/project/gpushift/)
36
+ ![python](https://img.shields.io/badge/python-3.10%2B-blue)
37
+ ![platforms](https://img.shields.io/badge/platforms-linux%20%7C%20windows%20%7C%20macos-lightgrey)
38
+ [![license](https://img.shields.io/badge/license-MIT-green)](LICENSE)
39
+
40
+ Share one GPU machine between your Claude Code agents and yourself. Agents queue
41
+ their GPU work instead of launching it, so they never crash each other's runs, and
42
+ the queue steps aside whenever you need the GPUs yourself.
43
+
44
+ - **One queue for every session.** A Claude Code hook stops agents that launch
45
+ training directly and tells them how to queue it.
46
+ - **The machine is still yours.** Free the GPUs with one command: running jobs save
47
+ a checkpoint and step aside, and carry on when you resume.
48
+ - **No idle GPUs.** Jobs run in the order they were queued, but short jobs may fill
49
+ a GPU that would otherwise sit idle, and small jobs share a GPU.
50
+ - **You stay informed.** Agents hear when their jobs end, you get a desktop
51
+ notification when one fails, and a local dashboard shows everything.
52
+ - Windows, Linux and macOS, any number of NVIDIA GPUs. No configuration needed.
53
+
54
+ <picture>
55
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/EdwardGlockner/gpushift/main/docs/img/gpushift-dark.svg">
56
+ <img alt="Claude sessions submit GPU jobs to one shared queue, which runs one job per GPU. A hook blocks direct launches. /gpushift:free makes jobs checkpoint and step aside, and /gpushift:resume continues them." src="https://raw.githubusercontent.com/EdwardGlockner/gpushift/main/docs/img/gpushift-light.svg">
57
+ </picture>
58
+
59
+ ## Quickstart
60
+
61
+ ```bash
62
+ uv tool install gpushift # or: pipx install gpushift
63
+ gpushift init # detects your GPUs and starts gpushift (also at login)
64
+ ```
65
+
66
+ Then, in Claude Code:
67
+
68
+ ```text
69
+ /plugin marketplace add EdwardGlockner/gpushift
70
+ /plugin install gpushift@gpushift
71
+ ```
72
+
73
+ That's it: agents now queue their GPU work. You can queue jobs too:
74
+
75
+ ```text
76
+ $ gpushift submit --one --eta 40m -- python train.py
77
+ job 14 queued (one: 1 GPU, 2 slots) tag=resnet
78
+ position 2 of 3, estimated start: ~40m (14:52)
79
+ ```
80
+
81
+ ## Dashboard
82
+
83
+ `gpushift ui` opens a live dashboard in your browser: what runs on each GPU, CPU and
84
+ disk usage, a timeline of what runs when, the queue (drag jobs to reorder them) and
85
+ each job's output. `gpushift status` shows the same in the terminal.
86
+
87
+ <picture>
88
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/EdwardGlockner/gpushift/main/docs/img/gpushift-dashboard-dark.png">
89
+ <img alt="The gpushift dashboard: two GPU cards with their load, memory, temperature and running job; CPU and storage cards; a timeline of running and queued jobs per GPU; and the queue." src="https://raw.githubusercontent.com/EdwardGlockner/gpushift/main/docs/img/gpushift-dashboard-light.png">
90
+ </picture>
91
+
92
+ ## Submitting jobs
93
+
94
+ Pick how much of the machine a job needs:
95
+
96
+ | Preset | For | Gets |
97
+ |---|---|---|
98
+ | `--light` | Small evals and inference | Shares one GPU with other light jobs |
99
+ | `--one` (default) | Most jobs | One GPU |
100
+ | `--two` | Multi-GPU training | All GPUs |
101
+ | `--exclusive` | Benchmarks | The whole machine |
102
+ | `--cpu` | Preprocessing | No GPU |
103
+
104
+ Useful options:
105
+
106
+ - `--eta 40m`: how long the job takes, for better start times. Without it, gpushift
107
+ learns from earlier runs of the same command.
108
+ - `--after 12`: start only once job 12 has succeeded, e.g. an eval after its
109
+ training run. Use this whenever order matters; otherwise jobs may run side by side.
110
+ - `--restartable`: the job is safe to stop and run again from the start.
111
+
112
+ Jobs run in the folder and environment you submitted them from (including your
113
+ virtualenv), on the GPUs gpushift picked for them. See `gpushift submit --help` for
114
+ everything else.
115
+
116
+ ## When you need the GPUs
117
+
118
+ ```bash
119
+ gpushift free # pause the queue and clear the GPUs
120
+ gpushift resume # carry on
121
+ ```
122
+
123
+ Jobs that can save a checkpoint do so and resume later, restartable jobs start over
124
+ later, and other jobs are paused in place (they keep their GPU memory). Only you can
125
+ free or resume; agents can't.
126
+
127
+ ## Claude Code plugin
128
+
129
+ ![An agent runs python train_lora.py; the gpushift hook blocks it and the agent submits it to the queue instead](https://raw.githubusercontent.com/EdwardGlockner/gpushift/main/docs/img/gpushift-hook.gif)
130
+
131
+ - **A skill** that teaches agents to queue GPU work and pick sensible options.
132
+ - **A hook** that blocks direct GPU launches (`python train.py`, `torchrun`,
133
+ `accelerate launch`, ...) and shows the agent how to queue them instead. Add
134
+ `# no-queue` to a command to let it through.
135
+ - **Wake-ups**: agents run `gpushift wait` in the background, so a session hears
136
+ when its jobs end, even if it was idle.
137
+ - **Commands**: `/gpushift:queue`, `/gpushift:priority`, `/gpushift:cancel`,
138
+ `/gpushift:free` and `/gpushift:resume`.
139
+
140
+ Not using the plugin? Add this to your `CLAUDE.md`:
141
+
142
+ > Never launch GPU jobs directly; submit them with `gpushift submit` (`gpushift submit --help`, `gpushift status`).
143
+
144
+ ## Making jobs resumable
145
+
146
+ So that freeing the GPUs doesn't cost progress, let your training loop check whether
147
+ gpushift wants it to stop, and save a checkpoint when it does:
148
+
149
+ ```python
150
+ from gpushift import checkpoint as ckpt
151
+
152
+ last = ckpt.latest_checkpoint("checkpoints", "step*.pt") # None on a fresh start
153
+ step = load(last) if last else 0
154
+ while step < total:
155
+ train_step()
156
+ step += 1
157
+ if ckpt.should_stop():
158
+ with ckpt.atomic_path(f"checkpoints/step{step:08d}.pt") as tmp:
159
+ torch.save(state, tmp)
160
+ break # gpushift requeues the job and resumes it later
161
+ ```
162
+
163
+ It has no dependencies and works in any environment. Examples for
164
+ [PyTorch](examples/pytorch_resumable.py), [HF Trainer](examples/hf_trainer_resumable.py)
165
+ and [Lightning](examples/lightning_resumable.py).
166
+
167
+ ## Commands
168
+
169
+ | Command | |
170
+ |---|---|
171
+ | `gpushift submit [preset] -- <cmd>` | Queue a job |
172
+ | `gpushift status` / `gpushift ui` | See what's running and waiting |
173
+ | `gpushift logs <id> -f` | Follow a job's output |
174
+ | `gpushift wait [<id>]` | Wait for a job (or the next of your jobs) to end |
175
+ | `gpushift cancel <id>` / `gpushift retry <id>` | Cancel a job / run it again |
176
+ | `gpushift priority <id>` | Move a job to the front |
177
+ | `gpushift free` / `gpushift resume` | Free the GPUs / carry on |
178
+ | `gpushift config --edit` | Change settings |
179
+
180
+ `gpushift --help` lists the rest.
181
+
182
+ ## Configuration
183
+
184
+ Nothing needs configuring. To change something, run `gpushift config --edit`: the
185
+ file explains every setting, such as which GPUs to use, the dashboard port, and whether Claude sessions take turns instead of first come,
186
+ first served.
187
+
188
+ ## How it works
189
+
190
+ A small background service per user keeps the queue in a local SQLite database and
191
+ starts each job when its GPUs are free. It recovers after crashes and reboots, and
192
+ the queue keeps its place even while the service is stopped. Its state lives in
193
+ `%LOCALAPPDATA%\gpushift` (Windows), `~/.local/state/gpushift` (Linux) or
194
+ `~/Library/Application Support/gpushift` (macOS).
195
+
196
+ ## Development
197
+
198
+ ```bash
199
+ pip install -e ".[dev]"
200
+ pytest
201
+ ruff check . && ruff format --check .
202
+ ```
203
+
204
+ The tests run a real queue on fake GPUs, so they don't need a GPU.
@@ -0,0 +1,173 @@
1
+ # gpushift
2
+
3
+ [![ci](https://github.com/EdwardGlockner/gpushift/actions/workflows/ci.yml/badge.svg)](https://github.com/EdwardGlockner/gpushift/actions/workflows/ci.yml)
4
+ [![pypi](https://img.shields.io/pypi/v/gpushift)](https://pypi.org/project/gpushift/)
5
+ ![python](https://img.shields.io/badge/python-3.10%2B-blue)
6
+ ![platforms](https://img.shields.io/badge/platforms-linux%20%7C%20windows%20%7C%20macos-lightgrey)
7
+ [![license](https://img.shields.io/badge/license-MIT-green)](LICENSE)
8
+
9
+ Share one GPU machine between your Claude Code agents and yourself. Agents queue
10
+ their GPU work instead of launching it, so they never crash each other's runs, and
11
+ the queue steps aside whenever you need the GPUs yourself.
12
+
13
+ - **One queue for every session.** A Claude Code hook stops agents that launch
14
+ training directly and tells them how to queue it.
15
+ - **The machine is still yours.** Free the GPUs with one command: running jobs save
16
+ a checkpoint and step aside, and carry on when you resume.
17
+ - **No idle GPUs.** Jobs run in the order they were queued, but short jobs may fill
18
+ a GPU that would otherwise sit idle, and small jobs share a GPU.
19
+ - **You stay informed.** Agents hear when their jobs end, you get a desktop
20
+ notification when one fails, and a local dashboard shows everything.
21
+ - Windows, Linux and macOS, any number of NVIDIA GPUs. No configuration needed.
22
+
23
+ <picture>
24
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/EdwardGlockner/gpushift/main/docs/img/gpushift-dark.svg">
25
+ <img alt="Claude sessions submit GPU jobs to one shared queue, which runs one job per GPU. A hook blocks direct launches. /gpushift:free makes jobs checkpoint and step aside, and /gpushift:resume continues them." src="https://raw.githubusercontent.com/EdwardGlockner/gpushift/main/docs/img/gpushift-light.svg">
26
+ </picture>
27
+
28
+ ## Quickstart
29
+
30
+ ```bash
31
+ uv tool install gpushift # or: pipx install gpushift
32
+ gpushift init # detects your GPUs and starts gpushift (also at login)
33
+ ```
34
+
35
+ Then, in Claude Code:
36
+
37
+ ```text
38
+ /plugin marketplace add EdwardGlockner/gpushift
39
+ /plugin install gpushift@gpushift
40
+ ```
41
+
42
+ That's it: agents now queue their GPU work. You can queue jobs too:
43
+
44
+ ```text
45
+ $ gpushift submit --one --eta 40m -- python train.py
46
+ job 14 queued (one: 1 GPU, 2 slots) tag=resnet
47
+ position 2 of 3, estimated start: ~40m (14:52)
48
+ ```
49
+
50
+ ## Dashboard
51
+
52
+ `gpushift ui` opens a live dashboard in your browser: what runs on each GPU, CPU and
53
+ disk usage, a timeline of what runs when, the queue (drag jobs to reorder them) and
54
+ each job's output. `gpushift status` shows the same in the terminal.
55
+
56
+ <picture>
57
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/EdwardGlockner/gpushift/main/docs/img/gpushift-dashboard-dark.png">
58
+ <img alt="The gpushift dashboard: two GPU cards with their load, memory, temperature and running job; CPU and storage cards; a timeline of running and queued jobs per GPU; and the queue." src="https://raw.githubusercontent.com/EdwardGlockner/gpushift/main/docs/img/gpushift-dashboard-light.png">
59
+ </picture>
60
+
61
+ ## Submitting jobs
62
+
63
+ Pick how much of the machine a job needs:
64
+
65
+ | Preset | For | Gets |
66
+ |---|---|---|
67
+ | `--light` | Small evals and inference | Shares one GPU with other light jobs |
68
+ | `--one` (default) | Most jobs | One GPU |
69
+ | `--two` | Multi-GPU training | All GPUs |
70
+ | `--exclusive` | Benchmarks | The whole machine |
71
+ | `--cpu` | Preprocessing | No GPU |
72
+
73
+ Useful options:
74
+
75
+ - `--eta 40m`: how long the job takes, for better start times. Without it, gpushift
76
+ learns from earlier runs of the same command.
77
+ - `--after 12`: start only once job 12 has succeeded, e.g. an eval after its
78
+ training run. Use this whenever order matters; otherwise jobs may run side by side.
79
+ - `--restartable`: the job is safe to stop and run again from the start.
80
+
81
+ Jobs run in the folder and environment you submitted them from (including your
82
+ virtualenv), on the GPUs gpushift picked for them. See `gpushift submit --help` for
83
+ everything else.
84
+
85
+ ## When you need the GPUs
86
+
87
+ ```bash
88
+ gpushift free # pause the queue and clear the GPUs
89
+ gpushift resume # carry on
90
+ ```
91
+
92
+ Jobs that can save a checkpoint do so and resume later, restartable jobs start over
93
+ later, and other jobs are paused in place (they keep their GPU memory). Only you can
94
+ free or resume; agents can't.
95
+
96
+ ## Claude Code plugin
97
+
98
+ ![An agent runs python train_lora.py; the gpushift hook blocks it and the agent submits it to the queue instead](https://raw.githubusercontent.com/EdwardGlockner/gpushift/main/docs/img/gpushift-hook.gif)
99
+
100
+ - **A skill** that teaches agents to queue GPU work and pick sensible options.
101
+ - **A hook** that blocks direct GPU launches (`python train.py`, `torchrun`,
102
+ `accelerate launch`, ...) and shows the agent how to queue them instead. Add
103
+ `# no-queue` to a command to let it through.
104
+ - **Wake-ups**: agents run `gpushift wait` in the background, so a session hears
105
+ when its jobs end, even if it was idle.
106
+ - **Commands**: `/gpushift:queue`, `/gpushift:priority`, `/gpushift:cancel`,
107
+ `/gpushift:free` and `/gpushift:resume`.
108
+
109
+ Not using the plugin? Add this to your `CLAUDE.md`:
110
+
111
+ > Never launch GPU jobs directly; submit them with `gpushift submit` (`gpushift submit --help`, `gpushift status`).
112
+
113
+ ## Making jobs resumable
114
+
115
+ So that freeing the GPUs doesn't cost progress, let your training loop check whether
116
+ gpushift wants it to stop, and save a checkpoint when it does:
117
+
118
+ ```python
119
+ from gpushift import checkpoint as ckpt
120
+
121
+ last = ckpt.latest_checkpoint("checkpoints", "step*.pt") # None on a fresh start
122
+ step = load(last) if last else 0
123
+ while step < total:
124
+ train_step()
125
+ step += 1
126
+ if ckpt.should_stop():
127
+ with ckpt.atomic_path(f"checkpoints/step{step:08d}.pt") as tmp:
128
+ torch.save(state, tmp)
129
+ break # gpushift requeues the job and resumes it later
130
+ ```
131
+
132
+ It has no dependencies and works in any environment. Examples for
133
+ [PyTorch](examples/pytorch_resumable.py), [HF Trainer](examples/hf_trainer_resumable.py)
134
+ and [Lightning](examples/lightning_resumable.py).
135
+
136
+ ## Commands
137
+
138
+ | Command | |
139
+ |---|---|
140
+ | `gpushift submit [preset] -- <cmd>` | Queue a job |
141
+ | `gpushift status` / `gpushift ui` | See what's running and waiting |
142
+ | `gpushift logs <id> -f` | Follow a job's output |
143
+ | `gpushift wait [<id>]` | Wait for a job (or the next of your jobs) to end |
144
+ | `gpushift cancel <id>` / `gpushift retry <id>` | Cancel a job / run it again |
145
+ | `gpushift priority <id>` | Move a job to the front |
146
+ | `gpushift free` / `gpushift resume` | Free the GPUs / carry on |
147
+ | `gpushift config --edit` | Change settings |
148
+
149
+ `gpushift --help` lists the rest.
150
+
151
+ ## Configuration
152
+
153
+ Nothing needs configuring. To change something, run `gpushift config --edit`: the
154
+ file explains every setting, such as which GPUs to use, the dashboard port, and whether Claude sessions take turns instead of first come,
155
+ first served.
156
+
157
+ ## How it works
158
+
159
+ A small background service per user keeps the queue in a local SQLite database and
160
+ starts each job when its GPUs are free. It recovers after crashes and reboots, and
161
+ the queue keeps its place even while the service is stopped. Its state lives in
162
+ `%LOCALAPPDATA%\gpushift` (Windows), `~/.local/state/gpushift` (Linux) or
163
+ `~/Library/Application Support/gpushift` (macOS).
164
+
165
+ ## Development
166
+
167
+ ```bash
168
+ pip install -e ".[dev]"
169
+ pytest
170
+ ruff check . && ruff format --check .
171
+ ```
172
+
173
+ The tests run a real queue on fake GPUs, so they don't need a GPU.
@@ -5,7 +5,7 @@ build-backend = "hatchling.build"
5
5
  [project]
6
6
  name = "gpushift"
7
7
  dynamic = ["version"]
8
- description = "Share one GPU machine between AI coding agents and yourself: a fair GPU job queue that steps aside when you need the GPUs."
8
+ description = "Share one GPU machine between AI coding agents and yourself: a GPU job queue that steps aside when you need the GPUs."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
11
11
  license = "MIT"
@@ -4,4 +4,4 @@ Keep this module free of imports: ``gpushift.checkpoint`` is imported by user
4
4
  training scripts and must stay dependency-free.
5
5
  """
6
6
 
7
- __version__ = "0.1.0"
7
+ __version__ = "0.1.2"
@@ -60,7 +60,8 @@ def get_proc(pid: int | None, ctime: float | None = None) -> psutil.Process | No
60
60
  p = psutil.Process(pid)
61
61
  if ctime and abs(p.create_time() - ctime) > 1.0:
62
62
  return None
63
- if p.status() == psutil.STATUS_ZOMBIE:
63
+ # Zombies only exist on POSIX; on Windows status() scans every process.
64
+ if not IS_WINDOWS and p.status() == psutil.STATUS_ZOMBIE:
64
65
  return None
65
66
  return p
66
67
  except psutil.Error:
@@ -85,6 +86,49 @@ def tree(p: psutil.Process) -> list[psutil.Process]:
85
86
  return [p]
86
87
 
87
88
 
89
+ class Snapshot:
90
+ """Parent links of all processes, read once. On Windows every psutil
91
+ children()/parents() call scans the whole process list, so the daemon
92
+ takes one snapshot per poll and answers all its tree questions from it."""
93
+
94
+ def __init__(self):
95
+ links = None
96
+ fast = getattr(psutil._psplatform, "ppid_map", None) # one scan; not public API, so optional
97
+ if fast is not None:
98
+ try:
99
+ links = dict(fast())
100
+ except Exception:
101
+ links = None
102
+ if links is None:
103
+ links = {p.pid: p.info["ppid"] for p in psutil.process_iter(["ppid"])}
104
+ self.parent: dict[int, int] = links
105
+ self.kids: dict[int, list[int]] = {}
106
+ for pid, ppid in links.items():
107
+ if ppid != pid:
108
+ self.kids.setdefault(ppid, []).append(pid)
109
+
110
+ def tree(self, pid: int) -> list[int]:
111
+ """pid and all its descendants."""
112
+ out, todo, seen = [], [pid], set()
113
+ while todo:
114
+ p = todo.pop()
115
+ if p in seen:
116
+ continue
117
+ seen.add(p)
118
+ out.append(p)
119
+ todo.extend(self.kids.get(p, ()))
120
+ return out
121
+
122
+ def ancestors(self, pid: int) -> list[int]:
123
+ out, seen = [], {pid}
124
+ p = self.parent.get(pid)
125
+ while p and p not in seen:
126
+ seen.add(p)
127
+ out.append(p)
128
+ p = self.parent.get(p)
129
+ return out
130
+
131
+
88
132
  def suspend_tree(pid: int | None, ctime: float | None = None) -> bool:
89
133
  p = get_proc(pid, ctime)
90
134
  if p is None:
@@ -13,7 +13,7 @@ import sys
13
13
  import time
14
14
  from pathlib import Path
15
15
 
16
- from . import __version__, autostart, config, control, daemon, db, gpus, paths
16
+ from . import __version__, autostart, config, control, daemon, db, gpus, notify, paths
17
17
  from ._proc import NO_WINDOW
18
18
  from .scheduler import PRESETS, PresetError, preset_requirements
19
19
 
@@ -328,6 +328,8 @@ def cmd_submit(a) -> int:
328
328
  if mode != "normal":
329
329
  print("note: the queue is paused (free mode); it will start after `gpushift resume`")
330
330
  print(f"logs: gpushift logs {jid} -f")
331
+ if os.environ.get("CLAUDE_CODE_SESSION_ID"):
332
+ print("to be woken when it ends, run `gpushift wait` as a background command (one is enough for all your jobs)")
331
333
  return 0
332
334
 
333
335
 
@@ -408,7 +410,6 @@ def status_data(con, cfg) -> dict:
408
410
  "schema": 1,
409
411
  "mode": mode,
410
412
  "mode_since": iso(db.get_kv(con, "mode_since")) if mode != "normal" else None,
411
- "auto_free": db.get_kv(con, "auto_free") if mode != "normal" else None,
412
413
  "daemon": {
413
414
  "running": daemon.is_running(),
414
415
  "pid": db.get_kv(con, "daemon_pid"),
@@ -439,9 +440,6 @@ def cmd_status(a) -> int:
439
440
  "free": "FREE (queue paused, machine freed)",
440
441
  "soft": "FREE --soft (queue paused, jobs frozen)",
441
442
  }[mode]
442
- if mode != "normal" and s.get("auto_free"):
443
- apps = ", ".join(s["auto_free"].get("apps") or [])
444
- mode_txt = f"FREE (automatic: {apps} is using the GPU; resumes after it closes)"
445
443
  dm = "running" if s["daemon"]["running"] else "NOT RUNNING (`gpushift start`)"
446
444
  print(f"gpushift mode: {mode_txt} | daemon: {dm} | slots: {s['slots']['used']}/{s['slots']['total']} used")
447
445
  print()
@@ -633,6 +631,8 @@ def cmd_logs(a) -> int:
633
631
 
634
632
 
635
633
  def cmd_wait(a) -> int:
634
+ if a.id is None:
635
+ return wait_for_mine(a)
636
636
  con = db.connect()
637
637
  get_job_or_fail(con, a.id)
638
638
  deadline = None if a.timeout is None else time.time() + parse_duration(a.timeout)
@@ -655,6 +655,48 @@ def cmd_wait(a) -> int:
655
655
  time.sleep(1)
656
656
 
657
657
 
658
+ def wait_for_mine(a) -> int:
659
+ """`gpushift wait` without a job id: wait until the next job this Claude
660
+ session (or, outside Claude Code, this terminal user) submitted ends, and
661
+ say how it went. Run in the background, it wakes an idle agent up."""
662
+ session = os.environ.get("CLAUDE_CODE_SESSION_ID")
663
+ con = db.connect()
664
+ deadline = None if a.timeout is None else time.time() + parse_duration(a.timeout)
665
+
666
+ def open_jobs() -> int:
667
+ return con.execute(
668
+ "SELECT COUNT(*) FROM jobs WHERE session IS ? AND state IN ('queued','running','frozen','evicting')",
669
+ (session,),
670
+ ).fetchone()[0]
671
+
672
+ while True:
673
+ with db.tx(con):
674
+ rows = con.execute(
675
+ "SELECT * FROM jobs WHERE session IS ? AND notified=0 AND state IN ('done','failed','cancelled') "
676
+ "ORDER BY id",
677
+ (session,),
678
+ ).fetchall()
679
+ ended = [db.decode(r) for r in rows]
680
+ for j in ended:
681
+ db.update(con, j["id"], notified=1)
682
+ if ended:
683
+ print(notify.for_agent(ended))
684
+ left = open_jobs()
685
+ if left:
686
+ print(
687
+ f"{left} more of your jobs {'are' if left != 1 else 'is'} queued or running: run `gpushift wait` "
688
+ "in the background again to hear when the next one ends."
689
+ )
690
+ return 0
691
+ if not open_jobs():
692
+ print("none of your jobs are queued or running")
693
+ return 0
694
+ if deadline and time.time() > deadline:
695
+ print("timed out; your jobs are still queued or running")
696
+ return 124
697
+ time.sleep(2)
698
+
699
+
658
700
  def _vram_summary(cfg) -> str:
659
701
  try:
660
702
  live = [g for g in gpus.query() if g.index in cfg.gpus]
@@ -1023,8 +1065,11 @@ def build_parser() -> argparse.ArgumentParser:
1023
1065
  s.add_argument("-n", "--tail", type=int, help="only the last N lines")
1024
1066
  s.set_defaults(func=cmd_logs)
1025
1067
 
1026
- s = sub.add_parser("wait", help="block until a job ends; exit code mirrors the job")
1027
- s.add_argument("id", type=int)
1068
+ s = sub.add_parser(
1069
+ "wait",
1070
+ help="block until a job ends (exit code mirrors the job); without an id, until the next of your own jobs ends",
1071
+ )
1072
+ s.add_argument("id", type=int, nargs="?")
1028
1073
  s.add_argument("--timeout", help="give up after this long (e.g. 30m)")
1029
1074
  s.set_defaults(func=cmd_wait)
1030
1075
 
@@ -27,29 +27,6 @@ class HookConfig:
27
27
  deny: list[str] = field(default_factory=list) # extra regexes that are always blocked
28
28
 
29
29
 
30
- # Programs that use the GPU all the time without being "heavy" GPU work.
31
- DEFAULT_IGNORE = [
32
- "dwm.exe", "explorer.exe", "csrss.exe", "searchapp.exe", "searchhost.exe", "shellexperiencehost.exe",
33
- "startmenuexperiencehost.exe", "textinputhost.exe", "lockapp.exe", "applicationframehost.exe",
34
- "chrome.exe", "msedge.exe", "msedgewebview2.exe", "firefox.exe", "brave.exe", "opera.exe",
35
- "discord.exe", "code.exe", "slack.exe", "teams.exe", "ms-teams.exe", "spotify.exe", "steamwebhelper.exe",
36
- "xorg", "gnome-shell", "kwin_x11", "kwin_wayland", "plasmashell", "windowserver",
37
- ] # fmt: skip
38
-
39
-
40
- @dataclass
41
- class AutoFreeConfig:
42
- """Free the GPUs while the user runs heavy GPU programs (games, Blender, ...)."""
43
-
44
- enabled: bool = True
45
- apps: list[str] = field(default_factory=list) # always count these programs (any GPU memory)
46
- ignore: list[str] = field(default_factory=lambda: list(DEFAULT_IGNORE))
47
- min_vram_mb: int = 1024 # other programs count once they use this much GPU memory
48
- after: int = 10 # seconds a program must keep using the GPU before gpushift frees it
49
- resume_after: int = 120 # seconds after the last such program exits before gpushift resumes
50
- include_agents: bool = False # also count programs started by Claude Code sessions
51
-
52
-
53
30
  @dataclass
54
31
  class Config:
55
32
  gpus: list[int] # GPU indices gpushift may use
@@ -65,7 +42,6 @@ class Config:
65
42
  notify_desktop: str = "failures" # all | failures | off
66
43
  ui_port: int = 8237 # web dashboard on 127.0.0.1; 0 turns it off
67
44
  hook: HookConfig = field(default_factory=HookConfig)
68
- auto_free: AutoFreeConfig = field(default_factory=AutoFreeConfig)
69
45
  detected: list[gpus_mod.GPU] = field(default_factory=list, repr=False)
70
46
 
71
47
  def to_dict(self) -> dict:
@@ -150,21 +126,6 @@ def load(detected: list[gpus_mod.GPU] | None = None) -> Config:
150
126
  if not isinstance(ui_port, int) or not 0 <= ui_port <= 65535:
151
127
  raise ConfigError("ui_port must be a port number (0 turns the dashboard off)")
152
128
 
153
- af = raw.get("auto_free", {}) or {}
154
- d = AutoFreeConfig()
155
- auto_free = AutoFreeConfig(
156
- enabled=bool(af.get("enabled", d.enabled)),
157
- apps=[str(a).lower() for a in af.get("apps", d.apps)],
158
- ignore=[str(a).lower() for a in af.get("ignore", d.ignore)],
159
- min_vram_mb=af.get("min_vram_mb", d.min_vram_mb),
160
- after=af.get("after", d.after),
161
- resume_after=af.get("resume_after", d.resume_after),
162
- include_agents=bool(af.get("include_agents", d.include_agents)),
163
- )
164
- for k in ("min_vram_mb", "after", "resume_after"):
165
- v = getattr(auto_free, k)
166
- if not isinstance(v, int) or v < 0:
167
- raise ConfigError(f"[auto_free] {k} must be a whole number >= 0")
168
129
  return Config(
169
130
  gpus=list(vis),
170
131
  slots=slots,
@@ -179,7 +140,6 @@ def load(detected: list[gpus_mod.GPU] | None = None) -> Config:
179
140
  notify_desktop=notify_desktop,
180
141
  ui_port=ui_port,
181
142
  hook=hook,
182
- auto_free=auto_free,
183
143
  detected=[g for g in detected if g.index in vis],
184
144
  )
185
145
 
@@ -247,19 +207,6 @@ def template(detected: list[gpus_mod.GPU]) -> str:
247
207
  # Desktop notifications when jobs end: "all", "failures" or "off".
248
208
  # desktop = "failures"
249
209
 
250
- [auto_free]
251
- # Free the GPUs while you run heavy GPU programs yourself (games, Blender, ...),
252
- # and resume when they have been closed for a while.
253
- # enabled = true
254
- # Programs that always count, whatever GPU memory they use:
255
- # apps = ["blender.exe", "Overwatch.exe"]
256
- # Other programs count once they use this much GPU memory (MB):
257
- # min_vram_mb = 1024
258
- # Seconds a program must keep going before gpushift frees, and seconds after the
259
- # last one exits before gpushift resumes:
260
- # after = 10
261
- # resume_after = 120
262
-
263
210
  [hook]
264
211
  # The Claude Code hook that redirects direct GPU launches to `gpushift submit`.
265
212
  # enabled = true