utopic 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.
utopic-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.
utopic-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,139 @@
1
+ Metadata-Version: 2.4
2
+ Name: utopic
3
+ Version: 0.1.0
4
+ Summary: Python package manager for the Utopic native runtime
5
+ Author: Utopic contributors
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/adavyas/utopic-package-manager
8
+ Project-URL: Source, https://github.com/adavyas/utopic-package-manager
9
+ Project-URL: NativeRuntime, https://github.com/adavyas/utopic
10
+ Keywords: diffusion,llm,gguf,llama.cpp,inference
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: Apache Software License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
18
+ Requires-Python: >=3.9
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Dynamic: license-file
22
+ Dynamic: requires-python
23
+
24
+ # Utopic Package Manager
25
+
26
+ Python package management for the Utopic native runtime.
27
+
28
+ This repository is intentionally thin. The wheel installs Python launchers only.
29
+ Native source checkout, build configuration, and binary installation all happen
30
+ later through `utopic setup`.
31
+
32
+ ## Install
33
+
34
+ ```sh
35
+ pip install git+https://github.com/adavyas/utopic-package-manager.git
36
+ utopic setup
37
+ ```
38
+
39
+ On Linux distributions that enforce PEP 668, install the launcher in an isolated
40
+ environment instead of the system Python:
41
+
42
+ ```sh
43
+ python3 -m venv ~/.venvs/utopic
44
+ ~/.venvs/utopic/bin/pip install git+https://github.com/adavyas/utopic-package-manager.git
45
+ ~/.venvs/utopic/bin/utopic setup
46
+ ```
47
+
48
+ `utopic setup` builds from package-managed native sources and installs the
49
+ runtime binaries under `~/.cache/utopic/bin`.
50
+
51
+ On NVIDIA hosts, build the CUDA backend:
52
+
53
+ ```sh
54
+ utopic setup --backend cuda
55
+ ```
56
+
57
+ The CUDA setup path detects the local GPU architecture and selects a suitable
58
+ CUDA compiler when possible, including CUDA 13 on GB10/DGX Spark hosts. On
59
+ constrained hosts, limit build parallelism:
60
+
61
+ ```sh
62
+ utopic setup --backend cuda --jobs 2
63
+ ```
64
+
65
+ If a Mac cannot initialize Metal, or you want a portable CPU-only build:
66
+
67
+ ```sh
68
+ utopic setup --backend cpu
69
+ ```
70
+
71
+ For local development from this checkout:
72
+
73
+ ```sh
74
+ git clone https://github.com/adavyas/utopic-package-manager.git
75
+ cd utopic-package-manager
76
+ pip install .
77
+ utopic setup
78
+ ```
79
+
80
+ ## Commands
81
+
82
+ The package installs these launchers:
83
+
84
+ - `utopic`
85
+ - `utopic-server`
86
+ - `utopic-mcp`
87
+ - `utopic-acp`
88
+
89
+ Run a one-shot prompt:
90
+
91
+ ```sh
92
+ utopic run -m /path/to/model.gguf -p "Answer with one word: 2+2?" -n 16
93
+ ```
94
+
95
+ For DiffusionGemma-style canvas models, use the entropy-bound path:
96
+
97
+ ```sh
98
+ utopic run -m /path/to/diffusiongemma.gguf -p "Answer with one word: 2+2?" -n 16 --eb-steps 48
99
+ ```
100
+
101
+ Run the OpenAI-compatible local server:
102
+
103
+ ```sh
104
+ utopic-server -m /path/to/model.gguf --host 127.0.0.1 --port 8910 -ngl 99
105
+ ```
106
+
107
+ Health and model list:
108
+
109
+ ```sh
110
+ curl http://127.0.0.1:8910/health
111
+ curl http://127.0.0.1:8910/v1/models
112
+ ```
113
+
114
+ ## What Setup Owns
115
+
116
+ The package manager owns the user-facing setup path:
117
+
118
+ - fetch the pinned compatible native runtime and dependency sources
119
+ - configure the native build for CPU or CUDA, including CUDA compiler and architecture detection
120
+ - build the dependency layer and Utopic
121
+ - copy the final binaries into the Utopic cache
122
+
123
+ The published wheel stays pure Python and does not fetch or compile native code
124
+ during `pip install`. Users should not need to clone dependency repositories or
125
+ run build-system commands directly for normal setup.
126
+
127
+ Use the package-managed binary produced by `utopic setup` for user-facing runs.
128
+ On the 2026-06-21 GB10 smoke, `/home/adavya/.cache/utopic-current/bin/utopic`
129
+ successfully generated from the installed Dream Q4, LLaDA Q4, DiffusionGemma
130
+ BF16, and DiffusionGemma Q4 GGUFs. The repo-local native build loaded the same
131
+ files, but was stale for DiffusionGemma prompt wrapping.
132
+
133
+ ## Development
134
+
135
+ Build a wheel:
136
+
137
+ ```sh
138
+ python -m pip wheel . --no-deps -w dist/
139
+ ```
utopic-0.1.0/README.md ADDED
@@ -0,0 +1,116 @@
1
+ # Utopic Package Manager
2
+
3
+ Python package management for the Utopic native runtime.
4
+
5
+ This repository is intentionally thin. The wheel installs Python launchers only.
6
+ Native source checkout, build configuration, and binary installation all happen
7
+ later through `utopic setup`.
8
+
9
+ ## Install
10
+
11
+ ```sh
12
+ pip install git+https://github.com/adavyas/utopic-package-manager.git
13
+ utopic setup
14
+ ```
15
+
16
+ On Linux distributions that enforce PEP 668, install the launcher in an isolated
17
+ environment instead of the system Python:
18
+
19
+ ```sh
20
+ python3 -m venv ~/.venvs/utopic
21
+ ~/.venvs/utopic/bin/pip install git+https://github.com/adavyas/utopic-package-manager.git
22
+ ~/.venvs/utopic/bin/utopic setup
23
+ ```
24
+
25
+ `utopic setup` builds from package-managed native sources and installs the
26
+ runtime binaries under `~/.cache/utopic/bin`.
27
+
28
+ On NVIDIA hosts, build the CUDA backend:
29
+
30
+ ```sh
31
+ utopic setup --backend cuda
32
+ ```
33
+
34
+ The CUDA setup path detects the local GPU architecture and selects a suitable
35
+ CUDA compiler when possible, including CUDA 13 on GB10/DGX Spark hosts. On
36
+ constrained hosts, limit build parallelism:
37
+
38
+ ```sh
39
+ utopic setup --backend cuda --jobs 2
40
+ ```
41
+
42
+ If a Mac cannot initialize Metal, or you want a portable CPU-only build:
43
+
44
+ ```sh
45
+ utopic setup --backend cpu
46
+ ```
47
+
48
+ For local development from this checkout:
49
+
50
+ ```sh
51
+ git clone https://github.com/adavyas/utopic-package-manager.git
52
+ cd utopic-package-manager
53
+ pip install .
54
+ utopic setup
55
+ ```
56
+
57
+ ## Commands
58
+
59
+ The package installs these launchers:
60
+
61
+ - `utopic`
62
+ - `utopic-server`
63
+ - `utopic-mcp`
64
+ - `utopic-acp`
65
+
66
+ Run a one-shot prompt:
67
+
68
+ ```sh
69
+ utopic run -m /path/to/model.gguf -p "Answer with one word: 2+2?" -n 16
70
+ ```
71
+
72
+ For DiffusionGemma-style canvas models, use the entropy-bound path:
73
+
74
+ ```sh
75
+ utopic run -m /path/to/diffusiongemma.gguf -p "Answer with one word: 2+2?" -n 16 --eb-steps 48
76
+ ```
77
+
78
+ Run the OpenAI-compatible local server:
79
+
80
+ ```sh
81
+ utopic-server -m /path/to/model.gguf --host 127.0.0.1 --port 8910 -ngl 99
82
+ ```
83
+
84
+ Health and model list:
85
+
86
+ ```sh
87
+ curl http://127.0.0.1:8910/health
88
+ curl http://127.0.0.1:8910/v1/models
89
+ ```
90
+
91
+ ## What Setup Owns
92
+
93
+ The package manager owns the user-facing setup path:
94
+
95
+ - fetch the pinned compatible native runtime and dependency sources
96
+ - configure the native build for CPU or CUDA, including CUDA compiler and architecture detection
97
+ - build the dependency layer and Utopic
98
+ - copy the final binaries into the Utopic cache
99
+
100
+ The published wheel stays pure Python and does not fetch or compile native code
101
+ during `pip install`. Users should not need to clone dependency repositories or
102
+ run build-system commands directly for normal setup.
103
+
104
+ Use the package-managed binary produced by `utopic setup` for user-facing runs.
105
+ On the 2026-06-21 GB10 smoke, `/home/adavya/.cache/utopic-current/bin/utopic`
106
+ successfully generated from the installed Dream Q4, LLaDA Q4, DiffusionGemma
107
+ BF16, and DiffusionGemma Q4 GGUFs. The repo-local native build loaded the same
108
+ files, but was stale for DiffusionGemma prompt wrapping.
109
+
110
+ ## Development
111
+
112
+ Build a wheel:
113
+
114
+ ```sh
115
+ python -m pip wheel . --no-deps -w dist/
116
+ ```
@@ -0,0 +1,41 @@
1
+ [build-system]
2
+ requires = [
3
+ "setuptools>=69",
4
+ "wheel",
5
+ ]
6
+ build-backend = "setuptools.build_meta"
7
+
8
+ [project]
9
+ name = "utopic"
10
+ version = "0.1.0"
11
+ description = "Python package manager for the Utopic native runtime"
12
+ readme = "README.md"
13
+ requires-python = ">=3.9"
14
+ license = { text = "Apache-2.0" }
15
+ authors = [
16
+ { name = "Utopic contributors" },
17
+ ]
18
+ keywords = ["diffusion", "llm", "gguf", "llama.cpp", "inference"]
19
+ classifiers = [
20
+ "Development Status :: 3 - Alpha",
21
+ "Environment :: Console",
22
+ "Intended Audience :: Developers",
23
+ "License :: OSI Approved :: Apache Software License",
24
+ "Programming Language :: Python :: 3",
25
+ "Programming Language :: Python :: 3 :: Only",
26
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
27
+ ]
28
+
29
+ [project.urls]
30
+ Homepage = "https://github.com/adavyas/utopic-package-manager"
31
+ Source = "https://github.com/adavyas/utopic-package-manager"
32
+ NativeRuntime = "https://github.com/adavyas/utopic"
33
+
34
+ [project.scripts]
35
+ utopic = "utopic.cli:main"
36
+ utopic-server = "utopic.server:main"
37
+ utopic-mcp = "utopic.mcp:main"
38
+ utopic-acp = "utopic.acp:main"
39
+
40
+ [tool.setuptools.packages.find]
41
+ where = ["python"]
@@ -0,0 +1,5 @@
1
+ """Python launchers for the Utopic native runtime."""
2
+
3
+ __all__ = ["__version__"]
4
+
5
+ __version__ = "0.1.0"
@@ -0,0 +1,27 @@
1
+ import os
2
+ import sys
3
+ from pathlib import Path
4
+ from typing import Optional, Sequence
5
+
6
+ from . import installer
7
+
8
+
9
+ def _binary_suffix() -> str:
10
+ return ".exe" if os.name == "nt" else ""
11
+
12
+
13
+ def binary_path(name: str) -> Path:
14
+ suffix = _binary_suffix()
15
+ path = installer.bin_dir() / f"{name}{suffix}"
16
+ if not path.exists():
17
+ raise RuntimeError(
18
+ f"Utopic native binary is not installed: {path}. "
19
+ "Run `utopic setup` to build and cache the native runtime."
20
+ )
21
+ return path
22
+
23
+
24
+ def main(binary_name: str, argv: Optional[Sequence[str]] = None) -> None:
25
+ args = list(sys.argv[1:] if argv is None else argv)
26
+ exe = binary_path(binary_name)
27
+ os.execv(str(exe), [str(exe), *args])
@@ -0,0 +1,5 @@
1
+ from ._native import main as _main
2
+
3
+
4
+ def main() -> None:
5
+ _main("utopic_acp")
@@ -0,0 +1,12 @@
1
+ import sys
2
+
3
+ from . import _native, installer
4
+
5
+
6
+ def main() -> None:
7
+ args = sys.argv[1:]
8
+ if args and args[0] == "setup":
9
+ raise SystemExit(installer.setup(args[1:]))
10
+ if args and args[0] == "run":
11
+ args = args[1:]
12
+ _native.main("utopic", args)
@@ -0,0 +1,324 @@
1
+ import argparse
2
+ import os
3
+ import shutil
4
+ import subprocess
5
+ from pathlib import Path
6
+ from typing import Mapping, Optional, Sequence
7
+
8
+
9
+ PACKAGE_DIR = Path(__file__).resolve().parent
10
+ UTOPIC_NATIVE_REPO = "https://github.com/adavyas/utopic.git"
11
+ UTOPIC_NATIVE_REF = "8f89b1351ee9908eeffec1f202e3737faaf028f7"
12
+ LLAMA_REPO = "https://github.com/ggml-org/llama.cpp.git"
13
+ LLAMA_REF = "9b4dae81f48b96765b6e24539c229c6ec304fc6c"
14
+ BIN_NAMES = ("utopic", "utopic_server", "utopic_mcp", "utopic_acp")
15
+ REQUIRED_LLAMA_SYMBOLS = (
16
+ "llama_diffusion_set_sc",
17
+ "llama_diffusion_device_sample",
18
+ "llama_diffusion_set_phase",
19
+ )
20
+ LLAMA_CMAKE_FLAGS = (
21
+ "-DLLAMA_BUILD_EXAMPLES=OFF",
22
+ "-DLLAMA_BUILD_TESTS=OFF",
23
+ "-DLLAMA_BUILD_TOOLS=OFF",
24
+ "-DLLAMA_BUILD_SERVER=OFF",
25
+ "-DLLAMA_BUILD_APP=OFF",
26
+ )
27
+ BACKENDS = ("auto", "cpu", "cuda")
28
+
29
+
30
+ def _positive_int(value: str) -> int:
31
+ parsed = int(value)
32
+ if parsed < 1:
33
+ raise argparse.ArgumentTypeError("must be at least 1")
34
+ return parsed
35
+
36
+
37
+ def cache_root() -> Path:
38
+ configured = os.environ.get("UTOPIC_HOME")
39
+ if configured:
40
+ return Path(configured).expanduser()
41
+ return Path.home() / ".cache" / "utopic"
42
+
43
+
44
+ def source_root() -> Path:
45
+ return cache_root() / "src"
46
+
47
+
48
+ def build_root() -> Path:
49
+ return cache_root() / "build"
50
+
51
+
52
+ def bin_dir() -> Path:
53
+ configured = os.environ.get("UTOPIC_BIN_DIR")
54
+ if configured:
55
+ return Path(configured).expanduser()
56
+ return cache_root() / "bin"
57
+
58
+
59
+ def default_native_dir() -> Path:
60
+ configured = os.environ.get("UTOPIC_NATIVE_DIR")
61
+ if configured:
62
+ return Path(configured).expanduser()
63
+ return source_root() / "Utopic"
64
+
65
+
66
+ def default_llama_dir() -> Path:
67
+ configured = os.environ.get("UTOPIC_LLAMACPP_DIR")
68
+ if configured:
69
+ return Path(configured).expanduser()
70
+ return source_root() / "llama.cpp"
71
+
72
+
73
+ def _run(
74
+ command: Sequence[object],
75
+ *,
76
+ cwd: Optional[Path] = None,
77
+ env: Optional[Mapping[str, str]] = None,
78
+ dry_run: bool = False,
79
+ ) -> None:
80
+ printable = " ".join(str(part) for part in command)
81
+ print(f"+ {printable}")
82
+ if dry_run:
83
+ return
84
+ subprocess.run(
85
+ [str(part) for part in command],
86
+ cwd=None if cwd is None else str(cwd),
87
+ env=None if env is None else dict(env),
88
+ check=True,
89
+ )
90
+
91
+
92
+ def _clone_or_checkout(repo: str, ref: str, dest: Path, *, dry_run: bool, reset: bool = False) -> None:
93
+ if dest.exists():
94
+ _run(["git", "fetch", "--all", "--tags"], cwd=dest, dry_run=dry_run)
95
+ else:
96
+ if not dry_run:
97
+ dest.parent.mkdir(parents=True, exist_ok=True)
98
+ _run(["git", "clone", repo, dest], dry_run=dry_run)
99
+ _run(["git", "checkout", ref], cwd=dest, dry_run=dry_run)
100
+ if reset:
101
+ _run(["git", "reset", "--hard", ref], cwd=dest, dry_run=dry_run)
102
+
103
+
104
+ def _cuda_compiler_candidates(cuda_architectures: Optional[str] = None) -> list[Path]:
105
+ candidates: list[Path] = []
106
+
107
+ def append(path: Path) -> None:
108
+ if path not in candidates:
109
+ candidates.append(path)
110
+
111
+ configured = os.environ.get("CUDACXX")
112
+ if configured:
113
+ append(Path(configured).expanduser())
114
+
115
+ arch_parts = (cuda_architectures or "").replace(",", ";").split(";")
116
+ if any(part.strip().startswith("12") for part in arch_parts):
117
+ append(Path("/usr/local/cuda-13.0/bin/nvcc"))
118
+ append(Path("/usr/local/cuda-13/bin/nvcc"))
119
+
120
+ found = shutil.which("nvcc")
121
+ if found:
122
+ append(Path(found))
123
+
124
+ for candidate in (
125
+ Path("/usr/local/cuda/bin/nvcc"),
126
+ Path("/usr/local/cuda-12.4/bin/nvcc"),
127
+ Path("/usr/local/cuda-12.3/bin/nvcc"),
128
+ Path("/usr/local/cuda-12.2/bin/nvcc"),
129
+ Path("/usr/local/cuda-12.1/bin/nvcc"),
130
+ Path("/usr/local/cuda-12.0/bin/nvcc"),
131
+ ):
132
+ append(candidate)
133
+ return candidates
134
+
135
+
136
+ def _find_cuda_compiler(cuda_architectures: Optional[str] = None) -> Optional[Path]:
137
+ for candidate in _cuda_compiler_candidates(cuda_architectures):
138
+ if candidate.exists():
139
+ return candidate
140
+ return None
141
+
142
+
143
+ def _detect_cuda_architectures() -> Optional[str]:
144
+ try:
145
+ completed = subprocess.run(
146
+ ["nvidia-smi", "--query-gpu=compute_cap", "--format=csv,noheader"],
147
+ check=True,
148
+ capture_output=True,
149
+ text=True,
150
+ )
151
+ except (OSError, subprocess.CalledProcessError):
152
+ return None
153
+
154
+ arches: list[str] = []
155
+ for line in completed.stdout.splitlines():
156
+ cap = line.strip()
157
+ if not cap:
158
+ continue
159
+ arch = cap.replace(".", "")
160
+ if arch and arch not in arches:
161
+ arches.append(arch)
162
+ return ";".join(arches) if arches else None
163
+
164
+
165
+ def _build_command(build_dir: Path, *, jobs: Optional[int]) -> list[object]:
166
+ command: list[object] = ["cmake", "--build", build_dir, "-j"]
167
+ if jobs is not None:
168
+ command.append(str(jobs))
169
+ return command
170
+
171
+
172
+ def _build_llama(
173
+ llama_dir: Path,
174
+ *,
175
+ backend: str,
176
+ cuda_architectures: Optional[str],
177
+ jobs: Optional[int],
178
+ dry_run: bool,
179
+ ) -> None:
180
+ command = ["cmake", "-B", llama_dir / "build", "-S", llama_dir, *LLAMA_CMAKE_FLAGS]
181
+ if backend == "cpu":
182
+ command.extend(["-DGGML_CUDA=OFF", "-DGGML_METAL=OFF"])
183
+ elif backend == "cuda":
184
+ command.append("-DGGML_CUDA=ON")
185
+ if cuda_architectures is None:
186
+ cuda_architectures = _detect_cuda_architectures()
187
+ cuda_compiler = _find_cuda_compiler(cuda_architectures)
188
+ if cuda_compiler:
189
+ command.append(f"-DCMAKE_CUDA_COMPILER={cuda_compiler}")
190
+ if cuda_architectures:
191
+ command.append(f"-DCMAKE_CUDA_ARCHITECTURES={cuda_architectures}")
192
+ _run(command, dry_run=dry_run)
193
+ _run(_build_command(llama_dir / "build", jobs=jobs), dry_run=dry_run)
194
+
195
+
196
+ def _verify_llama_apis(llama_dir: Path) -> None:
197
+ header = llama_dir / "include" / "llama.h"
198
+ if not header.exists():
199
+ raise RuntimeError(
200
+ f"Utopic native dependency header was not found: {header}. "
201
+ "Run `utopic setup --force` to refresh the package-managed sources."
202
+ )
203
+ text = header.read_text(encoding="utf-8")
204
+ missing = [symbol for symbol in REQUIRED_LLAMA_SYMBOLS if symbol not in text]
205
+ if missing:
206
+ names = ", ".join(missing)
207
+ raise RuntimeError(
208
+ "The Utopic native dependency is missing required diffusion APIs: "
209
+ f"{names}. Run `utopic setup --force` to refresh the package-managed sources."
210
+ )
211
+
212
+
213
+ def _build_utopic(native_dir: Path, llama_dir: Path, *, jobs: Optional[int], dry_run: bool) -> Path:
214
+ out_dir = build_root() / "utopic"
215
+
216
+ _run(
217
+ ["cmake", "-B", out_dir, "-S", native_dir / "native", f"-DUTOPIC_LLAMACPP_DIR={llama_dir}"],
218
+ dry_run=dry_run,
219
+ )
220
+ _run(_build_command(out_dir, jobs=jobs), dry_run=dry_run)
221
+ return out_dir
222
+
223
+
224
+ def _install_binaries(build_dir: Path) -> None:
225
+ dest_dir = bin_dir()
226
+ dest_dir.mkdir(parents=True, exist_ok=True)
227
+ suffix = ".exe" if os.name == "nt" else ""
228
+
229
+ for name in BIN_NAMES:
230
+ src = build_dir / f"{name}{suffix}"
231
+ if not src.exists():
232
+ raise RuntimeError(f"Expected Utopic build output was not found: {src}")
233
+ dest = dest_dir / src.name
234
+ shutil.copy2(src, dest)
235
+ dest.chmod(0o755)
236
+
237
+
238
+ def setup(argv: Optional[Sequence[str]] = None) -> int:
239
+ parser = argparse.ArgumentParser(
240
+ prog="utopic setup",
241
+ description="Build and cache Utopic from package-managed native sources.",
242
+ )
243
+ parser.add_argument(
244
+ "--backend",
245
+ choices=BACKENDS,
246
+ default=os.environ.get("UTOPIC_BACKEND", "auto"),
247
+ help="Native acceleration backend to build. Use cuda on NVIDIA hosts.",
248
+ )
249
+ parser.add_argument("--cuda", action="store_true", help=argparse.SUPPRESS)
250
+ parser.add_argument(
251
+ "--cuda-architectures",
252
+ default=os.environ.get("UTOPIC_CUDA_ARCHITECTURES"),
253
+ help="CUDA architecture list for the Utopic native build, for example 89 on RTX 4090 hosts.",
254
+ )
255
+ parser.add_argument("--dry-run", action="store_true", help="Print commands without running them.")
256
+ parser.add_argument("--force", action="store_true", help="Remove cached binaries before rebuilding.")
257
+ parser.add_argument(
258
+ "--jobs",
259
+ type=_positive_int,
260
+ default=int(os.environ["UTOPIC_BUILD_JOBS"]) if os.environ.get("UTOPIC_BUILD_JOBS") else None,
261
+ help="Limit native build parallelism when disk or temporary space is constrained.",
262
+ )
263
+ parser.add_argument("--llama-dir", help=argparse.SUPPRESS)
264
+ parser.add_argument("--native-dir", help=argparse.SUPPRESS)
265
+ parser.add_argument(
266
+ "--skip-llama-build",
267
+ action="store_true",
268
+ help=argparse.SUPPRESS,
269
+ )
270
+ args = parser.parse_args(list(argv) if argv is not None else None)
271
+
272
+ dry_run = bool(args.dry_run)
273
+ backend = "cuda" if args.cuda else args.backend
274
+ llama_dir = Path(args.llama_dir).expanduser() if args.llama_dir else default_llama_dir()
275
+ native_dir = Path(args.native_dir).expanduser() if args.native_dir else default_native_dir()
276
+
277
+ if args.force and bin_dir().exists():
278
+ print(f"+ remove {bin_dir()}")
279
+ if not dry_run:
280
+ shutil.rmtree(bin_dir())
281
+
282
+ if args.llama_dir or os.environ.get("UTOPIC_LLAMACPP_DIR"):
283
+ print(f"Using maintainer-provided native dependency source at {llama_dir}")
284
+ else:
285
+ print(f"Managing native dependency source at {llama_dir}")
286
+ _clone_or_checkout(
287
+ os.environ.get("UTOPIC_LLAMA_REPO", LLAMA_REPO),
288
+ os.environ.get("UTOPIC_LLAMA_REF", LLAMA_REF),
289
+ llama_dir,
290
+ dry_run=dry_run,
291
+ reset=True,
292
+ )
293
+
294
+ if not dry_run:
295
+ _verify_llama_apis(llama_dir)
296
+
297
+ if not args.skip_llama_build:
298
+ _build_llama(
299
+ llama_dir,
300
+ backend=backend,
301
+ cuda_architectures=args.cuda_architectures,
302
+ jobs=args.jobs,
303
+ dry_run=dry_run,
304
+ )
305
+
306
+ if args.native_dir or os.environ.get("UTOPIC_NATIVE_DIR"):
307
+ print(f"Using external Utopic source at {native_dir}")
308
+ else:
309
+ print(f"Managing Utopic source at {native_dir}")
310
+ _clone_or_checkout(
311
+ os.environ.get("UTOPIC_NATIVE_REPO", UTOPIC_NATIVE_REPO),
312
+ os.environ.get("UTOPIC_NATIVE_REF", UTOPIC_NATIVE_REF),
313
+ native_dir,
314
+ dry_run=dry_run,
315
+ )
316
+
317
+ native_build_dir = _build_utopic(native_dir, llama_dir, jobs=args.jobs, dry_run=dry_run)
318
+ if dry_run:
319
+ print(f"Would install Utopic native binaries to {bin_dir()}")
320
+ return 0
321
+
322
+ _install_binaries(native_build_dir)
323
+ print(f"Installed Utopic native binaries to {bin_dir()}")
324
+ return 0
@@ -0,0 +1,5 @@
1
+ from ._native import main as _main
2
+
3
+
4
+ def main() -> None:
5
+ _main("utopic_mcp")
@@ -0,0 +1,5 @@
1
+ from ._native import main as _main
2
+
3
+
4
+ def main() -> None:
5
+ _main("utopic_server")
@@ -0,0 +1,139 @@
1
+ Metadata-Version: 2.4
2
+ Name: utopic
3
+ Version: 0.1.0
4
+ Summary: Python package manager for the Utopic native runtime
5
+ Author: Utopic contributors
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/adavyas/utopic-package-manager
8
+ Project-URL: Source, https://github.com/adavyas/utopic-package-manager
9
+ Project-URL: NativeRuntime, https://github.com/adavyas/utopic
10
+ Keywords: diffusion,llm,gguf,llama.cpp,inference
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: Apache Software License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
18
+ Requires-Python: >=3.9
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Dynamic: license-file
22
+ Dynamic: requires-python
23
+
24
+ # Utopic Package Manager
25
+
26
+ Python package management for the Utopic native runtime.
27
+
28
+ This repository is intentionally thin. The wheel installs Python launchers only.
29
+ Native source checkout, build configuration, and binary installation all happen
30
+ later through `utopic setup`.
31
+
32
+ ## Install
33
+
34
+ ```sh
35
+ pip install git+https://github.com/adavyas/utopic-package-manager.git
36
+ utopic setup
37
+ ```
38
+
39
+ On Linux distributions that enforce PEP 668, install the launcher in an isolated
40
+ environment instead of the system Python:
41
+
42
+ ```sh
43
+ python3 -m venv ~/.venvs/utopic
44
+ ~/.venvs/utopic/bin/pip install git+https://github.com/adavyas/utopic-package-manager.git
45
+ ~/.venvs/utopic/bin/utopic setup
46
+ ```
47
+
48
+ `utopic setup` builds from package-managed native sources and installs the
49
+ runtime binaries under `~/.cache/utopic/bin`.
50
+
51
+ On NVIDIA hosts, build the CUDA backend:
52
+
53
+ ```sh
54
+ utopic setup --backend cuda
55
+ ```
56
+
57
+ The CUDA setup path detects the local GPU architecture and selects a suitable
58
+ CUDA compiler when possible, including CUDA 13 on GB10/DGX Spark hosts. On
59
+ constrained hosts, limit build parallelism:
60
+
61
+ ```sh
62
+ utopic setup --backend cuda --jobs 2
63
+ ```
64
+
65
+ If a Mac cannot initialize Metal, or you want a portable CPU-only build:
66
+
67
+ ```sh
68
+ utopic setup --backend cpu
69
+ ```
70
+
71
+ For local development from this checkout:
72
+
73
+ ```sh
74
+ git clone https://github.com/adavyas/utopic-package-manager.git
75
+ cd utopic-package-manager
76
+ pip install .
77
+ utopic setup
78
+ ```
79
+
80
+ ## Commands
81
+
82
+ The package installs these launchers:
83
+
84
+ - `utopic`
85
+ - `utopic-server`
86
+ - `utopic-mcp`
87
+ - `utopic-acp`
88
+
89
+ Run a one-shot prompt:
90
+
91
+ ```sh
92
+ utopic run -m /path/to/model.gguf -p "Answer with one word: 2+2?" -n 16
93
+ ```
94
+
95
+ For DiffusionGemma-style canvas models, use the entropy-bound path:
96
+
97
+ ```sh
98
+ utopic run -m /path/to/diffusiongemma.gguf -p "Answer with one word: 2+2?" -n 16 --eb-steps 48
99
+ ```
100
+
101
+ Run the OpenAI-compatible local server:
102
+
103
+ ```sh
104
+ utopic-server -m /path/to/model.gguf --host 127.0.0.1 --port 8910 -ngl 99
105
+ ```
106
+
107
+ Health and model list:
108
+
109
+ ```sh
110
+ curl http://127.0.0.1:8910/health
111
+ curl http://127.0.0.1:8910/v1/models
112
+ ```
113
+
114
+ ## What Setup Owns
115
+
116
+ The package manager owns the user-facing setup path:
117
+
118
+ - fetch the pinned compatible native runtime and dependency sources
119
+ - configure the native build for CPU or CUDA, including CUDA compiler and architecture detection
120
+ - build the dependency layer and Utopic
121
+ - copy the final binaries into the Utopic cache
122
+
123
+ The published wheel stays pure Python and does not fetch or compile native code
124
+ during `pip install`. Users should not need to clone dependency repositories or
125
+ run build-system commands directly for normal setup.
126
+
127
+ Use the package-managed binary produced by `utopic setup` for user-facing runs.
128
+ On the 2026-06-21 GB10 smoke, `/home/adavya/.cache/utopic-current/bin/utopic`
129
+ successfully generated from the installed Dream Q4, LLaDA Q4, DiffusionGemma
130
+ BF16, and DiffusionGemma Q4 GGUFs. The repo-local native build loaded the same
131
+ files, but was stale for DiffusionGemma prompt wrapping.
132
+
133
+ ## Development
134
+
135
+ Build a wheel:
136
+
137
+ ```sh
138
+ python -m pip wheel . --no-deps -w dist/
139
+ ```
@@ -0,0 +1,16 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ setup.py
5
+ python/utopic/__init__.py
6
+ python/utopic/_native.py
7
+ python/utopic/acp.py
8
+ python/utopic/cli.py
9
+ python/utopic/installer.py
10
+ python/utopic/mcp.py
11
+ python/utopic/server.py
12
+ python/utopic.egg-info/PKG-INFO
13
+ python/utopic.egg-info/SOURCES.txt
14
+ python/utopic.egg-info/dependency_links.txt
15
+ python/utopic.egg-info/entry_points.txt
16
+ python/utopic.egg-info/top_level.txt
@@ -0,0 +1,5 @@
1
+ [console_scripts]
2
+ utopic = utopic.cli:main
3
+ utopic-acp = utopic.acp:main
4
+ utopic-mcp = utopic.mcp:main
5
+ utopic-server = utopic.server:main
@@ -0,0 +1 @@
1
+ utopic
utopic-0.1.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
utopic-0.1.0/setup.py ADDED
@@ -0,0 +1,20 @@
1
+ from setuptools import find_packages, setup
2
+
3
+
4
+ setup(
5
+ name="utopic",
6
+ version="0.1.0",
7
+ description="Python package manager for the Utopic native runtime",
8
+ package_dir={"": "python"},
9
+ packages=find_packages(where="python"),
10
+ package_data={"utopic": ["patches/*.patch"]},
11
+ python_requires=">=3.9",
12
+ entry_points={
13
+ "console_scripts": [
14
+ "utopic=utopic.cli:main",
15
+ "utopic-server=utopic.server:main",
16
+ "utopic-mcp=utopic.mcp:main",
17
+ "utopic-acp=utopic.acp:main",
18
+ ],
19
+ },
20
+ )