Skip to content

Commit c490c4d

Browse files
authored
Merge pull request #4 from m5stack/dev
Dev
2 parents 9d1dfce + a830d44 commit c490c4d

File tree

690 files changed

+182685
-877
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

690 files changed

+182685
-877
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.vscode/settings.json
22
projects/core135_llm_product_test_ui
3-
projects/imx678_test
3+
projects/imx678_test
4+
projects/test_*

ext_components/ax-samples/SConstruct

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,13 @@ if "CONFIG_AX_SAMPLES_ENABLED" in os.environ:
2929
LINK_SEARCH_PATH = []
3030

3131
INCLUDE += [
32-
os.path.join(env["GIT_REPO_LISTS"]["ax-samples"]["path"], "examples/base"),
33-
os.path.join(env["GIT_REPO_LISTS"]["ax-samples"]["path"], "examples/utilities"),
32+
os.path.join(env["GIT_REPO_LISTS"]["ax-samples"]["path"], "examples"),
3433
]
3534
if "CONFIG_AX_620E_MSP_ENABLED" in os.environ:
3635
INCLUDE += [
3736
os.path.join(
3837
env["GIT_REPO_LISTS"]["ax-samples"]["path"],
39-
"examples/ax620e/middleware",
38+
"examples/ax620e",
4039
)
4140
]
4241

projects/llm_framework/SConstruct

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import shutil
55
os.environ['SDK_PATH'] = os.path.normpath(str(Path(os.getcwd())/'..'/'..'/'SDK'))
66
os.environ['EXT_COMPONENTS_PATH'] = os.path.normpath(str(Path(os.getcwd())/'..'/'..'/'ext_components'))
77

8-
version = 'v0.0.5'
8+
version = 'v0.0.7'
99
static_lib = 'static_lib'
1010
update = False
1111

@@ -26,4 +26,6 @@ if update:
2626
exec(f.read())
2727
down_url = "https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/linux/llm/static_lib_{}.tar.gz".format(version)
2828
down_path = check_wget_down(down_url, "static_lib_{}.tar.gz".format(version))
29+
if os.path.exists(static_lib):
30+
shutil.rmtree(static_lib)
2931
shutil.move(down_path, static_lib)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// sherpa-onnx/csrc/fast-clustering-config.h
2+
//
3+
// Copyright (c) 2024 Xiaomi Corporation
4+
5+
#ifndef SHERPA_ONNX_CSRC_FAST_CLUSTERING_CONFIG_H_
6+
#define SHERPA_ONNX_CSRC_FAST_CLUSTERING_CONFIG_H_
7+
8+
#include <string>
9+
10+
#include "sherpa-onnx/csrc/parse-options.h"
11+
12+
namespace sherpa_onnx {
13+
14+
struct FastClusteringConfig {
15+
// If greater than 0, then threshold is ignored.
16+
//
17+
// We strongly recommend that you set it if you know the number of clusters
18+
// in advance
19+
int32_t num_clusters = -1;
20+
21+
// distance threshold.
22+
//
23+
// The smaller, the more clusters it will generate.
24+
// The larger, the fewer clusters it will generate.
25+
float threshold = 0.5;
26+
27+
FastClusteringConfig() = default;
28+
29+
FastClusteringConfig(int32_t num_clusters, float threshold)
30+
: num_clusters(num_clusters), threshold(threshold) {}
31+
32+
std::string ToString() const;
33+
34+
void Register(ParseOptions *po);
35+
bool Validate() const;
36+
};
37+
38+
} // namespace sherpa_onnx
39+
#endif // SHERPA_ONNX_CSRC_FAST_CLUSTERING_CONFIG_H_
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// sherpa-onnx/csrc/fast-clustering.h
2+
//
3+
// Copyright (c) 2024 Xiaomi Corporation
4+
5+
#ifndef SHERPA_ONNX_CSRC_FAST_CLUSTERING_H_
6+
#define SHERPA_ONNX_CSRC_FAST_CLUSTERING_H_
7+
8+
#include <memory>
9+
#include <vector>
10+
11+
#include "sherpa-onnx/csrc/fast-clustering-config.h"
12+
13+
namespace sherpa_onnx {
14+
15+
class FastClustering {
16+
public:
17+
explicit FastClustering(const FastClusteringConfig &config);
18+
~FastClustering();
19+
20+
/**
21+
* @param features Pointer to a 2-D feature matrix in row major. Each row
22+
* is a feature frame. It is changed in-place. We will
23+
* convert each feature frame to a normalized vector.
24+
* That is, the L2-norm of each vector will be equal to 1.
25+
* It uses cosine dissimilarity,
26+
* which is 1 - (cosine similarity)
27+
* @param num_rows Number of feature frames
28+
* @param num-cols The feature dimension.
29+
*
30+
* @return Return a vector of size num_rows. ans[i] contains the label
31+
* for the i-th feature frame, i.e., the i-th row of the feature
32+
* matrix.
33+
*/
34+
std::vector<int32_t> Cluster(float *features, int32_t num_rows,
35+
int32_t num_cols) const;
36+
37+
private:
38+
class Impl;
39+
std::unique_ptr<Impl> impl_;
40+
};
41+
42+
} // namespace sherpa_onnx
43+
#endif // SHERPA_ONNX_CSRC_FAST_CLUSTERING_H_

projects/llm_framework/include/sherpa/sherpa-onnx/csrc/features.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ struct FeatureExtractorConfig {
5757
float frame_length_ms = 25.0f; // in milliseconds.
5858
bool is_librosa = false;
5959
bool remove_dc_offset = true; // Subtract mean of wave before FFT.
60+
float preemph_coeff = 0.97f; // Preemphasis coefficient.
6061
std::string window_type = "povey"; // e.g. Hamming window
6162

6263
// For models from NeMo
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// sherpa-onnx/csrc/fst-utils.h
2+
//
3+
// Copyright (c) 2024 Xiaomi Corporation
4+
5+
#ifndef SHERPA_ONNX_CSRC_FST_UTILS_H_
6+
#define SHERPA_ONNX_CSRC_FST_UTILS_H_
7+
8+
#include <string>
9+
10+
#include "fst/fstlib.h"
11+
12+
namespace sherpa_onnx {
13+
14+
fst::Fst<fst::StdArc> *ReadGraph(const std::string &filename);
15+
16+
}
17+
18+
#endif // SHERPA_ONNX_CSRC_FST_UTILS_H_

projects/llm_framework/include/sherpa/sherpa-onnx/csrc/hypothesis.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,13 @@ struct Hypothesis {
5151
// LM log prob if any.
5252
double lm_log_prob = 0;
5353

54-
// the nn lm score for next token given the current ys
54+
// the nn lm score for next token given the current ys,
55+
// when using shallow fusion
5556
CopyableOrtValue nn_lm_scores;
57+
58+
// cur scored tokens by RNN LM, when rescoring
59+
int32_t cur_scored_pos = 0;
60+
5661
// the nn lm states
5762
std::vector<CopyableOrtValue> nn_lm_states;
5863

projects/llm_framework/include/sherpa/sherpa-onnx/csrc/keyword-spotter-transducer-impl.h

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,25 @@ class KeywordSpotterTransducerImpl : public KeywordSpotterImpl {
6666
public:
6767
explicit KeywordSpotterTransducerImpl(const KeywordSpotterConfig &config)
6868
: config_(config),
69-
model_(OnlineTransducerModel::Create(config.model_config)),
70-
sym_(config.model_config.tokens) {
69+
model_(OnlineTransducerModel::Create(config.model_config)) {
70+
if (!config.model_config.tokens_buf.empty()) {
71+
sym_ = SymbolTable(config.model_config.tokens_buf, false);
72+
} else {
73+
/// assuming tokens_buf and tokens are guaranteed not being both empty
74+
sym_ = SymbolTable(config.model_config.tokens, true);
75+
}
76+
7177
if (sym_.Contains("<unk>")) {
7278
unk_id_ = sym_["<unk>"];
7379
}
7480

7581
model_->SetFeatureDim(config.feat_config.feature_dim);
7682

77-
InitKeywords();
83+
if (config.keywords_buf.empty()) {
84+
InitKeywords();
85+
} else {
86+
InitKeywordsFromBufStr();
87+
}
7888

7989
decoder_ = std::make_unique<TransducerKeywordDecoder>(
8090
model_.get(), config_.max_active_paths, config_.num_trailing_blanks,
@@ -305,6 +315,12 @@ class KeywordSpotterTransducerImpl : public KeywordSpotterImpl {
305315
}
306316
#endif
307317

318+
void InitKeywordsFromBufStr() {
319+
// keywords_buf's content is supposed to be same as the keywords_file's
320+
std::istringstream is(config_.keywords_buf);
321+
InitKeywords(is);
322+
}
323+
308324
void InitOnlineStream(OnlineStream *stream) const {
309325
auto r = decoder_->GetEmptyResult();
310326
SHERPA_ONNX_CHECK_EQ(r.hyps.Size(), 1);

projects/llm_framework/include/sherpa/sherpa-onnx/csrc/keyword-spotter.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ struct KeywordSpotterConfig {
6969

7070
std::string keywords_file;
7171

72+
/// if keywords_buf is non-empty,
73+
/// the keywords will be loaded from the buffer instead of from the
74+
/// "keywrods_file"
75+
std::string keywords_buf;
76+
7277
KeywordSpotterConfig() = default;
7378

7479
KeywordSpotterConfig(const FeatureExtractorConfig &feat_config,

0 commit comments

Comments
 (0)