Class: Cohere::Transcribe::ASR::BatchTelemetry

Inherits:
Object
  • Object
show all
Defined in:
lib/cohere/transcribe/asr/batching.rb

Overview

Mutable, run-local telemetry for native ASR batching. The public statistics object intentionally remains immutable; Engine copies these counters into it after a group completes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBatchTelemetry

Returns a new instance of BatchTelemetry.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cohere/transcribe/asr/batching.rb', line 24

def initialize
  @asr_batches = 0
  @processor_rows = 0
  @generated_tokens = 0
  @oom_retries = 0
  @effective_batch_min = 0
  @effective_batch_max = 0
  @final_batch_size = 0
  @final_batch_cap = 0
  @feature_worker_seconds = 0.0
  @h2d_seconds = 0.0
  @generate_device_seconds = 0.0
  @generation_analysis_seconds = 0.0
  @batch_history = []
end

Instance Attribute Details

#asr_batchesObject

Returns the value of attribute asr_batches.



10
11
12
# File 'lib/cohere/transcribe/asr/batching.rb', line 10

def asr_batches
  @asr_batches
end

#batch_historyObject (readonly)

Returns the value of attribute batch_history.



22
23
24
# File 'lib/cohere/transcribe/asr/batching.rb', line 22

def batch_history
  @batch_history
end

#effective_batch_maxObject

Returns the value of attribute effective_batch_max.



10
11
12
# File 'lib/cohere/transcribe/asr/batching.rb', line 10

def effective_batch_max
  @effective_batch_max
end

#effective_batch_minObject

Returns the value of attribute effective_batch_min.



10
11
12
# File 'lib/cohere/transcribe/asr/batching.rb', line 10

def effective_batch_min
  @effective_batch_min
end

#feature_worker_secondsObject

Returns the value of attribute feature_worker_seconds.



10
11
12
# File 'lib/cohere/transcribe/asr/batching.rb', line 10

def feature_worker_seconds
  @feature_worker_seconds
end

#final_batch_capObject

Returns the value of attribute final_batch_cap.



10
11
12
# File 'lib/cohere/transcribe/asr/batching.rb', line 10

def final_batch_cap
  @final_batch_cap
end

#final_batch_sizeObject

Returns the value of attribute final_batch_size.



10
11
12
# File 'lib/cohere/transcribe/asr/batching.rb', line 10

def final_batch_size
  @final_batch_size
end

#generate_device_secondsObject

Returns the value of attribute generate_device_seconds.



10
11
12
# File 'lib/cohere/transcribe/asr/batching.rb', line 10

def generate_device_seconds
  @generate_device_seconds
end

#generated_tokensObject

Returns the value of attribute generated_tokens.



10
11
12
# File 'lib/cohere/transcribe/asr/batching.rb', line 10

def generated_tokens
  @generated_tokens
end

#generation_analysis_secondsObject

Returns the value of attribute generation_analysis_seconds.



10
11
12
# File 'lib/cohere/transcribe/asr/batching.rb', line 10

def generation_analysis_seconds
  @generation_analysis_seconds
end

#h2d_secondsObject

Returns the value of attribute h2d_seconds.



10
11
12
# File 'lib/cohere/transcribe/asr/batching.rb', line 10

def h2d_seconds
  @h2d_seconds
end

#oom_retriesObject

Returns the value of attribute oom_retries.



10
11
12
# File 'lib/cohere/transcribe/asr/batching.rb', line 10

def oom_retries
  @oom_retries
end

#processor_rowsObject

Returns the value of attribute processor_rows.



10
11
12
# File 'lib/cohere/transcribe/asr/batching.rb', line 10

def processor_rows
  @processor_rows
end

Instance Method Details

#finalize(controller) ⇒ Object



86
87
88
89
90
# File 'lib/cohere/transcribe/asr/batching.rb', line 86

def finalize(controller)
  @final_batch_size = controller.current_size
  @final_batch_cap = controller.max_size
  self
end

#record_oom(rows, max_new_tokens:) ⇒ Object



77
78
79
80
81
82
83
84
# File 'lib/cohere/transcribe/asr/batching.rb', line 77

def record_oom(rows, max_new_tokens:)
  @oom_retries += 1
  @batch_history << {
    "event" => "oom",
    "segments" => rows,
    "max_new_tokens" => max_new_tokens
  }.freeze
end

#record_success(rows, max_new_tokens:, generated_tokens: 0, generated_tokens_by_row: [], generation_call_wall_seconds: nil, padded_audio_seconds: nil, native_metrics: nil) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/cohere/transcribe/asr/batching.rb', line 40

def record_success(rows, max_new_tokens:, generated_tokens: 0, generated_tokens_by_row: [],
                   generation_call_wall_seconds: nil, padded_audio_seconds: nil,
                   native_metrics: nil)
  prepare_seconds = native_metrics && (
    native_metrics.fetch(:feature_wall_seconds, 0.0) +
    native_metrics.fetch(:mel_pack_seconds, 0.0)
  )
  h2d_seconds = native_metrics&.fetch(:encoder_input_seconds, nil)
  generate_device_seconds = native_metrics && (
    native_metrics.fetch(:encoder_compute_seconds, 0.0) +
    native_metrics.fetch(:decoder_total_seconds, 0.0)
  )
  generation_analysis_seconds = native_metrics&.fetch(:render_seconds, nil)
  @asr_batches += 1
  @processor_rows += rows
  @generated_tokens += generated_tokens
  @effective_batch_min = @effective_batch_min.zero? ? rows : [@effective_batch_min, rows].min
  @effective_batch_max = [@effective_batch_max, rows].max
  @feature_worker_seconds += prepare_seconds.to_f
  @h2d_seconds += h2d_seconds.to_f
  @generate_device_seconds += generate_device_seconds.to_f
  @generation_analysis_seconds += generation_analysis_seconds.to_f
  @batch_history << {
    "segments" => rows,
    "processor_rows" => rows,
    "max_new_tokens" => max_new_tokens,
    "generated_tokens" => generated_tokens,
    "generated_tokens_by_row" => generated_tokens_by_row.freeze,
    "prepare_seconds" => prepare_seconds,
    "h2d_seconds" => h2d_seconds,
    "generation_call_wall_seconds" => generation_call_wall_seconds,
    "generate_device_seconds" => generate_device_seconds,
    "generation_analysis_seconds" => generation_analysis_seconds,
    "padded_audio_seconds" => padded_audio_seconds
  }.freeze
end