Skip to content

Commit

Permalink
bump_padacioso 0.2.1a7 (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl authored Jul 12, 2023
1 parent 0a16999 commit 59b8d48
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 62 deletions.
43 changes: 7 additions & 36 deletions ovos_core/intent_services/padatious_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,12 @@ def __init__(self, bus, config):
self.conf_high = self.padatious_config.get("conf_high") or 0.95
self.conf_med = self.padatious_config.get("conf_med") or 0.8
self.conf_low = self.padatious_config.get("conf_low") or 0.5
self.workers = self.padatious_config.get("workers") or 4

if self.is_regex_only:
LOG.debug('Using Padacioso intent parser.')
self.containers = {lang: FallbackIntentContainer(
self.padatious_config.get("fuzz"))
self.padatious_config.get("fuzz"), n_workers=self.workers)
for lang in langs}
else:
LOG.debug('Using Padatious intent parser.')
Expand Down Expand Up @@ -176,10 +177,10 @@ def is_regex_only(self):

@property
def threaded_inference(self):
if not self.is_regex_only:
# Padatious isn't thread-safe, so don't even try
return False
return self.padatious_config.get("threaded_inference", False)
LOG.warning("threaded_inference config has been deprecated")
# Padatious isn't thread-safe, so don't even try
# Padacioso already uses concurrent.futures internally, no benefit
return False

def train(self, message=None):
"""Perform padatious training.
Expand Down Expand Up @@ -314,38 +315,8 @@ def calc_intent(self, utterances: List[str], lang: str = None) -> Optional[Padat
lang = lang or self.lang
lang = lang.lower()
if lang in self.containers:
intents = []
intent_container = self.containers.get(lang)

if self.threaded_inference:
# differences between ThreadPoolExecutor and ProcessPoolExecutor
# ThreadPoolExecutor
# Uses Threads, not processes.
# Lightweight workers, not heavyweight workers.
# Shared Memory, not inter-process communication.
# Subject to the GIL, not parallel execution.
# Suited to IO-bound Tasks, not CPU-bound tasks.
# Create 10s to 1,000s Workers, not really constrained.
#
# ProcessPoolExecutor
# Uses Processes, not threads.
# Heavyweight Workers, not lightweight workers.
# Inter-Process Communication, not shared memory.
# Not Subject to the GIL, not constrained to sequential execution.
# Suited to CPU-bound Tasks, probably not IO-bound tasks.
# Create 10s of Workers, not 100s or 1,000s of tasks.

self.workers = 4 # do the work in parallel instead of sequentially
with concurrent.futures.ProcessPoolExecutor(max_workers=self.workers) as executor:
future_to_source = {
executor.submit(_calc_padatious_intent,
(s, intent_container)): s
for s in utterances
}
intents = [future.result() for future in concurrent.futures.as_completed(future_to_source)]
else:
intents = [_calc_padatious_intent(utt, intent_container) for utt in utterances]

intents = [_calc_padatious_intent(utt, intent_container) for utt in utterances]
intents = [i for i in intents if i is not None]
# select best
if intents:
Expand Down
2 changes: 1 addition & 1 deletion requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ python-dateutil>=2.6, <3.0
watchdog>=2.1, <3.0
combo-lock>=0.2.2, <0.3

padacioso~=0.2
padacioso~=0.2, >=0.2.1a8
adapt-parser>=1.0.0, <2.0.0

ovos_bus_client<0.1.0, >=0.0.5
Expand Down
25 changes: 0 additions & 25 deletions test/unittests/skills/test_utterance_intents.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,28 +117,3 @@ def test_regex_fuzz_intent(self):
self.assertEqual(intent.matches, {'thing': 'Mycroft'})
self.assertEqual(intent.sent, utterance)
self.assertTrue(intent.conf <= 0.8)

def test_threaded_intent(self):
from time import time
intent_service = self.get_service(regex_only=True, fuzz=False)
utterances = []
for i in range(50):
utterances.append("tell me about Mycroft")
intent_service.padatious_config['threaded_inference'] = False
start = time()
intent = intent_service.calc_intent(utterances, "en-US")
single_thread_time = time() - start
self.assertEqual(intent.name, "test2")
self.assertEqual(intent.matches, {'thing': 'Mycroft'})
self.assertEqual(intent.sent, utterances[0])

intent_service.padatious_config['threaded_inference'] = True
start = time()
intent2 = intent_service.calc_intent(utterances, "en-US")
multi_thread_time = time() - start
self.assertEqual(intent.__dict__, intent2.__dict__)

speedup = (single_thread_time - multi_thread_time) / len(utterances)
print(f"speedup={speedup}")
# Assert threaded execution was faster (or at least not much slower)
self.assertGreaterEqual(speedup, -0.01)

0 comments on commit 59b8d48

Please sign in to comment.