refactor: Reorganize batch managers + expose decoder state explicitly (Issues #1 & #4)#502
Conversation
Moves all batch transcription files from Parakeet root into SlidingWindow/, organized by decoding algorithm (TDT vs CTC). This fixes the fundamental misorganization where batch managers were scattered at root instead of grouped with the SlidingWindow public API they support. Changes: - Move 8 TDT batch files → SlidingWindow/TDT/ - Move 12 Decoder files → SlidingWindow/TDT/Decoder/ - Move 4 CTC language files → SlidingWindow/CTC/ - Mirror structure in test directory (10 test files) - Update DirectoryStructure.md with new organization Impact: - Before: 15 files at Parakeet root, unclear organization - After: 3 files at Parakeet root (shared utilities), clear module boundaries - Zero code changes required (Swift Package Manager handles paths) Fixes #457 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
9c3029c to
f5ae76a
Compare
There was a problem hiding this comment.
Devin Review found 1 potential issue.
🐛 1 issue in files not directly in the diff
🐛 Accidentally committed fake FLAC file containing HuggingFace error text (test-audio/1089-134686-0000.flac:1)
The file test-audio/1089-134686-0000.flac was added in this PR but is not a valid FLAC audio file — it's a 15-byte text file containing Entry not found, which is a HuggingFace download error response. Any code or test attempting to decode this as audio will fail. This also violates the repository rule in AGENTS.md/CLAUDE.md: "NEVER create dummy/mock models or synthetic audio data." The file should be removed from the commit, and *.flac (or test-audio/) should likely be added to .gitignore.
View 2 additional findings in Devin Review.
Offline VBx Pipeline ResultsSpeaker Diarization Performance (VBx Batch Mode)Optimal clustering with Hungarian algorithm for maximum accuracy
Offline VBx Pipeline Timing BreakdownTime spent in each stage of batch diarization
Speaker Diarization Research ComparisonOffline VBx achieves competitive accuracy with batch processing
Pipeline Details:
🎯 Offline VBx Test • AMI Corpus ES2004a • 1049.0s meeting audio • 246.8s processing • Test runtime: 4m 12s • 04/07/2026, 11:46 PM EST |
✅ Japanese ASR Benchmark Results (CTC)Status: Passed
✅ Benchmark completed successfully. The TDT Japanese hybrid model (CTC preprocessor/encoder + TDT decoder/joint) is working correctly. View benchmark log |
Parakeet EOU Benchmark Results ✅Status: Benchmark passed Performance Metrics
Streaming Metrics
Test runtime: 1m6s • 04/07/2026, 11:44 PM EST RTFx = Real-Time Factor (higher is better) • Processing includes: Model inference, audio preprocessing, state management, and file I/O |
✅ Japanese ASR Benchmark Results (CTC)Status: Passed
✅ Benchmark completed successfully. The TDT Japanese hybrid model (CTC preprocessor/encoder + TDT decoder/joint) is working correctly. View benchmark log |
Qwen3-ASR int8 Smoke Test ✅
Performance Metrics
Runtime: 3m25s Note: CI VM lacks physical GPU — CoreML MLState (macOS 15) KV cache produces degraded results on virtualized runners. On Apple Silicon: ~1.3% WER / 2.5x RTFx. |
VAD Benchmark ResultsPerformance Comparison
Dataset Details
✅: Average F1-Score above 70% |
PocketTTS Smoke Test ✅
Runtime: 0m35s Note: PocketTTS uses CoreML MLState (macOS 15) KV cache + Mimi streaming state. CI VM lacks physical GPU — audio quality may differ from Apple Silicon. |
Kokoro TTS Smoke Test ✅
Runtime: 0m42s Note: Kokoro TTS uses CoreML flow matching + Vocos vocoder. CI VM lacks physical ANE — performance may differ from Apple Silicon. |
Speaker Diarization Benchmark ResultsSpeaker Diarization PerformanceEvaluating "who spoke when" detection accuracy
Diarization Pipeline Timing BreakdownTime spent in each stage of speaker diarization
Speaker Diarization Research ComparisonResearch baselines typically achieve 18-30% DER on standard datasets
Note: RTFx shown above is from GitHub Actions runner. On Apple Silicon with ANE:
🎯 Speaker Diarization Test • AMI Corpus ES2004a • 1049.0s meeting audio • 36.5s diarization time • Test runtime: 1m 43s • 04/07/2026, 11:39 PM EST |
**Breaking Change**: Remove per-source decoder state routing from AsrManager. Callers now manage their own TdtDecoderState explicitly via `inout` parameters. ## Changes ### Core API Changes - **AsrManager**: Removed `microphoneDecoderState` and `systemDecoderState` properties - **Public methods** now require `decoderState: inout TdtDecoderState` parameter: - `transcribe(_ audioBuffer:, decoderState:)` - `transcribe(_ url:, decoderState:)` - `transcribeDiskBacked(_ url:, decoderState:)` - `transcribe(_ audioSamples:, decoderState:)` - **Removed methods**: - `resetDecoderState()` - callers create fresh state with `TdtDecoderState.make()` - `resetDecoderState(for:)` - no longer needed - `initializeDecoderState(for:)` - internal method removed ### Internal Changes - **AsrManager+Transcription**: Updated `transcribeWithState` and `transcribeChunk` to use `inout` state - **SlidingWindowAsrManager**: Manages own `decoderState` property - **ChunkProcessor**: Added `decoderState: inout TdtDecoderState` parameter (unused, for API consistency) - **TdtDecoderState**: Made `public` to expose in public API ### Updated Call Sites - **CLI**: AsrBenchmark, FleursBenchmark, CtcEarningsBenchmark, TranscribeCommand, TTSCommand - **Tests**: AsrManagerTests, StressTests ## Migration Example ```swift // Before: let result = try await manager.transcribe(audio, source: .microphone) // After: var state = TdtDecoderState.make() let result = try await manager.transcribe(audio, decoderState: &state) ``` ## Benefits 1. **Explicit state management**: Caller controls decoder state lifecycle 2. **Unlimited concurrency**: Can manage any number of independent states 3. **Clearer architecture**: AsrManager manages models, not application state 4. **Simpler testing**: State is a visible parameter, not hidden internal field ## Testing - ✅ Build: Zero errors - ✅ Tests: 57/57 AsrManagerTests passed - ✅ CLI: All commands updated and functional Related: #457 (Issue #4 - Decoder State Management Flaw) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Sortformer High-Latency Benchmark ResultsES2004a Performance (30.4s latency config)
Sortformer High-Latency • ES2004a • Runtime: 2m 23s • 2026-04-08T03:38:26.392Z |
ASR Benchmark Results ✅Status: All benchmarks passed Parakeet v3 (multilingual)
Parakeet v2 (English-optimized)
Streaming (v3)
Streaming (v2)
Streaming tests use 5 files with 0.5s chunks to simulate real-time audio streaming 25 files per dataset • Test runtime: 8m5s • 04/07/2026, 11:48 PM EST RTFx = Real-Time Factor (higher is better) • Calculated as: Total audio duration ÷ Total processing time Expected RTFx Performance on Physical M1 Hardware:• M1 Mac: ~28x (clean), ~25x (other) Testing methodology follows HuggingFace Open ASR Leaderboard |
✅ Japanese ASR Benchmark Results (CTC)Status: Passed
✅ Benchmark completed successfully. The TDT Japanese hybrid model (CTC preprocessor/encoder + TDT decoder/joint) is working correctly. View benchmark log |
Fixes 4 issues identified in Devin review: 1. **Workflow path references** - Updated Japanese ASR workflow paths after file reorganization - Lines 7, 8, 48: Updated paths from `Parakeet/TdtJa*.swift` to `Parakeet/SlidingWindow/TDT/TdtJa*.swift` - Ensures workflow triggers correctly on PR changes 2. **Decoder state layer count mismatch** - Use model's actual layer count instead of hardcoded default - Made `AsrManager.decoderLayerCount` public - Updated all CLI commands and tests to use `TdtDecoderState.make(decoderLayers: await manager.decoderLayerCount)` - Prevents CoreML shape mismatches with tdtCtc110m (1 layer) vs v2/v3 (2 layers) - Fixed in: AsrBenchmark, FleursBenchmark, CtcEarningsBenchmark, TranscribeCommand, TTSCommand, StressTests 3. **Unused inout parameter in ChunkProcessor** - Removed misleading parameter - `ChunkProcessor.process()` does stateless processing (creates fresh state per chunk) - Removed unused `decoderState: inout TdtDecoderState` parameter - Updated call sites in AsrManager+Transcription and AsrManager.transcribeDiskBacked 4. **Invalid test audio file** - Already fixed in previous commit (removed test-audio/1089-134686-0000.flac) ## Testing - ✅ Build: Zero errors - ✅ Tests: 57/57 AsrManagerTests passed - ✅ CLI: All commands functional Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
✅ Japanese ASR Benchmark Results (CTC)Status: Passed
✅ Benchmark completed successfully. The TDT Japanese hybrid model (CTC preprocessor/encoder + TDT decoder/joint) is working correctly. View benchmark log |
|
|
||
| // Measure only inference time for accurate RTFx calculation | ||
| let url = URL(fileURLWithPath: sample.audioPath) | ||
| var decoderState = TdtDecoderState.make() |
There was a problem hiding this comment.
🟡 Missing decoderLayers argument in processSingleSample creates incorrectly shaped decoder state for non-default models
FleursBenchmark.processSingleSample creates TdtDecoderState.make() at line 1238 without passing decoderLayers, defaulting to 2. Every other production call site in this PR correctly queries the model's actual layer count via await asrManager.decoderLayerCount (e.g., FleursBenchmark.processLanguageSamples at FleursBenchmark.swift:574). If processSingleSample is ever called with an AsrManager configured with the tdtCtc110m model (which has 1 decoder layer per AsrModels.swift:66), the decoder state shape [2, 1, 640] will mismatch the model's expected [1, 1, 640], causing a CoreML inference error.
| var decoderState = TdtDecoderState.make() | |
| var decoderState = TdtDecoderState.make(decoderLayers: await asrManager.decoderLayerCount) |
Was this helpful? React with 👍 or 👎 to provide feedback.
…tes benchmark suite functionality
✅ Japanese ASR Benchmark Results (CTC)Status: Passed
✅ Benchmark completed successfully. The TDT Japanese hybrid model (CTC preprocessor/encoder + TDT decoder/joint) is working correctly. View benchmark log |
Summary
This PR addresses two architectural issues from the consolidated report (#457):
SlidingWindow/, grouped by algorithm (TDT vs CTC)Both changes improve architecture clarity and eliminate hidden complexity.
Issue #1: File Organization ✅
Problem: Batch managers scattered at
Parakeet/root, unclear relationship toSlidingWindowAsrManagerSolution: Moved 34 files into
SlidingWindow/, organized by decoding algorithmFile Moves (24 source files + 10 test files)
TDT Batch Processing →
SlidingWindow/TDT/:TDT Infrastructure →
SlidingWindow/TDT/Decoder/:CTC Language Models →
SlidingWindow/CTC/:New Structure
Documentation
Documentation/ASR/DirectoryStructure.mdwith new structureIssue #4: Decoder State Management ✅
Problem: AsrManager maintained hidden per-source decoder states:
Solution: Expose decoder state explicitly via
inoutparametersAPI Changes (Breaking)
Before:
After:
Changed Methods
All public transcription methods now require
decoderState: inout TdtDecoderState:transcribe(_ audioBuffer:, decoderState:)transcribe(_ url:, decoderState:)transcribeDiskBacked(_ url:, decoderState:)transcribe(_ audioSamples:, decoderState:)Removed Methods
resetDecoderState()- callers create fresh state withTdtDecoderState.make()resetDecoderState(for:)- no longer neededinitializeDecoderState(for:)- removedInternal Changes
inoutstatedecoderStatepropertydecoderStateparameterpublicfor external useUpdated Call Sites
Benefits
✅ Explicit state management - Caller controls state lifecycle
✅ Unlimited concurrency - No limit on simultaneous transcriptions
✅ Clearer architecture - AsrManager manages models, not app state
✅ Better testing - State is visible, not hidden
Testing
✅ All tests pass:
✅ Build succeeds with zero errors
✅ CLI commands work correctly
Migration Notes
Issue #1: Zero code changes required. Swift Package Manager treats all of
Sources/FluidAudio/as a single module, so moving files between subdirectories requires no import changes.Issue #4: Breaking API change. Update all
transcribe()calls to create and pass decoder state explicitly (see examples above). Most users useSlidingWindowAsrManager(high-level API) which handles state internally—no migration needed.Impact Summary
Before:
After: