Skip to content

Commit 59634c3

Browse files
ZhaoChaoqunclaude
andcommitted
Prefer INT8 over FP32 for Streaming Paraformer to reduce memory usage
Switches model loading priority from FP32 to INT8, reducing runtime memory from ~2GB to ~1GB. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6d0d9d1 commit 59634c3

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

Sources/SherpaOnnxManager.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -148,26 +148,26 @@ class SherpaOnnxManager: NSObject {
148148
return nil
149149
}
150150

151-
// 优先使用 FP32 版本(精度更高)
152-
let encoderFP32 = modelDir.appendingPathComponent("encoder.onnx")
153-
let decoderFP32 = modelDir.appendingPathComponent("decoder.onnx")
154-
155-
if FileManager.default.fileExists(atPath: encoderFP32.path),
156-
FileManager.default.fileExists(atPath: decoderFP32.path) {
157-
print("[SherpaOnnx] 使用 FP32 版本 Streaming Paraformer(精度更高)")
158-
return (encoderFP32.path, decoderFP32.path, tokensPath.path)
159-
}
160-
161-
// 回退到 INT8 版本
151+
// 优先使用 INT8 版本(内存占用更小)
162152
let encoderINT8 = modelDir.appendingPathComponent("encoder.int8.onnx")
163153
let decoderINT8 = modelDir.appendingPathComponent("decoder.int8.onnx")
164154

165155
if FileManager.default.fileExists(atPath: encoderINT8.path),
166156
FileManager.default.fileExists(atPath: decoderINT8.path) {
167-
print("[SherpaOnnx] 使用 INT8 版本 Streaming Paraformer")
157+
print("[SherpaOnnx] 使用 INT8 版本 Streaming Paraformer(内存占用更小)")
168158
return (encoderINT8.path, decoderINT8.path, tokensPath.path)
169159
}
170160

161+
// 回退到 FP32 版本
162+
let encoderFP32 = modelDir.appendingPathComponent("encoder.onnx")
163+
let decoderFP32 = modelDir.appendingPathComponent("decoder.onnx")
164+
165+
if FileManager.default.fileExists(atPath: encoderFP32.path),
166+
FileManager.default.fileExists(atPath: decoderFP32.path) {
167+
print("[SherpaOnnx] 使用 FP32 版本 Streaming Paraformer")
168+
return (encoderFP32.path, decoderFP32.path, tokensPath.path)
169+
}
170+
171171
return nil
172172
}
173173

0 commit comments

Comments
 (0)