haru-speech-mlx 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.
- haru_speech_mlx-0.1.0/LICENSE +201 -0
- haru_speech_mlx-0.1.0/PKG-INFO +142 -0
- haru_speech_mlx-0.1.0/README.md +118 -0
- haru_speech_mlx-0.1.0/THIRD_PARTY_NOTICES.md +157 -0
- haru_speech_mlx-0.1.0/haru_mlx/__init__.py +31 -0
- haru_speech_mlx-0.1.0/haru_mlx/assets/card_templates.json +231 -0
- haru_speech_mlx-0.1.0/haru_mlx/assets/cards/de.json +9 -0
- haru_speech_mlx-0.1.0/haru_mlx/assets/cards/en.json +9 -0
- haru_speech_mlx-0.1.0/haru_mlx/assets/cards/es.json +9 -0
- haru_speech_mlx-0.1.0/haru_mlx/assets/cards/fr.json +9 -0
- haru_speech_mlx-0.1.0/haru_mlx/assets/cards/ja.json +9 -0
- haru_speech_mlx-0.1.0/haru_mlx/assets/cards/ko.json +9 -0
- haru_speech_mlx-0.1.0/haru_mlx/assets/cards/pt.json +9 -0
- haru_speech_mlx-0.1.0/haru_mlx/assets/cards/ru.json +9 -0
- haru_speech_mlx-0.1.0/haru_mlx/assets/cards/zh.json +9 -0
- haru_speech_mlx-0.1.0/haru_mlx/audio.py +80 -0
- haru_speech_mlx-0.1.0/haru_mlx/backends.py +196 -0
- haru_speech_mlx-0.1.0/haru_mlx/config.py +95 -0
- haru_speech_mlx-0.1.0/haru_mlx/frames.py +33 -0
- haru_speech_mlx-0.1.0/haru_mlx/hub.py +18 -0
- haru_speech_mlx-0.1.0/haru_mlx/lm_config.py +78 -0
- haru_speech_mlx-0.1.0/haru_mlx/models/__init__.py +6 -0
- haru_speech_mlx-0.1.0/haru_mlx/models/gated_delta.py +148 -0
- haru_speech_mlx-0.1.0/haru_mlx/models/haru.py +144 -0
- haru_speech_mlx-0.1.0/haru_mlx/models/loaders.py +64 -0
- haru_speech_mlx-0.1.0/haru_mlx/models/meanflow_head.py +165 -0
- haru_speech_mlx-0.1.0/haru_mlx/models/qwen3_5.py +289 -0
- haru_speech_mlx-0.1.0/haru_mlx/models/vibevoice_codec.py +387 -0
- haru_speech_mlx-0.1.0/haru_mlx/native.py +384 -0
- haru_speech_mlx-0.1.0/haru_mlx/prompt.py +151 -0
- haru_speech_mlx-0.1.0/haru_mlx/run_inference.py +92 -0
- haru_speech_mlx-0.1.0/haru_mlx/sampling.py +143 -0
- haru_speech_mlx-0.1.0/haru_mlx/session.py +184 -0
- haru_speech_mlx-0.1.0/haru_mlx/weights.py +236 -0
- haru_speech_mlx-0.1.0/haru_mlx/worker.py +75 -0
- haru_speech_mlx-0.1.0/haru_speech_mlx.egg-info/PKG-INFO +142 -0
- haru_speech_mlx-0.1.0/haru_speech_mlx.egg-info/SOURCES.txt +49 -0
- haru_speech_mlx-0.1.0/haru_speech_mlx.egg-info/dependency_links.txt +1 -0
- haru_speech_mlx-0.1.0/haru_speech_mlx.egg-info/entry_points.txt +3 -0
- haru_speech_mlx-0.1.0/haru_speech_mlx.egg-info/requires.txt +9 -0
- haru_speech_mlx-0.1.0/haru_speech_mlx.egg-info/top_level.txt +1 -0
- haru_speech_mlx-0.1.0/pyproject.toml +49 -0
- haru_speech_mlx-0.1.0/setup.cfg +4 -0
- haru_speech_mlx-0.1.0/tests/test_audio.py +53 -0
- haru_speech_mlx-0.1.0/tests/test_imports.py +50 -0
- haru_speech_mlx-0.1.0/tests/test_model.py +176 -0
- haru_speech_mlx-0.1.0/tests/test_parity.py +129 -0
- haru_speech_mlx-0.1.0/tests/test_prompt.py +113 -0
- haru_speech_mlx-0.1.0/tests/test_sampling.py +79 -0
- haru_speech_mlx-0.1.0/tests/test_shared_code.py +91 -0
- haru_speech_mlx-0.1.0/tests/test_weights.py +109 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: haru-speech-mlx
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Haru on Apple silicon: the MLX implementation of the full-duplex spoken dialogue model
|
|
5
|
+
Author: higurashi
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://higurashi.ai
|
|
8
|
+
Project-URL: Repository, https://github.com/higurashi-ai/Haru
|
|
9
|
+
Project-URL: Issues, https://github.com/higurashi-ai/Haru/issues
|
|
10
|
+
Project-URL: Model, https://huggingface.co/higurashi-ai/Haru-4B
|
|
11
|
+
Requires-Python: >=3.10
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
License-File: THIRD_PARTY_NOTICES.md
|
|
15
|
+
Requires-Dist: mlx>=0.32
|
|
16
|
+
Requires-Dist: tokenizers>=0.21
|
|
17
|
+
Requires-Dist: huggingface-hub>=0.26
|
|
18
|
+
Requires-Dist: numpy>=1.26
|
|
19
|
+
Requires-Dist: scipy>=1.13
|
|
20
|
+
Requires-Dist: soundfile>=0.13
|
|
21
|
+
Provides-Extra: dev
|
|
22
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# haru_mlx
|
|
26
|
+
|
|
27
|
+
<!-- This README is also the project description on PyPI, where relative links do not resolve. Link to other files in the repository with absolute GitHub URLs. -->
|
|
28
|
+
|
|
29
|
+
Haru on Apple silicon: the [MLX](https://github.com/ml-explore/mlx)
|
|
30
|
+
implementation of the Haru full-duplex spoken dialogue model. It loads the
|
|
31
|
+
same checkpoint as the PyTorch package `haru` (`higurashi-ai/Haru-4B`) and has
|
|
32
|
+
the same Python API.
|
|
33
|
+
|
|
34
|
+
Haru listens and speaks at the same time. Every 133 ms it takes one frame of
|
|
35
|
+
your audio and produces one frame of its own speech together with its text.
|
|
36
|
+
|
|
37
|
+
## Install
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pip install -e . # from this directory
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Requires a Mac with Apple silicon and Python 3.10 or later. The checkpoint is
|
|
44
|
+
about 10 GB; it is downloaded from Hugging Face on first use.
|
|
45
|
+
|
|
46
|
+
## Talk to it
|
|
47
|
+
|
|
48
|
+
**[Haru for macOS](https://github.com/higurashi-ai/Haru/blob/main/haru_mlx/swift/README.md)** is the way to talk to the model on a
|
|
49
|
+
Mac: a native app that handles the microphone and speakers with Core Audio and
|
|
50
|
+
runs this package as its model server. Build it with `swift/build_app.sh`.
|
|
51
|
+
|
|
52
|
+
Haru ships without voice clips: in the app, choose or record a clip of the
|
|
53
|
+
voice the model should speak with (one speaker, 3 seconds to 3 minutes). Only
|
|
54
|
+
use voices you have the right to use.
|
|
55
|
+
|
|
56
|
+
To give the app a default voice, save a clip as
|
|
57
|
+
`haru_mlx/assets/voices/<language>.flac` (`en.flac`, `ja.flac`, ...; the path
|
|
58
|
+
is relative to this directory) and reopen the app: it then offers the clip as
|
|
59
|
+
the default voice of that language. Without the file, the app does not show
|
|
60
|
+
the option.
|
|
61
|
+
|
|
62
|
+
## Offline
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
python -m haru_mlx.run_inference user.wav reply.wav --reference voice.wav --system-prompt "..."
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
A recording in, the model's side of the conversation out. `--model DIR` or
|
|
69
|
+
`--hf-repo REPO` selects the checkpoint, and `--quantize` its precision. The
|
|
70
|
+
app starts in bfloat16 and can switch to 8-bit in its settings:
|
|
71
|
+
|
|
72
|
+
| `--quantize` | Backbone weights |
|
|
73
|
+
|---|---|
|
|
74
|
+
| `none` (default) | bfloat16, as published |
|
|
75
|
+
| `8` | 8-bit: smaller, and a frame reads fewer bytes |
|
|
76
|
+
|
|
77
|
+
Quantization covers the language model's weight matrices and the embedding
|
|
78
|
+
table; the audio codec, the audio head and all normalization gains keep the
|
|
79
|
+
checkpoint's precision.
|
|
80
|
+
|
|
81
|
+
## Python API
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
import numpy as np
|
|
85
|
+
from haru_mlx import DuplexConfig, DuplexSession, HaruModel
|
|
86
|
+
from haru_mlx.audio import load_audio, prepare_reference
|
|
87
|
+
|
|
88
|
+
model = HaruModel.from_pretrained("higurashi-ai/Haru-4B") # quantize=8 for an 8-bit backbone
|
|
89
|
+
voice = prepare_reference(load_audio("voice.wav")) # mono float32, 24 kHz
|
|
90
|
+
session = DuplexSession(model, system_prompt="...", reference=voice, config=DuplexConfig(seed=0))
|
|
91
|
+
|
|
92
|
+
frame = session.start() # model frame 0
|
|
93
|
+
while not frame.done:
|
|
94
|
+
user = np.zeros(3200, dtype=np.float32) # 133 ms of your audio
|
|
95
|
+
frame = session.step(user) # -> frame.audio (3200 samples), frame.text
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
`DuplexConfig` has the same fields as in `haru`. A live client can also hand
|
|
99
|
+
over microphone audio as it arrives, which spreads the audio encoder's work
|
|
100
|
+
over the frame:
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
session.feed(block) # any length, as the microphone delivers it
|
|
104
|
+
if session.frames_ready:
|
|
105
|
+
frame = session.step()
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
MLX keeps its GPU streams per thread: load the model and drive its sessions
|
|
109
|
+
from one thread (`haru_mlx.worker.MLXWorker` is that thread for the app's
|
|
110
|
+
model server).
|
|
111
|
+
|
|
112
|
+
## Metal kernels
|
|
113
|
+
|
|
114
|
+
Two inner loops of a frame run as custom Metal kernels: the Gated DeltaNet
|
|
115
|
+
recurrence of the language model and the depthwise convolution blocks of the
|
|
116
|
+
audio codec. Both have plain MLX fallbacks with the same results, which are
|
|
117
|
+
used on devices without Metal.
|
|
118
|
+
|
|
119
|
+
## Layout
|
|
120
|
+
|
|
121
|
+
| Module | |
|
|
122
|
+
|---|---|
|
|
123
|
+
| `models/haru.py` | `HaruModel`: the three input streams, the backbone, text logits |
|
|
124
|
+
| `models/qwen3_5.py` | Qwen3.5 text backbone (Gated DeltaNet + attention), laid out for one position per frame |
|
|
125
|
+
| `models/gated_delta.py` | the Gated DeltaNet recurrence (Metal kernel, with an array fallback) |
|
|
126
|
+
| `models/meanflow_head.py` | one-step MeanFlow head: hidden state -> audio latent |
|
|
127
|
+
| `models/vibevoice_codec.py` | VibeVoice acoustic codec, streaming (Metal kernel for its depthwise convolutions, with an array fallback) |
|
|
128
|
+
| `models/loaders.py`, `weights.py` | checkpoint loading; the tensor -> parameter mapping |
|
|
129
|
+
| `session.py` | `DuplexSession`: one conversation |
|
|
130
|
+
| `native.py` | the model server of the macOS app (a Unix socket) |
|
|
131
|
+
| `run_inference.py` | offline inference |
|
|
132
|
+
|
|
133
|
+
## Tests
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
pip install -e ".[dev]"
|
|
137
|
+
pytest # the tests that need no checkpoint
|
|
138
|
+
HARU_MODEL=/path/to/Haru-4B pytest # + checkpoint coverage and a short conversation
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Most tests run without MLX. [`tests/README.md`](https://github.com/higurashi-ai/Haru/blob/main/haru_mlx/tests/README.md) describes the
|
|
142
|
+
numerical comparison with the PyTorch package and the checks to run on a Mac.
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# haru_mlx
|
|
2
|
+
|
|
3
|
+
<!-- This README is also the project description on PyPI, where relative links do not resolve. Link to other files in the repository with absolute GitHub URLs. -->
|
|
4
|
+
|
|
5
|
+
Haru on Apple silicon: the [MLX](https://github.com/ml-explore/mlx)
|
|
6
|
+
implementation of the Haru full-duplex spoken dialogue model. It loads the
|
|
7
|
+
same checkpoint as the PyTorch package `haru` (`higurashi-ai/Haru-4B`) and has
|
|
8
|
+
the same Python API.
|
|
9
|
+
|
|
10
|
+
Haru listens and speaks at the same time. Every 133 ms it takes one frame of
|
|
11
|
+
your audio and produces one frame of its own speech together with its text.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install -e . # from this directory
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Requires a Mac with Apple silicon and Python 3.10 or later. The checkpoint is
|
|
20
|
+
about 10 GB; it is downloaded from Hugging Face on first use.
|
|
21
|
+
|
|
22
|
+
## Talk to it
|
|
23
|
+
|
|
24
|
+
**[Haru for macOS](https://github.com/higurashi-ai/Haru/blob/main/haru_mlx/swift/README.md)** is the way to talk to the model on a
|
|
25
|
+
Mac: a native app that handles the microphone and speakers with Core Audio and
|
|
26
|
+
runs this package as its model server. Build it with `swift/build_app.sh`.
|
|
27
|
+
|
|
28
|
+
Haru ships without voice clips: in the app, choose or record a clip of the
|
|
29
|
+
voice the model should speak with (one speaker, 3 seconds to 3 minutes). Only
|
|
30
|
+
use voices you have the right to use.
|
|
31
|
+
|
|
32
|
+
To give the app a default voice, save a clip as
|
|
33
|
+
`haru_mlx/assets/voices/<language>.flac` (`en.flac`, `ja.flac`, ...; the path
|
|
34
|
+
is relative to this directory) and reopen the app: it then offers the clip as
|
|
35
|
+
the default voice of that language. Without the file, the app does not show
|
|
36
|
+
the option.
|
|
37
|
+
|
|
38
|
+
## Offline
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
python -m haru_mlx.run_inference user.wav reply.wav --reference voice.wav --system-prompt "..."
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
A recording in, the model's side of the conversation out. `--model DIR` or
|
|
45
|
+
`--hf-repo REPO` selects the checkpoint, and `--quantize` its precision. The
|
|
46
|
+
app starts in bfloat16 and can switch to 8-bit in its settings:
|
|
47
|
+
|
|
48
|
+
| `--quantize` | Backbone weights |
|
|
49
|
+
|---|---|
|
|
50
|
+
| `none` (default) | bfloat16, as published |
|
|
51
|
+
| `8` | 8-bit: smaller, and a frame reads fewer bytes |
|
|
52
|
+
|
|
53
|
+
Quantization covers the language model's weight matrices and the embedding
|
|
54
|
+
table; the audio codec, the audio head and all normalization gains keep the
|
|
55
|
+
checkpoint's precision.
|
|
56
|
+
|
|
57
|
+
## Python API
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
import numpy as np
|
|
61
|
+
from haru_mlx import DuplexConfig, DuplexSession, HaruModel
|
|
62
|
+
from haru_mlx.audio import load_audio, prepare_reference
|
|
63
|
+
|
|
64
|
+
model = HaruModel.from_pretrained("higurashi-ai/Haru-4B") # quantize=8 for an 8-bit backbone
|
|
65
|
+
voice = prepare_reference(load_audio("voice.wav")) # mono float32, 24 kHz
|
|
66
|
+
session = DuplexSession(model, system_prompt="...", reference=voice, config=DuplexConfig(seed=0))
|
|
67
|
+
|
|
68
|
+
frame = session.start() # model frame 0
|
|
69
|
+
while not frame.done:
|
|
70
|
+
user = np.zeros(3200, dtype=np.float32) # 133 ms of your audio
|
|
71
|
+
frame = session.step(user) # -> frame.audio (3200 samples), frame.text
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
`DuplexConfig` has the same fields as in `haru`. A live client can also hand
|
|
75
|
+
over microphone audio as it arrives, which spreads the audio encoder's work
|
|
76
|
+
over the frame:
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
session.feed(block) # any length, as the microphone delivers it
|
|
80
|
+
if session.frames_ready:
|
|
81
|
+
frame = session.step()
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
MLX keeps its GPU streams per thread: load the model and drive its sessions
|
|
85
|
+
from one thread (`haru_mlx.worker.MLXWorker` is that thread for the app's
|
|
86
|
+
model server).
|
|
87
|
+
|
|
88
|
+
## Metal kernels
|
|
89
|
+
|
|
90
|
+
Two inner loops of a frame run as custom Metal kernels: the Gated DeltaNet
|
|
91
|
+
recurrence of the language model and the depthwise convolution blocks of the
|
|
92
|
+
audio codec. Both have plain MLX fallbacks with the same results, which are
|
|
93
|
+
used on devices without Metal.
|
|
94
|
+
|
|
95
|
+
## Layout
|
|
96
|
+
|
|
97
|
+
| Module | |
|
|
98
|
+
|---|---|
|
|
99
|
+
| `models/haru.py` | `HaruModel`: the three input streams, the backbone, text logits |
|
|
100
|
+
| `models/qwen3_5.py` | Qwen3.5 text backbone (Gated DeltaNet + attention), laid out for one position per frame |
|
|
101
|
+
| `models/gated_delta.py` | the Gated DeltaNet recurrence (Metal kernel, with an array fallback) |
|
|
102
|
+
| `models/meanflow_head.py` | one-step MeanFlow head: hidden state -> audio latent |
|
|
103
|
+
| `models/vibevoice_codec.py` | VibeVoice acoustic codec, streaming (Metal kernel for its depthwise convolutions, with an array fallback) |
|
|
104
|
+
| `models/loaders.py`, `weights.py` | checkpoint loading; the tensor -> parameter mapping |
|
|
105
|
+
| `session.py` | `DuplexSession`: one conversation |
|
|
106
|
+
| `native.py` | the model server of the macOS app (a Unix socket) |
|
|
107
|
+
| `run_inference.py` | offline inference |
|
|
108
|
+
|
|
109
|
+
## Tests
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
pip install -e ".[dev]"
|
|
113
|
+
pytest # the tests that need no checkpoint
|
|
114
|
+
HARU_MODEL=/path/to/Haru-4B pytest # + checkpoint coverage and a short conversation
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Most tests run without MLX. [`tests/README.md`](https://github.com/higurashi-ai/Haru/blob/main/haru_mlx/tests/README.md) describes the
|
|
118
|
+
numerical comparison with the PyTorch package and the checks to run on a Mac.
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
Haru is licensed under the Apache License 2.0 (see `LICENSE`). It includes or
|
|
4
|
+
derives from the following third-party work.
|
|
5
|
+
|
|
6
|
+
## VibeVoice acoustic tokenizer
|
|
7
|
+
|
|
8
|
+
The audio codec (`haru/haru/models/vibevoice_codec.py`,
|
|
9
|
+
`haru/haru/codec_triton/`, `haru_mlx/haru_mlx/models/vibevoice_codec.py`) implements
|
|
10
|
+
the architecture of the VibeVoice acoustic tokenizer, and the released model
|
|
11
|
+
weights include its parameters.
|
|
12
|
+
|
|
13
|
+
- Copyright (c) 2025 Microsoft
|
|
14
|
+
- License: MIT
|
|
15
|
+
|
|
16
|
+
## Moshi web client
|
|
17
|
+
|
|
18
|
+
The web client (`client/`, and its built bundle in `haru/haru/static/`) is
|
|
19
|
+
derived from the Moshi web client.
|
|
20
|
+
|
|
21
|
+
- Copyright (c) Kyutai
|
|
22
|
+
- License: MIT (see `client/LICENSE`)
|
|
23
|
+
|
|
24
|
+
## mlx-lm
|
|
25
|
+
|
|
26
|
+
`haru_mlx/haru_mlx/models/gated_delta.py` and `haru_mlx/haru_mlx/models/qwen3_5.py`
|
|
27
|
+
are derived from the Qwen3.5 model code of mlx-lm.
|
|
28
|
+
|
|
29
|
+
- Copyright (c) Apple Inc.
|
|
30
|
+
- License: MIT
|
|
31
|
+
|
|
32
|
+
## Bundled in the web client build
|
|
33
|
+
|
|
34
|
+
| Package | Copyright | License |
|
|
35
|
+
| --- | --- | --- |
|
|
36
|
+
| opus-recorder | Original work Copyright © 2013 Matt Diamond; modified work Copyright © 2014 Christopher Rudmin | MIT |
|
|
37
|
+
| libopus (in the opus-recorder workers) | Copyright 2001-2011 Xiph.Org, Skype Limited, Octasic, Jean-Marc Valin, Timothy B. Terriberry, CSIRO, Gregory Maxwell, Mark Borgerding, Erik de Castro Lopo | BSD-3-Clause (Opus License below) |
|
|
38
|
+
| speexdsp resampler (in the opus-recorder workers) | © 2002-2003, Jean-Marc Valin/Xiph.Org Foundation | BSD-3-Clause (Speex License below) |
|
|
39
|
+
| react, react-dom, scheduler (Meta Platforms, Inc.) | | MIT |
|
|
40
|
+
| lucide-react | | ISC |
|
|
41
|
+
| webm-duration-fix | buynao | ISC (declared in its package.json, which ships no license file) |
|
|
42
|
+
| buffer | Copyright (c) Feross Aboukhadijeh, and other contributors | MIT |
|
|
43
|
+
| base64-js | Copyright (c) 2014 Jameson Little | MIT |
|
|
44
|
+
| ieee754 | Copyright 2008 Fair Oaks Labs, Inc. | BSD-3-Clause (ieee754 License below) |
|
|
45
|
+
| ebml-block | Copyright (c) 2016 Mathias Rasmussen | MIT |
|
|
46
|
+
| int64-buffer | Copyright (c) 2015-2026 Yusuke Kawasaki | MIT |
|
|
47
|
+
| events | Copyright Joyent, Inc. and other Node contributors | MIT |
|
|
48
|
+
| Tailwind CSS (preflight styles) | Copyright (c) Tailwind Labs, Inc. | MIT |
|
|
49
|
+
|
|
50
|
+
## MIT License
|
|
51
|
+
|
|
52
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
53
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
54
|
+
in the Software without restriction, including without limitation the rights
|
|
55
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
56
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
57
|
+
furnished to do so, subject to the following conditions:
|
|
58
|
+
|
|
59
|
+
The above copyright notice and this permission notice shall be included in all
|
|
60
|
+
copies or substantial portions of the Software.
|
|
61
|
+
|
|
62
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
63
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
64
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
65
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
66
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
67
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
68
|
+
SOFTWARE.
|
|
69
|
+
|
|
70
|
+
## Opus License
|
|
71
|
+
|
|
72
|
+
Copyright 2001-2011 Xiph.Org, Skype Limited, Octasic,
|
|
73
|
+
Jean-Marc Valin, Timothy B. Terriberry,
|
|
74
|
+
CSIRO, Gregory Maxwell, Mark Borgerding,
|
|
75
|
+
Erik de Castro Lopo
|
|
76
|
+
|
|
77
|
+
Redistribution and use in source and binary forms, with or without
|
|
78
|
+
modification, are permitted provided that the following conditions
|
|
79
|
+
are met:
|
|
80
|
+
|
|
81
|
+
- Redistributions of source code must retain the above copyright
|
|
82
|
+
notice, this list of conditions and the following disclaimer.
|
|
83
|
+
|
|
84
|
+
- Redistributions in binary form must reproduce the above copyright
|
|
85
|
+
notice, this list of conditions and the following disclaimer in the
|
|
86
|
+
documentation and/or other materials provided with the distribution.
|
|
87
|
+
|
|
88
|
+
- Neither the name of Internet Society, IETF or IETF Trust, nor the
|
|
89
|
+
names of specific contributors, may be used to endorse or promote
|
|
90
|
+
products derived from this software without specific prior written
|
|
91
|
+
permission.
|
|
92
|
+
|
|
93
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
94
|
+
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
95
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
96
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
|
97
|
+
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
98
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
99
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
100
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
101
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
102
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
103
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
104
|
+
|
|
105
|
+
Opus is subject to the royalty-free patent licenses which are
|
|
106
|
+
specified at:
|
|
107
|
+
|
|
108
|
+
Xiph.Org Foundation:
|
|
109
|
+
https://datatracker.ietf.org/ipr/1524/
|
|
110
|
+
|
|
111
|
+
Microsoft Corporation:
|
|
112
|
+
https://datatracker.ietf.org/ipr/1914/
|
|
113
|
+
|
|
114
|
+
Broadcom Corporation:
|
|
115
|
+
https://datatracker.ietf.org/ipr/1526/
|
|
116
|
+
|
|
117
|
+
## Speex License
|
|
118
|
+
|
|
119
|
+
© 2002-2003, Jean-Marc Valin/Xiph.Org Foundation
|
|
120
|
+
|
|
121
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
122
|
+
|
|
123
|
+
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
124
|
+
|
|
125
|
+
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
126
|
+
|
|
127
|
+
- Neither the name of the Xiph.org Foundation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
128
|
+
|
|
129
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
130
|
+
|
|
131
|
+
## ieee754 License
|
|
132
|
+
|
|
133
|
+
Copyright 2008 Fair Oaks Labs, Inc.
|
|
134
|
+
|
|
135
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
136
|
+
|
|
137
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
138
|
+
|
|
139
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
140
|
+
|
|
141
|
+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
142
|
+
|
|
143
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
144
|
+
|
|
145
|
+
## ISC License
|
|
146
|
+
|
|
147
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
148
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
149
|
+
copyright notice and this permission notice appear in all copies.
|
|
150
|
+
|
|
151
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
152
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
153
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
154
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
155
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
156
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
157
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""Haru on Apple silicon: the MLX implementation of the full-duplex spoken dialogue model."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
|
+
|
|
7
|
+
from .config import HaruConfig
|
|
8
|
+
from .frames import DuplexConfig, Frame
|
|
9
|
+
|
|
10
|
+
__version__ = "0.1.0"
|
|
11
|
+
__all__ = ["DuplexConfig", "DuplexSession", "Frame", "HaruConfig", "HaruModel", "load_model"]
|
|
12
|
+
|
|
13
|
+
if TYPE_CHECKING:
|
|
14
|
+
from .models import HaruModel, load_model
|
|
15
|
+
from .session import DuplexSession
|
|
16
|
+
|
|
17
|
+
# Everything that needs MLX is loaded on first use, so the pure-Python
|
|
18
|
+
# modules (config, sampling, audio, weights, server, ...) work without it.
|
|
19
|
+
_LAZY = {
|
|
20
|
+
"HaruModel": "models",
|
|
21
|
+
"load_model": "models",
|
|
22
|
+
"DuplexSession": "session",
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def __getattr__(name: str):
|
|
27
|
+
if name in _LAZY:
|
|
28
|
+
from importlib import import_module
|
|
29
|
+
|
|
30
|
+
return getattr(import_module(f".{_LAZY[name]}", __name__), name)
|
|
31
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|