Class: Cohere::Transcribe::Runtime::WordPipeline::PairBudgetReload
- Inherits:
-
Object
- Object
- Cohere::Transcribe::Runtime::WordPipeline::PairBudgetReload
- Defined in:
- lib/cohere/transcribe/runtime/word_pipeline.rb
Overview
Reloads alignment PCM with one worker and at most one lookahead. The next file may overlap MMS computation only when the current/next PCM pair fits the configured budget; otherwise the current reference is dropped before the next decode starts.
Constant Summary collapse
- SAMPLE_BYTES =
4
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(works, memory_byte_limit:, reload:, started: nil) ⇒ PairBudgetReload
constructor
A new instance of PairBudgetReload.
Constructor Details
#initialize(works, memory_byte_limit:, reload:, started: nil) ⇒ PairBudgetReload
Returns a new instance of PairBudgetReload.
230 231 232 233 234 235 236 237 238 239 |
# File 'lib/cohere/transcribe/runtime/word_pipeline.rb', line 230 def initialize(works, memory_byte_limit:, reload:, started: nil) @works = works.to_a.freeze @memory_byte_limit = Integer(memory_byte_limit) raise ArgumentError, "memory_byte_limit must be positive" unless @memory_byte_limit.positive? raise ArgumentError, "reload must respond to call" unless reload.respond_to?(:call) raise ArgumentError, "started must respond to call" if started && !started.respond_to?(:call) @reload = reload @started = started end |
Instance Method Details
#each ⇒ Object
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/cohere/transcribe/runtime/word_pipeline.rb', line 241 def each return enum_for(__method__) unless block_given? return if @works.empty? pending = submit(@works.first, 0) @started&.call @works.each_with_index do |work, index| current = pending pending = nil reload_result = current.value current = nil # rubocop:disable Lint/UselessAssignment -- release Thread#value before a serial decode next_work = @works[index + 1] pending = submit(next_work, index + 1) if next_work && pair_fits?(work, next_work) yield [work, reload_result].freeze reload_result = nil # rubocop:disable Lint/UselessAssignment -- release PCM before a serial decode unless pending || next_work.nil? GC.start(full_mark: false, immediate_mark: true, immediate_sweep: true) pending = submit(next_work, index + 1) end end completed = true ensure cancel(pending) if defined?(pending) && pending cancel(current) if defined?(current) && current GC.start(full_mark: false, immediate_mark: true, immediate_sweep: true) if defined?(completed) && completed end |