modelmap 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.
modelmap/treemap.py ADDED
@@ -0,0 +1,196 @@
1
+ """Squarified treemap layout: pure geometry, no drawing and no files.
2
+
3
+ The algorithm is the one in Bruls, Huizing and van Wijk, "Squarified
4
+ Treemaps" (2000): take the items in decreasing order and fill the
5
+ rectangle with rows laid along its shorter side, adding items to the
6
+ current row for as long as that does not worsen the row's worst aspect
7
+ ratio.
8
+
9
+ The area of every rectangle is its share of the total, exactly: nothing
10
+ here insets, pads or rounds. A drawing layer that wants gaps must draw
11
+ them on top of these rectangles, not shrink them.
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ from collections.abc import Sequence
17
+ from dataclasses import dataclass, field
18
+
19
+
20
+ @dataclass(frozen=True)
21
+ class Rect:
22
+ """An axis-aligned rectangle; ``y`` grows downward, as in SVG."""
23
+
24
+ x: float
25
+ y: float
26
+ w: float
27
+ h: float
28
+
29
+ @property
30
+ def area(self) -> float:
31
+ return self.w * self.h
32
+
33
+ @property
34
+ def aspect(self) -> float:
35
+ """Long side over short side; 1 for a square, infinite when flat."""
36
+ short, long = sorted((self.w, self.h))
37
+ return long / short if short > 0 else float("inf")
38
+
39
+
40
+ def worst(largest: float, smallest: float, total: float, side: float) -> float:
41
+ """The highest aspect ratio in a row, as the paper defines it.
42
+
43
+ :param largest: Largest area in the row.
44
+ :param smallest: Smallest area in the row.
45
+ :param total: Sum of the areas in the row.
46
+ :param side: Length of the side the row is laid along.
47
+ """
48
+ return max(side * side * largest / (total * total), total * total / (side * side * smallest))
49
+
50
+
51
+ def squarify(sizes: Sequence[float], rect: Rect) -> list[Rect]:
52
+ """Divide a rectangle among sizes, keeping the pieces close to square.
53
+
54
+ :param sizes: Positive sizes, in any order.
55
+ :param rect: The rectangle to fill.
56
+ :return: One rectangle per size, in the order of ``sizes``. Their areas
57
+ are in proportion to the sizes and together they tile ``rect``.
58
+ :raises ValueError: If a size is not positive.
59
+ """
60
+ if any(not size > 0 for size in sizes):
61
+ raise ValueError("sizes must be positive")
62
+ if not sizes:
63
+ return []
64
+ order = sorted(range(len(sizes)), key=lambda i: (-sizes[i], i))
65
+ scale = rect.area / sum(sizes)
66
+ areas = [sizes[i] * scale for i in order]
67
+ placed: list[Rect] = []
68
+ x, y, w, h = rect.x, rect.y, rect.w, rect.h
69
+ start = 0
70
+ while start < len(areas):
71
+ side = min(w, h)
72
+ end = start + 1
73
+ total = areas[start]
74
+ ratio = worst(areas[start], areas[start], total, side)
75
+ while end < len(areas):
76
+ grown = total + areas[end]
77
+ # The row is in decreasing order: the first is its largest.
78
+ grown_ratio = worst(areas[start], areas[end], grown, side)
79
+ if grown_ratio > ratio:
80
+ break
81
+ total, ratio, end = grown, grown_ratio, end + 1
82
+
83
+ last_row = end == len(areas)
84
+ if w >= h:
85
+ # A column on the left; the last row takes all that is left,
86
+ # so rounding never leaves a sliver uncovered.
87
+ thick = w if last_row else total / h
88
+ offset = y
89
+ for k in range(start, end):
90
+ length = (y + h - offset) if k == end - 1 else areas[k] / thick
91
+ placed.append(Rect(x, offset, thick, length))
92
+ offset += length
93
+ x, w = x + thick, w - thick
94
+ else:
95
+ thick = h if last_row else total / w
96
+ offset = x
97
+ for k in range(start, end):
98
+ length = (x + w - offset) if k == end - 1 else areas[k] / thick
99
+ placed.append(Rect(offset, y, length, thick))
100
+ offset += length
101
+ y, h = y + thick, h - thick
102
+ start = end
103
+
104
+ result = [placed[0]] * len(sizes)
105
+ for position, index in enumerate(order):
106
+ result[index] = placed[position]
107
+ return result
108
+
109
+
110
+ @dataclass(frozen=True)
111
+ class Item:
112
+ """One thing to place on the map.
113
+
114
+ :param key: Unique identity, for example a path.
115
+ :param group: Name of the group the item belongs to.
116
+ :param size: Size that sets the tile's area; must be positive.
117
+ :param label: Text for sorting ties and for display.
118
+ """
119
+
120
+ key: str
121
+ group: str
122
+ size: float
123
+ label: str = ""
124
+
125
+
126
+ @dataclass
127
+ class Tile:
128
+ """A placed item, or several small items merged into one tile.
129
+
130
+ :param key: The item's key; for a merged tile, a key made from the group.
131
+ :param group: Group name.
132
+ :param size: The item's size, or the sum for a merged tile.
133
+ :param rect: Where the tile is.
134
+ :param label: The item's label; empty for a merged tile.
135
+ :param members: Keys of the items a merged tile stands for; empty for a
136
+ tile that is one item.
137
+ """
138
+
139
+ key: str
140
+ group: str
141
+ size: float
142
+ rect: Rect
143
+ label: str = ""
144
+ members: list[str] = field(default_factory=list)
145
+
146
+
147
+ @dataclass
148
+ class Group:
149
+ """A group of tiles and the rectangle they fill."""
150
+
151
+ name: str
152
+ size: float
153
+ rect: Rect
154
+ tiles: list[Tile] = field(default_factory=list)
155
+
156
+
157
+ def layout(items: Sequence[Item], rect: Rect, *, min_fraction: float = 0.0) -> list[Group]:
158
+ """Lay out items in two levels: groups, then the items of each group.
159
+
160
+ :param items: Items with positive sizes and unique keys.
161
+ :param rect: The canvas.
162
+ :param min_fraction: Items smaller than this share of the whole are
163
+ merged into one tile per group, when a group has two or more of
164
+ them, so that every tile drawn is large enough to see.
165
+ :return: Groups from largest to smallest, each with its tiles from
166
+ largest to smallest. Equal sizes are ordered by label, then key,
167
+ so the same items always give the same layout.
168
+ """
169
+ total = sum(item.size for item in items)
170
+ by_group: dict[str, list[Item]] = {}
171
+ for item in items:
172
+ by_group.setdefault(item.group, []).append(item)
173
+ names = sorted(by_group, key=lambda name: (-sum(i.size for i in by_group[name]), name))
174
+ group_sizes = [sum(i.size for i in by_group[name]) for name in names]
175
+ groups = []
176
+ for name, size, group_rect in zip(names, group_sizes, squarify(group_sizes, rect)):
177
+ members = sorted(by_group[name], key=lambda i: (-i.size, i.label, i.key))
178
+ small = [i for i in members if i.size < min_fraction * total]
179
+ if len(small) < 2:
180
+ small = []
181
+ shown = members[: len(members) - len(small)]
182
+ tiles = [Tile(i.key, name, i.size, group_rect, i.label) for i in shown]
183
+ if small:
184
+ merged = Tile(
185
+ key=f"{name}\x00merged",
186
+ group=name,
187
+ size=sum(i.size for i in small),
188
+ rect=group_rect,
189
+ members=[i.key for i in small],
190
+ )
191
+ tiles.append(merged)
192
+ for tile, tile_rect in zip(tiles, squarify([t.size for t in tiles], group_rect)):
193
+ tile.rect = tile_rect
194
+ tiles.sort(key=lambda t: (-t.size, bool(t.members), t.label, t.key))
195
+ groups.append(Group(name, size, group_rect, tiles))
196
+ return groups
modelmap/units.py ADDED
@@ -0,0 +1,62 @@
1
+ """Sizes and counts as people write them."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import re
6
+
7
+ _UNITS = ("B", "kB", "MB", "GB", "TB", "PB")
8
+ _SIZE = re.compile(r"^\s*(\d+(?:\.\d+)?)\s*([kmgtp]?)(i?)b?\s*$", re.IGNORECASE)
9
+
10
+
11
+ def format_size(size: int) -> str:
12
+ """A byte count in decimal units, as model hubs and macOS show sizes.
13
+
14
+ :param size: Bytes.
15
+ :return: Text such as ``27.2 GB``, with three significant figures at most.
16
+ """
17
+ value = float(size)
18
+ for unit in _UNITS:
19
+ if value < 999.5 or unit == _UNITS[-1]:
20
+ break
21
+ value /= 1000
22
+ if unit == "B":
23
+ return f"{int(value)} B"
24
+ return f"{value:.1f} {unit}" if value < 99.95 else f"{value:.0f} {unit}"
25
+
26
+
27
+ def parse_size(text: str) -> int:
28
+ """Read a size such as ``50MB``, ``1.5 GB``, ``4GiB`` or ``1000``.
29
+
30
+ :param text: A number with an optional unit. ``k``, ``M``, ``G``, ``T``
31
+ and ``P`` are powers of 1000; with ``i`` they are powers of 1024.
32
+ :return: Bytes.
33
+ :raises ValueError: If the text is not a size.
34
+ """
35
+ match = _SIZE.match(text)
36
+ if not match:
37
+ raise ValueError(f"not a size: {text!r} (examples: 50MB, 1.5GB, 4GiB)")
38
+ number, prefix, binary = match.groups()
39
+ exponent = "kmgtp".index(prefix.lower()) + 1 if prefix else 0
40
+ return int(float(number) * (1024 if binary else 1000) ** exponent)
41
+
42
+
43
+ def format_count(count: int | None, exact: bool = True) -> str:
44
+ """A parameter count such as ``8.19B`` or ``~335M``; empty when unknown.
45
+
46
+ :param count: Number of parameters, or None.
47
+ :param exact: False marks the count as an estimate with ``~``.
48
+ """
49
+ if count is None:
50
+ return ""
51
+ for divisor, suffix in ((1e12, "T"), (1e9, "B"), (1e6, "M"), (1e3, "K")):
52
+ if count >= divisor:
53
+ value = count / divisor
54
+ text = (
55
+ f"{value:.2f}"
56
+ if value < 9.995
57
+ else f"{value:.1f}"
58
+ if value < 99.95
59
+ else f"{value:.0f}"
60
+ )
61
+ return f"{'' if exact else '~'}{text}{suffix}"
62
+ return f"{'' if exact else '~'}{count}"
@@ -0,0 +1,126 @@
1
+ Metadata-Version: 2.4
2
+ Name: modelmap
3
+ Version: 0.1.0
4
+ Summary: Find local LLM model files across Hugging Face, Ollama, oMLX, LM Studio and llama.cpp, and draw them as a treemap
5
+ License-Expression: BSD-3-Clause
6
+ License-File: LICENSE
7
+ Keywords: llm,gguf,safetensors,ollama,huggingface,mlx,disk-usage,treemap
8
+ Author: Eric G. Suchanek, PhD
9
+ Author-email: suchanek@flux-frontiers.com
10
+ Requires-Python: >=3.10
11
+ Classifier: Development Status :: 2 - Pre-Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: End Users/Desktop
14
+ Classifier: Topic :: System :: Filesystems
15
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Project-URL: Changelog, https://github.com/Flux-Frontiers/modelmap/blob/main/CHANGELOG.md
22
+ Project-URL: Documentation, https://github.com/Flux-Frontiers/modelmap/blob/main/docs/guide.md
23
+ Project-URL: Homepage, https://github.com/Flux-Frontiers/modelmap
24
+ Project-URL: Issues, https://github.com/Flux-Frontiers/modelmap/issues
25
+ Project-URL: Repository, https://github.com/Flux-Frontiers/modelmap
26
+ Description-Content-Type: text/markdown
27
+
28
+ [![CI](https://github.com/Flux-Frontiers/modelmap/actions/workflows/ci.yml/badge.svg)](https://github.com/Flux-Frontiers/modelmap/actions/workflows/ci.yml)
29
+ [![Python](https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13-blue.svg)](https://www.python.org/)
30
+ [![License: BSD-3-Clause](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://github.com/Flux-Frontiers/modelmap/blob/main/LICENSE)
31
+ [![Version](https://img.shields.io/badge/version-0.1.0-blue.svg)](https://github.com/Flux-Frontiers/modelmap/releases)
32
+ [![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json)](https://python-poetry.org/)
33
+ [![DOI](https://img.shields.io/badge/DOI-10.5281%2Fzenodo.24520428-blue.svg)](https://doi.org/10.5281/zenodo.24520428)
34
+ [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://pre-commit.com/)
35
+ [![ORCID](https://img.shields.io/badge/ORCID-0009--0009--0891--1507-A6CE39.svg)](https://orcid.org/0009-0009-0891-1507)
36
+
37
+ # modelmap -- Find, Map and Remove Local LLM Models
38
+
39
+ **See every language-model file on a machine, how much space each one takes, and remove the ones you no longer need.**
40
+
41
+ modelmap reads the stores of Hugging Face, Ollama, oMLX, LM Studio,
42
+ llama.cpp, GPT4All, Jan and Whisper, follows the settings and symlinks
43
+ that move them, and sweeps your home folder for loose GGUF, safetensors
44
+ and checkpoint files. It reads file headers for parameter counts and
45
+ quantization, counts each file once however many names point at it, and
46
+ draws everything as a map you can open down to the individual files.
47
+
48
+ <img src="https://raw.githubusercontent.com/Flux-Frontiers/modelmap/main/assets/map.png" alt="The map: one block per store, one tile per model, sized by space used" width="760">
49
+
50
+ Status: pre-alpha, not yet released. It runs on macOS and Linux with
51
+ Python 3.10 or later and needs nothing beyond the standard library.
52
+
53
+ ## Install
54
+
55
+ From a clone:
56
+
57
+ ```bash
58
+ pip install .
59
+ ```
60
+
61
+ ## Use
62
+
63
+ ```bash
64
+ modelmap map --open # the map, opened in your browser
65
+ modelmap scan # totals by store
66
+ modelmap list # every model, largest first
67
+ modelmap providers # where each store is looked for
68
+ modelmap rm ollama:qwen3:4b # remove a model, after showing what goes and asking
69
+ ```
70
+
71
+ On the map, click a tile to open the model; the square is redrawn as its
72
+ files, with each file's path and the `modelmap rm` command beside it.
73
+ Escape goes back up.
74
+
75
+ `modelmap rm` removes Ollama models with `ollama rm`, Hugging Face cache
76
+ repositories with `hf cache rm`, and moves anything else to the Trash. It
77
+ shows every file or command first, asks, and refuses caches and files
78
+ that another model also uses.
79
+
80
+ To map a machine you cannot reach, ask its owner for an inventory:
81
+
82
+ ```bash
83
+ modelmap scan --json --redact > inventory.json # on their machine
84
+ modelmap map --from-json inventory.json --open # on yours
85
+ ```
86
+
87
+ ## Documentation
88
+
89
+ - [Guide](https://github.com/Flux-Frontiers/modelmap/blob/main/docs/guide.md): what is scanned, how sizes are counted, the map,
90
+ removing models, and the limits.
91
+ - [Command reference](https://github.com/Flux-Frontiers/modelmap/blob/main/docs/cli.md): every command and option.
92
+ - [Cheat sheet](https://github.com/Flux-Frontiers/modelmap/blob/main/docs/cheatsheet.md): one page.
93
+
94
+ ## Development
95
+
96
+ ```bash
97
+ poetry install --with dev
98
+ .venv/bin/pytest
99
+ ```
100
+
101
+ ## Citation
102
+
103
+ If you use modelmap in your research or project, please cite it:
104
+
105
+ > Suchanek, E. G. (2026). *modelmap: Find, Map and Remove Local LLM Models* (Version 0.1.0) [Software]. Flux-Frontiers. https://doi.org/10.5281/zenodo.24520428
106
+
107
+ ```bibtex
108
+ @software{suchanek_modelmap,
109
+ author = {Suchanek, Eric G.},
110
+ title = {{modelmap}: Find, Map and Remove Local LLM Models},
111
+ version = {0.1.0},
112
+ year = {2026},
113
+ publisher = {Flux-Frontiers},
114
+ url = {https://github.com/Flux-Frontiers/modelmap},
115
+ doi = {10.5281/zenodo.24520428},
116
+ }
117
+ ```
118
+
119
+ The DOI is the Zenodo concept DOI, which always resolves to the newest
120
+ archived release. The citation metadata is also in [CITATION.cff](https://github.com/Flux-Frontiers/modelmap/blob/main/CITATION.cff). See the
121
+ [changelog](https://github.com/Flux-Frontiers/modelmap/blob/main/CHANGELOG.md) for release history.
122
+
123
+ ## License
124
+
125
+ BSD-3-Clause. See [LICENSE](https://github.com/Flux-Frontiers/modelmap/blob/main/LICENSE).
126
+
@@ -0,0 +1,27 @@
1
+ modelmap/__init__.py,sha256=RNyn-ypo9Odjeg77K9gI54d54gRz3jxmeHlzQjIABGU,94
2
+ modelmap/__main__.py,sha256=g0rr6_iDDsEJbFtsQOz8ZXgzeqaN6YMHaxP2Cymmbp0,95
3
+ modelmap/cli.py,sha256=Glf3jPgpHaZ59aIdrNG0H8xBYQYwaKZCY4igiHffPec,17142
4
+ modelmap/headers.py,sha256=CNk9O8W2s4QtlQctZXx_NG9xAm-7Rwi7nuWRbg7Qk2s,15324
5
+ modelmap/mapdata.py,sha256=fGNntqBT2x4H-4I4efbULYAWsb5tA2wcKhrvxqmmDY0,2740
6
+ modelmap/palette.py,sha256=ebCQ29qE0XtfAiPh6c_29UQ0ZuKst2T90HB_cZmK0Ns,3167
7
+ modelmap/providers/__init__.py,sha256=MSazGnbzk6dARz2OYttBFnL1v6Eqa8pvYp7ovM3bJHA,497
8
+ modelmap/providers/base.py,sha256=KUMKf72s_dIXQ1driSOgiN_J-xxX98DhPpIldXl8eB8,8731
9
+ modelmap/providers/describe.py,sha256=MXpoFc2iOwq0T50p4ANihzbWt_UAOFa1PExIulZnKA0,8063
10
+ modelmap/providers/generic.py,sha256=NePfbLciU8cMkMITWPEQh9q39_dykDHU4SP3ewzftE8,9378
11
+ modelmap/providers/hf.py,sha256=ewlH7SF1PAZpf99UxRbB1eMhMe0ZsdA7Jq5siGQZZgE,8363
12
+ modelmap/providers/ollama.py,sha256=m_QiA1VOlihrLXjyAvYO1EZhHCrO7Vtyv3bdTuCV-UY,9613
13
+ modelmap/providers/omlx.py,sha256=zCPedGIuTG82PwQXa_oGZMRcwjzMBzmJFUi1zL2HlGw,2537
14
+ modelmap/providers/stores.py,sha256=FHsoU_OCcyn-MAlG7G3OJF4pvMTLTVUoEW3iRqroN4o,6402
15
+ modelmap/records.py,sha256=G6wakBcl8zOi5ErfGAtHWHUtskpvCu0wA3UKQ4W8ZFM,6607
16
+ modelmap/removal.py,sha256=Tp_epnjImQva1Sh9q0GTrn42YgZKTpjC2_qV3QUmOso,15072
17
+ modelmap/render_html.py,sha256=HTovah2kpxhZDeBtoQfCXzLV_TMV65CCSGe-74lwUlM,30849
18
+ modelmap/render_svg.py,sha256=wBj3gsGiMDHBeSoeyl7O36a4mQ3mayh8GNzbYI3IWX8,13037
19
+ modelmap/scanner.py,sha256=b1tcndAcDwIGUOrwrJe7vN0pPC9OsIRU8PGWz_n-7o0,9492
20
+ modelmap/sizing.py,sha256=UpQZGoE4MlRHOcyrAPlgRPyXNfOwwSG2jvQ1GlqnEv8,3577
21
+ modelmap/treemap.py,sha256=tUa6fJnNV29y-seURAbjLnP0gAJ0Wh9Ml4ldLaNLCps,7103
22
+ modelmap/units.py,sha256=15S_QQkAlh0zD_-5uMnSm718jN7iAhg_kJvX5KzBmGM,2112
23
+ modelmap-0.1.0.dist-info/METADATA,sha256=Nc93RaPyk9XifbSv_84ObhJS-njviwptWFTEOOtVRaU,5762
24
+ modelmap-0.1.0.dist-info/WHEEL,sha256=EGEvSphFYqXKs23-kQBeyNoJP1nrT8ZJKQoi5p5DYL8,88
25
+ modelmap-0.1.0.dist-info/entry_points.txt,sha256=QraSFIfWLOP8uGYPGa4dbzTf9IRvX1rBJsBwoXwyqcw,46
26
+ modelmap-0.1.0.dist-info/licenses/LICENSE,sha256=_xb40bECn2359Q9306cPDBCxGQTZKVQis52u9n_6LVM,1529
27
+ modelmap-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 2.4.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ modelmap=modelmap.cli:main
3
+
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2026, Eric G. Suchanek, PhD
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.