localtune 0.1.0__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.
- localtune-0.1.0/.github/workflows/ci.yml +41 -0
- localtune-0.1.0/.gitignore +31 -0
- localtune-0.1.0/LICENSE +202 -0
- localtune-0.1.0/PKG-INFO +49 -0
- localtune-0.1.0/README.md +36 -0
- localtune-0.1.0/pyproject.toml +55 -0
- localtune-0.1.0/scripts/build_price_tables.py +189 -0
- localtune-0.1.0/src/localtune/__init__.py +7 -0
- localtune-0.1.0/src/localtune/cli.py +132 -0
- localtune-0.1.0/src/localtune/cost.py +32 -0
- localtune-0.1.0/src/localtune/data/prices_countries.csv +42 -0
- localtune-0.1.0/src/localtune/data/prices_us_states.csv +52 -0
- localtune-0.1.0/src/localtune/data/prices_us_zips.csv +23451 -0
- localtune-0.1.0/src/localtune/gpu_monitor.py +164 -0
- localtune-0.1.0/src/localtune/hardware.py +127 -0
- localtune-0.1.0/src/localtune/prices.py +86 -0
- localtune-0.1.0/tests/test_cli.py +96 -0
- localtune-0.1.0/tests/test_cost.py +18 -0
- localtune-0.1.0/tests/test_gpu_monitor.py +76 -0
- localtune-0.1.0/tests/test_hardware.py +75 -0
- localtune-0.1.0/tests/test_init.py +11 -0
- localtune-0.1.0/tests/test_prices.py +70 -0
- localtune-0.1.0/uv.lock +485 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# CI (continuous integration): GitHub's robot that re-checks localtune on a fresh computer
|
|
2
|
+
# every time a change is proposed or lands on main. It catches problems that only show up on
|
|
3
|
+
# someone else's machine before they reach main. A green check on a PR means all of this passed.
|
|
4
|
+
name: CI
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
push:
|
|
8
|
+
branches: [main]
|
|
9
|
+
pull_request:
|
|
10
|
+
|
|
11
|
+
# One run per Python version: the oldest and newest that localtune supports
|
|
12
|
+
# (requires-python in pyproject.toml), so it keeps working for users on either end.
|
|
13
|
+
jobs:
|
|
14
|
+
test:
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
strategy:
|
|
17
|
+
matrix:
|
|
18
|
+
python-version: ["3.10", "3.13"]
|
|
19
|
+
|
|
20
|
+
# The same steps a person would do: get the code, install it with the exact tool versions
|
|
21
|
+
# from uv.lock, then run the same checks you can run locally (ruff for mistakes and
|
|
22
|
+
# formatting, pytest for the tests in tests/).
|
|
23
|
+
steps:
|
|
24
|
+
- uses: actions/checkout@v5
|
|
25
|
+
|
|
26
|
+
- uses: astral-sh/setup-uv@v6
|
|
27
|
+
with:
|
|
28
|
+
python-version: ${{ matrix.python-version }}
|
|
29
|
+
activate-environment: true
|
|
30
|
+
|
|
31
|
+
- name: Install
|
|
32
|
+
run: uv sync --locked
|
|
33
|
+
|
|
34
|
+
- name: Lint
|
|
35
|
+
run: uv run ruff check
|
|
36
|
+
|
|
37
|
+
- name: Check formatting
|
|
38
|
+
run: uv run ruff format --check
|
|
39
|
+
|
|
40
|
+
- name: Test
|
|
41
|
+
run: uv run pytest
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.pyc
|
|
4
|
+
.venv/
|
|
5
|
+
venv/
|
|
6
|
+
|
|
7
|
+
# Test and lint caches
|
|
8
|
+
.pytest_cache/
|
|
9
|
+
.ruff_cache/
|
|
10
|
+
|
|
11
|
+
# Build output
|
|
12
|
+
build/
|
|
13
|
+
dist/
|
|
14
|
+
*.egg-info/
|
|
15
|
+
|
|
16
|
+
# Secrets
|
|
17
|
+
.env
|
|
18
|
+
|
|
19
|
+
# Model weights (too big for GitHub)
|
|
20
|
+
*.gguf
|
|
21
|
+
*.safetensors
|
|
22
|
+
*.bin
|
|
23
|
+
*.pt
|
|
24
|
+
models/
|
|
25
|
+
|
|
26
|
+
# Editor / OS junk
|
|
27
|
+
.vscode/
|
|
28
|
+
.DS_Store
|
|
29
|
+
|
|
30
|
+
# Raw downloads used to build the price tables
|
|
31
|
+
raw-price-data/
|
localtune-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
localtune-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: localtune
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Benchmark local LLMs on your own hardware: speed, memory use and power.
|
|
5
|
+
Author: Justin Hartman
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Requires-Dist: pydantic>=2.14.1
|
|
10
|
+
Requires-Dist: rich>=15.0.0
|
|
11
|
+
Requires-Dist: typer>=0.27.3
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# localtune
|
|
15
|
+
|
|
16
|
+
Benchmark local LLMs on your own hardware, and find out which model, quantization and KV cache
|
|
17
|
+
setting runs best on your machine.
|
|
18
|
+
|
|
19
|
+
Each run measures:
|
|
20
|
+
|
|
21
|
+
| Metric | Meaning |
|
|
22
|
+
| --- | --- |
|
|
23
|
+
| Prefill tok/s | How fast the model reads your prompt |
|
|
24
|
+
| Decode tok/s | How fast it writes the answer |
|
|
25
|
+
| TTFT ms | Time to first token: the wait before the answer starts |
|
|
26
|
+
| Peak VRAM GB | GPU memory used at the busiest moment |
|
|
27
|
+
| Avg / peak W | GPU power draw |
|
|
28
|
+
| Energy Wh | Electricity the GPU used during the run |
|
|
29
|
+
| Cost | That energy times an electricity price |
|
|
30
|
+
|
|
31
|
+
## Data sources
|
|
32
|
+
|
|
33
|
+
Electricity cost uses the most local price localtune has: your zip code, then your state or
|
|
34
|
+
country, then the US average. A price per kWh that you give yourself always replaces these.
|
|
35
|
+
Each cost records which price it was based on.
|
|
36
|
+
|
|
37
|
+
| Price | Source | Covers | License |
|
|
38
|
+
| --- | --- | --- | --- |
|
|
39
|
+
| US zip codes | [NREL, U.S. Electric Utility Companies and Rates (2023)](https://catalog.data.gov/dataset/u-s-electric-utility-companies-and-rates-look-up-by-zipcode-2023), scaled by each state's change since 2023 (EIA) | Zip codes where one company both sells and delivers power | CC BY 4.0 |
|
|
40
|
+
| US states | [EIA-861M monthly sales and revenue by state](https://www.eia.gov/electricity/data/state/), last 12 months | All 50 states and DC | Public domain |
|
|
41
|
+
| Countries | [Eurostat, electricity prices for household consumers (nrg_pc_204)](https://ec.europa.eu/eurostat/databrowser/view/nrg_pc_204/default/table), all taxes included, in euros | 41 European countries | CC BY 4.0 |
|
|
42
|
+
| US average | [EIA Short-Term Energy Outlook](https://www.eia.gov/outlooks/steo/report/elec_coal_renew.php), October 2026 | Whole US | Public domain |
|
|
43
|
+
|
|
44
|
+
The tables in `src/localtune/data/` are built from these sources by
|
|
45
|
+
`scripts/build_price_tables.py`.
|
|
46
|
+
|
|
47
|
+
## License
|
|
48
|
+
|
|
49
|
+
[Apache 2.0](LICENSE)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# localtune
|
|
2
|
+
|
|
3
|
+
Benchmark local LLMs on your own hardware, and find out which model, quantization and KV cache
|
|
4
|
+
setting runs best on your machine.
|
|
5
|
+
|
|
6
|
+
Each run measures:
|
|
7
|
+
|
|
8
|
+
| Metric | Meaning |
|
|
9
|
+
| --- | --- |
|
|
10
|
+
| Prefill tok/s | How fast the model reads your prompt |
|
|
11
|
+
| Decode tok/s | How fast it writes the answer |
|
|
12
|
+
| TTFT ms | Time to first token: the wait before the answer starts |
|
|
13
|
+
| Peak VRAM GB | GPU memory used at the busiest moment |
|
|
14
|
+
| Avg / peak W | GPU power draw |
|
|
15
|
+
| Energy Wh | Electricity the GPU used during the run |
|
|
16
|
+
| Cost | That energy times an electricity price |
|
|
17
|
+
|
|
18
|
+
## Data sources
|
|
19
|
+
|
|
20
|
+
Electricity cost uses the most local price localtune has: your zip code, then your state or
|
|
21
|
+
country, then the US average. A price per kWh that you give yourself always replaces these.
|
|
22
|
+
Each cost records which price it was based on.
|
|
23
|
+
|
|
24
|
+
| Price | Source | Covers | License |
|
|
25
|
+
| --- | --- | --- | --- |
|
|
26
|
+
| US zip codes | [NREL, U.S. Electric Utility Companies and Rates (2023)](https://catalog.data.gov/dataset/u-s-electric-utility-companies-and-rates-look-up-by-zipcode-2023), scaled by each state's change since 2023 (EIA) | Zip codes where one company both sells and delivers power | CC BY 4.0 |
|
|
27
|
+
| US states | [EIA-861M monthly sales and revenue by state](https://www.eia.gov/electricity/data/state/), last 12 months | All 50 states and DC | Public domain |
|
|
28
|
+
| Countries | [Eurostat, electricity prices for household consumers (nrg_pc_204)](https://ec.europa.eu/eurostat/databrowser/view/nrg_pc_204/default/table), all taxes included, in euros | 41 European countries | CC BY 4.0 |
|
|
29
|
+
| US average | [EIA Short-Term Energy Outlook](https://www.eia.gov/outlooks/steo/report/elec_coal_renew.php), October 2026 | Whole US | Public domain |
|
|
30
|
+
|
|
31
|
+
The tables in `src/localtune/data/` are built from these sources by
|
|
32
|
+
`scripts/build_price_tables.py`.
|
|
33
|
+
|
|
34
|
+
## License
|
|
35
|
+
|
|
36
|
+
[Apache 2.0](LICENSE)
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# The project's ID card. Tools like uv and pip read this file to learn what localtune is,
|
|
2
|
+
# what it needs, and how to package it so anyone can install it.
|
|
3
|
+
|
|
4
|
+
# Who and what localtune is: the facts shown when someone looks the package up or installs it.
|
|
5
|
+
# "dependencies" are the outside libraries localtune needs to run: pydantic gives every piece
|
|
6
|
+
# of data a fixed, checked shape; typer turns Python functions into terminal commands; rich
|
|
7
|
+
# prints tidy tables and colors in the terminal.
|
|
8
|
+
[project]
|
|
9
|
+
name = "localtune"
|
|
10
|
+
dynamic = ["version"]
|
|
11
|
+
description = "Benchmark local LLMs on your own hardware: speed, memory use and power."
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
license = "Apache-2.0"
|
|
14
|
+
license-files = ["LICENSE"]
|
|
15
|
+
authors = [{ name = "Justin Hartman" }]
|
|
16
|
+
requires-python = ">=3.10"
|
|
17
|
+
dependencies = [
|
|
18
|
+
"pydantic>=2.14.1",
|
|
19
|
+
"rich>=15.0.0",
|
|
20
|
+
"typer>=0.27.3",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
# Creates the "localtune" terminal command when the package is installed, and points it at
|
|
24
|
+
# the app in src/localtune/cli.py.
|
|
25
|
+
[project.scripts]
|
|
26
|
+
localtune = "localtune.cli:app"
|
|
27
|
+
|
|
28
|
+
# How the code in src/ gets bundled into an installable package. The version number is read
|
|
29
|
+
# from the package itself, so it only ever has to be changed in one place.
|
|
30
|
+
[build-system]
|
|
31
|
+
requires = ["hatchling"]
|
|
32
|
+
build-backend = "hatchling.build"
|
|
33
|
+
|
|
34
|
+
[tool.hatch.version]
|
|
35
|
+
path = "src/localtune/__init__.py"
|
|
36
|
+
|
|
37
|
+
# Tools for people working on localtune, not for people using it: pytest runs the tests in
|
|
38
|
+
# tests/, and ruff keeps the code free of common mistakes and consistently formatted.
|
|
39
|
+
# The same checks run automatically on GitHub (see .github/workflows/ci.yml).
|
|
40
|
+
[dependency-groups]
|
|
41
|
+
dev = [
|
|
42
|
+
"openpyxl>=3.1.5",
|
|
43
|
+
"pytest>=9.1.1",
|
|
44
|
+
"ruff>=0.17.2",
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
[tool.pytest.ini_options]
|
|
48
|
+
testpaths = ["tests"]
|
|
49
|
+
|
|
50
|
+
[tool.ruff]
|
|
51
|
+
line-length = 100
|
|
52
|
+
target-version = "py310"
|
|
53
|
+
|
|
54
|
+
[tool.ruff.lint]
|
|
55
|
+
select = ["E", "F", "I", "UP", "B"]
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"""Build localtune's electricity price tables from public data.
|
|
2
|
+
|
|
3
|
+
Run from the project folder:
|
|
4
|
+
uv run python scripts/build_price_tables.py
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
# localtune ships three small price tables (src/localtune/data/) so that nobody using it needs
|
|
8
|
+
# an internet connection or an API key to get a local electricity price. This script makes those
|
|
9
|
+
# tables from the original public data, and is re-run every few months to bring them up to date.
|
|
10
|
+
# Only people working on localtune run it; users only ever read the finished tables.
|
|
11
|
+
#
|
|
12
|
+
# Steps: download the raw files (or reuse ones already in raw-price-data/), boil each down to a
|
|
13
|
+
# price per kWh per place, and write the three tables.
|
|
14
|
+
|
|
15
|
+
import argparse
|
|
16
|
+
import csv
|
|
17
|
+
import urllib.request
|
|
18
|
+
from collections import defaultdict
|
|
19
|
+
from pathlib import Path
|
|
20
|
+
|
|
21
|
+
import openpyxl
|
|
22
|
+
|
|
23
|
+
SOURCES = {
|
|
24
|
+
# NREL: each US zip code's electric utilities and their average rates (2023), CC BY 4.0.
|
|
25
|
+
"iou_zipcodes_2023.csv": "https://data.openei.org/files/6225/iou_zipcodes_2023.csv",
|
|
26
|
+
"non_iou_zipcodes_2023.csv": "https://data.openei.org/files/6225/non_iou_zipcodes_2023.csv",
|
|
27
|
+
# EIA: monthly revenue and electricity sold, by state and sector (2010 on), public domain.
|
|
28
|
+
"HS861M 2010-.xlsx": "https://www.eia.gov/electricity/data/state/xls/861m/HS861M%202010-.xlsx",
|
|
29
|
+
# Eurostat: household electricity prices twice a year by country, CC BY 4.0.
|
|
30
|
+
"estat_nrg_pc_204_en.csv": "https://ec.europa.eu/eurostat/api/dissemination/sdmx/2.1/data/nrg_pc_204/?format=SDMX-CSV",
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
ROOT = Path(__file__).resolve().parent.parent
|
|
34
|
+
RAW_DIR = ROOT / "raw-price-data"
|
|
35
|
+
OUT_DIR = ROOT / "src" / "localtune" / "data"
|
|
36
|
+
NREL_YEAR = 2023
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def download(raw_dir: Path) -> None:
|
|
40
|
+
raw_dir.mkdir(exist_ok=True)
|
|
41
|
+
for name, url in SOURCES.items():
|
|
42
|
+
if not (raw_dir / name).exists():
|
|
43
|
+
print(f"Downloading {name}")
|
|
44
|
+
urllib.request.urlretrieve(url, raw_dir / name)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
# US states (EIA). Home prices swing with the seasons, so each state's price is the last 12
|
|
48
|
+
# months of revenue divided by the last 12 months of electricity sold. The same sum for NREL's
|
|
49
|
+
# year is kept too, to bring the older zip code rates up to date below.
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def state_prices(xlsx: Path) -> tuple[dict[str, float], dict[str, float], str]:
|
|
53
|
+
sheet = openpyxl.load_workbook(xlsx, read_only=True)["Monthly-States"]
|
|
54
|
+
revenue: dict[tuple[str, int, int], float] = {}
|
|
55
|
+
sales: dict[tuple[str, int, int], float] = {}
|
|
56
|
+
for row in sheet.iter_rows(min_row=4, values_only=True):
|
|
57
|
+
year, month, state = row[0], row[1], row[2]
|
|
58
|
+
if not isinstance(year, int) or not state:
|
|
59
|
+
continue
|
|
60
|
+
revenue[(state, year, month)] = row[4] or 0
|
|
61
|
+
sales[(state, year, month)] = row[5] or 0
|
|
62
|
+
|
|
63
|
+
latest = max((year, month) for _, year, month in revenue)
|
|
64
|
+
last_12 = set()
|
|
65
|
+
year, month = latest
|
|
66
|
+
for _ in range(12):
|
|
67
|
+
last_12.add((year, month))
|
|
68
|
+
year, month = (year, month - 1) if month > 1 else (year - 1, 12)
|
|
69
|
+
|
|
70
|
+
now, then = defaultdict(lambda: [0.0, 0.0]), defaultdict(lambda: [0.0, 0.0])
|
|
71
|
+
for (state, year, month), dollars in revenue.items():
|
|
72
|
+
mwh = sales[(state, year, month)]
|
|
73
|
+
if (year, month) in last_12:
|
|
74
|
+
now[state][0] += dollars
|
|
75
|
+
now[state][1] += mwh
|
|
76
|
+
if year == NREL_YEAR:
|
|
77
|
+
then[state][0] += dollars
|
|
78
|
+
then[state][1] += mwh
|
|
79
|
+
|
|
80
|
+
def per_kwh(totals: dict[str, list[float]]) -> dict[str, float]:
|
|
81
|
+
# Thousand dollars / megawatt-hours = dollars per kWh.
|
|
82
|
+
return {state: d / mwh for state, (d, mwh) in totals.items() if mwh}
|
|
83
|
+
|
|
84
|
+
return per_kwh(now), per_kwh(then), f"{latest[0]}-{latest[1]:02d}"
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
# US zip codes (NREL). A zip code served by several utilities gets the average of their home
|
|
88
|
+
# rates. Only zip codes where every utility both sells and delivers the power ("bundled") are
|
|
89
|
+
# kept. Where people shop for their power separately (much of Texas, Ohio and the Northeast),
|
|
90
|
+
# NREL only has the delivery part of the bill, so those zip codes fall back to their state
|
|
91
|
+
# average instead of looking far too cheap. Each rate is then scaled by how much its state's
|
|
92
|
+
# average has changed since NREL's year.
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def zip_prices(
|
|
96
|
+
csv_files: list[Path], now: dict[str, float], then: dict[str, float]
|
|
97
|
+
) -> list[tuple[str, str, float]]:
|
|
98
|
+
rates: dict[str, list[float]] = defaultdict(list)
|
|
99
|
+
states: dict[str, str] = {}
|
|
100
|
+
not_bundled: set[str] = set()
|
|
101
|
+
for path in csv_files:
|
|
102
|
+
with path.open(newline="") as f:
|
|
103
|
+
for row in csv.DictReader(f):
|
|
104
|
+
zip_code = row["zip"].zfill(5)
|
|
105
|
+
rate = float(row["res_rate"] or 0)
|
|
106
|
+
if row["service_type"] != "Bundled":
|
|
107
|
+
not_bundled.add(zip_code)
|
|
108
|
+
elif rate > 0:
|
|
109
|
+
rates[zip_code].append(rate)
|
|
110
|
+
states.setdefault(zip_code, row["state"])
|
|
111
|
+
|
|
112
|
+
table = []
|
|
113
|
+
for zip_code, values in sorted(rates.items()):
|
|
114
|
+
if zip_code in not_bundled:
|
|
115
|
+
continue
|
|
116
|
+
state = states[zip_code]
|
|
117
|
+
change = now[state] / then[state] if state in now and state in then else 1.0
|
|
118
|
+
table.append((zip_code, state, sum(values) / len(values) * change))
|
|
119
|
+
return table
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
# Countries (Eurostat). The price for a typical household (2,500-5,000 kWh a year), with all
|
|
123
|
+
# taxes, in euros, from the latest half-year each country has reported. Countries that stopped
|
|
124
|
+
# reporting more than a year before the newest data (the UK after 2020) are left out.
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def country_prices(csv_file: Path) -> list[tuple[str, float, str]]:
|
|
128
|
+
latest: dict[str, tuple[str, float]] = {}
|
|
129
|
+
with csv_file.open(newline="") as f:
|
|
130
|
+
for row in csv.DictReader(f):
|
|
131
|
+
if (
|
|
132
|
+
row["nrg_cons"] == "KWH2500-4999"
|
|
133
|
+
and row["tax"] == "I_TAX"
|
|
134
|
+
and row["currency"] == "EUR"
|
|
135
|
+
and row["unit"] == "KWH"
|
|
136
|
+
and row["OBS_VALUE"]
|
|
137
|
+
):
|
|
138
|
+
geo, period = row["geo"], row["TIME_PERIOD"]
|
|
139
|
+
if geo not in latest or period > latest[geo][0]:
|
|
140
|
+
latest[geo] = (period, float(row["OBS_VALUE"]))
|
|
141
|
+
newest_year = int(max(period for period, _ in latest.values())[:4])
|
|
142
|
+
return [
|
|
143
|
+
(geo, value, period)
|
|
144
|
+
for geo, (period, value) in sorted(latest.items())
|
|
145
|
+
if int(period[:4]) >= newest_year - 1
|
|
146
|
+
]
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def write(name: str, header: list[str], rows: list) -> None:
|
|
150
|
+
with (OUT_DIR / name).open("w", newline="") as f:
|
|
151
|
+
writer = csv.writer(f, lineterminator="\n")
|
|
152
|
+
writer.writerow(header)
|
|
153
|
+
writer.writerows(rows)
|
|
154
|
+
print(f"Wrote {name}: {len(rows)} rows")
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def main() -> None:
|
|
158
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
159
|
+
parser.add_argument("--raw-dir", type=Path, default=RAW_DIR, help="Where the raw files go.")
|
|
160
|
+
raw_dir = parser.parse_args().raw_dir
|
|
161
|
+
|
|
162
|
+
download(raw_dir)
|
|
163
|
+
now, then, period = state_prices(raw_dir / "HS861M 2010-.xlsx")
|
|
164
|
+
zips = zip_prices(
|
|
165
|
+
[raw_dir / "iou_zipcodes_2023.csv", raw_dir / "non_iou_zipcodes_2023.csv"], now, then
|
|
166
|
+
)
|
|
167
|
+
countries = country_prices(raw_dir / "estat_nrg_pc_204_en.csv")
|
|
168
|
+
|
|
169
|
+
OUT_DIR.mkdir(exist_ok=True)
|
|
170
|
+
write(
|
|
171
|
+
"prices_us_states.csv",
|
|
172
|
+
["state", "per_kwh", "period"],
|
|
173
|
+
[
|
|
174
|
+
(state, round(price, 4), f"12 months to {period}")
|
|
175
|
+
for state, price in sorted(now.items())
|
|
176
|
+
],
|
|
177
|
+
)
|
|
178
|
+
write(
|
|
179
|
+
"prices_us_zips.csv", ["zip", "state", "per_kwh"], [(z, s, round(p, 4)) for z, s, p in zips]
|
|
180
|
+
)
|
|
181
|
+
write(
|
|
182
|
+
"prices_countries.csv",
|
|
183
|
+
["country", "per_kwh", "currency", "period"],
|
|
184
|
+
[(geo, round(value, 4), "EUR", p) for geo, value, p in countries],
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
if __name__ == "__main__":
|
|
189
|
+
main()
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"""localtune: benchmark local LLMs on your own hardware."""
|
|
2
|
+
|
|
3
|
+
# The heart of the package. Every module localtune gains later lives in this folder,
|
|
4
|
+
# and this file is what runs when anything does "import localtune".
|
|
5
|
+
# The version number below is the single source of truth: packaging (pyproject.toml) reads it,
|
|
6
|
+
# and saved benchmark results will record it, so each result shows which version measured it.
|
|
7
|
+
__version__ = "0.1.0"
|