Class: Ignis::AI::BatchProcessor
- Inherits:
-
Object
- Object
- Ignis::AI::BatchProcessor
- Defined in:
- lib/nnw/ai/inference.rb
Overview
BatchProcessor — concurrent inference with dynamic batching.
Instance Method Summary collapse
-
#initialize(model, tokenizer, max_batch_size: 8, max_wait_ms: 50) ⇒ BatchProcessor
constructor
A new instance of BatchProcessor.
-
#start! ⇒ Thread
Start the batch processing loop in a background thread.
-
#stop! ⇒ void
Stop the processor.
-
#submit(prompt, **params) ⇒ String
Submit a request for processing.
Constructor Details
#initialize(model, tokenizer, max_batch_size: 8, max_wait_ms: 50) ⇒ BatchProcessor
Returns a new instance of BatchProcessor.
156 157 158 159 160 161 162 |
# File 'lib/nnw/ai/inference.rb', line 156 def initialize(model, tokenizer, max_batch_size: 8, max_wait_ms: 50) @generator = TextGenerator.new(model, tokenizer) @max_batch_size = max_batch_size @max_wait_ms = max_wait_ms @queue = Queue.new @running = false end |
Instance Method Details
#start! ⇒ Thread
Start the batch processing loop in a background thread.
176 177 178 179 180 |
# File 'lib/nnw/ai/inference.rb', line 176 def start! @running = true @thread = Thread.new { batch_loop } @thread end |
#stop! ⇒ void
This method returns an undefined value.
Stop the processor.
184 185 186 187 |
# File 'lib/nnw/ai/inference.rb', line 184 def stop! @running = false @thread&.join(5) end |
#submit(prompt, **params) ⇒ String
Submit a request for processing.
168 169 170 171 172 |
# File 'lib/nnw/ai/inference.rb', line 168 def submit(prompt, **params) result_queue = Queue.new @queue << { prompt: prompt, params: params, result: result_queue } result_queue.pop end |