Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lexiconfree beam search #101

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
1e7035e
Implement simple lexiconfree time-sync beam search
Feb 19, 2025
bf0a8ce
Add some comments
Feb 19, 2025
d6689b4
Add `createSearchAlgorithm` to Search::Module
Feb 20, 2025
664945c
Fix compilation
Feb 26, 2025
488fb0e
Refactor traceback/lattice building and construct proper (nonlinear) …
Feb 28, 2025
1599302
Factor out time statistics into new Core::StopWatch class
Feb 28, 2025
9a60916
Don't copy sibling from predecessor
Feb 28, 2025
8e96423
Better handling of blank index
Feb 28, 2025
536ac82
Apply suggestions from code review
Feb 28, 2025
f21935e
Implement StopWatch class
Mar 4, 2025
5f82460
Use TIMER_START and TIMER_STOP macros instead
Mar 4, 2025
4779dd5
Simplify AdvancedTreeSearch PerformanceCounter by inheriting from Sto…
Mar 4, 2025
f5a3182
Small fixes in StopWatch class
Mar 4, 2025
97e5bd7
Make StopWatch a member of PerformanceCounter instead of inheriting
Mar 4, 2025
b77cf23
Implement LatticeTrace class
Mar 4, 2025
5fcfff7
Make predecessor and sibling public members
Mar 4, 2025
3152300
Look for initial trace instead of associating empty trace with initia…
Mar 4, 2025
0b676f9
Remove redundant includes
Mar 4, 2025
159fbd8
Add assertions for assumptions in lattice building
Mar 5, 2025
f2f4cf7
Merge remote-tracking branch 'origin/lattice_traces' into lexiconfree…
SimBe195 Mar 5, 2025
0577e79
Remove wrong assertion
SimBe195 Mar 5, 2025
04b6ac4
Merge remote-tracking branch 'origin/lattice_traces' into lexiconfree…
SimBe195 Mar 5, 2025
b454e39
Remove initial item in `performTraceback`
SimBe195 Mar 5, 2025
b3d5f02
Merge remote-tracking branch 'origin/lattice_traces' into lexiconfree…
SimBe195 Mar 5, 2025
d393c7e
Fix arc scores
SimBe195 Mar 5, 2025
b1ed20e
Merge remote-tracking branch 'origin/lattice_traces' into lexiconfree…
SimBe195 Mar 5, 2025
f112113
Merge remote-tracking branch 'origin/stopwatch' into lexiconfree_beam…
SimBe195 Mar 5, 2025
d67cf45
Update traceback/lattice building logic
SimBe195 Mar 5, 2025
54535e6
Make `elapsed` functions const
SimBe195 Mar 5, 2025
f0832f8
Merge branch 'stopwatch' into lexiconfree_beam_search
SimBe195 Mar 5, 2025
a125afa
Merge branch 'stopwatch' into lattice_traces
SimBe195 Mar 5, 2025
46ee1a8
Merge branch 'lattice_traces' into lexiconfree_beam_search
SimBe195 Mar 5, 2025
eb17fcb
Remove unused parameters
SimBe195 Mar 21, 2025
abeaa66
Merge branch 'master' into lexiconfree_beam_search
SimBe195 Mar 21, 2025
7a41f8c
Get rid of sorting and perform score-pruning and recombination on uns…
SimBe195 Mar 26, 2025
4d182f4
Use Core::Statistics for hyp counts
SimBe195 Mar 26, 2025
4208e6f
Pre-allocate intermediate vectors
SimBe195 Mar 26, 2025
deb0a68
Rename `createSearchAlgorithm` to `createSearchAlgorithmV2`
SimBe195 Mar 26, 2025
0331bcb
Use `LIBS_SEARCH` in Makefiles
SimBe195 Mar 26, 2025
48765f7
Use dedicated debug channel to replace config parameter "debug-logging"
SimBe195 Mar 26, 2025
1027984
Import sorting
SimBe195 Mar 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Modules.make
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ endif

# ****** Libraries ******
LIBS_SEARCH = src/Search/libSprintSearch.$(a)
LIBS_SEARCH += src/Search/LexiconfreeTimesyncBeamSearch/libSprintLexiconfreeTimesyncBeamSearch.$(a)
ifdef MODULE_SEARCH_WFST
LIBS_SEARCH += src/Search/Wfst/libSprintSearchWfst.$(a)
LIBS_SEARCH += src/OpenFst/libSprintOpenFst.$(a)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ endif

# ****** Libraries ******
LIBS_SEARCH = src/Search/libSprintSearch.$(a)
LIBS_SEARCH += src/Search/LexiconfreeTimesyncBeamSearch/libSprintLexiconfreeTimesyncBeamSearch.$(a)
ifdef MODULE_SEARCH_WFST
LIBS_SEARCH += src/Search/Wfst/libSprintSearchWfst.$(a)
LIBS_SEARCH += src/OpenFst/libSprintOpenFst.$(a)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ endif

# ****** Libraries ******
LIBS_SEARCH = src/Search/libSprintSearch.$(a)
LIBS_SEARCH += src/Search/LexiconfreeTimesyncBeamSearch/libSprintLexiconfreeTimesyncBeamSearch.$(a)
ifdef MODULE_SEARCH_WFST
LIBS_SEARCH += src/Search/Wfst/libSprintSearchWfst.$(a)
LIBS_SEARCH += src/OpenFst/libSprintOpenFst.$(a)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ endif

# ****** Libraries ******
LIBS_SEARCH = src/Search/libSprintSearch.$(a)
LIBS_SEARCH += src/Search/LexiconfreeTimesyncBeamSearch/libSprintLexiconfreeTimesyncBeamSearch.$(a)
ifdef MODULE_SEARCH_WFST
LIBS_SEARCH += src/Search/Wfst/libSprintSearchWfst.$(a)
LIBS_SEARCH += src/OpenFst/libSprintOpenFst.$(a)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ endif

# ****** Libraries ******
LIBS_SEARCH = src/Search/libSprintSearch.$(a)
LIBS_SEARCH += src/Search/LexiconfreeTimesyncBeamSearch/libSprintLexiconfreeTimesyncBeamSearch.$(a)
ifdef MODULE_SEARCH_WFST
LIBS_SEARCH += src/Search/Wfst/libSprintSearchWfst.$(a)
LIBS_SEARCH += src/OpenFst/libSprintOpenFst.$(a)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ endif

# ****** Libraries ******
LIBS_SEARCH = src/Search/libSprintSearch.$(a)
LIBS_SEARCH += src/Search/LexiconfreeTimesyncBeamSearch/libSprintLexiconfreeTimesyncBeamSearch.$(a)
ifdef MODULE_SEARCH_WFST
LIBS_SEARCH += src/Search/Wfst/libSprintSearchWfst.$(a)
LIBS_SEARCH += src/OpenFst/libSprintOpenFst.$(a)
Expand Down
1 change: 1 addition & 0 deletions src/Core/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ LIBSPRINTCORE_O = $(OBJDIR)/Application.o \
$(OBJDIR)/ReferenceCounting.o \
$(OBJDIR)/ResourceUsageInfo.o \
$(OBJDIR)/Statistics.o \
$(OBJDIR)/StopWatch.o \
$(OBJDIR)/StringExpression.o \
$(OBJDIR)/StringUtilities.o \
$(OBJDIR)/TextStream.o \
Expand Down
78 changes: 78 additions & 0 deletions src/Core/StopWatch.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/** Copyright 2025 RWTH Aachen University. All rights reserved.
*
* Licensed under the RWTH ASR License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.hltpr.rwth-aachen.de/rwth-asr/rwth-asr-license.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "StopWatch.hh"
#include "Utility.hh"

namespace Core {

StopWatch::StopWatch()
: running_(false), startTime_(), elapsedSeconds_(0.0) {}

void StopWatch::start() {
if (running_) {
return;
}

TIMER_START(startTime_);
running_ = true;
}

void StopWatch::stop() {
if (not running_) {
return;
}

timeval endTime;
TIMER_STOP(startTime_, endTime, elapsedSeconds_);

running_ = false;
}

void StopWatch::reset() {
elapsedSeconds_ = 0;
running_ = false;
}

double StopWatch::elapsedSeconds() const {
if (running_) {
timeval endTime;
double currentTime = 0; // in seconds

// Note: This macro doesn't actually "stop" anything, it just writes into `endTime` and `currentTime`
TIMER_STOP(const_cast<timeval&>(startTime_), endTime, currentTime);

return elapsedSeconds_ + currentTime;
}
return elapsedSeconds_;
}

double StopWatch::elapsedCentiseconds() const {
return elapsedSeconds() * 1e2;
}

double StopWatch::elapsedMilliseconds() const {
return elapsedSeconds() * 1e3;
}

double StopWatch::elapsedMicroseconds() const {
return elapsedSeconds() * 1e6;
}

double StopWatch::elapsedNanoseconds() const {
return elapsedSeconds() * 1e9;
}

} // namespace Core
63 changes: 63 additions & 0 deletions src/Core/StopWatch.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/** Copyright 2025 RWTH Aachen University. All rights reserved.
*
* Licensed under the RWTH ASR License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.hltpr.rwth-aachen.de/rwth-asr/rwth-asr-license.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef STOPWATCH_HH
#define STOPWATCH_HH

#include <sys/time.h>

namespace Core {

/*
* Simple timer class with start/stop functions that accumulates all the timed intervals
* to a total.
*/
struct StopWatch {
public:
StopWatch();

/*
* Stops timer if it is running and resets accumulated time to zero.
*/
void reset();

/*
* Start timer. Does nothing if timer is already running.
*/
void start();

/*
* End running timer and add duration to total. Does nothing if timer is not running.
*/
void stop();

/*
* Getter functions to get the total elapsed time in different units. Includes the current interval
* if the timer is running.
*/
double elapsedSeconds() const;
double elapsedCentiseconds() const;
double elapsedMilliseconds() const;
double elapsedMicroseconds() const;
double elapsedNanoseconds() const;

private:
bool running_;
timeval startTime_;
double elapsedSeconds_;
};

} // namespace Core

#endif // TIMER_HH
2 changes: 2 additions & 0 deletions src/Nn/LabelScorer/LabelScorer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ public:
LABEL_TO_BLANK,
BLANK_TO_LABEL,
BLANK_LOOP,
INITIAL_LABEL,
INITIAL_BLANK,
};

// Request for scoring or context extension
Expand Down
56 changes: 16 additions & 40 deletions src/Search/AdvancedTreeSearch/Helpers.hh
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
#define HELPERS_HH

#include <Core/ReferenceCounting.hh>
#include <Core/StopWatch.hh>
#include <Core/Types.hh>
#include <Core/Utility.hh>
#include <string>
#include <time.h>
#include "SearchSpaceStatistics.hh"

namespace Search {
Expand All @@ -36,64 +35,41 @@ class Configuration;

bool isBackwardRecognition(const Core::Configuration& config);

class PerformanceCounter {
class PerformanceCounter : public Core::StopWatch {
public:
PerformanceCounter(Search::SearchSpaceStatistics& stats, const std::string& name, bool start = true)
: running_(false),
totalTime_(0),
timeStats(stats.customStatistics("Profiling: " + name + ": Centiseconds")) {
if (start)
this->start();
: stopWatch_(), timeStats_(stats.customStatistics("Profiling: " + name + ": Centiseconds")) {
if (start) {
stopWatch_.start();
}
}

~PerformanceCounter() {
stopAndYield();
}

void start() {
stop();

running_ = true;
TIMER_START(starttime_);
stopWatch_.stop();
stopWatch_.start();
}

void stop() {
if (running_) {
running_ = false;

double diff = 0; // in secs
timeval end;

TIMER_STOP(starttime_, end, diff);
totalTime_ += diff * 100; // centi secs
}
stopWatch_.stop();
}

/// Prints the current instruction count to the statistics object
void stopAndYield(bool print = false) {
stop();
timeStats += totalTime_;
if (print)
std::cout << " time: " << totalTime_ << std::endl;
totalTime_ = 0;
}

static inline u64 instructions() {
unsigned int a, d;
asm __volatile__(""
:
:
: "memory");
asm volatile("rdtsc"
: "=a"(a), "=d"(d));
return ((u64)a) | (((u64)d) << 32);
timeStats_ += stopWatch_.elapsedCentiseconds();
if (print) {
std::cout << " time: " << stopWatch_.elapsedCentiseconds() << std::endl;
}
stopWatch_.reset();
}

private:
bool running_;
timeval starttime_;
f32 totalTime_;
Core::Statistics<f32>& timeStats;
Core::StopWatch stopWatch_;
Core::Statistics<f32>& timeStats_;
};

inline f32 scaledLogAdd(f32 a, f32 b, f32 scale, f32 invertedScale) {
Expand Down
Loading