|
1 | 1 | import Foundation |
| 2 | +import UIKit |
2 | 3 | import whisper |
3 | 4 |
|
4 | 5 | enum WhisperError: Error { |
@@ -64,67 +65,69 @@ actor WhisperContext { |
64 | 65 | } |
65 | 66 |
|
66 | 67 | func benchFull(modelName: String) async -> String { |
67 | | - let n_threads = Int32(min(4, cpuCount())) // Default in whisper.cpp |
| 68 | + let nThreads = Int32(min(4, cpuCount())) // Default in whisper.cpp |
68 | 69 |
|
69 | | - let n_mels = whisper_model_n_mels(context) |
70 | | - if (whisper_set_mel(context, nil, 0, n_mels) != 0) { |
| 70 | + let nMels = whisper_model_n_mels(context) |
| 71 | + if (whisper_set_mel(context, nil, 0, nMels) != 0) { |
71 | 72 | return "error: failed to set mel" |
72 | 73 | } |
73 | 74 |
|
74 | 75 | // heat encoder |
75 | | - if (whisper_encode(context, 0, n_threads) != 0) { |
| 76 | + if (whisper_encode(context, 0, nThreads) != 0) { |
76 | 77 | return "error: failed to encode" |
77 | 78 | } |
78 | 79 |
|
79 | 80 | var tokens = [whisper_token](repeating: 0, count: 512) |
80 | 81 |
|
81 | 82 | // prompt heat |
82 | | - if (whisper_decode(context, &tokens, 256, 0, n_threads) != 0) { |
| 83 | + if (whisper_decode(context, &tokens, 256, 0, nThreads) != 0) { |
83 | 84 | return "error: failed to decode" |
84 | 85 | } |
85 | 86 |
|
86 | 87 | // text-generation heat |
87 | | - if (whisper_decode(context, &tokens, 1, 256, n_threads) != 0) { |
| 88 | + if (whisper_decode(context, &tokens, 1, 256, nThreads) != 0) { |
88 | 89 | return "error: failed to decode" |
89 | 90 | } |
90 | 91 |
|
91 | 92 | whisper_reset_timings(context) |
92 | 93 |
|
93 | 94 | // actual run |
94 | | - if (whisper_encode(context, 0, n_threads) != 0) { |
| 95 | + if (whisper_encode(context, 0, nThreads) != 0) { |
95 | 96 | return "error: failed to encode" |
96 | 97 | } |
97 | 98 |
|
98 | 99 | // text-generation |
99 | 100 | for i in 0..<256 { |
100 | | - if (whisper_decode(context, &tokens, 1, Int32(i), n_threads) != 0) { |
| 101 | + if (whisper_decode(context, &tokens, 1, Int32(i), nThreads) != 0) { |
101 | 102 | return "error: failed to decode" |
102 | 103 | } |
103 | 104 | } |
104 | 105 |
|
105 | 106 | // batched decoding |
106 | 107 | for _ in 0..<64 { |
107 | | - if (whisper_decode(context, &tokens, 5, 0, n_threads) != 0) { |
| 108 | + if (whisper_decode(context, &tokens, 5, 0, nThreads) != 0) { |
108 | 109 | return "error: failed to decode" |
109 | 110 | } |
110 | 111 | } |
111 | 112 |
|
112 | 113 | // prompt processing |
113 | 114 | for _ in 0..<16 { |
114 | | - if (whisper_decode(context, &tokens, 256, 0, n_threads) != 0) { |
| 115 | + if (whisper_decode(context, &tokens, 256, 0, nThreads) != 0) { |
115 | 116 | return "error: failed to decode" |
116 | 117 | } |
117 | 118 | } |
118 | 119 |
|
119 | 120 | whisper_print_timings(context) |
120 | 121 |
|
121 | | - let system_info = self.systemInfo() |
| 122 | + let deviceModel = UIDevice.current.model |
| 123 | + let systemName = UIDevice.current.systemName |
| 124 | + let systemInfo = self.systemInfo() |
122 | 125 | let timings: whisper_timings = whisper_get_timings(context).pointee |
123 | | - let encode_ms = String(format: "%.2f", timings.encode_ms) |
124 | | - let decode_ms = String(format: "%.2f", timings.decode_ms) |
125 | | - let batchd_ms = String(format: "%.2f", timings.batchd_ms) |
126 | | - let prompt_ms = String(format: "%.2f", timings.prompt_ms) |
127 | | - return "| <todo> | iOS | \(system_info) | \(modelName) | \(n_threads) | 1 | \(encode_ms) | \(decode_ms) | \(batchd_ms) | \(prompt_ms) | <todo> |" |
| 126 | + let encodeMs = String(format: "%.2f", timings.encode_ms) |
| 127 | + let decodeMs = String(format: "%.2f", timings.decode_ms) |
| 128 | + let batchdMs = String(format: "%.2f", timings.batchd_ms) |
| 129 | + let promptMs = String(format: "%.2f", timings.prompt_ms) |
| 130 | + return "| \(deviceModel) | \(systemName) | \(systemInfo) | \(modelName) | \(nThreads) | 1 | \(encodeMs) | \(decodeMs) | \(batchdMs) | \(promptMs) | <todo> |" |
128 | 131 | } |
129 | 132 |
|
130 | 133 | static func createContext(path: String) throws -> WhisperContext { |
|
0 commit comments