hugpy-queue 0.1.0__py3-none-any.whl
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.
- hugpy_queue/__init__.py +1 -0
- hugpy_queue/__main__.py +5 -0
- hugpy_queue/calls.py +70 -0
- hugpy_queue/cli.py +81 -0
- hugpy_queue/core_sql.py +62 -0
- hugpy_queue/door.py +305 -0
- hugpy_queue/imports/__init__.py +37 -0
- hugpy_queue/imports/constants.py +47 -0
- hugpy_queue/rows.py +205 -0
- hugpy_queue/store.py +166 -0
- hugpy_queue/system/__init__.py +19 -0
- hugpy_queue/system/system.py +170 -0
- hugpy_queue-0.1.0.dist-info/METADATA +155 -0
- hugpy_queue-0.1.0.dist-info/RECORD +17 -0
- hugpy_queue-0.1.0.dist-info/WHEEL +5 -0
- hugpy_queue-0.1.0.dist-info/entry_points.txt +2 -0
- hugpy_queue-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hugpy-queue
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: The queue of a Hugpy worker: the front door, a record of every call, and the stages each call passes
|
|
5
|
+
Requires-Python: >=3.11
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: hugpy-utilities<0.2,>=0.1.0
|
|
8
|
+
|
|
9
|
+
# hugpy-queue
|
|
10
|
+
|
|
11
|
+
The queue of a Hugpy worker: the front door every request comes in through, a record of every call, and the
|
|
12
|
+
stages each call passes on its way to an answer.
|
|
13
|
+
|
|
14
|
+
A Hugpy worker is made of four parts, each with its own service, account and database:
|
|
15
|
+
|
|
16
|
+
| Part | Package | What it answers |
|
|
17
|
+
|---|---|---|
|
|
18
|
+
| Discovery | `hugpy-discovery` | where a model is stored |
|
|
19
|
+
| Resources | `hugpy-resources` | where a model is loaded |
|
|
20
|
+
| Engines | `hugpy-engine` | what a model is doing and what it needs |
|
|
21
|
+
| Queue | `hugpy-queue` | what a call is and what it has |
|
|
22
|
+
|
|
23
|
+
`hugpy-wrapper` is the bundle that installs all four and connects their databases.
|
|
24
|
+
|
|
25
|
+
## What it does
|
|
26
|
+
|
|
27
|
+
- **Front door.** It listens on one address and takes every request for the worker. Each request is put on record
|
|
28
|
+
with its method, route, status, time and size.
|
|
29
|
+
- **Calls.** Every `POST` is a call. It gets a row saying what it is and what it has, and one row for each stage
|
|
30
|
+
it passes.
|
|
31
|
+
- **Hand-off.** The call is passed on to `hugpy-resources`, and the reply is passed back to the caller as it
|
|
32
|
+
comes, so a streamed reply still arrives piece by piece.
|
|
33
|
+
- **Health.** `GET /health` answers for the whole worker: the queue under its own name, and the health of the part
|
|
34
|
+
behind it as that part gave it.
|
|
35
|
+
|
|
36
|
+
Who may call is decided by `hugpy-resources`. The queue passes every header on unchanged, and names a caller from
|
|
37
|
+
another machine in `X-Forwarded-For`, so the caller is asked for its key exactly as it would be at that door.
|
|
38
|
+
|
|
39
|
+
## Install
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
pip install hugpy-queue
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Python 3.11 or later. The only dependency is `hugpy-utilities`.
|
|
46
|
+
|
|
47
|
+
To run it as a service of the host (Linux with systemd, as root):
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
sudo hugpy-queue system install
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
This makes the account `hugpy-queue`, the folder `/var/lib/hugpy/queue`, the database `queue.sqlite3` and the unit
|
|
54
|
+
`hugpy-queue.service`, then starts it. `sudo hugpy-queue system status` shows its state, and
|
|
55
|
+
`sudo hugpy-queue system uninstall` stops and removes the unit; the record and the settings are kept.
|
|
56
|
+
|
|
57
|
+
## Use
|
|
58
|
+
|
|
59
|
+
Send a call to the door the same way it would be sent to the worker:
|
|
60
|
+
|
|
61
|
+
```sh
|
|
62
|
+
curl http://127.0.0.1:15203/v1/chat/completions \
|
|
63
|
+
-H 'content-type: application/json' \
|
|
64
|
+
-d '{"model": "MODEL", "messages": [{"role": "user", "content": "hello"}]}'
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The reply carries a `queue_id`: the number of the call's row.
|
|
68
|
+
|
|
69
|
+
### Commands
|
|
70
|
+
|
|
71
|
+
| Command | What it does |
|
|
72
|
+
|---|---|
|
|
73
|
+
| `hugpy-queue serve` | run the front door in the foreground (the service runs this) |
|
|
74
|
+
| `hugpy-queue calls` | the latest calls and the stages each passed |
|
|
75
|
+
| `hugpy-queue door` | what has been asked of the door, by route and status |
|
|
76
|
+
| `hugpy-queue settings` | every setting, its value, and where the database is |
|
|
77
|
+
| `hugpy-queue set NAME VALUE` | save one setting |
|
|
78
|
+
| `sudo hugpy-queue system install \| status \| uninstall` | the service of the host |
|
|
79
|
+
| `sudo hugpy-queue system set NAME VALUE` | save one setting and restart the service on it |
|
|
80
|
+
|
|
81
|
+
### The queue's own reads
|
|
82
|
+
|
|
83
|
+
These are answered by the queue itself and are not passed on:
|
|
84
|
+
|
|
85
|
+
| Route | What it returns |
|
|
86
|
+
|---|---|
|
|
87
|
+
| `GET /health` | the worker's health: the queue, and the part behind it |
|
|
88
|
+
| `GET /_queue/health` | the queue alone: its version, where it hands calls, how many are in flight |
|
|
89
|
+
| `GET /_queue/calls?limit=N` | the latest calls with their stages (20 by default, 500 at most) |
|
|
90
|
+
| `GET /_queue/door` | requests by method, route and status, with counts and times |
|
|
91
|
+
| `GET /_queue/stages` | the order of stages |
|
|
92
|
+
|
|
93
|
+
Every other request is passed on to `hugpy-resources`.
|
|
94
|
+
|
|
95
|
+
## Settings
|
|
96
|
+
|
|
97
|
+
| Setting | Default | What it is |
|
|
98
|
+
|---|---|---|
|
|
99
|
+
| `host` | `127.0.0.1` | the address the door listens on |
|
|
100
|
+
| `port` | `15203` | the port the door listens on |
|
|
101
|
+
| `wrapper_url` | `http://127.0.0.1:15202` | where a call is handed: the address of `hugpy-resources` |
|
|
102
|
+
|
|
103
|
+
A saved setting is a row of the `settings` table of the queue's database.
|
|
104
|
+
|
|
105
|
+
Two environment variables say where its data is kept:
|
|
106
|
+
|
|
107
|
+
| Variable | What it sets |
|
|
108
|
+
|---|---|
|
|
109
|
+
| `HUGPY_DATA_DIR` | the data directory shared by the Hugpy tools of a host (the service uses `/var/lib/hugpy`; a person's own default is `~/.local/share/hugpy`) |
|
|
110
|
+
| `HUGPY_QUEUE_STATE` | the queue's own folder (default: `queue` under the data directory) |
|
|
111
|
+
|
|
112
|
+
## The order of stages
|
|
113
|
+
|
|
114
|
+
A call passes these stages in order. Sorting only predicts; running acts.
|
|
115
|
+
|
|
116
|
+
| No. | Stage | Owner | Phase | What it is |
|
|
117
|
+
|---|---|---|---|---|
|
|
118
|
+
| 10 | `received` | queue | sort | recorded: what it is |
|
|
119
|
+
| 20 | `engine_range` | engine | sort | time-to-processed range from tokens in and out; impossible placements out |
|
|
120
|
+
| 30 | `reap_prediction` | discovery | sort | seconds to place the model on a worker drive |
|
|
121
|
+
| 40 | `evict_prediction` | resources | sort | seconds to make room in memory; finishes the sort |
|
|
122
|
+
| 50 | `turn` | queue | run | this row is next |
|
|
123
|
+
| 60 | `accommodate` | discovery | run | the model placed on a worker drive |
|
|
124
|
+
| 70 | `evict` | resources | run | room made |
|
|
125
|
+
| 80 | `load` | resources | run | the engine loads |
|
|
126
|
+
| 90 | `intake` | engine | run | the engine takes the call |
|
|
127
|
+
| 100 | `done` | queue | run | answered |
|
|
128
|
+
| 110 | `responded` | queue | run | the reply written to the caller |
|
|
129
|
+
|
|
130
|
+
The order is data: it is the `stage_order` table, and `GET /_queue/stages` returns it.
|
|
131
|
+
|
|
132
|
+
## What is recorded
|
|
133
|
+
|
|
134
|
+
The database is `queue.sqlite3` in the queue's folder. One thread of the queue's own process writes it; nothing else
|
|
135
|
+
does.
|
|
136
|
+
|
|
137
|
+
| Table or view | What it holds |
|
|
138
|
+
|---|---|
|
|
139
|
+
| `calls` | every call: what it is and what it has |
|
|
140
|
+
| `call_stages` | a row for each stage a call passed, with when it started and finished |
|
|
141
|
+
| `call_times` | view: each call with its times |
|
|
142
|
+
| `front_door` | every request at the door |
|
|
143
|
+
| `front_door_hours` | answered reads, counted by hour |
|
|
144
|
+
| `front_door_routes` | view: requests by method, route and status |
|
|
145
|
+
| `stage_order` | the order of stages |
|
|
146
|
+
| `settings` | the saved settings |
|
|
147
|
+
|
|
148
|
+
An answered read keeps its own `front_door` row for two minutes. It is then counted into its hour in
|
|
149
|
+
`front_door_hours` and the row is removed.
|
|
150
|
+
|
|
151
|
+
## Limits of this release
|
|
152
|
+
|
|
153
|
+
The queue does not sort calls or decide whose turn it is yet. A call is handed to `hugpy-resources` whole, and
|
|
154
|
+
`hugpy-resources` still does stages 20 to 90 itself. That hand-off is on record as one stage row, `handed`, from the
|
|
155
|
+
moment the call is sent until the answer begins. Each stage moves to its owner's door as that door is made.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
hugpy_queue/__init__.py,sha256=FFR8EEvAr4LWDY9BTjq4EQIKE4bUcJ4Hq1egOCPlLoE,116
|
|
2
|
+
hugpy_queue/__main__.py,sha256=E6Gls0DNz8GQK2K-kOUIx8cYhgANW_CH54VKrfCfs14,52
|
|
3
|
+
hugpy_queue/calls.py,sha256=QDnsvUPqe3H_jNpYFVwBlai4jVYGIdI7tnPZkQRbGuQ,4208
|
|
4
|
+
hugpy_queue/cli.py,sha256=3okdEbs2EWZKJ39wBMRz_RApUTqaiM2Mm5v1N1TouzI,3733
|
|
5
|
+
hugpy_queue/core_sql.py,sha256=jn8Uk5NCG99Lql4CENNDFayllez2k2YiiqZTS7lRves,3945
|
|
6
|
+
hugpy_queue/door.py,sha256=5kTUraLQuNmIdo2WjmfawBkO1r2Yzgpf5evhpDMZhsk,14631
|
|
7
|
+
hugpy_queue/rows.py,sha256=BfubjznUj2ZiVZkZyX5Fh-LoavKqz-RDPRcgTtQSvwg,12064
|
|
8
|
+
hugpy_queue/store.py,sha256=UTe0-6-9w0J-90al6d-GWk71G7u7jZBFTDjwfBQDb28,8448
|
|
9
|
+
hugpy_queue/imports/__init__.py,sha256=UtZfvvwZzbY_kwMaKMtr5U-Dv3h8DOfG2xLv-g98Qms,809
|
|
10
|
+
hugpy_queue/imports/constants.py,sha256=FDCiKEZSkIiqIHm3cAmFBzZcMdspgSfsSnVF_mNV3d8,2588
|
|
11
|
+
hugpy_queue/system/__init__.py,sha256=cK9qQLfeRwaPpgz8qUD7bKdKGjfyFVyFN3UbPdC7P7o,850
|
|
12
|
+
hugpy_queue/system/system.py,sha256=9URAY50y30TQfs2TbBKloqxckBs92wlc-6dZkJ6-Db0,6789
|
|
13
|
+
hugpy_queue-0.1.0.dist-info/METADATA,sha256=iYr8c0jKAvTho4NuPjmgD-U4ji-VauzDu3bvt7hAcXg,6678
|
|
14
|
+
hugpy_queue-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
15
|
+
hugpy_queue-0.1.0.dist-info/entry_points.txt,sha256=GBVHKrLzT38EhWK6tSZh0TrCuKkBgbRBe7h3N8Kv3CY,53
|
|
16
|
+
hugpy_queue-0.1.0.dist-info/top_level.txt,sha256=e6Prka6gKyhTrMnm2-HlBmbj4oec2hRB9vew-k3KSPY,12
|
|
17
|
+
hugpy_queue-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
hugpy_queue
|