-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'smalton/DOR-484-decoder' into 'master'
DOR-484: Unify decoder interfaces Closes DOR-484 See merge request machine-learning/dorado!770
- Loading branch information
Showing
19 changed files
with
227 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#pragma once | ||
|
||
#include "ModelRunner.h" | ||
#include "ModelRunnerBase.h" | ||
|
||
#include <ATen/core/TensorBody.h> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include "ModelRunner.h" | ||
|
||
#include "CRFModel.h" | ||
#include "decode/Decoder.h" | ||
|
||
namespace dorado::basecall { | ||
|
||
ModelRunner::ModelRunner(const CRFModelConfig &model_config, | ||
const std::string &device, | ||
int chunk_size, | ||
int batch_size) | ||
: m_config(model_config), | ||
m_decoder(decode::create_decoder(device, model_config)), | ||
m_options(at::TensorOptions().dtype(m_decoder->dtype()).device(device)), | ||
m_module(load_crf_model(model_config, m_options)) { | ||
m_decoder_options.q_shift = model_config.qbias; | ||
m_decoder_options.q_scale = model_config.qscale; | ||
|
||
// adjust chunk size to be a multiple of the stride | ||
chunk_size -= chunk_size % model_config.stride; | ||
|
||
m_input = at::zeros({batch_size, model_config.num_features, chunk_size}, | ||
at::TensorOptions().dtype(m_decoder->dtype()).device(at::kCPU)); | ||
} | ||
|
||
std::vector<decode::DecodedChunk> ModelRunner::call_chunks(int num_chunks) { | ||
at::InferenceMode guard; | ||
dorado::stats::Timer timer; | ||
auto scores = m_module->forward(m_input.to(m_options.device())); | ||
const auto forward_ms = timer.GetElapsedMS(); | ||
auto decoded_chunks = m_decoder->beam_search_part_2( | ||
m_decoder->beam_search_part_1({scores, num_chunks, m_decoder_options})); | ||
const auto forward_plus_decode_ms = timer.GetElapsedMS(); | ||
++m_num_batches_called; | ||
m_model_ms += forward_ms; | ||
m_decode_ms += forward_plus_decode_ms - forward_ms; | ||
return decoded_chunks; | ||
} | ||
|
||
void ModelRunner::accept_chunk(int chunk_idx, const at::Tensor &chunk) { | ||
m_input.index_put_({chunk_idx, at::indexing::Ellipsis}, chunk); | ||
} | ||
|
||
stats::NamedStats ModelRunner::sample_stats() const { | ||
stats::NamedStats stats; | ||
stats["batches_called"] = double(m_num_batches_called); | ||
stats["model_ms"] = double(m_model_ms); | ||
stats["decode_ms"] = double(m_decode_ms); | ||
return stats; | ||
} | ||
|
||
} // namespace dorado::basecall |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#pragma once | ||
|
||
#include "decode/Decoder.h" | ||
#include "utils/stats.h" | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
namespace at { | ||
class Tensor; | ||
} | ||
|
||
namespace dorado::basecall { | ||
|
||
struct CRFModelConfig; | ||
|
||
class ModelRunnerBase { | ||
public: | ||
virtual ~ModelRunnerBase() = default; | ||
virtual void accept_chunk(int chunk_idx, const at::Tensor &chunk) = 0; | ||
virtual std::vector<decode::DecodedChunk> call_chunks(int num_chunks) = 0; | ||
virtual const CRFModelConfig &config() const = 0; | ||
virtual size_t model_stride() const = 0; | ||
virtual size_t chunk_size() const = 0; | ||
virtual size_t batch_size() const = 0; | ||
virtual void terminate() = 0; | ||
virtual void restart() = 0; | ||
virtual std::string get_name() const = 0; | ||
virtual stats::NamedStats sample_stats() const = 0; | ||
}; | ||
|
||
using RunnerPtr = std::unique_ptr<ModelRunnerBase>; | ||
|
||
} // namespace dorado::basecall |
Oops, something went wrong.