Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions Sources/Config/DownloadProgressInfo.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,21 @@ struct DownloadProgressInfo: Equatable, Sendable {
let totalBytes: Int64
let speedBytesPerSecond: Double

init(
fraction: Double,
elapsedSeconds: TimeInterval,
completedBytes: Int64,
totalBytes: Int64,
speedBytesPerSecond: Double
) {
let completedBytes = max(completedBytes, 0)
self.fraction = Self.clampFraction(fraction)
self.elapsedSeconds = elapsedSeconds.isFinite ? max(elapsedSeconds, 0) : 0
self.completedBytes = completedBytes
self.totalBytes = totalBytes > 0 ? max(totalBytes, completedBytes) : 0
self.speedBytesPerSecond = speedBytesPerSecond.isFinite ? max(speedBytesPerSecond, 0) : 0
}

var percentText: String {
"\(Int(clampedFraction * 100))%"
}
Expand DownExpand Up@@ -78,7 +93,7 @@ final class DownloadProgressTracker: @unchecked Sendable {
init(startDate: Date = Date(), initialBytes: Int64 = 0) {
self.startDate = startDate
lastTime = startDate
lastBytes = initialBytes
lastBytes = max(initialBytes, 0)
}

func update(progress: Progress, fraction: Double? = nil) -> DownloadProgressInfo {
Expand All@@ -90,17 +105,27 @@ final class DownloadProgressTracker: @unchecked Sendable {
}

func update(completedBytes rawCompleted: Int64, totalBytes rawTotal: Int64, fraction: Double? = nil) -> DownloadProgressInfo {
update(completedBytes: rawCompleted, totalBytes: rawTotal, fraction: fraction, at: Date())
}

func update(
completedBytes rawCompleted: Int64,
totalBytes rawTotal: Int64,
fraction: Double? = nil,
at now: Date
) -> DownloadProgressInfo {
lock.lock()
defer { lock.unlock() }

let completedBytes = max(rawCompleted, 0)
let totalBytes = max(rawTotal, 0)
let now = Date()
let totalBytes = rawTotal > 0 ? max(rawTotal, completedBytes) : 0
let sampleElapsed = now.timeIntervalSince(lastTime)
if sampleElapsed > 0.5 {
let deltaBytes = completedBytes - lastBytes
if deltaBytes >= 0 {
lastSpeedBytesPerSecond = Double(deltaBytes) / sampleElapsed
} else {
lastSpeedBytesPerSecond = 0
}
lastTime = now
lastBytes = completedBytes
Expand Down
12 changes: 9 additions & 3 deletions Sources/Config/ModelCatalog.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -210,15 +210,21 @@ final class ModelCatalog: ObservableObject {
whisperModels[idx].downloadProgress = 0

do {
let tracker = DownloadProgressTracker()
let modelDir = ModelStorage.whisperVariantDir(id)
let tracker = DownloadProgressTracker(initialBytes: ModelStorage.directorySize(at: modelDir))

_ = try await WhisperKit.download(
variant: id,
downloadBase: Self.whisperDownloadBase,
progressCallback: { [weak self] p in
Task { @MainActor in
guard let self, let i = self.whisperModels.firstIndex(where: { $0.id == id }) else { return }
let info = tracker.update(progress: p)
let completedBytes = ModelStorage.directorySize(at: modelDir)
let info = tracker.update(
completedBytes: completedBytes > 0 ? completedBytes : p.completedUnitCount,
totalBytes: p.totalUnitCount,
fraction: p.fractionCompleted
)
self.whisperModels[i].downloadProgress = info.fraction
self.whisperModels[i].downloadDetail = info.detailText
}
Expand DownExpand Up@@ -279,9 +285,9 @@ final class ModelCatalog: ObservableObject {
llmModels[idx].downloadProgress = 0

do {
let tracker = DownloadProgressTracker()
let estimatedTotalBytes = estimatedLLMDownloadBytes(id) ?? 0
let repoDir = ModelStorage.hubModelRepoDir(id)
let tracker = DownloadProgressTracker(initialBytes: ModelStorage.directorySize(at: repoDir))
let config = ModelConfiguration(id: id)
_ = try await LLMModelFactory.shared.loadContainer(
from: MLXModelLoading.downloader,
Expand Down
2 changes: 1 addition & 1 deletion Sources/Config/ModelCatalogASR.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -82,8 +82,8 @@ extension ModelCatalog {
try await ensureMimoRepository()
}
if !asrModelFilesAreComplete(id) {
let tracker = DownloadProgressTracker(startDate: startedAt, initialBytes: asrRepoSize(id))
for (repoIndex, repoID) in repos.enumerated() {
let tracker = DownloadProgressTracker(startDate: startedAt)
_ = try await api.snapshot(from: ModelStorage.hubModelRepo(repoID)) { [weak self] progress in
Task { @MainActor in
guard let self, let i = self.asrModels.firstIndex(where: { $0.id == id }) else { return }
Expand Down
77 changes: 68 additions & 9 deletions Sources/Config/ModelCatalogDownloadEstimates.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,30 +3,89 @@ import Foundation
@MainActor
extension ModelCatalog {
func estimatedLLMDownloadBytes(_ id: String) -> Int64? {
if let bytes = Self.defaultDownloadEstimateBytes(for: id) { return bytes }
guard let model = llmModels.first(where: { $0.id == id }) else { return nil }
return Self.estimatedDownloadBytes(from: model.hint)
}

func estimatedASRDownloadBytes(_ id: String) -> Int64? {
if let bytes = Self.defaultDownloadEstimateBytes(for: id) { return bytes }
guard let model = asrModels.first(where: { $0.id == id }) else { return nil }
return Self.estimatedDownloadBytes(from: model.hint)
}

static func estimatedDownloadBytes(from text: String) -> Int64? {
let pattern = #"([0-9]+(?:\.[0-9]+)?)\s*(GB|MB)"#
guard let regex = try? NSRegularExpression(pattern: pattern, options: [.caseInsensitive]) else {
return nil
}
static func defaultDownloadEstimateBytes(for id: String) -> Int64? {
defaultDownloadEstimateBytes[id]
}

static func estimatedDownloadBytes(from text: String) -> Int64? {
let range = NSRange(text.startIndex..<text.endIndex, in: text)
guard let match = regex.matches(in: text, range: range).last,
guard let match = downloadEstimateRegex.matches(in: text, range: range).last,
match.numberOfRanges == 3,
let valueRange = Range(match.range(at: 1), in: text),
let unitRange = Range(match.range(at: 2), in: text),
let value = Double(text[valueRange]) else { return nil }
let value = parseDownloadEstimateValue(String(text[valueRange])) else { return nil }

let unit = text[unitRange].uppercased()
let multiplier = unit == "GB" ? 1_000_000_000.0 : 1_000_000.0
return Int64(value * multiplier)
guard let multiplier = downloadEstimateMultiplier(for: unit) else { return nil }
let bytes = value * multiplier
guard bytes.isFinite, bytes > 0, bytes <= Double(Int64.max) else { return nil }
return Int64(bytes)
}

private static let defaultDownloadEstimateBytes: [String: Int64] = [
"mlx-community/Qwen3.5-0.8B-MLX-4bit": 652_027_143,
"mlx-community/Qwen3.5-2B-4bit": 1_749_079_691,
"mlx-community/Qwen3.5-9B-5bit": 7_096_163_574,
"mlx-community/Qwen3-30B-A3B-4bit": 17_190_783_781,
"mlx-community/Qwen3.5-35B-A3B-4bit": 20_418_622_319,
"mlx-community/Qwen2.5-0.5B-Instruct-4bit": 289_598_797,
"mlx-community/Qwen2.5-1.5B-Instruct-4bit": 880_169_797,
"mlx-community/Qwen2.5-3B-Instruct-4bit": 1_747_849_050,
"mlx-community/Qwen3-0.6B-4bit": 351_383_618,
"mlx-community/Qwen3-1.7B-4bit": 984_013_244,
"mlx-community/Qwen3-4B-4bit": 2_278_969_756,
"mlx-community/gemma-4-e2b-it-4bit": 3_613_528_388,
"mlx-community/gemma-4-e4b-it-4bit": 5_249_809_327,
"mlx-community/gemma-3-1b-it-4bit": 771_860_852,
"mlx-community/gemma-3-4b-it-4bit": 3_439_894_985,
"mlx-community/gemma-3-12b-it-4bit": 8_068_018_787,
"mlx-community/Llama-4-Scout-17B-16E-Instruct-4bit": 61_143_654_248,
"mlx-community/Llama-4-Maverick-17B-128E-Instruct-4bit": 225_923_469_800,
LocalASRConfiguration.qwen3DefaultModel: 4_080_707_826,
LocalASRConfiguration.mimoDefaultModel: 35_997_080_271,
]

private static let downloadEstimateRegex = try! NSRegularExpression(
pattern: #"([0-9]+(?:[\.,][0-9]+)?)\s*(TiB|GiB|MiB|KiB|TB|GB|MB|KB|T|G|M|K)(?![A-Za-z])"#,
options: [.caseInsensitive]
)

private static func parseDownloadEstimateValue(_ rawValue: String) -> Double? {
if rawValue.contains("."), rawValue.contains(",") {
return Double(rawValue.replacingOccurrences(of: ",", with: ""))
}
if let commaIndex = rawValue.firstIndex(of: ",") {
let fraction = rawValue[rawValue.index(after: commaIndex)...]
let normalized = fraction.count == 3
? rawValue.replacingOccurrences(of: ",", with: "")
: rawValue.replacingOccurrences(of: ",", with: ".")
return Double(normalized)
}
return Double(rawValue)
}

private static func downloadEstimateMultiplier(for rawUnit: String) -> Double? {
switch rawUnit {
case "TIB": return pow(1024, 4)
case "GIB": return pow(1024, 3)
case "MIB": return pow(1024, 2)
case "KIB": return 1024
case "TB", "T": return 1_000_000_000_000
case "GB", "G": return 1_000_000_000
case "MB", "M": return 1_000_000
case "KB", "K": return 1_000
default: return nil
}
}
}
2 changes: 1 addition & 1 deletion Sources/LLM/LLMEngine.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,9 +30,9 @@ actor LLMEngine {
speedBytesPerSecond: 0
))
} else {
let tracker = DownloadProgressTracker()
let estimatedTotalBytes = estimatedDownloadBytes ?? 0
let repoDir = ModelStorage.hubModelRepoDir(id)
let tracker = DownloadProgressTracker(initialBytes: ModelStorage.directorySize(at: repoDir))
let config = Self.modelConfiguration(for: id)
container = try await LLMModelFactory.shared.loadContainer(
from: MLXModelLoading.downloader,
Expand Down
34 changes: 17 additions & 17 deletions Sources/Resources/en.lproj/Localizable.strings
Original file line numberDiff line numberDiff line change
Expand Up@@ -164,24 +164,24 @@
"model.last_formatting_value" = "%.2fs";
"model.compiling" = "Compiling…";
"model.loading" = "Loading…";
"model.smallest" = "Smallest, fastest ~335 MB";
"model.balanced" = "Balanced ~1 GB";
"model.best_quality" = "Best quality ~2.3 GB";
"model.qwen3_fast" = "Fastest, weaker cleanup ~335 MB";
"model.qwen3_balanced" = "Qwen3, balanced ~1 GB";
"model.smallest" = "Smallest, fastest ~290 MB";
"model.balanced" = "Balanced ~880 MB";
"model.best_quality" = "Best quality ~1.7 GB";
"model.qwen3_fast" = "Fastest, weaker cleanup ~351 MB";
"model.qwen3_balanced" = "Qwen3, balanced ~984 MB";
"model.qwen3_quality" = "Qwen3, best quality ~2.3 GB";
"model.qwen3_moe" = "Qwen3 MoE flagship, recommended ~5 GB";
"model.qwen35_tiny" = "Qwen3.5, fastest ~620 MB";
"model.qwen35_fast" = "Recommended for Smart Format ~1.5 GB";
"model.qwen35_quality" = "Best quality cleanup 5-bit ~5.5 GB";
"model.qwen35_moe" = "Qwen3.5 MoE flagship ~6 GB";
"model.gemma_fast" = "Gemma 3, fast ~600 MB";
"model.gemma_balanced" = "Gemma 3, balanced ~2.5 GB";
"model.gemma_quality" = "Gemma 3, best quality ~7 GB";
"model.qwen3_moe" = "Qwen3 MoE flagship, recommended ~17.2 GB";
"model.qwen35_tiny" = "Qwen3.5, fastest ~652 MB";
"model.qwen35_fast" = "Recommended for Smart Format ~1.7 GB";
"model.qwen35_quality" = "Best quality cleanup 5-bit ~7.1 GB";
"model.qwen35_moe" = "Qwen3.5 MoE flagship ~20.4 GB";
"model.gemma_fast" = "Gemma 3, fast ~772 MB";
"model.gemma_balanced" = "Gemma 3, balanced ~3.4 GB";
"model.gemma_quality" = "Gemma 3, best quality ~8.1 GB";
"model.gemma4_edge" = "Gemma 4 edge model ~3.6 GB";
"model.gemma4_edge_quality" = "Gemma 4 edge quality ~5.2 GB";
"model.llama_balanced" = "Llama 4 Scout, balanced ~10 GB";
"model.llama_quality" = "Llama 4 Maverick, high quality ~25 GB";
"model.llama_balanced" = "Llama 4 Scout, balanced ~61.1 GB";
"model.llama_quality" = "Llama 4 Maverick, high quality ~225.9 GB";
"model.import_local" = "Import Local Model…";
"model.import_invalid" = "Invalid model directory: config.json not found";
"model.import_failed" = "Import Failed";
Expand DownExpand Up@@ -341,8 +341,8 @@
"local_asr.tokenizer_path" = "Audio tokenizer path";
"qwen_asr.config_hint" = "Choose Qwen3-ASR, then click Download to fetch the local model and prepare its Python runtime.";
"mimo_asr.config_hint" = "Choose MiMo-V2.5-ASR, then click Download to fetch the model, audio tokenizer, and runtime files.";
"model.qwen3_asr_quality" = "Local ASR through MLX, ~4 GB";
"model.mimo_asr_quality" = "Local ASR model plus audio tokenizer";
"model.qwen3_asr_quality" = "Local ASR through MLX, ~4.1 GB";
"model.mimo_asr_quality" = "Local ASR model plus audio tokenizer ~36 GB";
"model.asr_incomplete" = "Download incomplete";
"model.asr_preparing_runtime" = "Preparing runtime files";
"model.asr_installing_runtime" = "Installing local runtime";
Expand Down
34 changes: 17 additions & 17 deletions Sources/Resources/zh-Hans.lproj/Localizable.strings
Original file line numberDiff line numberDiff line change
Expand Up@@ -164,24 +164,24 @@
"model.last_formatting_value" = "%.2f 秒";
"model.compiling" = "编译中…";
"model.loading" = "加载中…";
"model.smallest" = "最小最快 ~335 MB";
"model.balanced" = "平衡选择 ~1 GB";
"model.best_quality" = "质量最佳 ~2.3 GB";
"model.qwen3_fast" = "极速,整理偏弱 ~335 MB";
"model.qwen3_balanced" = "Qwen3 均衡 ~1 GB";
"model.smallest" = "最小最快 ~290 MB";
"model.balanced" = "平衡选择 ~880 MB";
"model.best_quality" = "质量最佳 ~1.7 GB";
"model.qwen3_fast" = "极速,整理偏弱 ~351 MB";
"model.qwen3_balanced" = "Qwen3 均衡 ~984 MB";
"model.qwen3_quality" = "Qwen3 高质量 ~2.3 GB";
"model.qwen3_moe" = "Qwen3 MoE 旗舰,推荐 ~5 GB";
"model.qwen35_tiny" = "Qwen3.5 极速 ~620 MB";
"model.qwen35_fast" = "智能整理推荐 ~1.5 GB";
"model.qwen35_quality" = "整理质量最佳 5-bit ~5.5 GB";
"model.qwen35_moe" = "Qwen3.5 MoE 旗舰 ~6 GB";
"model.gemma_fast" = "Gemma 3 极速 ~600 MB";
"model.gemma_balanced" = "Gemma 3 均衡 ~2.5 GB";
"model.gemma_quality" = "Gemma 3 高质量 ~7 GB";
"model.qwen3_moe" = "Qwen3 MoE 旗舰,推荐 ~17.2 GB";
"model.qwen35_tiny" = "Qwen3.5 极速 ~652 MB";
"model.qwen35_fast" = "智能整理推荐 ~1.7 GB";
"model.qwen35_quality" = "整理质量最佳 5-bit ~7.1 GB";
"model.qwen35_moe" = "Qwen3.5 MoE 旗舰 ~20.4 GB";
"model.gemma_fast" = "Gemma 3 极速 ~772 MB";
"model.gemma_balanced" = "Gemma 3 均衡 ~3.4 GB";
"model.gemma_quality" = "Gemma 3 高质量 ~8.1 GB";
"model.gemma4_edge" = "Gemma 4 端侧模型 ~3.6 GB";
"model.gemma4_edge_quality" = "Gemma 4 端侧高质量 ~5.2 GB";
"model.llama_balanced" = "Llama 4 Scout 均衡 ~10 GB";
"model.llama_quality" = "Llama 4 Maverick 高质量 ~25 GB";
"model.llama_balanced" = "Llama 4 Scout 均衡 ~61.1 GB";
"model.llama_quality" = "Llama 4 Maverick 高质量 ~225.9 GB";
"model.import_local" = "导入本地模型…";
"model.import_invalid" = "无效的模型目录:未找到 config.json";
"model.import_failed" = "导入失败";
Expand DownExpand Up@@ -341,8 +341,8 @@
"local_asr.tokenizer_path" = "音频 tokenizer 路径";
"qwen_asr.config_hint" = "选择 Qwen3-ASR 后,请点击下载按钮获取本地模型,并准备对应的 Python 运行环境。";
"mimo_asr.config_hint" = "选择 MiMo-V2.5-ASR 后,请点击下载按钮获取模型、音频 tokenizer 和运行文件。";
"model.qwen3_asr_quality" = "本地 MLX 语音识别,约 4 GB";
"model.mimo_asr_quality" = "本地语音识别模型 + 音频 tokenizer";
"model.qwen3_asr_quality" = "本地 MLX 语音识别,约 4.1 GB";
"model.mimo_asr_quality" = "本地语音识别模型 + 音频 tokenizer,约 36 GB";
"model.asr_incomplete" = "下载不完整";
"model.asr_preparing_runtime" = "准备运行文件";
"model.asr_installing_runtime" = "安装本地运行环境";
Expand Down
6 changes: 4 additions & 2 deletions Sources/Speech/WhisperEngine.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -82,7 +82,8 @@ final class WhisperEngine: SpeechEngine, @unchecked Sendable {

progress(dp(0.02, stage: .downloading))

let tracker = DownloadProgressTracker()
let modelDir = ModelStorage.whisperVariantDir(selectedModel)
let tracker = DownloadProgressTracker(initialBytes: ModelStorage.directorySize(at: modelDir))

let folder: URL
if let localFolder {
Expand All@@ -93,7 +94,8 @@ final class WhisperEngine: SpeechEngine, @unchecked Sendable {
variant: selectedModel,
downloadBase: ModelCatalog.whisperDownloadBase,
progressCallback: { p in
let completed = p.completedUnitCount
let downloadedBytes = ModelStorage.directorySize(at: modelDir)
let completed = downloadedBytes > 0 ? downloadedBytes : p.completedUnitCount
let total = p.totalUnitCount

let frac = 0.02 + p.fractionCompleted * 0.58
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions Sources/Config/DownloadProgressInfo.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,21 @@ struct DownloadProgressInfo: Equatable, Sendable {
let totalBytes: Int64
let speedBytesPerSecond: Double

init(
fraction: Double,
elapsedSeconds: TimeInterval,
completedBytes: Int64,
totalBytes: Int64,
speedBytesPerSecond: Double
) {
let completedBytes = max(completedBytes, 0)
self.fraction = Self.clampFraction(fraction)
self.elapsedSeconds = elapsedSeconds.isFinite ? max(elapsedSeconds, 0) : 0
self.completedBytes = completedBytes
self.totalBytes = totalBytes > 0 ? max(totalBytes, completedBytes) : 0
self.speedBytesPerSecond = speedBytesPerSecond.isFinite ? max(speedBytesPerSecond, 0) : 0
}

var percentText: String {
"\(Int(clampedFraction * 100))%"
}
Expand DownExpand Up@@ -78,7 +93,7 @@ final class DownloadProgressTracker: @unchecked Sendable {
init(startDate: Date = Date(), initialBytes: Int64 = 0) {
self.startDate = startDate
lastTime = startDate
lastBytes = initialBytes
lastBytes = max(initialBytes, 0)
}

func update(progress: Progress, fraction: Double? = nil) -> DownloadProgressInfo {
Expand All@@ -90,17 +105,27 @@ final class DownloadProgressTracker: @unchecked Sendable {
}

func update(completedBytes rawCompleted: Int64, totalBytes rawTotal: Int64, fraction: Double? = nil) -> DownloadProgressInfo {
update(completedBytes: rawCompleted, totalBytes: rawTotal, fraction: fraction, at: Date())
}

func update(
completedBytes rawCompleted: Int64,
totalBytes rawTotal: Int64,
fraction: Double? = nil,
at now: Date
) -> DownloadProgressInfo {
lock.lock()
defer { lock.unlock() }

let completedBytes = max(rawCompleted, 0)
let totalBytes = max(rawTotal, 0)
let now = Date()
let totalBytes = rawTotal > 0 ? max(rawTotal, completedBytes) : 0
let sampleElapsed = now.timeIntervalSince(lastTime)
if sampleElapsed > 0.5 {
let deltaBytes = completedBytes - lastBytes
if deltaBytes >= 0 {
lastSpeedBytesPerSecond = Double(deltaBytes) / sampleElapsed
} else {
lastSpeedBytesPerSecond = 0
}
lastTime = now
lastBytes = completedBytes
Expand Down
12 changes: 9 additions & 3 deletions Sources/Config/ModelCatalog.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -210,15 +210,21 @@ final class ModelCatalog: ObservableObject {
whisperModels[idx].downloadProgress = 0

do {
let tracker = DownloadProgressTracker()
let modelDir = ModelStorage.whisperVariantDir(id)
let tracker = DownloadProgressTracker(initialBytes: ModelStorage.directorySize(at: modelDir))

_ = try await WhisperKit.download(
variant: id,
downloadBase: Self.whisperDownloadBase,
progressCallback: { [weak self] p in
Task { @MainActor in
guard let self, let i = self.whisperModels.firstIndex(where: { $0.id == id }) else { return }
let info = tracker.update(progress: p)
let completedBytes = ModelStorage.directorySize(at: modelDir)
let info = tracker.update(
completedBytes: completedBytes > 0 ? completedBytes : p.completedUnitCount,
totalBytes: p.totalUnitCount,
fraction: p.fractionCompleted
)
self.whisperModels[i].downloadProgress = info.fraction
self.whisperModels[i].downloadDetail = info.detailText
}
Expand DownExpand Up@@ -279,9 +285,9 @@ final class ModelCatalog: ObservableObject {
llmModels[idx].downloadProgress = 0

do {
let tracker = DownloadProgressTracker()
let estimatedTotalBytes = estimatedLLMDownloadBytes(id) ?? 0
let repoDir = ModelStorage.hubModelRepoDir(id)
let tracker = DownloadProgressTracker(initialBytes: ModelStorage.directorySize(at: repoDir))
let config = ModelConfiguration(id: id)
_ = try await LLMModelFactory.shared.loadContainer(
from: MLXModelLoading.downloader,
Expand Down
2 changes: 1 addition & 1 deletion Sources/Config/ModelCatalogASR.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -82,8 +82,8 @@ extension ModelCatalog {
try await ensureMimoRepository()
}
if !asrModelFilesAreComplete(id) {
let tracker = DownloadProgressTracker(startDate: startedAt, initialBytes: asrRepoSize(id))
for (repoIndex, repoID) in repos.enumerated() {
let tracker = DownloadProgressTracker(startDate: startedAt)
_ = try await api.snapshot(from: ModelStorage.hubModelRepo(repoID)) { [weak self] progress in
Task { @MainActor in
guard let self, let i = self.asrModels.firstIndex(where: { $0.id == id }) else { return }
Expand Down
77 changes: 68 additions & 9 deletions Sources/Config/ModelCatalogDownloadEstimates.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,30 +3,89 @@ import Foundation
@MainActor
extension ModelCatalog {
func estimatedLLMDownloadBytes(_ id: String) -> Int64? {
if let bytes = Self.defaultDownloadEstimateBytes(for: id) { return bytes }
guard let model = llmModels.first(where: { $0.id == id }) else { return nil }
return Self.estimatedDownloadBytes(from: model.hint)
}

func estimatedASRDownloadBytes(_ id: String) -> Int64? {
if let bytes = Self.defaultDownloadEstimateBytes(for: id) { return bytes }
guard let model = asrModels.first(where: { $0.id == id }) else { return nil }
return Self.estimatedDownloadBytes(from: model.hint)
}

static func estimatedDownloadBytes(from text: String) -> Int64? {
let pattern = #"([0-9]+(?:\.[0-9]+)?)\s*(GB|MB)"#
guard let regex = try? NSRegularExpression(pattern: pattern, options: [.caseInsensitive]) else {
return nil
}
static func defaultDownloadEstimateBytes(for id: String) -> Int64? {
defaultDownloadEstimateBytes[id]
}

static func estimatedDownloadBytes(from text: String) -> Int64? {
let range = NSRange(text.startIndex..<text.endIndex, in: text)
guard let match = regex.matches(in: text, range: range).last,
guard let match = downloadEstimateRegex.matches(in: text, range: range).last,
match.numberOfRanges == 3,
let valueRange = Range(match.range(at: 1), in: text),
let unitRange = Range(match.range(at: 2), in: text),
let value = Double(text[valueRange]) else { return nil }
let value = parseDownloadEstimateValue(String(text[valueRange])) else { return nil }

let unit = text[unitRange].uppercased()
let multiplier = unit == "GB" ? 1_000_000_000.0 : 1_000_000.0
return Int64(value * multiplier)
guard let multiplier = downloadEstimateMultiplier(for: unit) else { return nil }
let bytes = value * multiplier
guard bytes.isFinite, bytes > 0, bytes <= Double(Int64.max) else { return nil }
return Int64(bytes)
}

private static let defaultDownloadEstimateBytes: [String: Int64] = [
"mlx-community/Qwen3.5-0.8B-MLX-4bit": 652_027_143,
"mlx-community/Qwen3.5-2B-4bit": 1_749_079_691,
"mlx-community/Qwen3.5-9B-5bit": 7_096_163_574,
"mlx-community/Qwen3-30B-A3B-4bit": 17_190_783_781,
"mlx-community/Qwen3.5-35B-A3B-4bit": 20_418_622_319,
"mlx-community/Qwen2.5-0.5B-Instruct-4bit": 289_598_797,
"mlx-community/Qwen2.5-1.5B-Instruct-4bit": 880_169_797,
"mlx-community/Qwen2.5-3B-Instruct-4bit": 1_747_849_050,
"mlx-community/Qwen3-0.6B-4bit": 351_383_618,
"mlx-community/Qwen3-1.7B-4bit": 984_013_244,
"mlx-community/Qwen3-4B-4bit": 2_278_969_756,
"mlx-community/gemma-4-e2b-it-4bit": 3_613_528_388,
"mlx-community/gemma-4-e4b-it-4bit": 5_249_809_327,
"mlx-community/gemma-3-1b-it-4bit": 771_860_852,
"mlx-community/gemma-3-4b-it-4bit": 3_439_894_985,
"mlx-community/gemma-3-12b-it-4bit": 8_068_018_787,
"mlx-community/Llama-4-Scout-17B-16E-Instruct-4bit": 61_143_654_248,
"mlx-community/Llama-4-Maverick-17B-128E-Instruct-4bit": 225_923_469_800,
LocalASRConfiguration.qwen3DefaultModel: 4_080_707_826,
LocalASRConfiguration.mimoDefaultModel: 35_997_080_271,
]

private static let downloadEstimateRegex = try! NSRegularExpression(
pattern: #"([0-9]+(?:[\.,][0-9]+)?)\s*(TiB|GiB|MiB|KiB|TB|GB|MB|KB|T|G|M|K)(?![A-Za-z])"#,
options: [.caseInsensitive]
)

private static func parseDownloadEstimateValue(_ rawValue: String) -> Double? {
if rawValue.contains("."), rawValue.contains(",") {
return Double(rawValue.replacingOccurrences(of: ",", with: ""))
}
if let commaIndex = rawValue.firstIndex(of: ",") {
let fraction = rawValue[rawValue.index(after: commaIndex)...]
let normalized = fraction.count == 3
? rawValue.replacingOccurrences(of: ",", with: "")
: rawValue.replacingOccurrences(of: ",", with: ".")
return Double(normalized)
}
return Double(rawValue)
}

private static func downloadEstimateMultiplier(for rawUnit: String) -> Double? {
switch rawUnit {
case "TIB": return pow(1024, 4)
case "GIB": return pow(1024, 3)
case "MIB": return pow(1024, 2)
case "KIB": return 1024
case "TB", "T": return 1_000_000_000_000
case "GB", "G": return 1_000_000_000
case "MB", "M": return 1_000_000
case "KB", "K": return 1_000
default: return nil
}
}
}
2 changes: 1 addition & 1 deletion Sources/LLM/LLMEngine.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,9 +30,9 @@ actor LLMEngine {
speedBytesPerSecond: 0
))
} else {
let tracker = DownloadProgressTracker()
let estimatedTotalBytes = estimatedDownloadBytes ?? 0
let repoDir = ModelStorage.hubModelRepoDir(id)
let tracker = DownloadProgressTracker(initialBytes: ModelStorage.directorySize(at: repoDir))
let config = Self.modelConfiguration(for: id)
container = try await LLMModelFactory.shared.loadContainer(
from: MLXModelLoading.downloader,
Expand Down
34 changes: 17 additions & 17 deletions Sources/Resources/en.lproj/Localizable.strings
Original file line numberDiff line numberDiff line change
Expand Up@@ -164,24 +164,24 @@
"model.last_formatting_value" = "%.2fs";
"model.compiling" = "Compiling…";
"model.loading" = "Loading…";
"model.smallest" = "Smallest, fastest ~335 MB";
"model.balanced" = "Balanced ~1 GB";
"model.best_quality" = "Best quality ~2.3 GB";
"model.qwen3_fast" = "Fastest, weaker cleanup ~335 MB";
"model.qwen3_balanced" = "Qwen3, balanced ~1 GB";
"model.smallest" = "Smallest, fastest ~290 MB";
"model.balanced" = "Balanced ~880 MB";
"model.best_quality" = "Best quality ~1.7 GB";
"model.qwen3_fast" = "Fastest, weaker cleanup ~351 MB";
"model.qwen3_balanced" = "Qwen3, balanced ~984 MB";
"model.qwen3_quality" = "Qwen3, best quality ~2.3 GB";
"model.qwen3_moe" = "Qwen3 MoE flagship, recommended ~5 GB";
"model.qwen35_tiny" = "Qwen3.5, fastest ~620 MB";
"model.qwen35_fast" = "Recommended for Smart Format ~1.5 GB";
"model.qwen35_quality" = "Best quality cleanup 5-bit ~5.5 GB";
"model.qwen35_moe" = "Qwen3.5 MoE flagship ~6 GB";
"model.gemma_fast" = "Gemma 3, fast ~600 MB";
"model.gemma_balanced" = "Gemma 3, balanced ~2.5 GB";
"model.gemma_quality" = "Gemma 3, best quality ~7 GB";
"model.qwen3_moe" = "Qwen3 MoE flagship, recommended ~17.2 GB";
"model.qwen35_tiny" = "Qwen3.5, fastest ~652 MB";
"model.qwen35_fast" = "Recommended for Smart Format ~1.7 GB";
"model.qwen35_quality" = "Best quality cleanup 5-bit ~7.1 GB";
"model.qwen35_moe" = "Qwen3.5 MoE flagship ~20.4 GB";
"model.gemma_fast" = "Gemma 3, fast ~772 MB";
"model.gemma_balanced" = "Gemma 3, balanced ~3.4 GB";
"model.gemma_quality" = "Gemma 3, best quality ~8.1 GB";
"model.gemma4_edge" = "Gemma 4 edge model ~3.6 GB";
"model.gemma4_edge_quality" = "Gemma 4 edge quality ~5.2 GB";
"model.llama_balanced" = "Llama 4 Scout, balanced ~10 GB";
"model.llama_quality" = "Llama 4 Maverick, high quality ~25 GB";
"model.llama_balanced" = "Llama 4 Scout, balanced ~61.1 GB";
"model.llama_quality" = "Llama 4 Maverick, high quality ~225.9 GB";
"model.import_local" = "Import Local Model…";
"model.import_invalid" = "Invalid model directory: config.json not found";
"model.import_failed" = "Import Failed";
Expand DownExpand Up@@ -341,8 +341,8 @@
"local_asr.tokenizer_path" = "Audio tokenizer path";
"qwen_asr.config_hint" = "Choose Qwen3-ASR, then click Download to fetch the local model and prepare its Python runtime.";
"mimo_asr.config_hint" = "Choose MiMo-V2.5-ASR, then click Download to fetch the model, audio tokenizer, and runtime files.";
"model.qwen3_asr_quality" = "Local ASR through MLX, ~4 GB";
"model.mimo_asr_quality" = "Local ASR model plus audio tokenizer";
"model.qwen3_asr_quality" = "Local ASR through MLX, ~4.1 GB";
"model.mimo_asr_quality" = "Local ASR model plus audio tokenizer ~36 GB";
"model.asr_incomplete" = "Download incomplete";
"model.asr_preparing_runtime" = "Preparing runtime files";
"model.asr_installing_runtime" = "Installing local runtime";
Expand Down
34 changes: 17 additions & 17 deletions Sources/Resources/zh-Hans.lproj/Localizable.strings
Original file line numberDiff line numberDiff line change
Expand Up@@ -164,24 +164,24 @@
"model.last_formatting_value" = "%.2f 秒";
"model.compiling" = "编译中…";
"model.loading" = "加载中…";
"model.smallest" = "最小最快 ~335 MB";
"model.balanced" = "平衡选择 ~1 GB";
"model.best_quality" = "质量最佳 ~2.3 GB";
"model.qwen3_fast" = "极速,整理偏弱 ~335 MB";
"model.qwen3_balanced" = "Qwen3 均衡 ~1 GB";
"model.smallest" = "最小最快 ~290 MB";
"model.balanced" = "平衡选择 ~880 MB";
"model.best_quality" = "质量最佳 ~1.7 GB";
"model.qwen3_fast" = "极速,整理偏弱 ~351 MB";
"model.qwen3_balanced" = "Qwen3 均衡 ~984 MB";
"model.qwen3_quality" = "Qwen3 高质量 ~2.3 GB";
"model.qwen3_moe" = "Qwen3 MoE 旗舰,推荐 ~5 GB";
"model.qwen35_tiny" = "Qwen3.5 极速 ~620 MB";
"model.qwen35_fast" = "智能整理推荐 ~1.5 GB";
"model.qwen35_quality" = "整理质量最佳 5-bit ~5.5 GB";
"model.qwen35_moe" = "Qwen3.5 MoE 旗舰 ~6 GB";
"model.gemma_fast" = "Gemma 3 极速 ~600 MB";
"model.gemma_balanced" = "Gemma 3 均衡 ~2.5 GB";
"model.gemma_quality" = "Gemma 3 高质量 ~7 GB";
"model.qwen3_moe" = "Qwen3 MoE 旗舰,推荐 ~17.2 GB";
"model.qwen35_tiny" = "Qwen3.5 极速 ~652 MB";
"model.qwen35_fast" = "智能整理推荐 ~1.7 GB";
"model.qwen35_quality" = "整理质量最佳 5-bit ~7.1 GB";
"model.qwen35_moe" = "Qwen3.5 MoE 旗舰 ~20.4 GB";
"model.gemma_fast" = "Gemma 3 极速 ~772 MB";
"model.gemma_balanced" = "Gemma 3 均衡 ~3.4 GB";
"model.gemma_quality" = "Gemma 3 高质量 ~8.1 GB";
"model.gemma4_edge" = "Gemma 4 端侧模型 ~3.6 GB";
"model.gemma4_edge_quality" = "Gemma 4 端侧高质量 ~5.2 GB";
"model.llama_balanced" = "Llama 4 Scout 均衡 ~10 GB";
"model.llama_quality" = "Llama 4 Maverick 高质量 ~25 GB";
"model.llama_balanced" = "Llama 4 Scout 均衡 ~61.1 GB";
"model.llama_quality" = "Llama 4 Maverick 高质量 ~225.9 GB";
"model.import_local" = "导入本地模型…";
"model.import_invalid" = "无效的模型目录:未找到 config.json";
"model.import_failed" = "导入失败";
Expand DownExpand Up@@ -341,8 +341,8 @@
"local_asr.tokenizer_path" = "音频 tokenizer 路径";
"qwen_asr.config_hint" = "选择 Qwen3-ASR 后,请点击下载按钮获取本地模型,并准备对应的 Python 运行环境。";
"mimo_asr.config_hint" = "选择 MiMo-V2.5-ASR 后,请点击下载按钮获取模型、音频 tokenizer 和运行文件。";
"model.qwen3_asr_quality" = "本地 MLX 语音识别,约 4 GB";
"model.mimo_asr_quality" = "本地语音识别模型 + 音频 tokenizer";
"model.qwen3_asr_quality" = "本地 MLX 语音识别,约 4.1 GB";
"model.mimo_asr_quality" = "本地语音识别模型 + 音频 tokenizer,约 36 GB";
"model.asr_incomplete" = "下载不完整";
"model.asr_preparing_runtime" = "准备运行文件";
"model.asr_installing_runtime" = "安装本地运行环境";
Expand Down
6 changes: 4 additions & 2 deletions Sources/Speech/WhisperEngine.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -82,7 +82,8 @@ final class WhisperEngine: SpeechEngine, @unchecked Sendable {

progress(dp(0.02, stage: .downloading))

let tracker = DownloadProgressTracker()
let modelDir = ModelStorage.whisperVariantDir(selectedModel)
let tracker = DownloadProgressTracker(initialBytes: ModelStorage.directorySize(at: modelDir))

let folder: URL
if let localFolder {
Expand All@@ -93,7 +94,8 @@ final class WhisperEngine: SpeechEngine, @unchecked Sendable {
variant: selectedModel,
downloadBase: ModelCatalog.whisperDownloadBase,
progressCallback: { p in
let completed = p.completedUnitCount
let downloadedBytes = ModelStorage.directorySize(at: modelDir)
let completed = downloadedBytes > 0 ? downloadedBytes : p.completedUnitCount
let total = p.totalUnitCount

let frac = 0.02 + p.fractionCompleted * 0.58
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions Sources/Config/DownloadProgressInfo.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,21 @@ struct DownloadProgressInfo: Equatable, Sendable {
let totalBytes: Int64
let speedBytesPerSecond: Double

init(
fraction: Double,
elapsedSeconds: TimeInterval,
completedBytes: Int64,
totalBytes: Int64,
speedBytesPerSecond: Double
) {
let completedBytes = max(completedBytes, 0)
self.fraction = Self.clampFraction(fraction)
self.elapsedSeconds = elapsedSeconds.isFinite ? max(elapsedSeconds, 0) : 0
self.completedBytes = completedBytes
self.totalBytes = totalBytes > 0 ? max(totalBytes, completedBytes) : 0
self.speedBytesPerSecond = speedBytesPerSecond.isFinite ? max(speedBytesPerSecond, 0) : 0
}

var percentText: String {
"\(Int(clampedFraction * 100))%"
}
Expand DownExpand Up@@ -78,7 +93,7 @@ final class DownloadProgressTracker: @unchecked Sendable {
init(startDate: Date = Date(), initialBytes: Int64 = 0) {
self.startDate = startDate
lastTime = startDate
lastBytes = initialBytes
lastBytes = max(initialBytes, 0)
}

func update(progress: Progress, fraction: Double? = nil) -> DownloadProgressInfo {
Expand All@@ -90,17 +105,27 @@ final class DownloadProgressTracker: @unchecked Sendable {
}

func update(completedBytes rawCompleted: Int64, totalBytes rawTotal: Int64, fraction: Double? = nil) -> DownloadProgressInfo {
update(completedBytes: rawCompleted, totalBytes: rawTotal, fraction: fraction, at: Date())
}

func update(
completedBytes rawCompleted: Int64,
totalBytes rawTotal: Int64,
fraction: Double? = nil,
at now: Date
) -> DownloadProgressInfo {
lock.lock()
defer { lock.unlock() }

let completedBytes = max(rawCompleted, 0)
let totalBytes = max(rawTotal, 0)
let now = Date()
let totalBytes = rawTotal > 0 ? max(rawTotal, completedBytes) : 0
let sampleElapsed = now.timeIntervalSince(lastTime)
if sampleElapsed > 0.5 {
let deltaBytes = completedBytes - lastBytes
if deltaBytes >= 0 {
lastSpeedBytesPerSecond = Double(deltaBytes) / sampleElapsed
} else {
lastSpeedBytesPerSecond = 0
}
lastTime = now
lastBytes = completedBytes
Expand Down
12 changes: 9 additions & 3 deletions Sources/Config/ModelCatalog.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -210,15 +210,21 @@ final class ModelCatalog: ObservableObject {
whisperModels[idx].downloadProgress = 0

do {
let tracker = DownloadProgressTracker()
let modelDir = ModelStorage.whisperVariantDir(id)
let tracker = DownloadProgressTracker(initialBytes: ModelStorage.directorySize(at: modelDir))

_ = try await WhisperKit.download(
variant: id,
downloadBase: Self.whisperDownloadBase,
progressCallback: { [weak self] p in
Task { @MainActor in
guard let self, let i = self.whisperModels.firstIndex(where: { $0.id == id }) else { return }
let info = tracker.update(progress: p)
let completedBytes = ModelStorage.directorySize(at: modelDir)
let info = tracker.update(
completedBytes: completedBytes > 0 ? completedBytes : p.completedUnitCount,
totalBytes: p.totalUnitCount,
fraction: p.fractionCompleted
)
self.whisperModels[i].downloadProgress = info.fraction
self.whisperModels[i].downloadDetail = info.detailText
}
Expand DownExpand Up@@ -279,9 +285,9 @@ final class ModelCatalog: ObservableObject {
llmModels[idx].downloadProgress = 0

do {
let tracker = DownloadProgressTracker()
let estimatedTotalBytes = estimatedLLMDownloadBytes(id) ?? 0
let repoDir = ModelStorage.hubModelRepoDir(id)
let tracker = DownloadProgressTracker(initialBytes: ModelStorage.directorySize(at: repoDir))
let config = ModelConfiguration(id: id)
_ = try await LLMModelFactory.shared.loadContainer(
from: MLXModelLoading.downloader,
Expand Down
2 changes: 1 addition & 1 deletion Sources/Config/ModelCatalogASR.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -82,8 +82,8 @@ extension ModelCatalog {
try await ensureMimoRepository()
}
if !asrModelFilesAreComplete(id) {
let tracker = DownloadProgressTracker(startDate: startedAt, initialBytes: asrRepoSize(id))
for (repoIndex, repoID) in repos.enumerated() {
let tracker = DownloadProgressTracker(startDate: startedAt)
_ = try await api.snapshot(from: ModelStorage.hubModelRepo(repoID)) { [weak self] progress in
Task { @MainActor in
guard let self, let i = self.asrModels.firstIndex(where: { $0.id == id }) else { return }
Expand Down
77 changes: 68 additions & 9 deletions Sources/Config/ModelCatalogDownloadEstimates.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,30 +3,89 @@ import Foundation
@MainActor
extension ModelCatalog {
func estimatedLLMDownloadBytes(_ id: String) -> Int64? {
if let bytes = Self.defaultDownloadEstimateBytes(for: id) { return bytes }
guard let model = llmModels.first(where: { $0.id == id }) else { return nil }
return Self.estimatedDownloadBytes(from: model.hint)
}

func estimatedASRDownloadBytes(_ id: String) -> Int64? {
if let bytes = Self.defaultDownloadEstimateBytes(for: id) { return bytes }
guard let model = asrModels.first(where: { $0.id == id }) else { return nil }
return Self.estimatedDownloadBytes(from: model.hint)
}

static func estimatedDownloadBytes(from text: String) -> Int64? {
let pattern = #"([0-9]+(?:\.[0-9]+)?)\s*(GB|MB)"#
guard let regex = try? NSRegularExpression(pattern: pattern, options: [.caseInsensitive]) else {
return nil
}
static func defaultDownloadEstimateBytes(for id: String) -> Int64? {
defaultDownloadEstimateBytes[id]
}

static func estimatedDownloadBytes(from text: String) -> Int64? {
let range = NSRange(text.startIndex..<text.endIndex, in: text)
guard let match = regex.matches(in: text, range: range).last,
guard let match = downloadEstimateRegex.matches(in: text, range: range).last,
match.numberOfRanges == 3,
let valueRange = Range(match.range(at: 1), in: text),
let unitRange = Range(match.range(at: 2), in: text),
let value = Double(text[valueRange]) else { return nil }
let value = parseDownloadEstimateValue(String(text[valueRange])) else { return nil }

let unit = text[unitRange].uppercased()
let multiplier = unit == "GB" ? 1_000_000_000.0 : 1_000_000.0
return Int64(value * multiplier)
guard let multiplier = downloadEstimateMultiplier(for: unit) else { return nil }
let bytes = value * multiplier
guard bytes.isFinite, bytes > 0, bytes <= Double(Int64.max) else { return nil }
return Int64(bytes)
}

private static let defaultDownloadEstimateBytes: [String: Int64] = [
"mlx-community/Qwen3.5-0.8B-MLX-4bit": 652_027_143,
"mlx-community/Qwen3.5-2B-4bit": 1_749_079_691,
"mlx-community/Qwen3.5-9B-5bit": 7_096_163_574,
"mlx-community/Qwen3-30B-A3B-4bit": 17_190_783_781,
"mlx-community/Qwen3.5-35B-A3B-4bit": 20_418_622_319,
"mlx-community/Qwen2.5-0.5B-Instruct-4bit": 289_598_797,
"mlx-community/Qwen2.5-1.5B-Instruct-4bit": 880_169_797,
"mlx-community/Qwen2.5-3B-Instruct-4bit": 1_747_849_050,
"mlx-community/Qwen3-0.6B-4bit": 351_383_618,
"mlx-community/Qwen3-1.7B-4bit": 984_013_244,
"mlx-community/Qwen3-4B-4bit": 2_278_969_756,
"mlx-community/gemma-4-e2b-it-4bit": 3_613_528_388,
"mlx-community/gemma-4-e4b-it-4bit": 5_249_809_327,
"mlx-community/gemma-3-1b-it-4bit": 771_860_852,
"mlx-community/gemma-3-4b-it-4bit": 3_439_894_985,
"mlx-community/gemma-3-12b-it-4bit": 8_068_018_787,
"mlx-community/Llama-4-Scout-17B-16E-Instruct-4bit": 61_143_654_248,
"mlx-community/Llama-4-Maverick-17B-128E-Instruct-4bit": 225_923_469_800,
LocalASRConfiguration.qwen3DefaultModel: 4_080_707_826,
LocalASRConfiguration.mimoDefaultModel: 35_997_080_271,
]

private static let downloadEstimateRegex = try! NSRegularExpression(
pattern: #"([0-9]+(?:[\.,][0-9]+)?)\s*(TiB|GiB|MiB|KiB|TB|GB|MB|KB|T|G|M|K)(?![A-Za-z])"#,
options: [.caseInsensitive]
)

private static func parseDownloadEstimateValue(_ rawValue: String) -> Double? {
if rawValue.contains("."), rawValue.contains(",") {
return Double(rawValue.replacingOccurrences(of: ",", with: ""))
}
if let commaIndex = rawValue.firstIndex(of: ",") {
let fraction = rawValue[rawValue.index(after: commaIndex)...]
let normalized = fraction.count == 3
? rawValue.replacingOccurrences(of: ",", with: "")
: rawValue.replacingOccurrences(of: ",", with: ".")
return Double(normalized)
}
return Double(rawValue)
}

private static func downloadEstimateMultiplier(for rawUnit: String) -> Double? {
switch rawUnit {
case "TIB": return pow(1024, 4)
case "GIB": return pow(1024, 3)
case "MIB": return pow(1024, 2)
case "KIB": return 1024
case "TB", "T": return 1_000_000_000_000
case "GB", "G": return 1_000_000_000
case "MB", "M": return 1_000_000
case "KB", "K": return 1_000
default: return nil
}
}
}
2 changes: 1 addition & 1 deletion Sources/LLM/LLMEngine.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,9 +30,9 @@ actor LLMEngine {
speedBytesPerSecond: 0
))
} else {
let tracker = DownloadProgressTracker()
let estimatedTotalBytes = estimatedDownloadBytes ?? 0
let repoDir = ModelStorage.hubModelRepoDir(id)
let tracker = DownloadProgressTracker(initialBytes: ModelStorage.directorySize(at: repoDir))
let config = Self.modelConfiguration(for: id)
container = try await LLMModelFactory.shared.loadContainer(
from: MLXModelLoading.downloader,
Expand Down
34 changes: 17 additions & 17 deletions Sources/Resources/en.lproj/Localizable.strings
Original file line numberDiff line numberDiff line change
Expand Up@@ -164,24 +164,24 @@
"model.last_formatting_value" = "%.2fs";
"model.compiling" = "Compiling…";
"model.loading" = "Loading…";
"model.smallest" = "Smallest, fastest ~335 MB";
"model.balanced" = "Balanced ~1 GB";
"model.best_quality" = "Best quality ~2.3 GB";
"model.qwen3_fast" = "Fastest, weaker cleanup ~335 MB";
"model.qwen3_balanced" = "Qwen3, balanced ~1 GB";
"model.smallest" = "Smallest, fastest ~290 MB";
"model.balanced" = "Balanced ~880 MB";
"model.best_quality" = "Best quality ~1.7 GB";
"model.qwen3_fast" = "Fastest, weaker cleanup ~351 MB";
"model.qwen3_balanced" = "Qwen3, balanced ~984 MB";
"model.qwen3_quality" = "Qwen3, best quality ~2.3 GB";
"model.qwen3_moe" = "Qwen3 MoE flagship, recommended ~5 GB";
"model.qwen35_tiny" = "Qwen3.5, fastest ~620 MB";
"model.qwen35_fast" = "Recommended for Smart Format ~1.5 GB";
"model.qwen35_quality" = "Best quality cleanup 5-bit ~5.5 GB";
"model.qwen35_moe" = "Qwen3.5 MoE flagship ~6 GB";
"model.gemma_fast" = "Gemma 3, fast ~600 MB";
"model.gemma_balanced" = "Gemma 3, balanced ~2.5 GB";
"model.gemma_quality" = "Gemma 3, best quality ~7 GB";
"model.qwen3_moe" = "Qwen3 MoE flagship, recommended ~17.2 GB";
"model.qwen35_tiny" = "Qwen3.5, fastest ~652 MB";
"model.qwen35_fast" = "Recommended for Smart Format ~1.7 GB";
"model.qwen35_quality" = "Best quality cleanup 5-bit ~7.1 GB";
"model.qwen35_moe" = "Qwen3.5 MoE flagship ~20.4 GB";
"model.gemma_fast" = "Gemma 3, fast ~772 MB";
"model.gemma_balanced" = "Gemma 3, balanced ~3.4 GB";
"model.gemma_quality" = "Gemma 3, best quality ~8.1 GB";
"model.gemma4_edge" = "Gemma 4 edge model ~3.6 GB";
"model.gemma4_edge_quality" = "Gemma 4 edge quality ~5.2 GB";
"model.llama_balanced" = "Llama 4 Scout, balanced ~10 GB";
"model.llama_quality" = "Llama 4 Maverick, high quality ~25 GB";
"model.llama_balanced" = "Llama 4 Scout, balanced ~61.1 GB";
"model.llama_quality" = "Llama 4 Maverick, high quality ~225.9 GB";
"model.import_local" = "Import Local Model…";
"model.import_invalid" = "Invalid model directory: config.json not found";
"model.import_failed" = "Import Failed";
Expand DownExpand Up@@ -341,8 +341,8 @@
"local_asr.tokenizer_path" = "Audio tokenizer path";
"qwen_asr.config_hint" = "Choose Qwen3-ASR, then click Download to fetch the local model and prepare its Python runtime.";
"mimo_asr.config_hint" = "Choose MiMo-V2.5-ASR, then click Download to fetch the model, audio tokenizer, and runtime files.";
"model.qwen3_asr_quality" = "Local ASR through MLX, ~4 GB";
"model.mimo_asr_quality" = "Local ASR model plus audio tokenizer";
"model.qwen3_asr_quality" = "Local ASR through MLX, ~4.1 GB";
"model.mimo_asr_quality" = "Local ASR model plus audio tokenizer ~36 GB";
"model.asr_incomplete" = "Download incomplete";
"model.asr_preparing_runtime" = "Preparing runtime files";
"model.asr_installing_runtime" = "Installing local runtime";
Expand Down
34 changes: 17 additions & 17 deletions Sources/Resources/zh-Hans.lproj/Localizable.strings
Original file line numberDiff line numberDiff line change
Expand Up@@ -164,24 +164,24 @@
"model.last_formatting_value" = "%.2f 秒";
"model.compiling" = "编译中…";
"model.loading" = "加载中…";
"model.smallest" = "最小最快 ~335 MB";
"model.balanced" = "平衡选择 ~1 GB";
"model.best_quality" = "质量最佳 ~2.3 GB";
"model.qwen3_fast" = "极速,整理偏弱 ~335 MB";
"model.qwen3_balanced" = "Qwen3 均衡 ~1 GB";
"model.smallest" = "最小最快 ~290 MB";
"model.balanced" = "平衡选择 ~880 MB";
"model.best_quality" = "质量最佳 ~1.7 GB";
"model.qwen3_fast" = "极速,整理偏弱 ~351 MB";
"model.qwen3_balanced" = "Qwen3 均衡 ~984 MB";
"model.qwen3_quality" = "Qwen3 高质量 ~2.3 GB";
"model.qwen3_moe" = "Qwen3 MoE 旗舰,推荐 ~5 GB";
"model.qwen35_tiny" = "Qwen3.5 极速 ~620 MB";
"model.qwen35_fast" = "智能整理推荐 ~1.5 GB";
"model.qwen35_quality" = "整理质量最佳 5-bit ~5.5 GB";
"model.qwen35_moe" = "Qwen3.5 MoE 旗舰 ~6 GB";
"model.gemma_fast" = "Gemma 3 极速 ~600 MB";
"model.gemma_balanced" = "Gemma 3 均衡 ~2.5 GB";
"model.gemma_quality" = "Gemma 3 高质量 ~7 GB";
"model.qwen3_moe" = "Qwen3 MoE 旗舰,推荐 ~17.2 GB";
"model.qwen35_tiny" = "Qwen3.5 极速 ~652 MB";
"model.qwen35_fast" = "智能整理推荐 ~1.7 GB";
"model.qwen35_quality" = "整理质量最佳 5-bit ~7.1 GB";
"model.qwen35_moe" = "Qwen3.5 MoE 旗舰 ~20.4 GB";
"model.gemma_fast" = "Gemma 3 极速 ~772 MB";
"model.gemma_balanced" = "Gemma 3 均衡 ~3.4 GB";
"model.gemma_quality" = "Gemma 3 高质量 ~8.1 GB";
"model.gemma4_edge" = "Gemma 4 端侧模型 ~3.6 GB";
"model.gemma4_edge_quality" = "Gemma 4 端侧高质量 ~5.2 GB";
"model.llama_balanced" = "Llama 4 Scout 均衡 ~10 GB";
"model.llama_quality" = "Llama 4 Maverick 高质量 ~25 GB";
"model.llama_balanced" = "Llama 4 Scout 均衡 ~61.1 GB";
"model.llama_quality" = "Llama 4 Maverick 高质量 ~225.9 GB";
"model.import_local" = "导入本地模型…";
"model.import_invalid" = "无效的模型目录:未找到 config.json";
"model.import_failed" = "导入失败";
Expand DownExpand Up@@ -341,8 +341,8 @@
"local_asr.tokenizer_path" = "音频 tokenizer 路径";
"qwen_asr.config_hint" = "选择 Qwen3-ASR 后,请点击下载按钮获取本地模型,并准备对应的 Python 运行环境。";
"mimo_asr.config_hint" = "选择 MiMo-V2.5-ASR 后,请点击下载按钮获取模型、音频 tokenizer 和运行文件。";
"model.qwen3_asr_quality" = "本地 MLX 语音识别,约 4 GB";
"model.mimo_asr_quality" = "本地语音识别模型 + 音频 tokenizer";
"model.qwen3_asr_quality" = "本地 MLX 语音识别,约 4.1 GB";
"model.mimo_asr_quality" = "本地语音识别模型 + 音频 tokenizer,约 36 GB";
"model.asr_incomplete" = "下载不完整";
"model.asr_preparing_runtime" = "准备运行文件";
"model.asr_installing_runtime" = "安装本地运行环境";
Expand Down
6 changes: 4 additions & 2 deletions Sources/Speech/WhisperEngine.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -82,7 +82,8 @@ final class WhisperEngine: SpeechEngine, @unchecked Sendable {

progress(dp(0.02, stage: .downloading))

let tracker = DownloadProgressTracker()
let modelDir = ModelStorage.whisperVariantDir(selectedModel)
let tracker = DownloadProgressTracker(initialBytes: ModelStorage.directorySize(at: modelDir))

let folder: URL
if let localFolder {
Expand All@@ -93,7 +94,8 @@ final class WhisperEngine: SpeechEngine, @unchecked Sendable {
variant: selectedModel,
downloadBase: ModelCatalog.whisperDownloadBase,
progressCallback: { p in
let completed = p.completedUnitCount
let downloadedBytes = ModelStorage.directorySize(at: modelDir)
let completed = downloadedBytes > 0 ? downloadedBytes : p.completedUnitCount
let total = p.totalUnitCount

let frac = 0.02 + p.fractionCompleted * 0.58
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions Sources/Config/DownloadProgressInfo.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,21 @@ struct DownloadProgressInfo: Equatable, Sendable {
let totalBytes: Int64
let speedBytesPerSecond: Double

init(
fraction: Double,
elapsedSeconds: TimeInterval,
completedBytes: Int64,
totalBytes: Int64,
speedBytesPerSecond: Double
) {
let completedBytes = max(completedBytes, 0)
self.fraction = Self.clampFraction(fraction)
self.elapsedSeconds = elapsedSeconds.isFinite ? max(elapsedSeconds, 0) : 0
self.completedBytes = completedBytes
self.totalBytes = totalBytes > 0 ? max(totalBytes, completedBytes) : 0
self.speedBytesPerSecond = speedBytesPerSecond.isFinite ? max(speedBytesPerSecond, 0) : 0
}

var percentText: String {
"\(Int(clampedFraction * 100))%"
}
Expand DownExpand Up@@ -78,7 +93,7 @@ final class DownloadProgressTracker: @unchecked Sendable {
init(startDate: Date = Date(), initialBytes: Int64 = 0) {
self.startDate = startDate
lastTime = startDate
lastBytes = initialBytes
lastBytes = max(initialBytes, 0)
}

func update(progress: Progress, fraction: Double? = nil) -> DownloadProgressInfo {
Expand All@@ -90,17 +105,27 @@ final class DownloadProgressTracker: @unchecked Sendable {
}

func update(completedBytes rawCompleted: Int64, totalBytes rawTotal: Int64, fraction: Double? = nil) -> DownloadProgressInfo {
update(completedBytes: rawCompleted, totalBytes: rawTotal, fraction: fraction, at: Date())
}

func update(
completedBytes rawCompleted: Int64,
totalBytes rawTotal: Int64,
fraction: Double? = nil,
at now: Date
) -> DownloadProgressInfo {
lock.lock()
defer { lock.unlock() }

let completedBytes = max(rawCompleted, 0)
let totalBytes = max(rawTotal, 0)
let now = Date()
let totalBytes = rawTotal > 0 ? max(rawTotal, completedBytes) : 0
let sampleElapsed = now.timeIntervalSince(lastTime)
if sampleElapsed > 0.5 {
let deltaBytes = completedBytes - lastBytes
if deltaBytes >= 0 {
lastSpeedBytesPerSecond = Double(deltaBytes) / sampleElapsed
} else {
lastSpeedBytesPerSecond = 0
}
lastTime = now
lastBytes = completedBytes
Expand Down
12 changes: 9 additions & 3 deletions Sources/Config/ModelCatalog.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -210,15 +210,21 @@ final class ModelCatalog: ObservableObject {
whisperModels[idx].downloadProgress = 0

do {
let tracker = DownloadProgressTracker()
let modelDir = ModelStorage.whisperVariantDir(id)
let tracker = DownloadProgressTracker(initialBytes: ModelStorage.directorySize(at: modelDir))

_ = try await WhisperKit.download(
variant: id,
downloadBase: Self.whisperDownloadBase,
progressCallback: { [weak self] p in
Task { @MainActor in
guard let self, let i = self.whisperModels.firstIndex(where: { $0.id == id }) else { return }
let info = tracker.update(progress: p)
let completedBytes = ModelStorage.directorySize(at: modelDir)
let info = tracker.update(
completedBytes: completedBytes > 0 ? completedBytes : p.completedUnitCount,
totalBytes: p.totalUnitCount,
fraction: p.fractionCompleted
)
self.whisperModels[i].downloadProgress = info.fraction
self.whisperModels[i].downloadDetail = info.detailText
}
Expand DownExpand Up@@ -279,9 +285,9 @@ final class ModelCatalog: ObservableObject {
llmModels[idx].downloadProgress = 0

do {
let tracker = DownloadProgressTracker()
let estimatedTotalBytes = estimatedLLMDownloadBytes(id) ?? 0
let repoDir = ModelStorage.hubModelRepoDir(id)
let tracker = DownloadProgressTracker(initialBytes: ModelStorage.directorySize(at: repoDir))
let config = ModelConfiguration(id: id)
_ = try await LLMModelFactory.shared.loadContainer(
from: MLXModelLoading.downloader,
Expand Down
2 changes: 1 addition & 1 deletion Sources/Config/ModelCatalogASR.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -82,8 +82,8 @@ extension ModelCatalog {
try await ensureMimoRepository()
}
if !asrModelFilesAreComplete(id) {
let tracker = DownloadProgressTracker(startDate: startedAt, initialBytes: asrRepoSize(id))
for (repoIndex, repoID) in repos.enumerated() {
let tracker = DownloadProgressTracker(startDate: startedAt)
_ = try await api.snapshot(from: ModelStorage.hubModelRepo(repoID)) { [weak self] progress in
Task { @MainActor in
guard let self, let i = self.asrModels.firstIndex(where: { $0.id == id }) else { return }
Expand Down
77 changes: 68 additions & 9 deletions Sources/Config/ModelCatalogDownloadEstimates.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,30 +3,89 @@ import Foundation
@MainActor
extension ModelCatalog {
func estimatedLLMDownloadBytes(_ id: String) -> Int64? {
if let bytes = Self.defaultDownloadEstimateBytes(for: id) { return bytes }
guard let model = llmModels.first(where: { $0.id == id }) else { return nil }
return Self.estimatedDownloadBytes(from: model.hint)
}

func estimatedASRDownloadBytes(_ id: String) -> Int64? {
if let bytes = Self.defaultDownloadEstimateBytes(for: id) { return bytes }
guard let model = asrModels.first(where: { $0.id == id }) else { return nil }
return Self.estimatedDownloadBytes(from: model.hint)
}

static func estimatedDownloadBytes(from text: String) -> Int64? {
let pattern = #"([0-9]+(?:\.[0-9]+)?)\s*(GB|MB)"#
guard let regex = try? NSRegularExpression(pattern: pattern, options: [.caseInsensitive]) else {
return nil
}
static func defaultDownloadEstimateBytes(for id: String) -> Int64? {
defaultDownloadEstimateBytes[id]
}

static func estimatedDownloadBytes(from text: String) -> Int64? {
let range = NSRange(text.startIndex..<text.endIndex, in: text)
guard let match = regex.matches(in: text, range: range).last,
guard let match = downloadEstimateRegex.matches(in: text, range: range).last,
match.numberOfRanges == 3,
let valueRange = Range(match.range(at: 1), in: text),
let unitRange = Range(match.range(at: 2), in: text),
let value = Double(text[valueRange]) else { return nil }
let value = parseDownloadEstimateValue(String(text[valueRange])) else { return nil }

let unit = text[unitRange].uppercased()
let multiplier = unit == "GB" ? 1_000_000_000.0 : 1_000_000.0
return Int64(value * multiplier)
guard let multiplier = downloadEstimateMultiplier(for: unit) else { return nil }
let bytes = value * multiplier
guard bytes.isFinite, bytes > 0, bytes <= Double(Int64.max) else { return nil }
return Int64(bytes)
}

private static let defaultDownloadEstimateBytes: [String: Int64] = [
"mlx-community/Qwen3.5-0.8B-MLX-4bit": 652_027_143,
"mlx-community/Qwen3.5-2B-4bit": 1_749_079_691,
"mlx-community/Qwen3.5-9B-5bit": 7_096_163_574,
"mlx-community/Qwen3-30B-A3B-4bit": 17_190_783_781,
"mlx-community/Qwen3.5-35B-A3B-4bit": 20_418_622_319,
"mlx-community/Qwen2.5-0.5B-Instruct-4bit": 289_598_797,
"mlx-community/Qwen2.5-1.5B-Instruct-4bit": 880_169_797,
"mlx-community/Qwen2.5-3B-Instruct-4bit": 1_747_849_050,
"mlx-community/Qwen3-0.6B-4bit": 351_383_618,
"mlx-community/Qwen3-1.7B-4bit": 984_013_244,
"mlx-community/Qwen3-4B-4bit": 2_278_969_756,
"mlx-community/gemma-4-e2b-it-4bit": 3_613_528_388,
"mlx-community/gemma-4-e4b-it-4bit": 5_249_809_327,
"mlx-community/gemma-3-1b-it-4bit": 771_860_852,
"mlx-community/gemma-3-4b-it-4bit": 3_439_894_985,
"mlx-community/gemma-3-12b-it-4bit": 8_068_018_787,
"mlx-community/Llama-4-Scout-17B-16E-Instruct-4bit": 61_143_654_248,
"mlx-community/Llama-4-Maverick-17B-128E-Instruct-4bit": 225_923_469_800,
LocalASRConfiguration.qwen3DefaultModel: 4_080_707_826,
LocalASRConfiguration.mimoDefaultModel: 35_997_080_271,
]

private static let downloadEstimateRegex = try! NSRegularExpression(
pattern: #"([0-9]+(?:[\.,][0-9]+)?)\s*(TiB|GiB|MiB|KiB|TB|GB|MB|KB|T|G|M|K)(?![A-Za-z])"#,
options: [.caseInsensitive]
)

private static func parseDownloadEstimateValue(_ rawValue: String) -> Double? {
if rawValue.contains("."), rawValue.contains(",") {
return Double(rawValue.replacingOccurrences(of: ",", with: ""))
}
if let commaIndex = rawValue.firstIndex(of: ",") {
let fraction = rawValue[rawValue.index(after: commaIndex)...]
let normalized = fraction.count == 3
? rawValue.replacingOccurrences(of: ",", with: "")
: rawValue.replacingOccurrences(of: ",", with: ".")
return Double(normalized)
}
return Double(rawValue)
}

private static func downloadEstimateMultiplier(for rawUnit: String) -> Double? {
switch rawUnit {
case "TIB": return pow(1024, 4)
case "GIB": return pow(1024, 3)
case "MIB": return pow(1024, 2)
case "KIB": return 1024
case "TB", "T": return 1_000_000_000_000
case "GB", "G": return 1_000_000_000
case "MB", "M": return 1_000_000
case "KB", "K": return 1_000
default: return nil
}
}
}
2 changes: 1 addition & 1 deletion Sources/LLM/LLMEngine.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,9 +30,9 @@ actor LLMEngine {
speedBytesPerSecond: 0
))
} else {
let tracker = DownloadProgressTracker()
let estimatedTotalBytes = estimatedDownloadBytes ?? 0
let repoDir = ModelStorage.hubModelRepoDir(id)
let tracker = DownloadProgressTracker(initialBytes: ModelStorage.directorySize(at: repoDir))
let config = Self.modelConfiguration(for: id)
container = try await LLMModelFactory.shared.loadContainer(
from: MLXModelLoading.downloader,
Expand Down
34 changes: 17 additions & 17 deletions Sources/Resources/en.lproj/Localizable.strings
Original file line numberDiff line numberDiff line change
Expand Up@@ -164,24 +164,24 @@
"model.last_formatting_value" = "%.2fs";
"model.compiling" = "Compiling…";
"model.loading" = "Loading…";
"model.smallest" = "Smallest, fastest ~335 MB";
"model.balanced" = "Balanced ~1 GB";
"model.best_quality" = "Best quality ~2.3 GB";
"model.qwen3_fast" = "Fastest, weaker cleanup ~335 MB";
"model.qwen3_balanced" = "Qwen3, balanced ~1 GB";
"model.smallest" = "Smallest, fastest ~290 MB";
"model.balanced" = "Balanced ~880 MB";
"model.best_quality" = "Best quality ~1.7 GB";
"model.qwen3_fast" = "Fastest, weaker cleanup ~351 MB";
"model.qwen3_balanced" = "Qwen3, balanced ~984 MB";
"model.qwen3_quality" = "Qwen3, best quality ~2.3 GB";
"model.qwen3_moe" = "Qwen3 MoE flagship, recommended ~5 GB";
"model.qwen35_tiny" = "Qwen3.5, fastest ~620 MB";
"model.qwen35_fast" = "Recommended for Smart Format ~1.5 GB";
"model.qwen35_quality" = "Best quality cleanup 5-bit ~5.5 GB";
"model.qwen35_moe" = "Qwen3.5 MoE flagship ~6 GB";
"model.gemma_fast" = "Gemma 3, fast ~600 MB";
"model.gemma_balanced" = "Gemma 3, balanced ~2.5 GB";
"model.gemma_quality" = "Gemma 3, best quality ~7 GB";
"model.qwen3_moe" = "Qwen3 MoE flagship, recommended ~17.2 GB";
"model.qwen35_tiny" = "Qwen3.5, fastest ~652 MB";
"model.qwen35_fast" = "Recommended for Smart Format ~1.7 GB";
"model.qwen35_quality" = "Best quality cleanup 5-bit ~7.1 GB";
"model.qwen35_moe" = "Qwen3.5 MoE flagship ~20.4 GB";
"model.gemma_fast" = "Gemma 3, fast ~772 MB";
"model.gemma_balanced" = "Gemma 3, balanced ~3.4 GB";
"model.gemma_quality" = "Gemma 3, best quality ~8.1 GB";
"model.gemma4_edge" = "Gemma 4 edge model ~3.6 GB";
"model.gemma4_edge_quality" = "Gemma 4 edge quality ~5.2 GB";
"model.llama_balanced" = "Llama 4 Scout, balanced ~10 GB";
"model.llama_quality" = "Llama 4 Maverick, high quality ~25 GB";
"model.llama_balanced" = "Llama 4 Scout, balanced ~61.1 GB";
"model.llama_quality" = "Llama 4 Maverick, high quality ~225.9 GB";
"model.import_local" = "Import Local Model…";
"model.import_invalid" = "Invalid model directory: config.json not found";
"model.import_failed" = "Import Failed";
Expand DownExpand Up@@ -341,8 +341,8 @@
"local_asr.tokenizer_path" = "Audio tokenizer path";
"qwen_asr.config_hint" = "Choose Qwen3-ASR, then click Download to fetch the local model and prepare its Python runtime.";
"mimo_asr.config_hint" = "Choose MiMo-V2.5-ASR, then click Download to fetch the model, audio tokenizer, and runtime files.";
"model.qwen3_asr_quality" = "Local ASR through MLX, ~4 GB";
"model.mimo_asr_quality" = "Local ASR model plus audio tokenizer";
"model.qwen3_asr_quality" = "Local ASR through MLX, ~4.1 GB";
"model.mimo_asr_quality" = "Local ASR model plus audio tokenizer ~36 GB";
"model.asr_incomplete" = "Download incomplete";
"model.asr_preparing_runtime" = "Preparing runtime files";
"model.asr_installing_runtime" = "Installing local runtime";
Expand Down
34 changes: 17 additions & 17 deletions Sources/Resources/zh-Hans.lproj/Localizable.strings
Original file line numberDiff line numberDiff line change
Expand Up@@ -164,24 +164,24 @@
"model.last_formatting_value" = "%.2f 秒";
"model.compiling" = "编译中…";
"model.loading" = "加载中…";
"model.smallest" = "最小最快 ~335 MB";
"model.balanced" = "平衡选择 ~1 GB";
"model.best_quality" = "质量最佳 ~2.3 GB";
"model.qwen3_fast" = "极速,整理偏弱 ~335 MB";
"model.qwen3_balanced" = "Qwen3 均衡 ~1 GB";
"model.smallest" = "最小最快 ~290 MB";
"model.balanced" = "平衡选择 ~880 MB";
"model.best_quality" = "质量最佳 ~1.7 GB";
"model.qwen3_fast" = "极速,整理偏弱 ~351 MB";
"model.qwen3_balanced" = "Qwen3 均衡 ~984 MB";
"model.qwen3_quality" = "Qwen3 高质量 ~2.3 GB";
"model.qwen3_moe" = "Qwen3 MoE 旗舰,推荐 ~5 GB";
"model.qwen35_tiny" = "Qwen3.5 极速 ~620 MB";
"model.qwen35_fast" = "智能整理推荐 ~1.5 GB";
"model.qwen35_quality" = "整理质量最佳 5-bit ~5.5 GB";
"model.qwen35_moe" = "Qwen3.5 MoE 旗舰 ~6 GB";
"model.gemma_fast" = "Gemma 3 极速 ~600 MB";
"model.gemma_balanced" = "Gemma 3 均衡 ~2.5 GB";
"model.gemma_quality" = "Gemma 3 高质量 ~7 GB";
"model.qwen3_moe" = "Qwen3 MoE 旗舰,推荐 ~17.2 GB";
"model.qwen35_tiny" = "Qwen3.5 极速 ~652 MB";
"model.qwen35_fast" = "智能整理推荐 ~1.7 GB";
"model.qwen35_quality" = "整理质量最佳 5-bit ~7.1 GB";
"model.qwen35_moe" = "Qwen3.5 MoE 旗舰 ~20.4 GB";
"model.gemma_fast" = "Gemma 3 极速 ~772 MB";
"model.gemma_balanced" = "Gemma 3 均衡 ~3.4 GB";
"model.gemma_quality" = "Gemma 3 高质量 ~8.1 GB";
"model.gemma4_edge" = "Gemma 4 端侧模型 ~3.6 GB";
"model.gemma4_edge_quality" = "Gemma 4 端侧高质量 ~5.2 GB";
"model.llama_balanced" = "Llama 4 Scout 均衡 ~10 GB";
"model.llama_quality" = "Llama 4 Maverick 高质量 ~25 GB";
"model.llama_balanced" = "Llama 4 Scout 均衡 ~61.1 GB";
"model.llama_quality" = "Llama 4 Maverick 高质量 ~225.9 GB";
"model.import_local" = "导入本地模型…";
"model.import_invalid" = "无效的模型目录:未找到 config.json";
"model.import_failed" = "导入失败";
Expand DownExpand Up@@ -341,8 +341,8 @@
"local_asr.tokenizer_path" = "音频 tokenizer 路径";
"qwen_asr.config_hint" = "选择 Qwen3-ASR 后,请点击下载按钮获取本地模型,并准备对应的 Python 运行环境。";
"mimo_asr.config_hint" = "选择 MiMo-V2.5-ASR 后,请点击下载按钮获取模型、音频 tokenizer 和运行文件。";
"model.qwen3_asr_quality" = "本地 MLX 语音识别,约 4 GB";
"model.mimo_asr_quality" = "本地语音识别模型 + 音频 tokenizer";
"model.qwen3_asr_quality" = "本地 MLX 语音识别,约 4.1 GB";
"model.mimo_asr_quality" = "本地语音识别模型 + 音频 tokenizer,约 36 GB";
"model.asr_incomplete" = "下载不完整";
"model.asr_preparing_runtime" = "准备运行文件";
"model.asr_installing_runtime" = "安装本地运行环境";
Expand Down
6 changes: 4 additions & 2 deletions Sources/Speech/WhisperEngine.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -82,7 +82,8 @@ final class WhisperEngine: SpeechEngine, @unchecked Sendable {

progress(dp(0.02, stage: .downloading))

let tracker = DownloadProgressTracker()
let modelDir = ModelStorage.whisperVariantDir(selectedModel)
let tracker = DownloadProgressTracker(initialBytes: ModelStorage.directorySize(at: modelDir))

let folder: URL
if let localFolder {
Expand All@@ -93,7 +94,8 @@ final class WhisperEngine: SpeechEngine, @unchecked Sendable {
variant: selectedModel,
downloadBase: ModelCatalog.whisperDownloadBase,
progressCallback: { p in
let completed = p.completedUnitCount
let downloadedBytes = ModelStorage.directorySize(at: modelDir)
let completed = downloadedBytes > 0 ? downloadedBytes : p.completedUnitCount
let total = p.totalUnitCount

let frac = 0.02 + p.fractionCompleted * 0.58
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions Sources/Config/DownloadProgressInfo.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,21 @@ struct DownloadProgressInfo: Equatable, Sendable {
let totalBytes: Int64
let speedBytesPerSecond: Double

init(
fraction: Double,
elapsedSeconds: TimeInterval,
completedBytes: Int64,
totalBytes: Int64,
speedBytesPerSecond: Double
) {
let completedBytes = max(completedBytes, 0)
self.fraction = Self.clampFraction(fraction)
self.elapsedSeconds = elapsedSeconds.isFinite ? max(elapsedSeconds, 0) : 0
self.completedBytes = completedBytes
self.totalBytes = totalBytes > 0 ? max(totalBytes, completedBytes) : 0
self.speedBytesPerSecond = speedBytesPerSecond.isFinite ? max(speedBytesPerSecond, 0) : 0
}

var percentText: String {
"\(Int(clampedFraction * 100))%"
}
Expand DownExpand Up@@ -78,7 +93,7 @@ final class DownloadProgressTracker: @unchecked Sendable {
init(startDate: Date = Date(), initialBytes: Int64 = 0) {
self.startDate = startDate
lastTime = startDate
lastBytes = initialBytes
lastBytes = max(initialBytes, 0)
}

func update(progress: Progress, fraction: Double? = nil) -> DownloadProgressInfo {
Expand All@@ -90,17 +105,27 @@ final class DownloadProgressTracker: @unchecked Sendable {
}

func update(completedBytes rawCompleted: Int64, totalBytes rawTotal: Int64, fraction: Double? = nil) -> DownloadProgressInfo {
update(completedBytes: rawCompleted, totalBytes: rawTotal, fraction: fraction, at: Date())
}

func update(
completedBytes rawCompleted: Int64,
totalBytes rawTotal: Int64,
fraction: Double? = nil,
at now: Date
) -> DownloadProgressInfo {
lock.lock()
defer { lock.unlock() }

let completedBytes = max(rawCompleted, 0)
let totalBytes = max(rawTotal, 0)
let now = Date()
let totalBytes = rawTotal > 0 ? max(rawTotal, completedBytes) : 0
let sampleElapsed = now.timeIntervalSince(lastTime)
if sampleElapsed > 0.5 {
let deltaBytes = completedBytes - lastBytes
if deltaBytes >= 0 {
lastSpeedBytesPerSecond = Double(deltaBytes) / sampleElapsed
} else {
lastSpeedBytesPerSecond = 0
}
lastTime = now
lastBytes = completedBytes
Expand Down
12 changes: 9 additions & 3 deletions Sources/Config/ModelCatalog.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -210,15 +210,21 @@ final class ModelCatalog: ObservableObject {
whisperModels[idx].downloadProgress = 0

do {
let tracker = DownloadProgressTracker()
let modelDir = ModelStorage.whisperVariantDir(id)
let tracker = DownloadProgressTracker(initialBytes: ModelStorage.directorySize(at: modelDir))

_ = try await WhisperKit.download(
variant: id,
downloadBase: Self.whisperDownloadBase,
progressCallback: { [weak self] p in
Task { @MainActor in
guard let self, let i = self.whisperModels.firstIndex(where: { $0.id == id }) else { return }
let info = tracker.update(progress: p)
let completedBytes = ModelStorage.directorySize(at: modelDir)
let info = tracker.update(
completedBytes: completedBytes > 0 ? completedBytes : p.completedUnitCount,
totalBytes: p.totalUnitCount,
fraction: p.fractionCompleted
)
self.whisperModels[i].downloadProgress = info.fraction
self.whisperModels[i].downloadDetail = info.detailText
}
Expand DownExpand Up@@ -279,9 +285,9 @@ final class ModelCatalog: ObservableObject {
llmModels[idx].downloadProgress = 0

do {
let tracker = DownloadProgressTracker()
let estimatedTotalBytes = estimatedLLMDownloadBytes(id) ?? 0
let repoDir = ModelStorage.hubModelRepoDir(id)
let tracker = DownloadProgressTracker(initialBytes: ModelStorage.directorySize(at: repoDir))
let config = ModelConfiguration(id: id)
_ = try await LLMModelFactory.shared.loadContainer(
from: MLXModelLoading.downloader,
Expand Down
2 changes: 1 addition & 1 deletion Sources/Config/ModelCatalogASR.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -82,8 +82,8 @@ extension ModelCatalog {
try await ensureMimoRepository()
}
if !asrModelFilesAreComplete(id) {
let tracker = DownloadProgressTracker(startDate: startedAt, initialBytes: asrRepoSize(id))
for (repoIndex, repoID) in repos.enumerated() {
let tracker = DownloadProgressTracker(startDate: startedAt)
_ = try await api.snapshot(from: ModelStorage.hubModelRepo(repoID)) { [weak self] progress in
Task { @MainActor in
guard let self, let i = self.asrModels.firstIndex(where: { $0.id == id }) else { return }
Expand Down
77 changes: 68 additions & 9 deletions Sources/Config/ModelCatalogDownloadEstimates.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,30 +3,89 @@ import Foundation
@MainActor
extension ModelCatalog {
func estimatedLLMDownloadBytes(_ id: String) -> Int64? {
if let bytes = Self.defaultDownloadEstimateBytes(for: id) { return bytes }
guard let model = llmModels.first(where: { $0.id == id }) else { return nil }
return Self.estimatedDownloadBytes(from: model.hint)
}

func estimatedASRDownloadBytes(_ id: String) -> Int64? {
if let bytes = Self.defaultDownloadEstimateBytes(for: id) { return bytes }
guard let model = asrModels.first(where: { $0.id == id }) else { return nil }
return Self.estimatedDownloadBytes(from: model.hint)
}

static func estimatedDownloadBytes(from text: String) -> Int64? {
let pattern = #"([0-9]+(?:\.[0-9]+)?)\s*(GB|MB)"#
guard let regex = try? NSRegularExpression(pattern: pattern, options: [.caseInsensitive]) else {
return nil
}
static func defaultDownloadEstimateBytes(for id: String) -> Int64? {
defaultDownloadEstimateBytes[id]
}

static func estimatedDownloadBytes(from text: String) -> Int64? {
let range = NSRange(text.startIndex..<text.endIndex, in: text)
guard let match = regex.matches(in: text, range: range).last,
guard let match = downloadEstimateRegex.matches(in: text, range: range).last,
match.numberOfRanges == 3,
let valueRange = Range(match.range(at: 1), in: text),
let unitRange = Range(match.range(at: 2), in: text),
let value = Double(text[valueRange]) else { return nil }
let value = parseDownloadEstimateValue(String(text[valueRange])) else { return nil }

let unit = text[unitRange].uppercased()
let multiplier = unit == "GB" ? 1_000_000_000.0 : 1_000_000.0
return Int64(value * multiplier)
guard let multiplier = downloadEstimateMultiplier(for: unit) else { return nil }
let bytes = value * multiplier
guard bytes.isFinite, bytes > 0, bytes <= Double(Int64.max) else { return nil }
return Int64(bytes)
}

private static let defaultDownloadEstimateBytes: [String: Int64] = [
"mlx-community/Qwen3.5-0.8B-MLX-4bit": 652_027_143,
"mlx-community/Qwen3.5-2B-4bit": 1_749_079_691,
"mlx-community/Qwen3.5-9B-5bit": 7_096_163_574,
"mlx-community/Qwen3-30B-A3B-4bit": 17_190_783_781,
"mlx-community/Qwen3.5-35B-A3B-4bit": 20_418_622_319,
"mlx-community/Qwen2.5-0.5B-Instruct-4bit": 289_598_797,
"mlx-community/Qwen2.5-1.5B-Instruct-4bit": 880_169_797,
"mlx-community/Qwen2.5-3B-Instruct-4bit": 1_747_849_050,
"mlx-community/Qwen3-0.6B-4bit": 351_383_618,
"mlx-community/Qwen3-1.7B-4bit": 984_013_244,
"mlx-community/Qwen3-4B-4bit": 2_278_969_756,
"mlx-community/gemma-4-e2b-it-4bit": 3_613_528_388,
"mlx-community/gemma-4-e4b-it-4bit": 5_249_809_327,
"mlx-community/gemma-3-1b-it-4bit": 771_860_852,
"mlx-community/gemma-3-4b-it-4bit": 3_439_894_985,
"mlx-community/gemma-3-12b-it-4bit": 8_068_018_787,
"mlx-community/Llama-4-Scout-17B-16E-Instruct-4bit": 61_143_654_248,
"mlx-community/Llama-4-Maverick-17B-128E-Instruct-4bit": 225_923_469_800,
LocalASRConfiguration.qwen3DefaultModel: 4_080_707_826,
LocalASRConfiguration.mimoDefaultModel: 35_997_080_271,
]

private static let downloadEstimateRegex = try! NSRegularExpression(
pattern: #"([0-9]+(?:[\.,][0-9]+)?)\s*(TiB|GiB|MiB|KiB|TB|GB|MB|KB|T|G|M|K)(?![A-Za-z])"#,
options: [.caseInsensitive]
)

private static func parseDownloadEstimateValue(_ rawValue: String) -> Double? {
if rawValue.contains("."), rawValue.contains(",") {
return Double(rawValue.replacingOccurrences(of: ",", with: ""))
}
if let commaIndex = rawValue.firstIndex(of: ",") {
let fraction = rawValue[rawValue.index(after: commaIndex)...]
let normalized = fraction.count == 3
? rawValue.replacingOccurrences(of: ",", with: "")
: rawValue.replacingOccurrences(of: ",", with: ".")
return Double(normalized)
}
return Double(rawValue)
}

private static func downloadEstimateMultiplier(for rawUnit: String) -> Double? {
switch rawUnit {
case "TIB": return pow(1024, 4)
case "GIB": return pow(1024, 3)
case "MIB": return pow(1024, 2)
case "KIB": return 1024
case "TB", "T": return 1_000_000_000_000
case "GB", "G": return 1_000_000_000
case "MB", "M": return 1_000_000
case "KB", "K": return 1_000
default: return nil
}
}
}
2 changes: 1 addition & 1 deletion Sources/LLM/LLMEngine.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,9 +30,9 @@ actor LLMEngine {
speedBytesPerSecond: 0
))
} else {
let tracker = DownloadProgressTracker()
let estimatedTotalBytes = estimatedDownloadBytes ?? 0
let repoDir = ModelStorage.hubModelRepoDir(id)
let tracker = DownloadProgressTracker(initialBytes: ModelStorage.directorySize(at: repoDir))
let config = Self.modelConfiguration(for: id)
container = try await LLMModelFactory.shared.loadContainer(
from: MLXModelLoading.downloader,
Expand Down
34 changes: 17 additions & 17 deletions Sources/Resources/en.lproj/Localizable.strings
Original file line numberDiff line numberDiff line change
Expand Up@@ -164,24 +164,24 @@
"model.last_formatting_value" = "%.2fs";
"model.compiling" = "Compiling…";
"model.loading" = "Loading…";
"model.smallest" = "Smallest, fastest ~335 MB";
"model.balanced" = "Balanced ~1 GB";
"model.best_quality" = "Best quality ~2.3 GB";
"model.qwen3_fast" = "Fastest, weaker cleanup ~335 MB";
"model.qwen3_balanced" = "Qwen3, balanced ~1 GB";
"model.smallest" = "Smallest, fastest ~290 MB";
"model.balanced" = "Balanced ~880 MB";
"model.best_quality" = "Best quality ~1.7 GB";
"model.qwen3_fast" = "Fastest, weaker cleanup ~351 MB";
"model.qwen3_balanced" = "Qwen3, balanced ~984 MB";
"model.qwen3_quality" = "Qwen3, best quality ~2.3 GB";
"model.qwen3_moe" = "Qwen3 MoE flagship, recommended ~5 GB";
"model.qwen35_tiny" = "Qwen3.5, fastest ~620 MB";
"model.qwen35_fast" = "Recommended for Smart Format ~1.5 GB";
"model.qwen35_quality" = "Best quality cleanup 5-bit ~5.5 GB";
"model.qwen35_moe" = "Qwen3.5 MoE flagship ~6 GB";
"model.gemma_fast" = "Gemma 3, fast ~600 MB";
"model.gemma_balanced" = "Gemma 3, balanced ~2.5 GB";
"model.gemma_quality" = "Gemma 3, best quality ~7 GB";
"model.qwen3_moe" = "Qwen3 MoE flagship, recommended ~17.2 GB";
"model.qwen35_tiny" = "Qwen3.5, fastest ~652 MB";
"model.qwen35_fast" = "Recommended for Smart Format ~1.7 GB";
"model.qwen35_quality" = "Best quality cleanup 5-bit ~7.1 GB";
"model.qwen35_moe" = "Qwen3.5 MoE flagship ~20.4 GB";
"model.gemma_fast" = "Gemma 3, fast ~772 MB";
"model.gemma_balanced" = "Gemma 3, balanced ~3.4 GB";
"model.gemma_quality" = "Gemma 3, best quality ~8.1 GB";
"model.gemma4_edge" = "Gemma 4 edge model ~3.6 GB";
"model.gemma4_edge_quality" = "Gemma 4 edge quality ~5.2 GB";
"model.llama_balanced" = "Llama 4 Scout, balanced ~10 GB";
"model.llama_quality" = "Llama 4 Maverick, high quality ~25 GB";
"model.llama_balanced" = "Llama 4 Scout, balanced ~61.1 GB";
"model.llama_quality" = "Llama 4 Maverick, high quality ~225.9 GB";
"model.import_local" = "Import Local Model…";
"model.import_invalid" = "Invalid model directory: config.json not found";
"model.import_failed" = "Import Failed";
Expand DownExpand Up@@ -341,8 +341,8 @@
"local_asr.tokenizer_path" = "Audio tokenizer path";
"qwen_asr.config_hint" = "Choose Qwen3-ASR, then click Download to fetch the local model and prepare its Python runtime.";
"mimo_asr.config_hint" = "Choose MiMo-V2.5-ASR, then click Download to fetch the model, audio tokenizer, and runtime files.";
"model.qwen3_asr_quality" = "Local ASR through MLX, ~4 GB";
"model.mimo_asr_quality" = "Local ASR model plus audio tokenizer";
"model.qwen3_asr_quality" = "Local ASR through MLX, ~4.1 GB";
"model.mimo_asr_quality" = "Local ASR model plus audio tokenizer ~36 GB";
"model.asr_incomplete" = "Download incomplete";
"model.asr_preparing_runtime" = "Preparing runtime files";
"model.asr_installing_runtime" = "Installing local runtime";
Expand Down
34 changes: 17 additions & 17 deletions Sources/Resources/zh-Hans.lproj/Localizable.strings
Original file line numberDiff line numberDiff line change
Expand Up@@ -164,24 +164,24 @@
"model.last_formatting_value" = "%.2f 秒";
"model.compiling" = "编译中…";
"model.loading" = "加载中…";
"model.smallest" = "最小最快 ~335 MB";
"model.balanced" = "平衡选择 ~1 GB";
"model.best_quality" = "质量最佳 ~2.3 GB";
"model.qwen3_fast" = "极速,整理偏弱 ~335 MB";
"model.qwen3_balanced" = "Qwen3 均衡 ~1 GB";
"model.smallest" = "最小最快 ~290 MB";
"model.balanced" = "平衡选择 ~880 MB";
"model.best_quality" = "质量最佳 ~1.7 GB";
"model.qwen3_fast" = "极速,整理偏弱 ~351 MB";
"model.qwen3_balanced" = "Qwen3 均衡 ~984 MB";
"model.qwen3_quality" = "Qwen3 高质量 ~2.3 GB";
"model.qwen3_moe" = "Qwen3 MoE 旗舰,推荐 ~5 GB";
"model.qwen35_tiny" = "Qwen3.5 极速 ~620 MB";
"model.qwen35_fast" = "智能整理推荐 ~1.5 GB";
"model.qwen35_quality" = "整理质量最佳 5-bit ~5.5 GB";
"model.qwen35_moe" = "Qwen3.5 MoE 旗舰 ~6 GB";
"model.gemma_fast" = "Gemma 3 极速 ~600 MB";
"model.gemma_balanced" = "Gemma 3 均衡 ~2.5 GB";
"model.gemma_quality" = "Gemma 3 高质量 ~7 GB";
"model.qwen3_moe" = "Qwen3 MoE 旗舰,推荐 ~17.2 GB";
"model.qwen35_tiny" = "Qwen3.5 极速 ~652 MB";
"model.qwen35_fast" = "智能整理推荐 ~1.7 GB";
"model.qwen35_quality" = "整理质量最佳 5-bit ~7.1 GB";
"model.qwen35_moe" = "Qwen3.5 MoE 旗舰 ~20.4 GB";
"model.gemma_fast" = "Gemma 3 极速 ~772 MB";
"model.gemma_balanced" = "Gemma 3 均衡 ~3.4 GB";
"model.gemma_quality" = "Gemma 3 高质量 ~8.1 GB";
"model.gemma4_edge" = "Gemma 4 端侧模型 ~3.6 GB";
"model.gemma4_edge_quality" = "Gemma 4 端侧高质量 ~5.2 GB";
"model.llama_balanced" = "Llama 4 Scout 均衡 ~10 GB";
"model.llama_quality" = "Llama 4 Maverick 高质量 ~25 GB";
"model.llama_balanced" = "Llama 4 Scout 均衡 ~61.1 GB";
"model.llama_quality" = "Llama 4 Maverick 高质量 ~225.9 GB";
"model.import_local" = "导入本地模型…";
"model.import_invalid" = "无效的模型目录:未找到 config.json";
"model.import_failed" = "导入失败";
Expand DownExpand Up@@ -341,8 +341,8 @@
"local_asr.tokenizer_path" = "音频 tokenizer 路径";
"qwen_asr.config_hint" = "选择 Qwen3-ASR 后,请点击下载按钮获取本地模型,并准备对应的 Python 运行环境。";
"mimo_asr.config_hint" = "选择 MiMo-V2.5-ASR 后,请点击下载按钮获取模型、音频 tokenizer 和运行文件。";
"model.qwen3_asr_quality" = "本地 MLX 语音识别,约 4 GB";
"model.mimo_asr_quality" = "本地语音识别模型 + 音频 tokenizer";
"model.qwen3_asr_quality" = "本地 MLX 语音识别,约 4.1 GB";
"model.mimo_asr_quality" = "本地语音识别模型 + 音频 tokenizer,约 36 GB";
"model.asr_incomplete" = "下载不完整";
"model.asr_preparing_runtime" = "准备运行文件";
"model.asr_installing_runtime" = "安装本地运行环境";
Expand Down
6 changes: 4 additions & 2 deletions Sources/Speech/WhisperEngine.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -82,7 +82,8 @@ final class WhisperEngine: SpeechEngine, @unchecked Sendable {

progress(dp(0.02, stage: .downloading))

let tracker = DownloadProgressTracker()
let modelDir = ModelStorage.whisperVariantDir(selectedModel)
let tracker = DownloadProgressTracker(initialBytes: ModelStorage.directorySize(at: modelDir))

let folder: URL
if let localFolder {
Expand All@@ -93,7 +94,8 @@ final class WhisperEngine: SpeechEngine, @unchecked Sendable {
variant: selectedModel,
downloadBase: ModelCatalog.whisperDownloadBase,
progressCallback: { p in
let completed = p.completedUnitCount
let downloadedBytes = ModelStorage.directorySize(at: modelDir)
let completed = downloadedBytes > 0 ? downloadedBytes : p.completedUnitCount
let total = p.totalUnitCount

let frac = 0.02 + p.fractionCompleted * 0.58
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions Sources/Config/DownloadProgressInfo.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,21 @@ struct DownloadProgressInfo: Equatable, Sendable {
let totalBytes: Int64
let speedBytesPerSecond: Double

init(
fraction: Double,
elapsedSeconds: TimeInterval,
completedBytes: Int64,
totalBytes: Int64,
speedBytesPerSecond: Double
) {
let completedBytes = max(completedBytes, 0)
self.fraction = Self.clampFraction(fraction)
self.elapsedSeconds = elapsedSeconds.isFinite ? max(elapsedSeconds, 0) : 0
self.completedBytes = completedBytes
self.totalBytes = totalBytes > 0 ? max(totalBytes, completedBytes) : 0
self.speedBytesPerSecond = speedBytesPerSecond.isFinite ? max(speedBytesPerSecond, 0) : 0
}

var percentText: String {
"\(Int(clampedFraction * 100))%"
}
Expand DownExpand Up@@ -78,7 +93,7 @@ final class DownloadProgressTracker: @unchecked Sendable {
init(startDate: Date = Date(), initialBytes: Int64 = 0) {
self.startDate = startDate
lastTime = startDate
lastBytes = initialBytes
lastBytes = max(initialBytes, 0)
}

func update(progress: Progress, fraction: Double? = nil) -> DownloadProgressInfo {
Expand All@@ -90,17 +105,27 @@ final class DownloadProgressTracker: @unchecked Sendable {
}

func update(completedBytes rawCompleted: Int64, totalBytes rawTotal: Int64, fraction: Double? = nil) -> DownloadProgressInfo {
update(completedBytes: rawCompleted, totalBytes: rawTotal, fraction: fraction, at: Date())
}

func update(
completedBytes rawCompleted: Int64,
totalBytes rawTotal: Int64,
fraction: Double? = nil,
at now: Date
) -> DownloadProgressInfo {
lock.lock()
defer { lock.unlock() }

let completedBytes = max(rawCompleted, 0)
let totalBytes = max(rawTotal, 0)
let now = Date()
let totalBytes = rawTotal > 0 ? max(rawTotal, completedBytes) : 0
let sampleElapsed = now.timeIntervalSince(lastTime)
if sampleElapsed > 0.5 {
let deltaBytes = completedBytes - lastBytes
if deltaBytes >= 0 {
lastSpeedBytesPerSecond = Double(deltaBytes) / sampleElapsed
} else {
lastSpeedBytesPerSecond = 0
}
lastTime = now
lastBytes = completedBytes
Expand Down
12 changes: 9 additions & 3 deletions Sources/Config/ModelCatalog.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -210,15 +210,21 @@ final class ModelCatalog: ObservableObject {
whisperModels[idx].downloadProgress = 0

do {
let tracker = DownloadProgressTracker()
let modelDir = ModelStorage.whisperVariantDir(id)
let tracker = DownloadProgressTracker(initialBytes: ModelStorage.directorySize(at: modelDir))

_ = try await WhisperKit.download(
variant: id,
downloadBase: Self.whisperDownloadBase,
progressCallback: { [weak self] p in
Task { @MainActor in
guard let self, let i = self.whisperModels.firstIndex(where: { $0.id == id }) else { return }
let info = tracker.update(progress: p)
let completedBytes = ModelStorage.directorySize(at: modelDir)
let info = tracker.update(
completedBytes: completedBytes > 0 ? completedBytes : p.completedUnitCount,
totalBytes: p.totalUnitCount,
fraction: p.fractionCompleted
)
self.whisperModels[i].downloadProgress = info.fraction
self.whisperModels[i].downloadDetail = info.detailText
}
Expand DownExpand Up@@ -279,9 +285,9 @@ final class ModelCatalog: ObservableObject {
llmModels[idx].downloadProgress = 0

do {
let tracker = DownloadProgressTracker()
let estimatedTotalBytes = estimatedLLMDownloadBytes(id) ?? 0
let repoDir = ModelStorage.hubModelRepoDir(id)
let tracker = DownloadProgressTracker(initialBytes: ModelStorage.directorySize(at: repoDir))
let config = ModelConfiguration(id: id)
_ = try await LLMModelFactory.shared.loadContainer(
from: MLXModelLoading.downloader,
Expand Down
2 changes: 1 addition & 1 deletion Sources/Config/ModelCatalogASR.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -82,8 +82,8 @@ extension ModelCatalog {
try await ensureMimoRepository()
}
if !asrModelFilesAreComplete(id) {
let tracker = DownloadProgressTracker(startDate: startedAt, initialBytes: asrRepoSize(id))
for (repoIndex, repoID) in repos.enumerated() {
let tracker = DownloadProgressTracker(startDate: startedAt)
_ = try await api.snapshot(from: ModelStorage.hubModelRepo(repoID)) { [weak self] progress in
Task { @MainActor in
guard let self, let i = self.asrModels.firstIndex(where: { $0.id == id }) else { return }
Expand Down
77 changes: 68 additions & 9 deletions Sources/Config/ModelCatalogDownloadEstimates.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,30 +3,89 @@ import Foundation
@MainActor
extension ModelCatalog {
func estimatedLLMDownloadBytes(_ id: String) -> Int64? {
if let bytes = Self.defaultDownloadEstimateBytes(for: id) { return bytes }
guard let model = llmModels.first(where: { $0.id == id }) else { return nil }
return Self.estimatedDownloadBytes(from: model.hint)
}

func estimatedASRDownloadBytes(_ id: String) -> Int64? {
if let bytes = Self.defaultDownloadEstimateBytes(for: id) { return bytes }
guard let model = asrModels.first(where: { $0.id == id }) else { return nil }
return Self.estimatedDownloadBytes(from: model.hint)
}

static func estimatedDownloadBytes(from text: String) -> Int64? {
let pattern = #"([0-9]+(?:\.[0-9]+)?)\s*(GB|MB)"#
guard let regex = try? NSRegularExpression(pattern: pattern, options: [.caseInsensitive]) else {
return nil
}
static func defaultDownloadEstimateBytes(for id: String) -> Int64? {
defaultDownloadEstimateBytes[id]
}

static func estimatedDownloadBytes(from text: String) -> Int64? {
let range = NSRange(text.startIndex..<text.endIndex, in: text)
guard let match = regex.matches(in: text, range: range).last,
guard let match = downloadEstimateRegex.matches(in: text, range: range).last,
match.numberOfRanges == 3,
let valueRange = Range(match.range(at: 1), in: text),
let unitRange = Range(match.range(at: 2), in: text),
let value = Double(text[valueRange]) else { return nil }
let value = parseDownloadEstimateValue(String(text[valueRange])) else { return nil }

let unit = text[unitRange].uppercased()
let multiplier = unit == "GB" ? 1_000_000_000.0 : 1_000_000.0
return Int64(value * multiplier)
guard let multiplier = downloadEstimateMultiplier(for: unit) else { return nil }
let bytes = value * multiplier
guard bytes.isFinite, bytes > 0, bytes <= Double(Int64.max) else { return nil }
return Int64(bytes)
}

private static let defaultDownloadEstimateBytes: [String: Int64] = [
"mlx-community/Qwen3.5-0.8B-MLX-4bit": 652_027_143,
"mlx-community/Qwen3.5-2B-4bit": 1_749_079_691,
"mlx-community/Qwen3.5-9B-5bit": 7_096_163_574,
"mlx-community/Qwen3-30B-A3B-4bit": 17_190_783_781,
"mlx-community/Qwen3.5-35B-A3B-4bit": 20_418_622_319,
"mlx-community/Qwen2.5-0.5B-Instruct-4bit": 289_598_797,
"mlx-community/Qwen2.5-1.5B-Instruct-4bit": 880_169_797,
"mlx-community/Qwen2.5-3B-Instruct-4bit": 1_747_849_050,
"mlx-community/Qwen3-0.6B-4bit": 351_383_618,
"mlx-community/Qwen3-1.7B-4bit": 984_013_244,
"mlx-community/Qwen3-4B-4bit": 2_278_969_756,
"mlx-community/gemma-4-e2b-it-4bit": 3_613_528_388,
"mlx-community/gemma-4-e4b-it-4bit": 5_249_809_327,
"mlx-community/gemma-3-1b-it-4bit": 771_860_852,
"mlx-community/gemma-3-4b-it-4bit": 3_439_894_985,
"mlx-community/gemma-3-12b-it-4bit": 8_068_018_787,
"mlx-community/Llama-4-Scout-17B-16E-Instruct-4bit": 61_143_654_248,
"mlx-community/Llama-4-Maverick-17B-128E-Instruct-4bit": 225_923_469_800,
LocalASRConfiguration.qwen3DefaultModel: 4_080_707_826,
LocalASRConfiguration.mimoDefaultModel: 35_997_080_271,
]

private static let downloadEstimateRegex = try! NSRegularExpression(
pattern: #"([0-9]+(?:[\.,][0-9]+)?)\s*(TiB|GiB|MiB|KiB|TB|GB|MB|KB|T|G|M|K)(?![A-Za-z])"#,
options: [.caseInsensitive]
)

private static func parseDownloadEstimateValue(_ rawValue: String) -> Double? {
if rawValue.contains("."), rawValue.contains(",") {
return Double(rawValue.replacingOccurrences(of: ",", with: ""))
}
if let commaIndex = rawValue.firstIndex(of: ",") {
let fraction = rawValue[rawValue.index(after: commaIndex)...]
let normalized = fraction.count == 3
? rawValue.replacingOccurrences(of: ",", with: "")
: rawValue.replacingOccurrences(of: ",", with: ".")
return Double(normalized)
}
return Double(rawValue)
}

private static func downloadEstimateMultiplier(for rawUnit: String) -> Double? {
switch rawUnit {
case "TIB": return pow(1024, 4)
case "GIB": return pow(1024, 3)
case "MIB": return pow(1024, 2)
case "KIB": return 1024
case "TB", "T": return 1_000_000_000_000
case "GB", "G": return 1_000_000_000
case "MB", "M": return 1_000_000
case "KB", "K": return 1_000
default: return nil
}
}
}
2 changes: 1 addition & 1 deletion Sources/LLM/LLMEngine.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,9 +30,9 @@ actor LLMEngine {
speedBytesPerSecond: 0
))
} else {
let tracker = DownloadProgressTracker()
let estimatedTotalBytes = estimatedDownloadBytes ?? 0
let repoDir = ModelStorage.hubModelRepoDir(id)
let tracker = DownloadProgressTracker(initialBytes: ModelStorage.directorySize(at: repoDir))
let config = Self.modelConfiguration(for: id)
container = try await LLMModelFactory.shared.loadContainer(
from: MLXModelLoading.downloader,
Expand Down
34 changes: 17 additions & 17 deletions Sources/Resources/en.lproj/Localizable.strings
Original file line numberDiff line numberDiff line change
Expand Up@@ -164,24 +164,24 @@
"model.last_formatting_value" = "%.2fs";
"model.compiling" = "Compiling…";
"model.loading" = "Loading…";
"model.smallest" = "Smallest, fastest ~335 MB";
"model.balanced" = "Balanced ~1 GB";
"model.best_quality" = "Best quality ~2.3 GB";
"model.qwen3_fast" = "Fastest, weaker cleanup ~335 MB";
"model.qwen3_balanced" = "Qwen3, balanced ~1 GB";
"model.smallest" = "Smallest, fastest ~290 MB";
"model.balanced" = "Balanced ~880 MB";
"model.best_quality" = "Best quality ~1.7 GB";
"model.qwen3_fast" = "Fastest, weaker cleanup ~351 MB";
"model.qwen3_balanced" = "Qwen3, balanced ~984 MB";
"model.qwen3_quality" = "Qwen3, best quality ~2.3 GB";
"model.qwen3_moe" = "Qwen3 MoE flagship, recommended ~5 GB";
"model.qwen35_tiny" = "Qwen3.5, fastest ~620 MB";
"model.qwen35_fast" = "Recommended for Smart Format ~1.5 GB";
"model.qwen35_quality" = "Best quality cleanup 5-bit ~5.5 GB";
"model.qwen35_moe" = "Qwen3.5 MoE flagship ~6 GB";
"model.gemma_fast" = "Gemma 3, fast ~600 MB";
"model.gemma_balanced" = "Gemma 3, balanced ~2.5 GB";
"model.gemma_quality" = "Gemma 3, best quality ~7 GB";
"model.qwen3_moe" = "Qwen3 MoE flagship, recommended ~17.2 GB";
"model.qwen35_tiny" = "Qwen3.5, fastest ~652 MB";
"model.qwen35_fast" = "Recommended for Smart Format ~1.7 GB";
"model.qwen35_quality" = "Best quality cleanup 5-bit ~7.1 GB";
"model.qwen35_moe" = "Qwen3.5 MoE flagship ~20.4 GB";
"model.gemma_fast" = "Gemma 3, fast ~772 MB";
"model.gemma_balanced" = "Gemma 3, balanced ~3.4 GB";
"model.gemma_quality" = "Gemma 3, best quality ~8.1 GB";
"model.gemma4_edge" = "Gemma 4 edge model ~3.6 GB";
"model.gemma4_edge_quality" = "Gemma 4 edge quality ~5.2 GB";
"model.llama_balanced" = "Llama 4 Scout, balanced ~10 GB";
"model.llama_quality" = "Llama 4 Maverick, high quality ~25 GB";
"model.llama_balanced" = "Llama 4 Scout, balanced ~61.1 GB";
"model.llama_quality" = "Llama 4 Maverick, high quality ~225.9 GB";
"model.import_local" = "Import Local Model…";
"model.import_invalid" = "Invalid model directory: config.json not found";
"model.import_failed" = "Import Failed";
Expand DownExpand Up@@ -341,8 +341,8 @@
"local_asr.tokenizer_path" = "Audio tokenizer path";
"qwen_asr.config_hint" = "Choose Qwen3-ASR, then click Download to fetch the local model and prepare its Python runtime.";
"mimo_asr.config_hint" = "Choose MiMo-V2.5-ASR, then click Download to fetch the model, audio tokenizer, and runtime files.";
"model.qwen3_asr_quality" = "Local ASR through MLX, ~4 GB";
"model.mimo_asr_quality" = "Local ASR model plus audio tokenizer";
"model.qwen3_asr_quality" = "Local ASR through MLX, ~4.1 GB";
"model.mimo_asr_quality" = "Local ASR model plus audio tokenizer ~36 GB";
"model.asr_incomplete" = "Download incomplete";
"model.asr_preparing_runtime" = "Preparing runtime files";
"model.asr_installing_runtime" = "Installing local runtime";
Expand Down
34 changes: 17 additions & 17 deletions Sources/Resources/zh-Hans.lproj/Localizable.strings
Original file line numberDiff line numberDiff line change
Expand Up@@ -164,24 +164,24 @@
"model.last_formatting_value" = "%.2f 秒";
"model.compiling" = "编译中…";
"model.loading" = "加载中…";
"model.smallest" = "最小最快 ~335 MB";
"model.balanced" = "平衡选择 ~1 GB";
"model.best_quality" = "质量最佳 ~2.3 GB";
"model.qwen3_fast" = "极速,整理偏弱 ~335 MB";
"model.qwen3_balanced" = "Qwen3 均衡 ~1 GB";
"model.smallest" = "最小最快 ~290 MB";
"model.balanced" = "平衡选择 ~880 MB";
"model.best_quality" = "质量最佳 ~1.7 GB";
"model.qwen3_fast" = "极速,整理偏弱 ~351 MB";
"model.qwen3_balanced" = "Qwen3 均衡 ~984 MB";
"model.qwen3_quality" = "Qwen3 高质量 ~2.3 GB";
"model.qwen3_moe" = "Qwen3 MoE 旗舰,推荐 ~5 GB";
"model.qwen35_tiny" = "Qwen3.5 极速 ~620 MB";
"model.qwen35_fast" = "智能整理推荐 ~1.5 GB";
"model.qwen35_quality" = "整理质量最佳 5-bit ~5.5 GB";
"model.qwen35_moe" = "Qwen3.5 MoE 旗舰 ~6 GB";
"model.gemma_fast" = "Gemma 3 极速 ~600 MB";
"model.gemma_balanced" = "Gemma 3 均衡 ~2.5 GB";
"model.gemma_quality" = "Gemma 3 高质量 ~7 GB";
"model.qwen3_moe" = "Qwen3 MoE 旗舰,推荐 ~17.2 GB";
"model.qwen35_tiny" = "Qwen3.5 极速 ~652 MB";
"model.qwen35_fast" = "智能整理推荐 ~1.7 GB";
"model.qwen35_quality" = "整理质量最佳 5-bit ~7.1 GB";
"model.qwen35_moe" = "Qwen3.5 MoE 旗舰 ~20.4 GB";
"model.gemma_fast" = "Gemma 3 极速 ~772 MB";
"model.gemma_balanced" = "Gemma 3 均衡 ~3.4 GB";
"model.gemma_quality" = "Gemma 3 高质量 ~8.1 GB";
"model.gemma4_edge" = "Gemma 4 端侧模型 ~3.6 GB";
"model.gemma4_edge_quality" = "Gemma 4 端侧高质量 ~5.2 GB";
"model.llama_balanced" = "Llama 4 Scout 均衡 ~10 GB";
"model.llama_quality" = "Llama 4 Maverick 高质量 ~25 GB";
"model.llama_balanced" = "Llama 4 Scout 均衡 ~61.1 GB";
"model.llama_quality" = "Llama 4 Maverick 高质量 ~225.9 GB";
"model.import_local" = "导入本地模型…";
"model.import_invalid" = "无效的模型目录:未找到 config.json";
"model.import_failed" = "导入失败";
Expand DownExpand Up@@ -341,8 +341,8 @@
"local_asr.tokenizer_path" = "音频 tokenizer 路径";
"qwen_asr.config_hint" = "选择 Qwen3-ASR 后,请点击下载按钮获取本地模型,并准备对应的 Python 运行环境。";
"mimo_asr.config_hint" = "选择 MiMo-V2.5-ASR 后,请点击下载按钮获取模型、音频 tokenizer 和运行文件。";
"model.qwen3_asr_quality" = "本地 MLX 语音识别,约 4 GB";
"model.mimo_asr_quality" = "本地语音识别模型 + 音频 tokenizer";
"model.qwen3_asr_quality" = "本地 MLX 语音识别,约 4.1 GB";
"model.mimo_asr_quality" = "本地语音识别模型 + 音频 tokenizer,约 36 GB";
"model.asr_incomplete" = "下载不完整";
"model.asr_preparing_runtime" = "准备运行文件";
"model.asr_installing_runtime" = "安装本地运行环境";
Expand Down
6 changes: 4 additions & 2 deletions Sources/Speech/WhisperEngine.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -82,7 +82,8 @@ final class WhisperEngine: SpeechEngine, @unchecked Sendable {

progress(dp(0.02, stage: .downloading))

let tracker = DownloadProgressTracker()
let modelDir = ModelStorage.whisperVariantDir(selectedModel)
let tracker = DownloadProgressTracker(initialBytes: ModelStorage.directorySize(at: modelDir))

let folder: URL
if let localFolder {
Expand All@@ -93,7 +94,8 @@ final class WhisperEngine: SpeechEngine, @unchecked Sendable {
variant: selectedModel,
downloadBase: ModelCatalog.whisperDownloadBase,
progressCallback: { p in
let completed = p.completedUnitCount
let downloadedBytes = ModelStorage.directorySize(at: modelDir)
let completed = downloadedBytes > 0 ? downloadedBytes : p.completedUnitCount
let total = p.totalUnitCount

let frac = 0.02 + p.fractionCompleted * 0.58
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions Sources/Config/DownloadProgressInfo.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,21 @@ struct DownloadProgressInfo: Equatable, Sendable {
let totalBytes: Int64
let speedBytesPerSecond: Double

init(
fraction: Double,
elapsedSeconds: TimeInterval,
completedBytes: Int64,
totalBytes: Int64,
speedBytesPerSecond: Double
) {
let completedBytes = max(completedBytes, 0)
self.fraction = Self.clampFraction(fraction)
self.elapsedSeconds = elapsedSeconds.isFinite ? max(elapsedSeconds, 0) : 0
self.completedBytes = completedBytes
self.totalBytes = totalBytes > 0 ? max(totalBytes, completedBytes) : 0
self.speedBytesPerSecond = speedBytesPerSecond.isFinite ? max(speedBytesPerSecond, 0) : 0
}

var percentText: String {
"\(Int(clampedFraction * 100))%"
}
Expand DownExpand Up@@ -78,7 +93,7 @@ final class DownloadProgressTracker: @unchecked Sendable {
init(startDate: Date = Date(), initialBytes: Int64 = 0) {
self.startDate = startDate
lastTime = startDate
lastBytes = initialBytes
lastBytes = max(initialBytes, 0)
}

func update(progress: Progress, fraction: Double? = nil) -> DownloadProgressInfo {
Expand All@@ -90,17 +105,27 @@ final class DownloadProgressTracker: @unchecked Sendable {
}

func update(completedBytes rawCompleted: Int64, totalBytes rawTotal: Int64, fraction: Double? = nil) -> DownloadProgressInfo {
update(completedBytes: rawCompleted, totalBytes: rawTotal, fraction: fraction, at: Date())
}

func update(
completedBytes rawCompleted: Int64,
totalBytes rawTotal: Int64,
fraction: Double? = nil,
at now: Date
) -> DownloadProgressInfo {
lock.lock()
defer { lock.unlock() }

let completedBytes = max(rawCompleted, 0)
let totalBytes = max(rawTotal, 0)
let now = Date()
let totalBytes = rawTotal > 0 ? max(rawTotal, completedBytes) : 0
let sampleElapsed = now.timeIntervalSince(lastTime)
if sampleElapsed > 0.5 {
let deltaBytes = completedBytes - lastBytes
if deltaBytes >= 0 {
lastSpeedBytesPerSecond = Double(deltaBytes) / sampleElapsed
} else {
lastSpeedBytesPerSecond = 0
}
lastTime = now
lastBytes = completedBytes
Expand Down
12 changes: 9 additions & 3 deletions Sources/Config/ModelCatalog.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -210,15 +210,21 @@ final class ModelCatalog: ObservableObject {
whisperModels[idx].downloadProgress = 0

do {
let tracker = DownloadProgressTracker()
let modelDir = ModelStorage.whisperVariantDir(id)
let tracker = DownloadProgressTracker(initialBytes: ModelStorage.directorySize(at: modelDir))

_ = try await WhisperKit.download(
variant: id,
downloadBase: Self.whisperDownloadBase,
progressCallback: { [weak self] p in
Task { @MainActor in
guard let self, let i = self.whisperModels.firstIndex(where: { $0.id == id }) else { return }
let info = tracker.update(progress: p)
let completedBytes = ModelStorage.directorySize(at: modelDir)
let info = tracker.update(
completedBytes: completedBytes > 0 ? completedBytes : p.completedUnitCount,
totalBytes: p.totalUnitCount,
fraction: p.fractionCompleted
)
self.whisperModels[i].downloadProgress = info.fraction
self.whisperModels[i].downloadDetail = info.detailText
}
Expand DownExpand Up@@ -279,9 +285,9 @@ final class ModelCatalog: ObservableObject {
llmModels[idx].downloadProgress = 0

do {
let tracker = DownloadProgressTracker()
let estimatedTotalBytes = estimatedLLMDownloadBytes(id) ?? 0
let repoDir = ModelStorage.hubModelRepoDir(id)
let tracker = DownloadProgressTracker(initialBytes: ModelStorage.directorySize(at: repoDir))
let config = ModelConfiguration(id: id)
_ = try await LLMModelFactory.shared.loadContainer(
from: MLXModelLoading.downloader,
Expand Down
2 changes: 1 addition & 1 deletion Sources/Config/ModelCatalogASR.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -82,8 +82,8 @@ extension ModelCatalog {
try await ensureMimoRepository()
}
if !asrModelFilesAreComplete(id) {
let tracker = DownloadProgressTracker(startDate: startedAt, initialBytes: asrRepoSize(id))
for (repoIndex, repoID) in repos.enumerated() {
let tracker = DownloadProgressTracker(startDate: startedAt)
_ = try await api.snapshot(from: ModelStorage.hubModelRepo(repoID)) { [weak self] progress in
Task { @MainActor in
guard let self, let i = self.asrModels.firstIndex(where: { $0.id == id }) else { return }
Expand Down
77 changes: 68 additions & 9 deletions Sources/Config/ModelCatalogDownloadEstimates.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,30 +3,89 @@ import Foundation
@MainActor
extension ModelCatalog {
func estimatedLLMDownloadBytes(_ id: String) -> Int64? {
if let bytes = Self.defaultDownloadEstimateBytes(for: id) { return bytes }
guard let model = llmModels.first(where: { $0.id == id }) else { return nil }
return Self.estimatedDownloadBytes(from: model.hint)
}

func estimatedASRDownloadBytes(_ id: String) -> Int64? {
if let bytes = Self.defaultDownloadEstimateBytes(for: id) { return bytes }
guard let model = asrModels.first(where: { $0.id == id }) else { return nil }
return Self.estimatedDownloadBytes(from: model.hint)
}

static func estimatedDownloadBytes(from text: String) -> Int64? {
let pattern = #"([0-9]+(?:\.[0-9]+)?)\s*(GB|MB)"#
guard let regex = try? NSRegularExpression(pattern: pattern, options: [.caseInsensitive]) else {
return nil
}
static func defaultDownloadEstimateBytes(for id: String) -> Int64? {
defaultDownloadEstimateBytes[id]
}

static func estimatedDownloadBytes(from text: String) -> Int64? {
let range = NSRange(text.startIndex..<text.endIndex, in: text)
guard let match = regex.matches(in: text, range: range).last,
guard let match = downloadEstimateRegex.matches(in: text, range: range).last,
match.numberOfRanges == 3,
let valueRange = Range(match.range(at: 1), in: text),
let unitRange = Range(match.range(at: 2), in: text),
let value = Double(text[valueRange]) else { return nil }
let value = parseDownloadEstimateValue(String(text[valueRange])) else { return nil }

let unit = text[unitRange].uppercased()
let multiplier = unit == "GB" ? 1_000_000_000.0 : 1_000_000.0
return Int64(value * multiplier)
guard let multiplier = downloadEstimateMultiplier(for: unit) else { return nil }
let bytes = value * multiplier
guard bytes.isFinite, bytes > 0, bytes <= Double(Int64.max) else { return nil }
return Int64(bytes)
}

private static let defaultDownloadEstimateBytes: [String: Int64] = [
"mlx-community/Qwen3.5-0.8B-MLX-4bit": 652_027_143,
"mlx-community/Qwen3.5-2B-4bit": 1_749_079_691,
"mlx-community/Qwen3.5-9B-5bit": 7_096_163_574,
"mlx-community/Qwen3-30B-A3B-4bit": 17_190_783_781,
"mlx-community/Qwen3.5-35B-A3B-4bit": 20_418_622_319,
"mlx-community/Qwen2.5-0.5B-Instruct-4bit": 289_598_797,
"mlx-community/Qwen2.5-1.5B-Instruct-4bit": 880_169_797,
"mlx-community/Qwen2.5-3B-Instruct-4bit": 1_747_849_050,
"mlx-community/Qwen3-0.6B-4bit": 351_383_618,
"mlx-community/Qwen3-1.7B-4bit": 984_013_244,
"mlx-community/Qwen3-4B-4bit": 2_278_969_756,
"mlx-community/gemma-4-e2b-it-4bit": 3_613_528_388,
"mlx-community/gemma-4-e4b-it-4bit": 5_249_809_327,
"mlx-community/gemma-3-1b-it-4bit": 771_860_852,
"mlx-community/gemma-3-4b-it-4bit": 3_439_894_985,
"mlx-community/gemma-3-12b-it-4bit": 8_068_018_787,
"mlx-community/Llama-4-Scout-17B-16E-Instruct-4bit": 61_143_654_248,
"mlx-community/Llama-4-Maverick-17B-128E-Instruct-4bit": 225_923_469_800,
LocalASRConfiguration.qwen3DefaultModel: 4_080_707_826,
LocalASRConfiguration.mimoDefaultModel: 35_997_080_271,
]

private static let downloadEstimateRegex = try! NSRegularExpression(
pattern: #"([0-9]+(?:[\.,][0-9]+)?)\s*(TiB|GiB|MiB|KiB|TB|GB|MB|KB|T|G|M|K)(?![A-Za-z])"#,
options: [.caseInsensitive]
)

private static func parseDownloadEstimateValue(_ rawValue: String) -> Double? {
if rawValue.contains("."), rawValue.contains(",") {
return Double(rawValue.replacingOccurrences(of: ",", with: ""))
}
if let commaIndex = rawValue.firstIndex(of: ",") {
let fraction = rawValue[rawValue.index(after: commaIndex)...]
let normalized = fraction.count == 3
? rawValue.replacingOccurrences(of: ",", with: "")
: rawValue.replacingOccurrences(of: ",", with: ".")
return Double(normalized)
}
return Double(rawValue)
}

private static func downloadEstimateMultiplier(for rawUnit: String) -> Double? {
switch rawUnit {
case "TIB": return pow(1024, 4)
case "GIB": return pow(1024, 3)
case "MIB": return pow(1024, 2)
case "KIB": return 1024
case "TB", "T": return 1_000_000_000_000
case "GB", "G": return 1_000_000_000
case "MB", "M": return 1_000_000
case "KB", "K": return 1_000
default: return nil
}
}
}
2 changes: 1 addition & 1 deletion Sources/LLM/LLMEngine.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,9 +30,9 @@ actor LLMEngine {
speedBytesPerSecond: 0
))
} else {
let tracker = DownloadProgressTracker()
let estimatedTotalBytes = estimatedDownloadBytes ?? 0
let repoDir = ModelStorage.hubModelRepoDir(id)
let tracker = DownloadProgressTracker(initialBytes: ModelStorage.directorySize(at: repoDir))
let config = Self.modelConfiguration(for: id)
container = try await LLMModelFactory.shared.loadContainer(
from: MLXModelLoading.downloader,
Expand Down
34 changes: 17 additions & 17 deletions Sources/Resources/en.lproj/Localizable.strings
Original file line numberDiff line numberDiff line change
Expand Up@@ -164,24 +164,24 @@
"model.last_formatting_value" = "%.2fs";
"model.compiling" = "Compiling…";
"model.loading" = "Loading…";
"model.smallest" = "Smallest, fastest ~335 MB";
"model.balanced" = "Balanced ~1 GB";
"model.best_quality" = "Best quality ~2.3 GB";
"model.qwen3_fast" = "Fastest, weaker cleanup ~335 MB";
"model.qwen3_balanced" = "Qwen3, balanced ~1 GB";
"model.smallest" = "Smallest, fastest ~290 MB";
"model.balanced" = "Balanced ~880 MB";
"model.best_quality" = "Best quality ~1.7 GB";
"model.qwen3_fast" = "Fastest, weaker cleanup ~351 MB";
"model.qwen3_balanced" = "Qwen3, balanced ~984 MB";
"model.qwen3_quality" = "Qwen3, best quality ~2.3 GB";
"model.qwen3_moe" = "Qwen3 MoE flagship, recommended ~5 GB";
"model.qwen35_tiny" = "Qwen3.5, fastest ~620 MB";
"model.qwen35_fast" = "Recommended for Smart Format ~1.5 GB";
"model.qwen35_quality" = "Best quality cleanup 5-bit ~5.5 GB";
"model.qwen35_moe" = "Qwen3.5 MoE flagship ~6 GB";
"model.gemma_fast" = "Gemma 3, fast ~600 MB";
"model.gemma_balanced" = "Gemma 3, balanced ~2.5 GB";
"model.gemma_quality" = "Gemma 3, best quality ~7 GB";
"model.qwen3_moe" = "Qwen3 MoE flagship, recommended ~17.2 GB";
"model.qwen35_tiny" = "Qwen3.5, fastest ~652 MB";
"model.qwen35_fast" = "Recommended for Smart Format ~1.7 GB";
"model.qwen35_quality" = "Best quality cleanup 5-bit ~7.1 GB";
"model.qwen35_moe" = "Qwen3.5 MoE flagship ~20.4 GB";
"model.gemma_fast" = "Gemma 3, fast ~772 MB";
"model.gemma_balanced" = "Gemma 3, balanced ~3.4 GB";
"model.gemma_quality" = "Gemma 3, best quality ~8.1 GB";
"model.gemma4_edge" = "Gemma 4 edge model ~3.6 GB";
"model.gemma4_edge_quality" = "Gemma 4 edge quality ~5.2 GB";
"model.llama_balanced" = "Llama 4 Scout, balanced ~10 GB";
"model.llama_quality" = "Llama 4 Maverick, high quality ~25 GB";
"model.llama_balanced" = "Llama 4 Scout, balanced ~61.1 GB";
"model.llama_quality" = "Llama 4 Maverick, high quality ~225.9 GB";
"model.import_local" = "Import Local Model…";
"model.import_invalid" = "Invalid model directory: config.json not found";
"model.import_failed" = "Import Failed";
Expand DownExpand Up@@ -341,8 +341,8 @@
"local_asr.tokenizer_path" = "Audio tokenizer path";
"qwen_asr.config_hint" = "Choose Qwen3-ASR, then click Download to fetch the local model and prepare its Python runtime.";
"mimo_asr.config_hint" = "Choose MiMo-V2.5-ASR, then click Download to fetch the model, audio tokenizer, and runtime files.";
"model.qwen3_asr_quality" = "Local ASR through MLX, ~4 GB";
"model.mimo_asr_quality" = "Local ASR model plus audio tokenizer";
"model.qwen3_asr_quality" = "Local ASR through MLX, ~4.1 GB";
"model.mimo_asr_quality" = "Local ASR model plus audio tokenizer ~36 GB";
"model.asr_incomplete" = "Download incomplete";
"model.asr_preparing_runtime" = "Preparing runtime files";
"model.asr_installing_runtime" = "Installing local runtime";
Expand Down
34 changes: 17 additions & 17 deletions Sources/Resources/zh-Hans.lproj/Localizable.strings
Original file line numberDiff line numberDiff line change
Expand Up@@ -164,24 +164,24 @@
"model.last_formatting_value" = "%.2f 秒";
"model.compiling" = "编译中…";
"model.loading" = "加载中…";
"model.smallest" = "最小最快 ~335 MB";
"model.balanced" = "平衡选择 ~1 GB";
"model.best_quality" = "质量最佳 ~2.3 GB";
"model.qwen3_fast" = "极速,整理偏弱 ~335 MB";
"model.qwen3_balanced" = "Qwen3 均衡 ~1 GB";
"model.smallest" = "最小最快 ~290 MB";
"model.balanced" = "平衡选择 ~880 MB";
"model.best_quality" = "质量最佳 ~1.7 GB";
"model.qwen3_fast" = "极速,整理偏弱 ~351 MB";
"model.qwen3_balanced" = "Qwen3 均衡 ~984 MB";
"model.qwen3_quality" = "Qwen3 高质量 ~2.3 GB";
"model.qwen3_moe" = "Qwen3 MoE 旗舰,推荐 ~5 GB";
"model.qwen35_tiny" = "Qwen3.5 极速 ~620 MB";
"model.qwen35_fast" = "智能整理推荐 ~1.5 GB";
"model.qwen35_quality" = "整理质量最佳 5-bit ~5.5 GB";
"model.qwen35_moe" = "Qwen3.5 MoE 旗舰 ~6 GB";
"model.gemma_fast" = "Gemma 3 极速 ~600 MB";
"model.gemma_balanced" = "Gemma 3 均衡 ~2.5 GB";
"model.gemma_quality" = "Gemma 3 高质量 ~7 GB";
"model.qwen3_moe" = "Qwen3 MoE 旗舰,推荐 ~17.2 GB";
"model.qwen35_tiny" = "Qwen3.5 极速 ~652 MB";
"model.qwen35_fast" = "智能整理推荐 ~1.7 GB";
"model.qwen35_quality" = "整理质量最佳 5-bit ~7.1 GB";
"model.qwen35_moe" = "Qwen3.5 MoE 旗舰 ~20.4 GB";
"model.gemma_fast" = "Gemma 3 极速 ~772 MB";
"model.gemma_balanced" = "Gemma 3 均衡 ~3.4 GB";
"model.gemma_quality" = "Gemma 3 高质量 ~8.1 GB";
"model.gemma4_edge" = "Gemma 4 端侧模型 ~3.6 GB";
"model.gemma4_edge_quality" = "Gemma 4 端侧高质量 ~5.2 GB";
"model.llama_balanced" = "Llama 4 Scout 均衡 ~10 GB";
"model.llama_quality" = "Llama 4 Maverick 高质量 ~25 GB";
"model.llama_balanced" = "Llama 4 Scout 均衡 ~61.1 GB";
"model.llama_quality" = "Llama 4 Maverick 高质量 ~225.9 GB";
"model.import_local" = "导入本地模型…";
"model.import_invalid" = "无效的模型目录:未找到 config.json";
"model.import_failed" = "导入失败";
Expand DownExpand Up@@ -341,8 +341,8 @@
"local_asr.tokenizer_path" = "音频 tokenizer 路径";
"qwen_asr.config_hint" = "选择 Qwen3-ASR 后,请点击下载按钮获取本地模型,并准备对应的 Python 运行环境。";
"mimo_asr.config_hint" = "选择 MiMo-V2.5-ASR 后,请点击下载按钮获取模型、音频 tokenizer 和运行文件。";
"model.qwen3_asr_quality" = "本地 MLX 语音识别,约 4 GB";
"model.mimo_asr_quality" = "本地语音识别模型 + 音频 tokenizer";
"model.qwen3_asr_quality" = "本地 MLX 语音识别,约 4.1 GB";
"model.mimo_asr_quality" = "本地语音识别模型 + 音频 tokenizer,约 36 GB";
"model.asr_incomplete" = "下载不完整";
"model.asr_preparing_runtime" = "准备运行文件";
"model.asr_installing_runtime" = "安装本地运行环境";
Expand Down
6 changes: 4 additions & 2 deletions Sources/Speech/WhisperEngine.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -82,7 +82,8 @@ final class WhisperEngine: SpeechEngine, @unchecked Sendable {

progress(dp(0.02, stage: .downloading))

let tracker = DownloadProgressTracker()
let modelDir = ModelStorage.whisperVariantDir(selectedModel)
let tracker = DownloadProgressTracker(initialBytes: ModelStorage.directorySize(at: modelDir))

let folder: URL
if let localFolder {
Expand All@@ -93,7 +94,8 @@ final class WhisperEngine: SpeechEngine, @unchecked Sendable {
variant: selectedModel,
downloadBase: ModelCatalog.whisperDownloadBase,
progressCallback: { p in
let completed = p.completedUnitCount
let downloadedBytes = ModelStorage.directorySize(at: modelDir)
let completed = downloadedBytes > 0 ? downloadedBytes : p.completedUnitCount
let total = p.totalUnitCount

let frac = 0.02 + p.fractionCompleted * 0.58
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions Sources/Config/DownloadProgressInfo.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,21 @@ struct DownloadProgressInfo: Equatable, Sendable {
let totalBytes: Int64
let speedBytesPerSecond: Double

init(
fraction: Double,
elapsedSeconds: TimeInterval,
completedBytes: Int64,
totalBytes: Int64,
speedBytesPerSecond: Double
) {
let completedBytes = max(completedBytes, 0)
self.fraction = Self.clampFraction(fraction)
self.elapsedSeconds = elapsedSeconds.isFinite ? max(elapsedSeconds, 0) : 0
self.completedBytes = completedBytes
self.totalBytes = totalBytes > 0 ? max(totalBytes, completedBytes) : 0
self.speedBytesPerSecond = speedBytesPerSecond.isFinite ? max(speedBytesPerSecond, 0) : 0
}

var percentText: String {
"\(Int(clampedFraction * 100))%"
}
Expand DownExpand Up@@ -78,7 +93,7 @@ final class DownloadProgressTracker: @unchecked Sendable {
init(startDate: Date = Date(), initialBytes: Int64 = 0) {
self.startDate = startDate
lastTime = startDate
lastBytes = initialBytes
lastBytes = max(initialBytes, 0)
}

func update(progress: Progress, fraction: Double? = nil) -> DownloadProgressInfo {
Expand All@@ -90,17 +105,27 @@ final class DownloadProgressTracker: @unchecked Sendable {
}

func update(completedBytes rawCompleted: Int64, totalBytes rawTotal: Int64, fraction: Double? = nil) -> DownloadProgressInfo {
update(completedBytes: rawCompleted, totalBytes: rawTotal, fraction: fraction, at: Date())
}

func update(
completedBytes rawCompleted: Int64,
totalBytes rawTotal: Int64,
fraction: Double? = nil,
at now: Date
) -> DownloadProgressInfo {
lock.lock()
defer { lock.unlock() }

let completedBytes = max(rawCompleted, 0)
let totalBytes = max(rawTotal, 0)
let now = Date()
let totalBytes = rawTotal > 0 ? max(rawTotal, completedBytes) : 0
let sampleElapsed = now.timeIntervalSince(lastTime)
if sampleElapsed > 0.5 {
let deltaBytes = completedBytes - lastBytes
if deltaBytes >= 0 {
lastSpeedBytesPerSecond = Double(deltaBytes) / sampleElapsed
} else {
lastSpeedBytesPerSecond = 0
}
lastTime = now
lastBytes = completedBytes
Expand Down
12 changes: 9 additions & 3 deletions Sources/Config/ModelCatalog.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -210,15 +210,21 @@ final class ModelCatalog: ObservableObject {
whisperModels[idx].downloadProgress = 0

do {
let tracker = DownloadProgressTracker()
let modelDir = ModelStorage.whisperVariantDir(id)
let tracker = DownloadProgressTracker(initialBytes: ModelStorage.directorySize(at: modelDir))

_ = try await WhisperKit.download(
variant: id,
downloadBase: Self.whisperDownloadBase,
progressCallback: { [weak self] p in
Task { @MainActor in
guard let self, let i = self.whisperModels.firstIndex(where: { $0.id == id }) else { return }
let info = tracker.update(progress: p)
let completedBytes = ModelStorage.directorySize(at: modelDir)
let info = tracker.update(
completedBytes: completedBytes > 0 ? completedBytes : p.completedUnitCount,
totalBytes: p.totalUnitCount,
fraction: p.fractionCompleted
)
self.whisperModels[i].downloadProgress = info.fraction
self.whisperModels[i].downloadDetail = info.detailText
}
Expand DownExpand Up@@ -279,9 +285,9 @@ final class ModelCatalog: ObservableObject {
llmModels[idx].downloadProgress = 0

do {
let tracker = DownloadProgressTracker()
let estimatedTotalBytes = estimatedLLMDownloadBytes(id) ?? 0
let repoDir = ModelStorage.hubModelRepoDir(id)
let tracker = DownloadProgressTracker(initialBytes: ModelStorage.directorySize(at: repoDir))
let config = ModelConfiguration(id: id)
_ = try await LLMModelFactory.shared.loadContainer(
from: MLXModelLoading.downloader,
Expand Down
2 changes: 1 addition & 1 deletion Sources/Config/ModelCatalogASR.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -82,8 +82,8 @@ extension ModelCatalog {
try await ensureMimoRepository()
}
if !asrModelFilesAreComplete(id) {
let tracker = DownloadProgressTracker(startDate: startedAt, initialBytes: asrRepoSize(id))
for (repoIndex, repoID) in repos.enumerated() {
let tracker = DownloadProgressTracker(startDate: startedAt)
_ = try await api.snapshot(from: ModelStorage.hubModelRepo(repoID)) { [weak self] progress in
Task { @MainActor in
guard let self, let i = self.asrModels.firstIndex(where: { $0.id == id }) else { return }
Expand Down
77 changes: 68 additions & 9 deletions Sources/Config/ModelCatalogDownloadEstimates.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,30 +3,89 @@ import Foundation
@MainActor
extension ModelCatalog {
func estimatedLLMDownloadBytes(_ id: String) -> Int64? {
if let bytes = Self.defaultDownloadEstimateBytes(for: id) { return bytes }
guard let model = llmModels.first(where: { $0.id == id }) else { return nil }
return Self.estimatedDownloadBytes(from: model.hint)
}

func estimatedASRDownloadBytes(_ id: String) -> Int64? {
if let bytes = Self.defaultDownloadEstimateBytes(for: id) { return bytes }
guard let model = asrModels.first(where: { $0.id == id }) else { return nil }
return Self.estimatedDownloadBytes(from: model.hint)
}

static func estimatedDownloadBytes(from text: String) -> Int64? {
let pattern = #"([0-9]+(?:\.[0-9]+)?)\s*(GB|MB)"#
guard let regex = try? NSRegularExpression(pattern: pattern, options: [.caseInsensitive]) else {
return nil
}
static func defaultDownloadEstimateBytes(for id: String) -> Int64? {
defaultDownloadEstimateBytes[id]
}

static func estimatedDownloadBytes(from text: String) -> Int64? {
let range = NSRange(text.startIndex..<text.endIndex, in: text)
guard let match = regex.matches(in: text, range: range).last,
guard let match = downloadEstimateRegex.matches(in: text, range: range).last,
match.numberOfRanges == 3,
let valueRange = Range(match.range(at: 1), in: text),
let unitRange = Range(match.range(at: 2), in: text),
let value = Double(text[valueRange]) else { return nil }
let value = parseDownloadEstimateValue(String(text[valueRange])) else { return nil }

let unit = text[unitRange].uppercased()
let multiplier = unit == "GB" ? 1_000_000_000.0 : 1_000_000.0
return Int64(value * multiplier)
guard let multiplier = downloadEstimateMultiplier(for: unit) else { return nil }
let bytes = value * multiplier
guard bytes.isFinite, bytes > 0, bytes <= Double(Int64.max) else { return nil }
return Int64(bytes)
}

private static let defaultDownloadEstimateBytes: [String: Int64] = [
"mlx-community/Qwen3.5-0.8B-MLX-4bit": 652_027_143,
"mlx-community/Qwen3.5-2B-4bit": 1_749_079_691,
"mlx-community/Qwen3.5-9B-5bit": 7_096_163_574,
"mlx-community/Qwen3-30B-A3B-4bit": 17_190_783_781,
"mlx-community/Qwen3.5-35B-A3B-4bit": 20_418_622_319,
"mlx-community/Qwen2.5-0.5B-Instruct-4bit": 289_598_797,
"mlx-community/Qwen2.5-1.5B-Instruct-4bit": 880_169_797,
"mlx-community/Qwen2.5-3B-Instruct-4bit": 1_747_849_050,
"mlx-community/Qwen3-0.6B-4bit": 351_383_618,
"mlx-community/Qwen3-1.7B-4bit": 984_013_244,
"mlx-community/Qwen3-4B-4bit": 2_278_969_756,
"mlx-community/gemma-4-e2b-it-4bit": 3_613_528_388,
"mlx-community/gemma-4-e4b-it-4bit": 5_249_809_327,
"mlx-community/gemma-3-1b-it-4bit": 771_860_852,
"mlx-community/gemma-3-4b-it-4bit": 3_439_894_985,
"mlx-community/gemma-3-12b-it-4bit": 8_068_018_787,
"mlx-community/Llama-4-Scout-17B-16E-Instruct-4bit": 61_143_654_248,
"mlx-community/Llama-4-Maverick-17B-128E-Instruct-4bit": 225_923_469_800,
LocalASRConfiguration.qwen3DefaultModel: 4_080_707_826,
LocalASRConfiguration.mimoDefaultModel: 35_997_080_271,
]

private static let downloadEstimateRegex = try! NSRegularExpression(
pattern: #"([0-9]+(?:[\.,][0-9]+)?)\s*(TiB|GiB|MiB|KiB|TB|GB|MB|KB|T|G|M|K)(?![A-Za-z])"#,
options: [.caseInsensitive]
)

private static func parseDownloadEstimateValue(_ rawValue: String) -> Double? {
if rawValue.contains("."), rawValue.contains(",") {
return Double(rawValue.replacingOccurrences(of: ",", with: ""))
}
if let commaIndex = rawValue.firstIndex(of: ",") {
let fraction = rawValue[rawValue.index(after: commaIndex)...]
let normalized = fraction.count == 3
? rawValue.replacingOccurrences(of: ",", with: "")
: rawValue.replacingOccurrences(of: ",", with: ".")
return Double(normalized)
}
return Double(rawValue)
}

private static func downloadEstimateMultiplier(for rawUnit: String) -> Double? {
switch rawUnit {
case "TIB": return pow(1024, 4)
case "GIB": return pow(1024, 3)
case "MIB": return pow(1024, 2)
case "KIB": return 1024
case "TB", "T": return 1_000_000_000_000
case "GB", "G": return 1_000_000_000
case "MB", "M": return 1_000_000
case "KB", "K": return 1_000
default: return nil
}
}
}
2 changes: 1 addition & 1 deletion Sources/LLM/LLMEngine.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,9 +30,9 @@ actor LLMEngine {
speedBytesPerSecond: 0
))
} else {
let tracker = DownloadProgressTracker()
let estimatedTotalBytes = estimatedDownloadBytes ?? 0
let repoDir = ModelStorage.hubModelRepoDir(id)
let tracker = DownloadProgressTracker(initialBytes: ModelStorage.directorySize(at: repoDir))
let config = Self.modelConfiguration(for: id)
container = try await LLMModelFactory.shared.loadContainer(
from: MLXModelLoading.downloader,
Expand Down
34 changes: 17 additions & 17 deletions Sources/Resources/en.lproj/Localizable.strings
Original file line numberDiff line numberDiff line change
Expand Up@@ -164,24 +164,24 @@
"model.last_formatting_value" = "%.2fs";
"model.compiling" = "Compiling…";
"model.loading" = "Loading…";
"model.smallest" = "Smallest, fastest ~335 MB";
"model.balanced" = "Balanced ~1 GB";
"model.best_quality" = "Best quality ~2.3 GB";
"model.qwen3_fast" = "Fastest, weaker cleanup ~335 MB";
"model.qwen3_balanced" = "Qwen3, balanced ~1 GB";
"model.smallest" = "Smallest, fastest ~290 MB";
"model.balanced" = "Balanced ~880 MB";
"model.best_quality" = "Best quality ~1.7 GB";
"model.qwen3_fast" = "Fastest, weaker cleanup ~351 MB";
"model.qwen3_balanced" = "Qwen3, balanced ~984 MB";
"model.qwen3_quality" = "Qwen3, best quality ~2.3 GB";
"model.qwen3_moe" = "Qwen3 MoE flagship, recommended ~5 GB";
"model.qwen35_tiny" = "Qwen3.5, fastest ~620 MB";
"model.qwen35_fast" = "Recommended for Smart Format ~1.5 GB";
"model.qwen35_quality" = "Best quality cleanup 5-bit ~5.5 GB";
"model.qwen35_moe" = "Qwen3.5 MoE flagship ~6 GB";
"model.gemma_fast" = "Gemma 3, fast ~600 MB";
"model.gemma_balanced" = "Gemma 3, balanced ~2.5 GB";
"model.gemma_quality" = "Gemma 3, best quality ~7 GB";
"model.qwen3_moe" = "Qwen3 MoE flagship, recommended ~17.2 GB";
"model.qwen35_tiny" = "Qwen3.5, fastest ~652 MB";
"model.qwen35_fast" = "Recommended for Smart Format ~1.7 GB";
"model.qwen35_quality" = "Best quality cleanup 5-bit ~7.1 GB";
"model.qwen35_moe" = "Qwen3.5 MoE flagship ~20.4 GB";
"model.gemma_fast" = "Gemma 3, fast ~772 MB";
"model.gemma_balanced" = "Gemma 3, balanced ~3.4 GB";
"model.gemma_quality" = "Gemma 3, best quality ~8.1 GB";
"model.gemma4_edge" = "Gemma 4 edge model ~3.6 GB";
"model.gemma4_edge_quality" = "Gemma 4 edge quality ~5.2 GB";
"model.llama_balanced" = "Llama 4 Scout, balanced ~10 GB";
"model.llama_quality" = "Llama 4 Maverick, high quality ~25 GB";
"model.llama_balanced" = "Llama 4 Scout, balanced ~61.1 GB";
"model.llama_quality" = "Llama 4 Maverick, high quality ~225.9 GB";
"model.import_local" = "Import Local Model…";
"model.import_invalid" = "Invalid model directory: config.json not found";
"model.import_failed" = "Import Failed";
Expand DownExpand Up@@ -341,8 +341,8 @@
"local_asr.tokenizer_path" = "Audio tokenizer path";
"qwen_asr.config_hint" = "Choose Qwen3-ASR, then click Download to fetch the local model and prepare its Python runtime.";
"mimo_asr.config_hint" = "Choose MiMo-V2.5-ASR, then click Download to fetch the model, audio tokenizer, and runtime files.";
"model.qwen3_asr_quality" = "Local ASR through MLX, ~4 GB";
"model.mimo_asr_quality" = "Local ASR model plus audio tokenizer";
"model.qwen3_asr_quality" = "Local ASR through MLX, ~4.1 GB";
"model.mimo_asr_quality" = "Local ASR model plus audio tokenizer ~36 GB";
"model.asr_incomplete" = "Download incomplete";
"model.asr_preparing_runtime" = "Preparing runtime files";
"model.asr_installing_runtime" = "Installing local runtime";
Expand Down
34 changes: 17 additions & 17 deletions Sources/Resources/zh-Hans.lproj/Localizable.strings
Original file line numberDiff line numberDiff line change
Expand Up@@ -164,24 +164,24 @@
"model.last_formatting_value" = "%.2f 秒";
"model.compiling" = "编译中…";
"model.loading" = "加载中…";
"model.smallest" = "最小最快 ~335 MB";
"model.balanced" = "平衡选择 ~1 GB";
"model.best_quality" = "质量最佳 ~2.3 GB";
"model.qwen3_fast" = "极速,整理偏弱 ~335 MB";
"model.qwen3_balanced" = "Qwen3 均衡 ~1 GB";
"model.smallest" = "最小最快 ~290 MB";
"model.balanced" = "平衡选择 ~880 MB";
"model.best_quality" = "质量最佳 ~1.7 GB";
"model.qwen3_fast" = "极速,整理偏弱 ~351 MB";
"model.qwen3_balanced" = "Qwen3 均衡 ~984 MB";
"model.qwen3_quality" = "Qwen3 高质量 ~2.3 GB";
"model.qwen3_moe" = "Qwen3 MoE 旗舰,推荐 ~5 GB";
"model.qwen35_tiny" = "Qwen3.5 极速 ~620 MB";
"model.qwen35_fast" = "智能整理推荐 ~1.5 GB";
"model.qwen35_quality" = "整理质量最佳 5-bit ~5.5 GB";
"model.qwen35_moe" = "Qwen3.5 MoE 旗舰 ~6 GB";
"model.gemma_fast" = "Gemma 3 极速 ~600 MB";
"model.gemma_balanced" = "Gemma 3 均衡 ~2.5 GB";
"model.gemma_quality" = "Gemma 3 高质量 ~7 GB";
"model.qwen3_moe" = "Qwen3 MoE 旗舰,推荐 ~17.2 GB";
"model.qwen35_tiny" = "Qwen3.5 极速 ~652 MB";
"model.qwen35_fast" = "智能整理推荐 ~1.7 GB";
"model.qwen35_quality" = "整理质量最佳 5-bit ~7.1 GB";
"model.qwen35_moe" = "Qwen3.5 MoE 旗舰 ~20.4 GB";
"model.gemma_fast" = "Gemma 3 极速 ~772 MB";
"model.gemma_balanced" = "Gemma 3 均衡 ~3.4 GB";
"model.gemma_quality" = "Gemma 3 高质量 ~8.1 GB";
"model.gemma4_edge" = "Gemma 4 端侧模型 ~3.6 GB";
"model.gemma4_edge_quality" = "Gemma 4 端侧高质量 ~5.2 GB";
"model.llama_balanced" = "Llama 4 Scout 均衡 ~10 GB";
"model.llama_quality" = "Llama 4 Maverick 高质量 ~25 GB";
"model.llama_balanced" = "Llama 4 Scout 均衡 ~61.1 GB";
"model.llama_quality" = "Llama 4 Maverick 高质量 ~225.9 GB";
"model.import_local" = "导入本地模型…";
"model.import_invalid" = "无效的模型目录:未找到 config.json";
"model.import_failed" = "导入失败";
Expand DownExpand Up@@ -341,8 +341,8 @@
"local_asr.tokenizer_path" = "音频 tokenizer 路径";
"qwen_asr.config_hint" = "选择 Qwen3-ASR 后,请点击下载按钮获取本地模型,并准备对应的 Python 运行环境。";
"mimo_asr.config_hint" = "选择 MiMo-V2.5-ASR 后,请点击下载按钮获取模型、音频 tokenizer 和运行文件。";
"model.qwen3_asr_quality" = "本地 MLX 语音识别,约 4 GB";
"model.mimo_asr_quality" = "本地语音识别模型 + 音频 tokenizer";
"model.qwen3_asr_quality" = "本地 MLX 语音识别,约 4.1 GB";
"model.mimo_asr_quality" = "本地语音识别模型 + 音频 tokenizer,约 36 GB";
"model.asr_incomplete" = "下载不完整";
"model.asr_preparing_runtime" = "准备运行文件";
"model.asr_installing_runtime" = "安装本地运行环境";
Expand Down
6 changes: 4 additions & 2 deletions Sources/Speech/WhisperEngine.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -82,7 +82,8 @@ final class WhisperEngine: SpeechEngine, @unchecked Sendable {

progress(dp(0.02, stage: .downloading))

let tracker = DownloadProgressTracker()
let modelDir = ModelStorage.whisperVariantDir(selectedModel)
let tracker = DownloadProgressTracker(initialBytes: ModelStorage.directorySize(at: modelDir))

let folder: URL
if let localFolder {
Expand All@@ -93,7 +94,8 @@ final class WhisperEngine: SpeechEngine, @unchecked Sendable {
variant: selectedModel,
downloadBase: ModelCatalog.whisperDownloadBase,
progressCallback: { p in
let completed = p.completedUnitCount
let downloadedBytes = ModelStorage.directorySize(at: modelDir)
let completed = downloadedBytes > 0 ? downloadedBytes : p.completedUnitCount
let total = p.totalUnitCount

let frac = 0.02 + p.fractionCompleted * 0.58
Expand Down
Loading
Loading