HY-2012 commited on
Commit
dd2737e
·
verified ·
1 Parent(s): abb8c8e

FastWave.AXERA: AX650 NPU audio super-resolution (U16)

Browse files
Files changed (39) hide show
  1. .gitattributes +17 -0
  2. LICENSE +202 -0
  3. README.md +81 -0
  4. models/README.md +13 -0
  5. models/fastwave_nfe.axmodel +3 -0
  6. python/benchmark.py +53 -0
  7. python/demo.py +41 -0
  8. python/fastwave_sdk/__init__.py +6 -0
  9. python/fastwave_sdk/assets/emb_p1_b.npy +3 -0
  10. python/fastwave_sdk/assets/emb_p1_w.npy +3 -0
  11. python/fastwave_sdk/assets/emb_p2_b.npy +3 -0
  12. python/fastwave_sdk/assets/emb_p2_w.npy +3 -0
  13. python/fastwave_sdk/assets/model_config.json +21 -0
  14. python/fastwave_sdk/audio.py +149 -0
  15. python/fastwave_sdk/pipeline.py +138 -0
  16. python/requirements.txt +2 -0
  17. reports/accuracy.md +62 -0
  18. reports/performance.md +34 -0
  19. reports/precision_analysis.md +26 -0
  20. requirements.txt +3 -0
  21. run_ax650.sh +7 -0
  22. samples/README.md +21 -0
  23. samples/listen/16k/speech_2_input_16k.wav +3 -0
  24. samples/listen/16k/speech_3_input_16k.wav +3 -0
  25. samples/listen/48k_from16k/speech_2_output_48k.wav +3 -0
  26. samples/listen/48k_from16k/speech_3_output_48k.wav +3 -0
  27. samples/listen/48k_from8k/OSR_cn_000_0072_output_48k.wav +3 -0
  28. samples/listen/48k_from8k/OSR_cn_000_0074_output_48k.wav +3 -0
  29. samples/listen/48k_from8k/OSR_us_000_0010_output_48k.wav +3 -0
  30. samples/listen/48k_from8k/OSR_us_000_0013_output_48k.wav +3 -0
  31. samples/listen/8k/OSR_cn_000_0072_input_8k.wav +3 -0
  32. samples/listen/8k/OSR_cn_000_0074_input_8k.wav +3 -0
  33. samples/listen/8k/OSR_us_000_0010_input_8k.wav +3 -0
  34. samples/listen/8k/OSR_us_000_0013_input_8k.wav +3 -0
  35. samples/listen/spectrograms/OSR_cn_000_0072.png +3 -0
  36. samples/listen/spectrograms/OSR_us_000_0010.png +3 -0
  37. samples/listen/spectrograms/speech_2.png +3 -0
  38. samples/listen/spectrograms/speech_3.png +3 -0
  39. setup.sh +9 -0
.gitattributes CHANGED
@@ -33,3 +33,20 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ models/fastwave_nfe.axmodel filter=lfs diff=lfs merge=lfs -text
37
+ samples/listen/16k/speech_2_input_16k.wav filter=lfs diff=lfs merge=lfs -text
38
+ samples/listen/16k/speech_3_input_16k.wav filter=lfs diff=lfs merge=lfs -text
39
+ samples/listen/48k_from16k/speech_2_output_48k.wav filter=lfs diff=lfs merge=lfs -text
40
+ samples/listen/48k_from16k/speech_3_output_48k.wav filter=lfs diff=lfs merge=lfs -text
41
+ samples/listen/48k_from8k/OSR_cn_000_0072_output_48k.wav filter=lfs diff=lfs merge=lfs -text
42
+ samples/listen/48k_from8k/OSR_cn_000_0074_output_48k.wav filter=lfs diff=lfs merge=lfs -text
43
+ samples/listen/48k_from8k/OSR_us_000_0010_output_48k.wav filter=lfs diff=lfs merge=lfs -text
44
+ samples/listen/48k_from8k/OSR_us_000_0013_output_48k.wav filter=lfs diff=lfs merge=lfs -text
45
+ samples/listen/8k/OSR_cn_000_0072_input_8k.wav filter=lfs diff=lfs merge=lfs -text
46
+ samples/listen/8k/OSR_cn_000_0074_input_8k.wav filter=lfs diff=lfs merge=lfs -text
47
+ samples/listen/8k/OSR_us_000_0010_input_8k.wav filter=lfs diff=lfs merge=lfs -text
48
+ samples/listen/8k/OSR_us_000_0013_input_8k.wav filter=lfs diff=lfs merge=lfs -text
49
+ samples/listen/spectrograms/OSR_cn_000_0072.png filter=lfs diff=lfs merge=lfs -text
50
+ samples/listen/spectrograms/OSR_us_000_0010.png filter=lfs diff=lfs merge=lfs -text
51
+ samples/listen/spectrograms/speech_2.png filter=lfs diff=lfs merge=lfs -text
52
+ samples/listen/spectrograms/speech_3.png filter=lfs diff=lfs merge=lfs -text
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.
README.md ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - en
5
+ - zh
6
+ tags:
7
+ - axera
8
+ - ax650
9
+ - npu
10
+ - audio-super-resolution
11
+ - speech-super-resolution
12
+ - bandwidth-extension
13
+ - diffuse
14
+ - audio-to-audio
15
+ library_name: axera
16
+ pipeline_tag: audio-to-audio
17
+ base_model: Nikait/FastWave
18
+ ---
19
+
20
+ # FastWave.AXERA
21
+
22
+ **AX650 上的通用音频超分(6–48 kHz → 48 kHz),单模型 3.8 MB,纯 NPU 推理,即取即用。**
23
+
24
+ FastWave 是 1.3 M 参数的扩散式音频超分模型(EDM preconditioning + NU-Wave 2 骨干,
25
+ [论文](https://arxiv.org/abs/2603.04122))。本仓库提供 AX650 NPU 版:
26
+
27
+ - `models/fastwave_nfe.axmodel`:量化后的单次 NFE 图(11.9 MB,U16 激活 / S8 权重),板端 8 步采样
28
+ - `python/`:完整流水线 SDK(分块 + overlap-add + EDM 采样),只依赖 `numpy` + `axengine`
29
+ - `samples/`:8 k / 16 k 输入与 48 k 输出示例
30
+ - `reports/`:精度与性能报告
31
+
32
+ - GitHub(源码 + 复现流程):https://github.com/ZY-2012/FastWave.AXERA
33
+ - 上游:https://github.com/Nikait/FastWave
34
+
35
+ ## 快速开始(AX650 板端)
36
+
37
+ ```bash
38
+ # 需要:python3 + numpy + axengine(AX650 BSP 镜像自带)
39
+ bash run_ax650.sh samples/listen/8k/OSR_us_000_0010_input_8k.wav output.wav
40
+ bash run_ax650.sh samples/listen/16k/speech_2_input_16k.wav output.wav --steps 4
41
+ ```
42
+
43
+ 输出固定 48 kHz。`--steps 4` 速度更快、质量略降;`--overlap 0.5`(默认)可改拼接重叠率。
44
+
45
+ ## 结果
46
+
47
+ | 输入 | 输出 |
48
+ |---|---|
49
+ | [▶ 8k OSR_us_000_0010](samples/listen/8k/OSR_us_000_0010_input_8k.wav) | [▶ 48k](samples/listen/48k_from8k/OSR_us_000_0010_output_48k.wav) |
50
+ | [▶ 8k OSR_cn_000_0072](samples/listen/8k/OSR_cn_000_0072_input_8k.wav) | [▶ 48k](samples/listen/48k_from8k/OSR_cn_000_0072_output_48k.wav) |
51
+ | [▶ 16k speech_2](samples/listen/16k/speech_2_input_16k.wav) | [▶ 48k](samples/listen/48k_from16k/speech_2_output_48k.wav) |
52
+
53
+ 频谱对比:[OSR_us_000_0010](samples/listen/spectrograms/OSR_us_000_0010.png) ·
54
+ [OSR_cn_000_0072](samples/listen/spectrograms/OSR_cn_000_0072.png) ·
55
+ [speech_2](samples/listen/spectrograms/speech_2.png)
56
+
57
+ ## 性能(AX650 NPU3,chunk 0.68 s)
58
+
59
+ | 配置 | 单次 NFE | 端到端 RTF |
60
+ |---|---|---|
61
+ | 8 步 + 50% overlap(默认) | 499.8 ms | **10.0** |
62
+ | 4 步 + 50% overlap(`--steps 4`) | 499.8 ms | **5.0** |
63
+
64
+ ## 精度
65
+
66
+ 量化配置:Pulsar2 8.0,**U16 激活 / S8 权重 / U16 输出**(`DEFAULT` 全图),MinMax 标定
67
+ (真实 48 kHz 语音,8/12/16/24 kHz 退化输入,8 个采样步全覆盖,64 个样本),`compiler.check=2`。
68
+ AXMODEL 与浮点 ONNX 的单步 NFE 余弦相似度见 `reports/accuracy.md`(最低 TBD)。
69
+
70
+ ## 实现要点
71
+
72
+ 1. 模型内部每层都有 STFT/iSTFT(FFC 全局分支)。AX NPU 不支持 FFT/复数算子,这里把
73
+ `torch.stft/istft` 等价改写为 32×32 Cooley-Tukey 矩阵乘 FFT(reflect padding、hann 窗、
74
+ overlap-add、窗包络归一化全部保留),与 torch 误差 < 1e-7,图上只有 MatMul/Add/Mul/Reshape。
75
+ 2. EDM 的 `c_skip/c_in/c_out` 与正弦扩散 embedding 只依赖 sigma,host 端预计算后作为图输入,
76
+ 图上没有 log/sqrt/sin/cos/OneHot。
77
+ 3. 输入采样率通过 band one-hot 输入,一个模型覆盖 6–48 kHz。
78
+
79
+ ## License
80
+
81
+ Apache-2.0(本仓库代码与量化模型)。上游 FastWave 模型为 MIT License。
models/README.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Models
2
+
3
+ 本目录在 GitHub 仓库中不包含 axmodel 文件。
4
+
5
+ 预编译 AX650 模型请从 HuggingFace 下载:
6
+
7
+ <https://huggingface.co/HY-2012/FastWave.AXERA/tree/main/models>
8
+
9
+ - `fastwave_nfe.axmodel` — 单次 NFE 图(11.9 MB)
10
+ - `model_config.json` — chunk / 采样参数
11
+
12
+ 编译配置:Pulsar2 8.0,AX650 / NPU3,**U16 激活 / S8 权重 / U16 输出**,MinMax 标定,
13
+ `highest_mix_precision=false`。精度与性能见 `reports/accuracy.md`、`reports/performance.md`。
models/fastwave_nfe.axmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c6c915903942ff645902af37155e8389d0fc2dfc0ee7e013d37cd57c20215297
3
+ size 11879890
python/benchmark.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Board benchmark: single-NFE latency and end-to-end RTF."""
3
+ import argparse
4
+ import os
5
+ import sys
6
+ import time
7
+
8
+ import numpy as np
9
+
10
+ HERE = os.path.dirname(os.path.abspath(__file__))
11
+ sys.path.insert(0, HERE)
12
+
13
+ from fastwave_sdk import FastWaveSR # noqa: E402
14
+ from fastwave_sdk import audio as A # noqa: E402
15
+
16
+
17
+ def main():
18
+ ap = argparse.ArgumentParser()
19
+ ap.add_argument("--model", default=os.path.join(HERE, "..", "models", "fastwave_nfe.axmodel"))
20
+ ap.add_argument("--wav", default=os.path.join(HERE, "..", "samples", "listen", "8k",
21
+ "OSR_us_000_0010_input_8k.wav"))
22
+ ap.add_argument("--seconds", type=float, default=3.0)
23
+ ap.add_argument("--steps", type=int, default=8)
24
+ ap.add_argument("--iters", type=int, default=20)
25
+ a = ap.parse_args()
26
+
27
+ m = FastWaveSR(a.model, num_steps=a.steps)
28
+ wav, sr = A.read_wav(a.wav)
29
+ wav = wav[: int(a.seconds * sr)]
30
+ low = A.low_quality(wav / (np.abs(wav).max() + 1e-8), sr)
31
+ band = A.band_onehot(sr).reshape(1, 2, -1)
32
+ seg = np.ascontiguousarray(low[: m.chunk].reshape(1, -1))
33
+ x = np.zeros((1, m.chunk), dtype=np.float32)
34
+
35
+ for _ in range(5):
36
+ m.nfe(x, seg, band, 0)
37
+ ts = []
38
+ for i in range(a.iters):
39
+ t0 = time.perf_counter()
40
+ m.nfe(x, seg, band, i % m.num_steps)
41
+ ts.append((time.perf_counter() - t0) * 1e3)
42
+ ts = np.array(ts)
43
+ print(f"NFE latency: mean {ts.mean():.2f} ms min {ts.min():.2f} max {ts.max():.2f}")
44
+
45
+ t0 = time.perf_counter()
46
+ out = m.enhance(wav, sr)
47
+ dt = time.perf_counter() - t0
48
+ dur = len(out) / 48000.0
49
+ print(f"end-to-end {dur:.2f}s audio in {dt:.2f}s -> RTF {dt/dur:.4f}")
50
+
51
+
52
+ if __name__ == "__main__":
53
+ main()
python/demo.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """FastWave.AXERA demo: any sample rate -> 48 kHz super resolution on AX650 NPU."""
3
+ import argparse
4
+ import os
5
+ import sys
6
+ import time
7
+
8
+ HERE = os.path.dirname(os.path.abspath(__file__))
9
+ sys.path.insert(0, HERE)
10
+
11
+ from fastwave_sdk import FastWaveSR # noqa: E402
12
+ from fastwave_sdk import audio as A # noqa: E402
13
+
14
+
15
+ def main():
16
+ ap = argparse.ArgumentParser(description="FastWave.AXERA 48 kHz audio super resolution")
17
+ ap.add_argument("input", help="input wav (6 kHz - 48 kHz)")
18
+ ap.add_argument("output", help="output wav (48 kHz)")
19
+ ap.add_argument("--model", default=os.path.join(HERE, "..", "models", "fastwave_nfe.axmodel"))
20
+ ap.add_argument("--chunk", type=int, default=None, help="chunk samples at 48 kHz (must match the axmodel, default from model_config.json)")
21
+ ap.add_argument("--overlap", type=float, default=0.5, help="chunk overlap ratio")
22
+ ap.add_argument("--steps", type=int, default=8, help="EDM sampling steps (4 or 8)")
23
+ ap.add_argument("--seed", type=int, default=1234)
24
+ args = ap.parse_args()
25
+
26
+ wav, sr = A.read_wav(args.input)
27
+ print(f"[input ] {args.input} {len(wav)/sr:.2f}s @ {sr} Hz")
28
+ model = FastWaveSR(args.model, num_steps=args.steps, chunk=args.chunk,
29
+ overlap=args.overlap, seed=args.seed)
30
+ t0 = time.time()
31
+ out = model.enhance(wav, sr, progress=lambda i, n: print(f"\r[chunk ] {i}/{n}", end="", flush=True))
32
+ dt = time.time() - t0
33
+ print()
34
+ A.write_wav(args.output, out, 48000)
35
+ dur = len(out) / 48000.0
36
+ print(f"[output] {args.output} {dur:.2f}s @ 48000 Hz")
37
+ print(f"[perf ] {dt:.2f}s RTF {dt / dur:.3f}")
38
+
39
+
40
+ if __name__ == "__main__":
41
+ main()
python/fastwave_sdk/__init__.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ """FastWave.AXERA — 48 kHz audio super-resolution on AX650 (NPU)."""
2
+
3
+ from .pipeline import FastWaveSR
4
+
5
+ __all__ = ["FastWaveSR"]
6
+ __version__ = "1.0.0"
python/fastwave_sdk/assets/emb_p1_b.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:56eb0ba80672dd4b474a72cf665645481fca907e35b89defdf48c9aa6623e9cb
3
+ size 2176
python/fastwave_sdk/assets/emb_p1_w.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:472e7ed0456762e5bcf2f4e47a609b9cacdd7c895e17a6a90dbc6f7a5b60eb47
3
+ size 262272
python/fastwave_sdk/assets/emb_p2_b.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:197f365eb799bfc44aa437800f443f7d4796c832cd120db7a39291e909f42cdc
3
+ size 2176
python/fastwave_sdk/assets/emb_p2_w.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a5db3ac68049e055d8b17e56691fb0e8e822543673f4005b1d0aa7066aa39d2e
3
+ size 1048704
python/fastwave_sdk/assets/model_config.json ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "FastWave",
3
+ "alias": "FastWave.AXERA",
4
+ "sample_rate": 48000,
5
+ "input_sr_supported": [
6
+ 6000,
7
+ 48000
8
+ ],
9
+ "chunk_samples": 32768,
10
+ "n_fft": 1024,
11
+ "hop_length": 256,
12
+ "num_steps": 8,
13
+ "sigma_min": 0.002,
14
+ "sigma_max": 80.0,
15
+ "rho": 7.0,
16
+ "pos_emb_channels": 128,
17
+ "pos_emb_scale": 50000.0,
18
+ "pos_emb_dim": 512,
19
+ "axmodel": "fastwave_nfe.axmodel",
20
+ "size_mb": 3.82
21
+ }
python/fastwave_sdk/audio.py ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Numpy-only audio helpers for the FastWave AX650 SDK.
2
+
3
+ - WAV read/write (PCM16 / PCM24 / float32) without soundfile
4
+ - polyphase resampling (scipy.signal.resample_poly compatible)
5
+ - band one-hot, hann window, overlap-add
6
+
7
+ Only numpy is required on the board.
8
+ """
9
+ import math
10
+
11
+ import numpy as np
12
+
13
+ SR_OUT = 48000
14
+ N_FFT = 1024
15
+ HOP = 256
16
+ FREQ = N_FFT // 2 + 1
17
+ CHUNK = 32768
18
+
19
+
20
+ # --------------------------------------------------------------------------- WAV
21
+ def read_wav(path):
22
+ """Return (float32 mono in [-1, 1], sample_rate)."""
23
+ import wave
24
+
25
+ with wave.open(path, "rb") as w:
26
+ sr = w.getframerate()
27
+ n_ch = w.getnchannels()
28
+ sw = w.getsampwidth()
29
+ n = w.getnframes()
30
+ raw = w.readframes(n)
31
+ if sw == 2:
32
+ x = np.frombuffer(raw, dtype="<i2").astype(np.float32) / 32768.0
33
+ elif sw == 3:
34
+ b = np.frombuffer(raw, dtype=np.uint8).reshape(-1, 3).astype(np.int32)
35
+ v = b[:, 0] | (b[:, 1] << 8) | (b[:, 2] << 16)
36
+ v = np.where(v >= 1 << 23, v - (1 << 24), v)
37
+ x = v.astype(np.float32) / (1 << 23)
38
+ elif sw == 4:
39
+ x = np.frombuffer(raw, dtype="<i4").astype(np.float32) / (1 << 31)
40
+ else:
41
+ raise ValueError(f"unsupported sample width: {sw}")
42
+ if n_ch > 1:
43
+ x = x.reshape(-1, n_ch).mean(axis=1)
44
+ return np.ascontiguousarray(x, dtype=np.float32), sr
45
+
46
+
47
+ def write_wav(path, x, sr):
48
+ import wave
49
+
50
+ x = np.asarray(x, dtype=np.float32)
51
+ x = np.clip(x, -1.0, 1.0)
52
+ pcm = (x * 32767.0).astype("<i2")
53
+ with wave.open(path, "wb") as w:
54
+ w.setnchannels(1)
55
+ w.setsampwidth(2)
56
+ w.setframerate(int(sr))
57
+ w.writeframes(pcm.tobytes())
58
+
59
+
60
+ # --------------------------------------------------------------------- resampling
61
+ def _firwin(cutoff, numtaps, beta=5.0):
62
+ """Lowpass FIR (same design as scipy.signal.firwin(..., window=('kaiser', beta)))."""
63
+ n = np.arange(numtaps)
64
+ alpha = (numtaps - 1) / 2.0
65
+ m = n - alpha
66
+ h = cutoff * np.sinc(cutoff * m)
67
+ h *= np.kaiser(numtaps, beta)
68
+ h /= h.sum()
69
+ return h
70
+
71
+
72
+ def resample_poly(x, up, down):
73
+ """Polyphase rational resampling, scipy.signal.resample_poly compatible."""
74
+ x = np.asarray(x, dtype=np.float64)
75
+ g = math.gcd(int(up), int(down))
76
+ up, down = int(up) // g, int(down) // g
77
+ if up == down:
78
+ return x.astype(np.float32)
79
+ max_rate = max(up, down)
80
+ half = 10 * max_rate
81
+ h = _firwin(1.0 / max_rate, 2 * half + 1) * up
82
+ # upsample + full convolution
83
+ y = np.zeros((len(x) - 1) * up + 1, dtype=np.float64)
84
+ y[::up] = x
85
+ y = np.convolve(y, h)
86
+ # compensate the FIR group delay, then decimate
87
+ y = y[half::down]
88
+ n_out = int(math.ceil(len(x) * up / down))
89
+ if len(y) >= n_out:
90
+ y = y[:n_out]
91
+ else:
92
+ y = np.pad(y, (0, n_out - len(y)))
93
+ return y.astype(np.float32)
94
+
95
+
96
+ def resample_to(x, sr_in, sr_out):
97
+ if sr_in == sr_out:
98
+ return np.asarray(x, dtype=np.float32).copy()
99
+ return resample_poly(x, int(sr_out), int(sr_in))
100
+
101
+
102
+ def low_quality(x, sr_in, out_sr=SR_OUT):
103
+ """Upsample the band-limited input to out_sr (same role as the training pipeline)."""
104
+ n_out = int(round(len(x) * out_sr / sr_in))
105
+ y = resample_to(x, sr_in, out_sr)
106
+ if len(y) > n_out:
107
+ y = y[:n_out]
108
+ elif len(y) < n_out:
109
+ y = np.pad(y, (0, n_out - len(y)))
110
+ return y
111
+
112
+
113
+ # ------------------------------------------------------------------------ misc
114
+ def band_onehot(sr_in, sr_out=SR_OUT, freq=FREQ):
115
+ """(2, freq) float32 one-hot of usable frequency bins."""
116
+ hi = float(sr_in) / float(sr_out)
117
+ band = np.zeros(freq, dtype=np.int64)
118
+ band[: int(hi * freq)] = 1
119
+ # matches F.one_hot(band).transpose(1, -1): ch0 = high band, ch1 = low band
120
+ out = np.zeros((2, freq), dtype=np.float32)
121
+ out[0, band == 0] = 1.0
122
+ out[1, band == 1] = 1.0
123
+ return out
124
+
125
+
126
+ def hann(n):
127
+ return (0.5 - 0.5 * np.cos(2.0 * np.pi * np.arange(n) / n)).astype(np.float32)
128
+
129
+
130
+ def chunk_bounds(n, chunk, hop):
131
+ """Start positions of overlapping chunks covering n samples."""
132
+ if n <= chunk:
133
+ return [0]
134
+ starts = list(range(0, n - chunk + 1, hop))
135
+ if starts[-1] + chunk < n:
136
+ starts.append(n - chunk)
137
+ return starts
138
+
139
+
140
+ def overlap_add(chunks, starts, n, chunk):
141
+ """Hann-window overlap-add."""
142
+ w = hann(chunk)
143
+ acc = np.zeros(n + chunk, dtype=np.float64)
144
+ wsum = np.zeros(n + chunk, dtype=np.float64)
145
+ for c, s in zip(chunks, starts):
146
+ acc[s: s + chunk] += c * w
147
+ wsum[s: s + chunk] += w
148
+ wsum = np.maximum(wsum, 1e-8)
149
+ return (acc[:n] / wsum[:n]).astype(np.float32)
python/fastwave_sdk/pipeline.py ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """FastWave EDM sampler on AX650 (pyaxengine) — numpy only.
2
+
3
+ The AXMODEL is one function evaluation (NFE):
4
+ y = D(x, sigma) = c_skip * x + c_out * F(c_in * x, audio_low, band, noise_emb)
5
+
6
+ Everything that only depends on sigma (the 8 EDM steps) is precomputed on the
7
+ host: c_skip / c_in / c_out and the diffusion embedding.
8
+ """
9
+ import json
10
+ import os
11
+
12
+ import numpy as np
13
+
14
+ from . import audio as A
15
+
16
+ ASSETS = os.path.join(os.path.dirname(os.path.abspath(__file__)), "assets")
17
+
18
+
19
+ def _silu(x):
20
+ return x / (1.0 + np.exp(-x))
21
+
22
+
23
+ class FastWaveSR:
24
+ def __init__(self, model_path, assets_dir=ASSETS, num_steps=8, provider="AxEngineExecutionProvider",
25
+ chunk=None, overlap=0.5, seed=1234, sigma_min=0.002, sigma_max=80.0, rho=7.0):
26
+ import axengine as axe
27
+
28
+ self.sess = axe.InferenceSession(model_path, providers=[provider])
29
+ self.input_names = [i.name for i in self.sess.get_inputs()]
30
+ meta = json.load(open(os.path.join(assets_dir, "model_config.json")))
31
+ self.meta = meta
32
+ self.chunk = int(chunk or meta.get("chunk_samples", 32768))
33
+ if self.chunk != int(meta.get("chunk_samples", 32768)):
34
+ print(f"[warn] chunk={self.chunk} differs from the compiled axmodel "
35
+ f"({meta.get('chunk_samples')}); recompile the model for a new chunk size")
36
+ self.overlap = float(overlap)
37
+ self.hop = (max(256, int(round(self.chunk * overlap)) // 256 * 256)
38
+ if overlap > 0 else self.chunk)
39
+ self.num_steps = int(num_steps)
40
+ self.rng = np.random.default_rng(seed)
41
+
42
+ self.sr_out = int(meta.get("sample_rate", A.SR_OUT))
43
+
44
+ p1w = np.load(os.path.join(assets_dir, "emb_p1_w.npy"))
45
+ p1b = np.load(os.path.join(assets_dir, "emb_p1_b.npy"))
46
+ p2w = np.load(os.path.join(assets_dir, "emb_p2_w.npy"))
47
+ p2b = np.load(os.path.join(assets_dir, "emb_p2_b.npy"))
48
+ half = int(p1w.shape[1]) // 2
49
+ scale = float(meta.get("pos_emb_scale", 50000.0))
50
+ freqs = np.exp(np.arange(half, dtype=np.float64) * (-np.log(10000.0) / (half - 1)))
51
+
52
+ idx = np.arange(self.num_steps, dtype=np.float64)
53
+ t = (sigma_max ** (1 / rho) + idx / (self.num_steps - 1)
54
+ * (sigma_min ** (1 / rho) - sigma_max ** (1 / rho))) ** rho
55
+ self.t_steps = np.concatenate([t, [0.0]]).astype(np.float32)
56
+
57
+ self.steps = []
58
+ for s in self.t_steps[:-1].astype(np.float64):
59
+ c_skip = 0.5 ** 2 / (s ** 2 + 0.5 ** 2)
60
+ c_in = 1.0 / np.sqrt(s ** 2 + 0.5 ** 2)
61
+ c_out = s * 0.5 / np.sqrt(s ** 2 + 0.5 ** 2)
62
+ c_noise = np.log(s) / 4.0
63
+ ang = scale * c_noise * freqs
64
+ emb = np.concatenate([np.sin(ang), np.cos(ang)]).astype(np.float32)
65
+ emb = _silu(emb @ p1w.T + p1b)
66
+ emb = _silu(emb @ p2w.T + p2b)
67
+ self.steps.append({
68
+ "c_skip": np.array([[c_skip]], dtype=np.float32),
69
+ "c_in": np.array([[c_in]], dtype=np.float32),
70
+ "c_out": np.array([[c_out]], dtype=np.float32),
71
+ "noise_emb": emb.reshape(1, -1).astype(np.float32),
72
+ })
73
+
74
+ # ------------------------------------------------------------------ graph
75
+ def nfe(self, x, low, band, step):
76
+ """One denoising step; x/low: (1, chunk) float32."""
77
+ s = self.steps[step]
78
+ feed = {
79
+ "x": np.ascontiguousarray(x, dtype=np.float32),
80
+ "audio_low": low,
81
+ "band_onehot": band,
82
+ "c_skip": s["c_skip"],
83
+ "c_in": s["c_in"],
84
+ "c_out": s["c_out"],
85
+ "noise_emb": s["noise_emb"],
86
+ }
87
+ return self.sess.run(None, {k: feed[k] for k in self.input_names})[0]
88
+
89
+ def denoise_chunk(self, low_chunk, band):
90
+ x = self.rng.standard_normal((1, self.chunk)).astype(np.float32) * self.t_steps[0]
91
+ for i in range(self.num_steps):
92
+ t_cur = self.t_steps[i]
93
+ t_next = self.t_steps[i + 1]
94
+ denoised = self.nfe(x, low_chunk, band, i)
95
+ x = x + (t_next - t_cur) * (x - denoised) / t_cur
96
+ return np.clip(x[0], -1.0, 1.0 - 1e-7)
97
+
98
+ # --------------------------------------------------------------- pipeline
99
+ def enhance(self, wav, sr_in, progress=None, normalize=True):
100
+ """wav: 1-D float32 at sr_in. Returns 48 kHz float32."""
101
+ wav = np.asarray(wav, dtype=np.float32)
102
+ peak = float(np.max(np.abs(wav))) if len(wav) else 0.0
103
+ if normalize and peak > 1e-8:
104
+ wav = wav / peak
105
+ else:
106
+ peak = 1.0
107
+ low = A.low_quality(wav, int(sr_in), self.sr_out)
108
+ band = A.band_onehot(int(sr_in), self.sr_out)
109
+ band3 = band.reshape(1, 2, -1)
110
+ n = len(low)
111
+ if n == 0:
112
+ return low
113
+ if self.overlap <= 0:
114
+ # fastest: pad to whole chunks, no overlap / no windowing
115
+ n_pad = int(np.ceil(n / self.chunk)) * self.chunk
116
+ if n_pad > n:
117
+ low = np.pad(low, (0, n_pad - n))
118
+ starts = list(range(0, n_pad, self.chunk))
119
+ outs = []
120
+ for i, s in enumerate(starts):
121
+ seg = low[s: s + self.chunk]
122
+ outs.append(self.denoise_chunk(
123
+ np.ascontiguousarray(seg.reshape(1, -1)), band3))
124
+ if progress:
125
+ progress(i + 1, len(starts))
126
+ return np.concatenate(outs)[:n].astype(np.float32) * peak
127
+ starts = A.chunk_bounds(n, self.chunk, self.hop)
128
+ outs = []
129
+ for i, s in enumerate(starts):
130
+ seg = low[s: s + self.chunk]
131
+ if len(seg) < self.chunk:
132
+ seg = np.pad(seg, (0, self.chunk - len(seg)))
133
+ outs.append(self.denoise_chunk(np.ascontiguousarray(seg.reshape(1, -1)), band3))
134
+ if progress:
135
+ progress(i + 1, len(starts))
136
+ if len(starts) == 1:
137
+ return outs[0][:n].astype(np.float32) * peak
138
+ return A.overlap_add(outs, starts, n, self.chunk) * peak
python/requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ numpy>=1.20
2
+ pyaxengine
reports/accuracy.md ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # FastWave.AXERA — 精度报告
2
+
3
+ ## 量化配置
4
+
5
+ - Pulsar2 8.0 / AX650 / NPU3,`compiler.check=2`
6
+ - 数据类型:**U16 激活 / S8 权重 / U16 输出**(`DEFAULT` 全图),`highest_mix_precision=false`
7
+ - 标定:真实 48 kHz 语音,8/12/16/24 kHz 退化输入,8 个 EDM 采样步全采样(64 个样本)
8
+
9
+ ### 量化工件内精度(Pulsar2 EndToEnd 逐算子)
10
+
11
+ - 统计算子 2245 个,cosine min 0.90369 / mean 0.99962
12
+ - 图输出 `y` cosine **0.99982**(MSE 0.00000)
13
+
14
+ ## 单步 NFE 精度(AXMODEL 板端 vs 浮点 ONNX,held-out 数据)
15
+
16
+ | case | 输入采样率 | 采样步 | cosine | SNR (dB) | max abs err |
17
+ |---|---|---|---|---|---|
18
+ | 0 | 8000 Hz | 0 | 0.997546 | 23.09 | 0.0108 |
19
+ | 0 | 8000 Hz | 1 | 0.994159 | 18.68 | 0.0152 |
20
+ | 0 | 8000 Hz | 2 | 0.995742 | 20.59 | 0.0098 |
21
+ | 0 | 8000 Hz | 3 | 0.997580 | 22.58 | 0.0072 |
22
+ | 0 | 8000 Hz | 4 | 0.992172 | 18.07 | 0.0135 |
23
+ | 0 | 8000 Hz | 5 | 0.999040 | 27.15 | 0.0039 |
24
+ | 0 | 8000 Hz | 6 | 0.999682 | 31.93 | 0.0045 |
25
+ | 0 | 8000 Hz | 7 | 0.988324 | 16.25 | 0.0057 |
26
+ | 1 | 24000 Hz | 0 | 0.999696 | 32.12 | 0.0717 |
27
+ | 1 | 24000 Hz | 1 | 0.999776 | 33.42 | 0.0647 |
28
+ | 1 | 24000 Hz | 2 | 0.999697 | 32.18 | 0.0809 |
29
+ | 1 | 24000 Hz | 3 | 0.999676 | 31.88 | 0.0940 |
30
+ | 1 | 24000 Hz | 4 | 0.999702 | 32.25 | 0.1098 |
31
+ | 1 | 24000 Hz | 5 | 0.999865 | 35.69 | 0.1106 |
32
+ | 1 | 24000 Hz | 6 | 0.999938 | 39.06 | 0.0829 |
33
+ | 1 | 24000 Hz | 7 | 0.999516 | 30.14 | 0.0062 |
34
+ | 2 | 16000 Hz | 0 | 0.996778 | 21.91 | 0.0157 |
35
+ | 2 | 16000 Hz | 1 | 0.990080 | 16.38 | 0.0148 |
36
+ | 2 | 16000 Hz | 2 | 0.994315 | 19.38 | 0.0092 |
37
+ | 2 | 16000 Hz | 3 | 0.996483 | 21.25 | 0.0067 |
38
+ | 2 | 16000 Hz | 4 | 0.986250 | 15.62 | 0.0125 |
39
+ | 2 | 16000 Hz | 5 | 0.998712 | 25.86 | 0.0035 |
40
+ | 2 | 16000 Hz | 6 | 0.999681 | 31.91 | 0.0025 |
41
+ | 2 | 16000 Hz | 7 | 0.983171 | 14.57 | 0.0056 |
42
+ | 3 | 12000 Hz | 0 | 0.999837 | 34.64 | 0.0651 |
43
+ | 3 | 12000 Hz | 1 | 0.999933 | 38.65 | 0.0465 |
44
+ | 3 | 12000 Hz | 2 | 0.999946 | 39.01 | 0.0457 |
45
+ | 3 | 12000 Hz | 3 | 0.999945 | 39.10 | 0.0370 |
46
+ | 3 | 12000 Hz | 4 | 0.999943 | 39.40 | 0.1066 |
47
+ | 3 | 12000 Hz | 5 | 0.999955 | 40.30 | 0.1270 |
48
+ | 3 | 12000 Hz | 6 | 0.999983 | 44.69 | 0.0420 |
49
+ | 3 | 12000 Hz | 7 | 0.999934 | 38.81 | 0.0060 |
50
+
51
+ - cosine 最小值 **0.983171**,平均值 0.997096
52
+ - 判定:PASS(端到端验证见下,quiet chunk 单步略低)
53
+
54
+ ## 端到端精度(一段 1.4 s 8 kHz 输入)
55
+
56
+ - NPU 输出 vs 浮点输出:cosine **0.99842**,SNR 24.93 dB
57
+
58
+ ## NPU 延迟
59
+
60
+ - 单次 NFE:平均 499.21 ms(min 498.57 / max 499.94)
61
+ - 8 步 / chunk(0.68 s):约 3.99 s
62
+
reports/performance.md ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # FastWave.AXERA — 性能报告
2
+
3
+ | 项目 | 数值 |
4
+ |---|---|
5
+ | 平台 | AX650 / 三核 NPU(NPU3,BSP V3.10.2,NPU clk 800 MHz) |
6
+ | axmodel | 11.9 MB(单次 NFE 图,含 15 个 FFC 块的矩阵乘 FFT) |
7
+ | 量化 | U16 激活 / S8 权重 / U16 输出,MinMax 标定,Pulsar2 8.0,`compiler.check=2` |
8
+ | 单次 NFE(chunk 32768 = 0.68 s @48k) | **499.8 ms**(min 499.5 / max 500.1,n=10) |
9
+ | 8 步 / chunk | 3.99 s |
10
+ | 端到端 RTF(8 步,50% overlap) | **10.0**(2.00 s 音频 20.07 s) |
11
+ | 端到端 RTF(4 步,50% overlap) | **5.0**(2.00 s 音频 10.06 s) |
12
+ | 端到端 RTF(8 步,`--overlap 0`) | ≈ 5.8(无重叠拼接,未实测) |
13
+
14
+ ## 说明
15
+
16
+ - chunk 固定 32768 点,约 0.68 s;每 chunk 调 8 次(或 4 次)NPU,扩散采样在 host 侧串联。
17
+ - 8 步与 4 步共用同一个 axmodel(sigma/系数由 host 提供),`--steps 4` 直接可用。
18
+ - 端到端耗时 ≈ 音频时长 × 2(50% overlap 的重叠系数)× NFE 次数 × 0.5 s。
19
+
20
+ ## 为什么是 0.5 s / NFE
21
+
22
+ 单次 NFE 的卷积算力约 12.8 GMAC,按 AX650 U16 实测(同尺寸 1x1 Conv 探针
23
+ ≈ 570 GMAC/s)只需 ~22 ms;其余 ~480 ms 花在 15 个 FFC 块的 STFT/iSTFT
24
+ (约 180 个 32×32 小 MatMul + 大量 32 通道逐元素算子,共 2600+ 个 op)上。
25
+ 该图是典型的"小张量、多算子"结构,受 DDR 带宽与算子启动开销限制,
26
+ NPU 只跑在 core0(图是严格串行的,三核无法并行)。
27
+
28
+ 可选的优化方向(按收益排序):
29
+
30
+ 1. **换成 int8 激活**(S8/U8)再测一次:同尺寸探针 U8 比 U16 快 2.8×,但 FFT
31
+ 分支的动态范围较大,需要重新看精度;
32
+ 2. 增大 chunk(如 65536)减少每秒的算子启动次数;
33
+ 3. 把 FFT 的 32×32 MatMul 换成一次更大的 GEMM(合并 stage1/stage2 的批维);
34
+ 4. 用 `compiler.npu_perf` / `dump_simulator_cycle_trace` 做逐算子定位后再定点优化。
reports/precision_analysis.md ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 量化精度分析(Pulsar2 EndToEnd,量化工件内)
2
+
3
+ 配置:U16 激活 / S8 权重 / U16 输出,MinMax,64 个真实样本,`compiler.check=2`。
4
+
5
+ - 统计算子数:2245
6
+ - 输出 `y` cosine(量化 vs 浮点):**0.99982**(MSE 0.00000)
7
+ - 逐算子 cosine:min 0.90369,mean 0.99962
8
+
9
+ | cosine 区间 | 算子数 |
10
+ |---|---|
11
+ | >=0.999 | 2196 |
12
+ | <0.999 | 35 |
13
+ | <0.99 | 12 |
14
+ | <0.95 | 2 |
15
+
16
+ 最差 6 个算子(FFT 的 twiddle/矩阵乘,位于 STFT 分支内部,量级很小):
17
+
18
+ | 算子 | 类型 | 输出 shape | dtype | cosine |
19
+ |---|---|---|---|---|
20
+ | /resid… | AxMul | /residu… | FP32 | 0.90369 |
21
+ | /resid… | AxMul | /residu… | FP32 | 0.94242 |
22
+ | /resid… | AxMul | /residu… | FP32 | 0.95310 |
23
+ | /resid… | AxMul | /residu… | FP32 | 0.95744 |
24
+ | /resid… | AxMul | /residu… | FP32 | 0.97668 |
25
+ | /resid… | AxMul | /residu… | FP32 | 0.98177 |
26
+
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ numpy>=1.20
2
+ # NPU 运行时:pip 包名 pyaxengine,导入名 axengine(AX650 BSP 镜像通常已自带)
3
+ pyaxengine
run_ax650.sh ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ # FastWave.AXERA on AX650: any sample rate -> 48 kHz
3
+ # usage: bash run_ax650.sh input.wav output.wav [extra demo.py args]
4
+ set -e
5
+ ROOT="$(cd "$(dirname "$0")" && pwd)"
6
+ export PYTHONPATH="$ROOT/python:$PYTHONPATH"
7
+ exec python3 "$ROOT/python/demo.py" "$@"
samples/README.md ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 示例音频
2
+
3
+ ## 输入
4
+
5
+ | 文件 | 采样率 | 来源 |
6
+ |---|---|---|
7
+ | `listen/8k/OSR_us_000_0010_input_8k.wav` | 8 kHz | Open Speech Repository (English) |
8
+ | `listen/8k/OSR_us_000_0013_input_8k.wav` | 8 kHz | Open Speech Repository (English) |
9
+ | `listen/8k/OSR_cn_000_0072_input_8k.wav` | 8 kHz | Open Speech Repository (Chinese) |
10
+ | `listen/8k/OSR_cn_000_0074_input_8k.wav` | 8 kHz | Open Speech Repository (Chinese) |
11
+ | `listen/16k/speech_2_input_16k.wav` | 16 kHz | 公开人声样例降采样 |
12
+ | `listen/16k/speech_3_input_16k.wav` | 16 kHz | 公开人声样例降采样 |
13
+
14
+ - Open Speech Repository: http://voiptroubleshooter.com/open_speech/index.html
15
+
16
+ ## 输出
17
+
18
+ `listen/48k_from8k/`、`listen/48k_from16k/` 为 FastWave.AXERA 在 AX650 板端的实际输出
19
+ (8 步 EDM 采样,chunk 32768 / 50% overlap)。
20
+
21
+ `listen/spectrograms/` 为输入/输出频谱对比图。
samples/listen/16k/speech_2_input_16k.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0c7773c82ce75aa5e8a14d5bb53ee5915dbb65f47272ae9f527ac767c7b1f80c
3
+ size 163884
samples/listen/16k/speech_3_input_16k.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:19cb7158760a383a60f1c2e5de23a780331f492fd5a7ccc63a58cadb8ad2f804
3
+ size 163884
samples/listen/48k_from16k/speech_2_output_48k.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c002dc9bc7a43585ccfb470e867caaab845d62dad0bfff3e272995389b561725
3
+ size 491564
samples/listen/48k_from16k/speech_3_output_48k.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:36de030f5ac7c574273c8799faeb119ea40bae6126b18f2fc727224f89de9a25
3
+ size 491564
samples/listen/48k_from8k/OSR_cn_000_0072_output_48k.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e2b28b841347e66f82a076918d998690091e6e3b24dc86ef2cfea2a976203a55
3
+ size 1916936
samples/listen/48k_from8k/OSR_cn_000_0074_output_48k.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e75ef0dc777a70732748b62288d87580bf493911e206e853337f4efe3272a8d0
3
+ size 2207708
samples/listen/48k_from8k/OSR_us_000_0010_output_48k.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:689ae6a81c4944091c315bf958b2054cc5ebc830798f2d8d13b27743e03e850f
3
+ size 3227864
samples/listen/48k_from8k/OSR_us_000_0013_output_48k.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6f5706bcb90ef65a6c7fa3c445abe9852b242c4eca722aa47273900df7a8920e
3
+ size 3124160
samples/listen/8k/OSR_cn_000_0072_input_8k.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a7e2e6c7a0476d0286c6b1df92d15ab938888dfecd73efb29e4a0b82740fa761
3
+ size 319526
samples/listen/8k/OSR_cn_000_0074_input_8k.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8ef91f9f846a94d5e617fdba65a9acbb1eaffcbbafee50880e92bb857e171c7f
3
+ size 367988
samples/listen/8k/OSR_us_000_0010_input_8k.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a4bf9becd046d7aedb6d05b6e12347a6294a44f74d263089c636fb0a2b1e6561
3
+ size 538014
samples/listen/8k/OSR_us_000_0013_input_8k.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3af3f5df07da603b7a421a345aad023df28c862ba92f68af360cc8c64c71436e
3
+ size 520730
samples/listen/spectrograms/OSR_cn_000_0072.png ADDED

Git LFS Details

  • SHA256: 71fa7b0ee0093cfbe2c1a7b85f1bd119b200c3ff2cf231dd569cc5f5d5833944
  • Pointer size: 131 Bytes
  • Size of remote file: 568 kB
samples/listen/spectrograms/OSR_us_000_0010.png ADDED

Git LFS Details

  • SHA256: 67ec7bfafddccc3a43b1b5ae1525503966b6d7321ec0295ffd620c80314e2fac
  • Pointer size: 131 Bytes
  • Size of remote file: 552 kB
samples/listen/spectrograms/speech_2.png ADDED

Git LFS Details

  • SHA256: 925678e5b235e050e4d24a2f3339c424c308fb820af6a1dc5e3483fdc07e36d3
  • Pointer size: 131 Bytes
  • Size of remote file: 503 kB
samples/listen/spectrograms/speech_3.png ADDED

Git LFS Details

  • SHA256: 14923e8c4bccbd1a4310aa9e4d66f383bd382cd56350079837d3355b1e9e5cbf
  • Pointer size: 131 Bytes
  • Size of remote file: 461 kB
setup.sh ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ # Install the Python dependencies required by FastWave.AXERA.
3
+ set -e
4
+ python3 -m pip install --upgrade numpy
5
+ # axengine (pyaxengine) is preinstalled on AXera BSP images; install it if missing:
6
+ python3 -c "import axengine" 2>/dev/null || {
7
+ echo "axengine not found. Install the axengine wheel shipped with your AX650 BSP, e.g.:"
8
+ echo " pip3 install --no-index --no-deps axengine-0.1.3-py3-none-any.whl"
9
+ }